Code Monkey home page Code Monkey logo

Comments (4)

mcabbott avatar mcabbott commented on June 12, 2024

Would be nice to have, and probably not so difficult. NamedDims does this:

julia> [x//y for x in rand(Int8, row=3), y in 10:10:50]
3×5 NamedDimsArray(::Matrix{Rational{Int64}}, (:row, :_)):
        → :_
↓ :row  -81//10  -81//20  -27//10  -81//40  -81//50
        -49//10  -49//20  -49//30  -49//40  -49//50
         42//5    21//5    14//5    21//10   42//25

which it catches so long as one of the first two is named, here: https://github.com/invenia/NamedDims.jl/blob/942bb283c62dd64c0ca484bda19c1bb832f268fa/src/functions.jl#L187-L201
i.e. If only some arguments have names, it still works and provided defaults for the rest. This package largely follows that behaviour, with Base.OneTo(n) as the default instead of :_.

from axiskeys.jl.

fredcallaway avatar fredcallaway commented on June 12, 2024

The plot thickens.... for reasons I don't fully understand, we already get the desired behavior when mapping over the ProductIterator.

x = KeyedArray(1:.1:1.3, x=1:.1:1.3)
y = 1:3
z = KeyedArray(['a', 'b'], z=['a', 'b'])
map(identity, Iterators.product(x, y, z))      

produces

3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   x ∈ 4-element StepRangeLen{Float64,...}
→   _ ∈ 3-element OneTo{Int}
□   z ∈ 2-element Vector{Char}
And data, 4×3×2 Array{Tuple{Float64,Int64,Char},3}:
[:, :, 1] ~ (:, :, 'a'):
        (1)               (2)               (3)
 (1.0)     (1.0, 1, 'a')     (1.0, 2, 'a')     (1.0, 3, 'a')
 (1.1)     (1.1, 1, 'a')     (1.1, 2, 'a')     (1.1, 3, 'a')
 (1.2)     (1.2, 1, 'a')     (1.2, 2, 'a')     (1.2, 3, 'a')
 (1.3)     (1.3, 1, 'a')     (1.3, 2, 'a')     (1.3, 3, 'a')

[:, :, 2] ~ (:, :, 'b'):
        (1)               (2)               (3)
 (1.0)     (1.0, 1, 'b')     (1.0, 2, 'b')     (1.0, 3, 'b')
 (1.1)     (1.1, 1, 'b')     (1.1, 2, 'b')     (1.1, 3, 'b')
 (1.2)     (1.2, 1, 'b')     (1.2, 2, 'b')     (1.2, 3, 'b')
 (1.3)     (1.3, 1, 'b')     (1.3, 2, 'b')     (1.3, 3, 'b')

This is enough for my use case. It would be nice if KeyedArray(Iterators.product(x, y, z)) worked as well though. Could that be accomplished using a similar method to the one you quoted from NamedDims?

from axiskeys.jl.

mcabbott avatar mcabbott commented on June 12, 2024

Oh I guess I forgot that I implemented this! @edit collect(x for x in Iterators.product(x, y, z)) is where this goes (for map(f, ::Any), but generator syntax calls the same thing).

To make KeyedArray(Iterators.product(x, y, z)) work just like that there would have to be one more method. Do you use it like this? I almost always either write the comprehension, or do something with the x,y,z before making the array.

from axiskeys.jl.

fredcallaway avatar fredcallaway commented on June 12, 2024

Haha, kind of like finding a $20 in your pocket!

Like you, I always immediately have a map over ProductIterator, so I don't think it's necessary to have the KeyedArray method. The only reason to implement it is for aesthetics, probably not worth either of our time :P

Thanks for the quick response and the awesome package!

from axiskeys.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.