-
Notifications
You must be signed in to change notification settings - Fork 149
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
reinterpret SVector as Vector{SVector} #634
Comments
Don't you want to do something like julia> reinterpret(SVector{3, Float64}, [SVector{12}(1.0:12.0),])
4-element reinterpret(SArray{Tuple{3},Float64,1,3}, ::Array{SArray{Tuple{12},Float64,1,12},1}):
[1.0, 2.0, 3.0]
[4.0, 5.0, 6.0]
[7.0, 8.0, 9.0]
[10.0, 11.0, 12.0] The current error seems consistent with other basic numerical types: julia> reinterpret(UInt32, 2.0)
ERROR: bitcast: argument size does not match size of target type |
Sure, in some sense that could be more valid/consistent. But I disagree for two reasons.
|
It needs to be an
You said you wanted to get a |
If that is the case, then shouldn't that be fixed in the Base code for I do want a |
AFAICT Unfortunately you can't If I understand, what you are asking is to make the |
The implementation of But yeah, it seems relatively friendly to generic @halleysfifthinc I don't think we can relax the constructors of |
Given that it seems fairly conclusive that the current intent of +1 for a For some backstory/clarification, my use case is small numbers (generally < 10) of 3 dimensional vectors/points. When I originally wrote the code, I tested actual julia> @benchmark mean(z) setup=(z = [ SVector{3}(rand(3)) for _ in 1:5 ])
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 4.773 ns (0.00% GC)
median time: 4.799 ns (0.00% GC)
mean time: 4.986 ns (0.00% GC)
maximum time: 25.641 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
julia> @benchmark mean(z) setup=(n = 5; z = reinterpret(SVector{3,Float64}, SVector{n*3}(rand(n*3))))
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 3.618 ns (0.00% GC)
median time: 3.633 ns (0.00% GC)
mean time: 3.694 ns (0.00% GC)
maximum time: 26.129 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000 The Regardless, although I imagine I must have also tested the performance of julia> @benchmark mean(z) setup=(n=5; z = SVector{n}([ SVector{3}(rand(3)) for _ in 1:n ]))
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 2.273 ns (0.00% GC)
median time: 2.297 ns (0.00% GC)
mean time: 2.341 ns (0.00% GC)
maximum time: 22.108 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000 |
You might have this backwards - I believe that is an implementation detail, not an intention. We'll find out for sure soon enough: |
Last year, I had code to reinterpret an SVector with length N*3 as a Vector{SVector{3}} like
reinterpret(SVector{3, Float64}, SVector{12}(1.0:12.0))
. However this now errors:The issue being that
SOneTo
will only convert identical UnitRanges (e.g.SOneTo{4} == 1:4
, this is due to a requirement in the constructor at src/SOneTo.jl:12), so the axes are unable to be properly constructed. It seems reasonable to me that if somebody is trying to convert a unit range to anSOneTo
, the range of the argument is most likely the intentional one, so relaxing the constructor to something like:Such a change makes my original example work again, and I will note that my example is also quite similar to the example given in #554. I wonder what the original intent behind this restriction was and/or if there are possible negatives to relaxing this? pinging @timholy as the author of that PR
The text was updated successfully, but these errors were encountered: