Skip to content

Commit

Permalink
Add convert routines for SubQuasiArray (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty authored Jul 7, 2024
1 parent d9ce29e commit a74169b
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

2 comments on commit a74169b

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110595

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.6 -m "<description of version>" a74169b4921b4d37bdedac3438d89cd35772b72b
git push origin v0.11.6

Please sign in to comment.