Skip to content

Commit

Permalink
Add convert routines for SubQuasiArray
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Jul 7, 2024
1 parent d9ce29e commit f9e535c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuasiArrays"
uuid = "c4ea9172-b204-11e9-377d-29865faadc5c"
authors = ["Sheehan Olver <[email protected]>"]
version = "0.11.5"
version = "0.11.6"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
5 changes: 5 additions & 0 deletions src/subquasiarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ pointer(V::SubQuasiArray, i::Int) = _pointer(V, i)
_pointer(V::SubQuasiArray{<:Any,1}, i::Int) = pointer(V, (i,))
_pointer(V::SubQuasiArray, i::Int) = pointer(V, Base._ind2sub(axes(V), i))

convert(::Type{AbstractQuasiArray{T}}, V::SubQuasiArray{T}) where T = V
convert(::Type{AbstractQuasiArray{T,N}}, V::SubQuasiArray{T,N}) where {T,N} = V
convert(::Type{AbstractQuasiArray{T}}, V::SubQuasiArray) where T = SubQuasiArray(convert(AbstractQuasiArray{T}, parent(V)), V.indices)
convert(::Type{AbstractQuasiArray{T,N}}, V::SubQuasiArray{<:Any,N}) where {T,N} = convert(AbstractQuasiArray{T}, V)


# indices are taken from the range/vector
# Since bounds-checking is performance-critical and uses
Expand Down
17 changes: 14 additions & 3 deletions test/test_quasisubarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,19 @@ using QuasiArrays, Base64, Test
@test view(A,:,:) == view(A,:,:)
@test A view(A,Inclusion(0:0.5:0.5),:)
@test view(A,Inclusion(0:0.5:0.5),:) A
@test A  view(B,Inclusion(0:0.5:1),:)
@test view(B,Inclusion(0:0.5:1),:)  A
@test view(B,Inclusion(0:0.5:1),:)  view(A,Inclusion(0:0.5:0.5),:)
@test A view(B,Inclusion(0:0.5:1),:)
@test view(B,Inclusion(0:0.5:1),:) A
@test view(B,Inclusion(0:0.5:1),:) view(A,Inclusion(0:0.5:0.5),:)
end

@testset "SubQuasiArray convert" begin
a = QuasiVector(randn(3), 0:0.5:1)
v = view(a, :)
@test convert(AbstractQuasiVector{Float64}, v) v
@test convert(AbstractQuasiVector{ComplexF64}, v) isa SubQuasiArray{ComplexF64}
@test convert(AbstractQuasiVector{ComplexF64}, v) == v
@test convert(AbstractQuasiArray{Float64}, v) v
@test convert(AbstractQuasiArray{ComplexF64}, v) isa SubQuasiArray{ComplexF64}
@test convert(AbstractQuasiArray{ComplexF64}, v) == v
end
end

0 comments on commit f9e535c

Please sign in to comment.