|
1 | 1 | # First we'll just support element type conversions. |
2 | 2 | # This is crucial since we can't pass DataTypes to UDF handlers. |
3 | 3 |
|
4 | | -# pass through for most cases |
5 | | -conform(M::AbstractGBArray) = M |
6 | | - |
7 | | -function Base.convert(::Type{M}, A::N; fill::F = getfill(A)) where {F, M<:AbstractGBArray, N<:AbstractGBArray} |
8 | | - !(F <: Union{Nothing, Missing}) && (fill = convert(eltype(M), fill)) |
9 | | - isabstracttype(M) && throw(ArgumentError("$M is an abstract type, which cannot be constructed.")) |
| 4 | +function applyjl!(F, C::AbstractGBArray, A::AbstractGBArray) |
| 5 | + isabstracttype(F) && throw(ArgumentError("$M is an abstract type, which cannot be constructed.")) |
10 | 6 | x = tempunpack!(A) |
11 | 7 | repack! = x[end] |
12 | 8 | values = x[end - 1] |
13 | 9 | indices = x[begin:end-2] |
14 | | - newvalues = unsafe_wrap(Array, _sizedjlmalloc(length(values), eltype(M)), size(values)) |
15 | | - copyto!(newvalues, values) |
| 10 | + newvalues = unsafe_wrap(Array, _sizedjlmalloc(length(values), storedeltype(C)), size(values)) |
| 11 | + map!(F, newvalues, values) |
16 | 12 | newindices = _copytoraw.(indices) |
17 | 13 | repack!() |
| 14 | + unsafepack!(C, newindices..., newvalues, false; decrementindices = false, order = storageorder(A)) |
| 15 | + return C |
| 16 | +end |
| 17 | + |
| 18 | +function Base.convert(::Type{M}, A::N; fill::F = getfill(A)) where {F, M<:AbstractGBArray, N<:AbstractGBArray} |
| 19 | + !(F <: Union{Nothing, Missing}) && (fill = convert(storedeltype(M), fill)) |
18 | 20 | B = M(size(A, 1), size(A, 2); fill) |
19 | | - unsafepack!(B, newindices..., newvalues, false; decrementindices = false, order = storageorder(A)) |
| 21 | + applyjl!(storedeltype(B), B, A) |
| 22 | +end |
| 23 | +function Base.convert(::Type{M}, A::N; fill::F = getfill(A)) where {F, M<:AbstractGBVector, N<:AbstractGBVector} |
| 24 | + !(F <: Union{Nothing, Missing}) && (fill = convert(eltype(M), fill)) |
| 25 | + B = M(size(A, 1); fill) |
| 26 | + applyjl!(storedeltype(B), B, A) |
20 | 27 | end |
21 | 28 |
|
22 | 29 | Base.convert(::Type{M}, A::M; fill = nothing) where {M<:AbstractGBArray} = A |
23 | 30 |
|
24 | 31 | function LinearAlgebra.copy_oftype(A::GBArrayOrTranspose, ::Type{T}) where T |
25 | 32 | order = storageorder(A) |
26 | 33 | C = similar(A, T, size(A)) |
27 | | - x = tempunpack!(A) |
28 | | - repack! = x[end] |
29 | | - values = x[end - 1] |
30 | | - indices = x[begin:end-2] |
31 | | - newvalues = unsafe_wrap(Array, _sizedjlmalloc(length(values), T), size(values)) |
32 | | - copyto!(newvalues, values) |
33 | | - newindices = _copytoraw.(indices) |
34 | | - repack!() |
35 | | - unsafepack!(C, newindices..., newvalues, false; order, decrementindices = false) |
| 34 | + applyjl!(T, C, A) |
36 | 35 | end |
37 | 36 | # TODO: Implement this? |
38 | 37 | Base.convert(::Type{M}, ::AbstractGBArray; fill = nothing) where {M<:AbstractGBShallowArray} = |
|
0 commit comments