Skip to content

Commit 1819a8c

Browse files
authored
Test continuous (#6)
* Test contnuous * start matmul tests * more * tests
1 parent 3950c80 commit 1819a8c

File tree

6 files changed

+78
-3
lines changed

6 files changed

+78
-3
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ julia = "1.1"
1313

1414
[extras]
1515
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
16+
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
1617

1718
[targets]
18-
test = ["Test"]
19+
test = ["Test","IntervalSets"]

src/QuasiArrays.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ include("quasidiagonal.jl")
9292

9393

9494

95+
function materialize(A::Applied{LazyQuasiArrayApplyStyle,typeof(*),<:Tuple{Vararg{<:Union{Adjoint,QuasiAdjoint,QuasiDiagonal}}}})
96+
checkaxescompatible(A.args...)
97+
ApplyQuasiArray(A)
98+
end
9599

96100
materialize(M::Applied{<:Any,typeof(*),<:Tuple{Vararg{<:Union{Adjoint,QuasiAdjoint,QuasiDiagonal}}}}) =
97101
apply(*,reverse(adjoint.(M.args))...)'

src/indices.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,15 @@ role as `Slice` does for offset arrays.
120120
struct Inclusion{T,AX} <: AbstractQuasiVector{T}
121121
domain::AX
122122
end
123-
Inclusion(domain) = Inclusion{eltype(domain),typeof(domain)}(domain)
123+
Inclusion{T}(domain) where T = Inclusion{T,typeof(domain)}(domain)
124+
Inclusion{T}(S::Inclusion) where T = Inclusion{T}(S.domain)
125+
Inclusion{T}(S::Slice) where T = Inclusion{T}(S.indices)
126+
Inclusion(domain) = Inclusion{eltype(domain)}(domain)
124127
Inclusion(S::Inclusion) = S
125128
Inclusion(S::Slice) = Inclusion(S.indices)
126129

130+
convert(::Type{Inclusion}, d::Inclusion) = d
131+
convert(::Type{Inclusion{T}}, d::Inclusion) where T = Inclusion{T}(d)
127132
convert(::Type{AbstractVector}, d::Inclusion{<:Any,<:AbstractVector}) =
128133
convert(AbstractVector, d.domain)
129134
convert(::Type{AbstractArray}, d::Inclusion{<:Any,<:AbstractVector}) =

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ include("test_quasibroadcast.jl")
55
include("test_arrayops.jl")
66
include("test_quasisubarray.jl")
77

8-
include("test_quasiadjtrans.jl")
8+
include("test_quasiadjtrans.jl")
9+
include("test_continuous.jl")
10+
include("test_matmul.jl")

test/test_continuous.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using QuasiArrays, IntervalSets, Test
2+
import QuasiArrays: ApplyQuasiArray
3+
4+
@testset "Continuous" begin
5+
@testset "Inclusion" begin
6+
x = Inclusion(0..1)
7+
@test axes(x) (x,)
8+
@test_throws InexactError x[0.1]
9+
@test x[1] 1
10+
@test_throws BoundsError x[2]
11+
12+
for x in (Inclusion{Float64}(0..1),Inclusion(0.0..1))
13+
@test Inclusion(x) Inclusion{Float64}(x) convert(Inclusion,x)
14+
convert(Inclusion{Float64},x) convert(AbstractQuasiArray,x)
15+
convert(AbstractQuasiArray{Float64},x) convert(AbstractQuasiVector{Float64},x)
16+
convert(AbstractQuasiVector,x) x
17+
@test axes(x) (x,)
18+
@test x[0.1] 0.1
19+
@test x[1] 1.0
20+
@test_throws BoundsError x[2]
21+
@test x[BigFloat(π)/4] == π/4
22+
end
23+
24+
@test Inclusion{Float64}(0..1) == Inclusion(0.0..1)
25+
@test Inclusion{Float64}(0..1) !== Inclusion(0.0..1)
26+
end
27+
28+
@testset "QuasiDiagonal" begin
29+
x = Inclusion(0.0..1)
30+
D = QuasiDiagonal(x)
31+
@test D[0.1,0.2] 0.0
32+
@test D[0.1,0.1] 0.1
33+
@test D[1,1] 1.0
34+
@test_throws BoundsError D[1.1,1.2]
35+
36+
D2 = D*D
37+
@test D2 isa ApplyQuasiArray
38+
end
39+
end

test/test_matmul.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using QuasiArrays, Test
2+
import QuasiArrays: ApplyQuasiArray
3+
4+
@testset "Multiplication" begin
5+
@testset "Diag * Inclusion" begin
6+
A = QuasiDiagonal(Inclusion(0:0.1:1))
7+
b = Inclusion(0:0.1:1)
8+
Ab = A*b
9+
@test Ab isa ApplyQuasiArray
10+
@test Ab[0.1] 0.1^2
11+
@test_throws DimensionMismatch A*Inclusion(1:2)
12+
end
13+
@testset "Quasi * Quasi" begin
14+
A = QuasiArray(rand(3,3),(0:0.5:1,0:0.5:1))
15+
@test A*A isa ApplyQuasiArray
16+
@test QuasiArray(A*A) == QuasiArray(A.parent*A.parent,A.axes)
17+
end
18+
@testset "Quasi * Array" begin
19+
A = QuasiArray(rand(3,3),(0:0.5:1,Base.OneTo(3)))
20+
B = rand(3,3)
21+
@test A*B isa ApplyQuasiArray
22+
@test QuasiArray(A*B) == QuasiArray(A.parent*B,A.axes)
23+
end
24+
end

0 commit comments

Comments
 (0)