-
Notifications
You must be signed in to change notification settings - Fork 40
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
missing convert method #171
Comments
No, because |
What about something like function Base.convert(::Type{T}, A::AbstractArray{<:Any,N}) where {N, T <: OffsetArray{<:Any,N}}
OffsetArray(A, ntuple(zero, Val(N))...)
end ? |
Related to this conversion is the constructor empty_localpart(T,N,A) = A(Array{T}(undef, ntuple(zero, N))) I wonder if it's worth adding the constructor as well? Although if this conversion is added, it might be possible for DistributedArrays to use that instead of the constructor, as ultimately this operation is a conversion of an |
We'll perhaps need to convert or constrain the julia> convert(OffsetArray{Float32,2}, rand(2,2))
2×2 OffsetArray(::Array{Float64,2}, 1:2, 1:2) with eltype Float64 with indices 1:2×1:2:
0.580097 0.655686
0.406192 0.0662347 Whether or not we allow the |
Not sure if this is the same issue, but I think I want a more narrow convert. I would like to convert between
One scenario for this:
|
Perhaps a combination of julia> function Base.convert(::Type{OffsetArray{T,N,AA}}, A::AbstractArray{<:Any,N}) where {T, N, AA}
OffsetArray{T,N,AA}(convert(AA, A), ntuple(zero, Val(N)))
end
julia> function Base.convert(::Type{OffsetArray{T,N,AA}}, A::OffsetArray{<:Any,N}) where {T, N, AA}
OffsetArray{T,N,AA}(convert(AA, A.parent), A.offsets)
end might help with conversions where all the type parameters are specified? With these, both the constructors work: julia> Foo2(A)
Foo2([0.0, 0.0, 0.0])
julia> Foo2(O)
Foo2([0.0, 0.0, 0.0]) We might need other method for more general conversions such as in the top post. Not sure what's the best way to go about these. |
Will it be type piracy if we define
convert(::Type{T}, x) where {T<:OffsetArray}
?The text was updated successfully, but these errors were encountered: