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

maximum(A, d), sum(A, d), ... should give an SMatrix for A::SMatrix #65

Closed
stevengj opened this issue Nov 2, 2016 · 5 comments
Closed

Comments

@stevengj
Copy link
Contributor

stevengj commented Nov 2, 2016

Currently, this is using the generic reduction code:

julia> A = SMatrix{3,3}(rand(3,3))
3×3 StaticArrays.SMatrix{3,3,Float64,9}:
 0.0121247  0.371658  0.950669 
 0.450277   0.363499  0.0998775
 0.322925   0.158552  0.548777 

julia> maximum(A,2)
3×1 StaticArrays.MMatrix{3,1,Float64,3}:
 0.950669
 0.450277
 0.548777

julia> @which maximum(A,2)
maximum(A::AbstractArray, region) at reducedim.jl:305
@andyferris
Copy link
Member

No... we shouldn't even do what is happening now (return MMatrix)! It's not type-stable, and I plan on fixing this (#22) soon.

To do this properly, we would need something like JuliaLang/julia#17880 (simultaneous inlining and inference) so that we have some way of constant-propagating the dimension you are selecting to reduce over inside another function.

Is this a function you find you use a lot? I almost never do, but maybe that is just me. (I would use things like sum(::Vector{SVector{3,Float64}}) for instance - reinterpret() is useful for this stuff). If someone absolutely needs this, we can add a Val version, e.g.

sum(rand(SMatrix{3,3}), Val{2})

@stevengj
Copy link
Contributor Author

stevengj commented Nov 2, 2016

I'm using it in a package I'm working on, but it's not that performance-critical.

@wsshin
Copy link
Contributor

wsshin commented Dec 12, 2016

Generated a PR addressing this: #86

@c42f
Copy link
Member

c42f commented Dec 13, 2016

Now that #86 is merged, maximum(A,Val{2}) works.

@andyferris
Copy link
Member

I'm going to close this... I think maximum(A, Val{2}) is the best we can hope for at this stage.

oschulz pushed a commit to oschulz/StaticArrays.jl that referenced this issue Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants