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

Similar with specified size #545

Open
rveltz opened this issue Nov 18, 2018 · 5 comments
Open

Similar with specified size #545

rveltz opened this issue Nov 18, 2018 · 5 comments
Labels
design speculative design related issue feature features and feature requests

Comments

@rveltz
Copy link

rveltz commented Nov 18, 2018

Hi,

Is there a way to make this work for Array and Static Arrays?

Thank you

v1 = MVector(1, 2, 3)
similar(v1,4)
@andyferris
Copy link
Member

similar(v1, Size(4)) is the current approach.

With constant propagation in Julia v1.0 we could potentially do this automatically, but then it would be difficult to get a dynamically sized array...

@fgasdia
Copy link

fgasdia commented Nov 26, 2018

I'm interested in the same (giordano/PolynomialRoots.jl#9). The problem with Size() of course is that it requires a package to import StaticArrays when we really just want to parameterize on a user supplied type, be it an Array or SArray.

@rveltz
Copy link
Author

rveltz commented May 18, 2019

If I define

similar(v::MVector,s::Int) = similar(v,Size(s))

is it likely to break your package somewhere?

@andyferris
Copy link
Member

andyferris commented May 19, 2019

Potentially? I'm not 100% sure.

The problem as I see it is that sometimes generic code might expect to call similar(v::AbstractVector, i::Int) where i can't possibly be known to the compiler. In this case emitting a static array could slow down the resulting code drastically, which is a bad result. Requiring the use of Size is not very ergonomic, which isn't fantastic either, but it does has the benefit of giving the programmer control.

I'm not sure what the endgame here is. We could maybe ask to be able to dispatch or branch on "constness" - but I strongly suspect the compiler people would say something like "the problem of determining whether any given variable is found to be constant or not is undecidable (or undefined, or at the very least frequently changing as the compiler evolves) and we don't want this to affect program behavior". Anyone have thoughts on the best way to proceed?

@c42f
Copy link
Member

c42f commented Jul 31, 2019

@EP-Guy ultimately we may require some traits like Size in Base to solve that dependency problem.

Generally, I don't know what we can do about this for the reasons described by Andy. Would probably need to be part of a larger carefully considered design iteration.

@c42f c42f added feature features and feature requests design speculative design related issue labels Jul 31, 2019
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

4 participants