Comments (4)
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.
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.
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.
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)
- wrapdims(::DataFrame) produces incorrect results when not all key combinations are present HOT 4
- Feature request: aggregation function for wrapdims (and populate!)
- Ambiguity error: ProjectTo(::KeyedArray(...)))((::NoTangent)) HOT 1
- `vcat`/`hcat`/`cat` bug at edge case with one `KeyedArray` HOT 2
- `getindex(::KeyedVector, ::Colon, ::Colon)` is broken
- Document `setkey!` in the README
- Error trying to `show` KeyedArray with undef values
- `ProjectTo` is too permissive? HOT 3
- Broadcasting ambiguity
- Interpolation
- isequal violates transitive property HOT 1
- Error in `LinearAlgebra.copy_oftype` on addition of symmetric `KeyedArray` and `UniformScaling` HOT 2
- `eachslice` fails on v1.9-beta2 HOT 1
- Feature request: `empty!`
- unsupported keyword argument "time" when taking a gradient with Zygote HOT 1
- Wrong FFT results
- Maybe update `LazyStack` so that this warning vanishes in Julia 1.9 HOT 1
- Slicing with larger key vectors is slow HOT 2
- Support for NaNStatistics HOT 2
- vcat / hcat is broken on julia 1.10 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axiskeys.jl.