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

setindex! with StaticArrays of a non-isbits type #39

Closed
JeffreySarnoff opened this issue Sep 30, 2016 · 4 comments
Closed

setindex! with StaticArrays of a non-isbits type #39

JeffreySarnoff opened this issue Sep 30, 2016 · 4 comments

Comments

@JeffreySarnoff
Copy link

Nice.

My ArbFloats, while an immutable type, are not strictly isbits types because one of their static fields may be either an immediate value or an offset into preallocated memory that holds a fixed length BigNum.
They share some isibits type's behavior: changing a value does not alter the bit patterns of a value's fields, instead a new realization of the type is constructed and used in place of the original value.

I would like them to play well with StaticArrays. Please let me know the fuctional signatures to provide (and what they are doing, if there is any subtilty -- I have not learned that part of Julia yet). Feel free to abbreviate the types ArbFloat{ bits_of_precision } as AFloat.

If some of the linear algebra that you support gets passed along to C routines, at the algorithmic point where that transition occur, there would need to be me dispatching over the handoff. And this is a larger issue for ArbFloats (it is a corner of v0.5 where BigFloats sink).

@andyferris
Copy link
Member

Did you have a look at #27 ?

It seems a little difficult to support this at the moment. In theory what was there before could end it up with garbage collection safety issues and we can actually work around that with a GC lock. However, there seemed to be a strong disagreement about this and I couldn't figure out why (I think the compiler makes assumptions about immutable references to mutable objects and could get into an inconsistent state).

On the other hand we can make it a bit slower by replacing the entire tuple - would a small speed penalty be a big problem to you?

@JeffreySarnoff
Copy link
Author

JeffreySarnoff commented Oct 5, 2016

No. I think the overall speedup of working with fixed size arrays far outweighs the small speed penalty.

@andyferris
Copy link
Member

Just so you know, you can now use (on the master branch, for now) a SizedArray which wraps a standard Array and can therefore handle any Julia type and do setindex. SizedArrays benefit from much (but not all) of the speedup of other static arrays, especially if you are careful to use mutating updates to minimize the number of allocations.

In Julia 0.6, if they introduce Buffer and remove unnecessary allocations of immutables containing references, I would think SizedArray is preferable as a mutable container.

Finally, quite often an immutable container like SArray, SMatrix or SVector is just as powerful as a mutable one - you can just try use SVector(::AFloat, ::AFloat, ::AFloat) to construct a 3-vector of AFloats and perform algorithms with that. The only problem with #27 was with my implementation of MArray/MMatrix/MVector. You shouldn't need to add special behavior to ArbFloats to make them compatible with StaticArrays.

@JeffreySarnoff
Copy link
Author

thanks

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

2 participants