Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalization of AbstractRange? #816

Closed
chakravala opened this issue Aug 17, 2020 · 10 comments
Closed

Generalization of AbstractRange? #816

chakravala opened this issue Aug 17, 2020 · 10 comments
Labels
design speculative design related issue feature features and feature requests

Comments

@chakravala
Copy link

Please see my post on discourse about generalizing AbstractRange objects to SVector inputs for multidimensional ragnes.

https://discourse.julialang.org/t/orthotope-grid-type-generalization-of-abstractrange/45072/3?u=chakravala

Either, this needs to be added to StaticArrays package to define the : constructor method without type piracy, or I need to add it to Grassmann and use my own custom vector input types for it.

Most likely, I’ll just add it to Grassmann since that has the least friction workflow for me, but if anyone else is interested, I can consider making a pull request to StaticArrays package.

@mateuszbaran
Copy link
Collaborator

What benefit does it have over the product iterator: https://docs.julialang.org/en/v1/base/iterators/#Base.Iterators.product ?

@chakravala
Copy link
Author

Didn't know about that before, but it seems the product iterator returns tuples, which is the wrong type.

@andyferris
Copy link
Member

Yeah - it would be nice if Iterators.product accepted a function, like map.

@stev47
Copy link
Contributor

stev47 commented Aug 21, 2020

Julia base often uses NTuple{N,AbstractRange{T}} (at least for integer T) and for use with indices there is the wrapper CartesianIndices that supports range syntax CartesianIndex(1,1):CartesianIndex(3,3) already. A dedicated Orthotope type could improve memory layout compared to these, though I don't see a reason why it needs to use SVectors instead of Tuples internally if it's just a multidimensional generalization of AbstractRange{T} in julia base.

@chakravala
Copy link
Author

chakravala commented Aug 21, 2020 via email

@chakravala
Copy link
Author

Regarding the types for the Orthotope field types, another reason for making them the same as the vector space element types is that simplifies methods and calculations used for generating the actual elements of the Orthogrid. For example,

function getindex(t::Orthogrid{V},i::Vararg{Int}) where V
     Chain{V,1}(value(t.x.min)+(SVector(i)-1).*step(t))
end

Thus, the Orthotope bound values can simply be added and subtracted as algebraic elements to generate grid points.

@stev47
Copy link
Contributor

stev47 commented Aug 21, 2020

Well, if you have an x::NTuple{N,AbstractRange{T}} it is just

mygetindex(x, i...) = getindex.(x, i)

(or similar, if you are wrapping that type) without reimplementing ranges. Julia does not seem to vectorize this access though, which would be one of the main reasons of having a dedicated type with better memory layout I think.

@c42f c42f added design speculative design related issue feature features and feature requests labels Sep 16, 2020
@c42f
Copy link
Member

c42f commented Sep 16, 2020

So is the main thing that it'd be desirable to iterate StaticArrays rather than Tuples vs the other options?

I'm in two minds about this. It seems handy, but also potentially obscure and non-obvious compared to using CartesianRange?

@chakravala
Copy link
Author

This issue can be closed as far as I am concerned at this point, since I am satisfied with my Orthogrid type in Grassmann now, so the rest is entirely up to you.

@c42f
Copy link
Member

c42f commented Sep 21, 2020

Ok, let's close this. Thanks for the discussion!

@c42f c42f closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design speculative design related issue feature features and feature requests
Projects
None yet
Development

No branches or pull requests

5 participants