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

The product of mutable arrays is a static array. That doesn't seem right. #383

Closed
danspielman opened this issue Mar 16, 2018 · 2 comments
Closed

Comments

@danspielman
Copy link

If I multiply a mutable array by a constant or another mutable array, I get a static array. This doesn't seem like it should be the desired behavior.

For example:

julia> 1.0*MMatrix{2,2}([1.0 2; 3 4])
2×2 StaticArrays.SArray{Tuple{2,2},Float64,2,4}:
 1.0  2.0
 3.0  4.0

or

julia> a = MMatrix{2,2}([1.0 2; 3 4])
2×2 StaticArrays.MArray{Tuple{2,2},Float64,2,4}:
 1.0  2.0
 3.0  4.0

julia> a*a
2×2 StaticArrays.SArray{Tuple{2,2},Float64,2,4}:
  7.0  10.0
 15.0  22.0
@andyferris
Copy link
Member

It's true - the default return type from similar_type is SArray. Generally this was chosen because it's faster, and using a "functional" style with StaticArrays is generally as or more performant that mutating a MArray (even if it is pre-allocated).

This behavior has been raised a few times, e.g. #327. I don't particularly mind where we go on this. Like I said, when I rewrote all my cleverly thought out code using pre-allocated MArrays with a functional form and SArrays, it got faster, so I see the current design a way of "educating" users to avoid mutatable arrays where possible, but I admit this may be an overreach.

Note also that we do support mul! (A_mul_B! on v0.6) and map! and broadcast! if you want to manually manage your memory resources. But these operations don't tend to invoke SIMD instructions, unfortunately, so they are slower than you would think/like.

@danspielman
Copy link
Author

If it was intended, then I won't complain.

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

2 participants