-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature request: mutable unsafe vectors #2
Comments
While it would, in theory, be nice to be able to grow an UnsafeVector, overwriting the parent array would be just a bit too unsafe ... :-)
|
Why? I have a vector [1 .... k ... k+ell ... N], with an unsafe view defined by [k... k+ell]. Writing into the unsafe view makes sense (overwriting the parent entry k+ell+1). Moving k or k+ell to the left or right makes sense (sliding window). Increasing ell, and overwriting the slot there makes sense. We would need the
Obviously the API would need to differ. Just like immutability of |
Well, for the use case of sliding windows, you would just create many unsafe views, but they wouldn't be resized. And if you need to resize an unsafe view, you can just create a new one. But the In fact, since an |
Actually, the |
Ok, you're right; mutable is the way to go for this. foobar from discourse is actually me, btw. I tend to use new pseudonyms for every account I make. |
Ok, I think a mutable version of |
As for sliding window use cases, I believe the right approach is to simply create a lot of throw-away views, as @uviews make them very very cheap. |
This could actually mesh well with TemporaryArrays.jl (new package, still in design phase). The idea there is to provide reusable temporary arrays, to avoid allocation cost for temporary arrays (e.g. target array for |
An unsafe vector could also provide
push!
,pop!
, etc which grow/shrink the view, respectively, overwriting entries of the parent.This would be used via
uview = push!(uview, val)
. These can be significantly faster than base vector push!/pop!, since we can avoid both theccall
and the stupid second read-increment-store due to the fact that vectors store both length and number of rows (why, oh why).One would need to also store a
pointer_from_objref
to the underlying vector, in order to not exceed its length, and resize it if necessary. See JuliaLang/julia#24909.The text was updated successfully, but these errors were encountered: