rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
262 stars 38 forks source link

How can I create a 2D array using broadcasting? #735

Open asinghvi17 opened 2 weeks ago

asinghvi17 commented 2 weeks ago

A common syntax to evaluate a function on a grid is:

lons = (LinRange(-180, 180, 360))
lats = (LinRange(-90, 90, 180))
tuple.(lons, lats')

If I try this with dimensions,

lons = X(LinRange(-180, 180, 360))
lats = Y(LinRange(-90, 90, 180))
tuple.(lons, lats')

then I get an error saying that adjoint is not defined for Y{...}. The same for e.g. transpose and permutedims.

Is there currently a way to make this syntax work, or interest in doing so?

rafaqz commented 2 weeks ago

Yeah, Dimensions are not AbstractArrays, just wrappers. I'm not sure taking the adjoint of them makes sense. But you can take the adjoint of lookup(xdim).

But also, what you are doing is pretty much DimPoints which also has the nice property of being lazy.