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

Implement copy #9

Open
chris-b1 opened this issue May 7, 2020 · 2 comments
Open

Implement copy #9

chris-b1 opened this issue May 7, 2020 · 2 comments

Comments

@chris-b1
Copy link

chris-b1 commented May 7, 2020

julia> a = accelerate([1, 2, 3], UniqueSortIndex)
3-element Array{Int64,1} + UniqueSortIndex:
 1
 2
 3

julia> copy(a)
3-element Array{Int64,1}:
 1
 2
 3

Unless I'm missing some subtlety where this could create an invalid state, this seems to work?

Base.copy(a::AcceleratedArray{T, N, A, I}) where {T,N,A,I} = AcceleratedArray{T, N, A, I}(copy(a.parent), a.index)
@andyferris
Copy link
Owner

That should be safe.

I haven't thought a lot about this - but copy is only useful if you want to mutate something, and currenty you can't safely mutate an AcceleratedArray (obviously we'd like to support that though). So we'd want to implement that first in any case, otherwise we might be leading people astray.

@chris-b1
Copy link
Author

Thanks, my motivating example is storing an AcceleratedArray in a DataFrame. For that, you don't necessarily need the underlying mutability, but do need a copy to prevent the index for being dropped on operations that copy the dataframe. E.g.

julia> df = DataFrame!(a=accelerate([1, 2, 3], UniqueSortIndex), b=[4, 5, 6])
3×2 DataFrameRowab     │
│     │ Int64Int64 │
├─────┼───────┼───────┤
│ 114     │
│ 225     │
│ 336julia> df.a
3-element Array{Int64,1} + UniqueSortIndex:
 1
 2
 3

julia> new = transform(df, :a => ByRow(isequal(1)) => :c)
3×3 DataFrameRowabc    │
│     │ Int64Int64Bool │
├─────┼───────┼───────┼──────┤
│ 1141    │
│ 2250    │
│ 3360julia> new.a
3-element Array{Int64,1}:
 1
 2
 3

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