|
26 | 26 | ar = randn_sparse(arraytype{Float64}, dims)
|
27 | 27 | ac = randn_sparse(arraytype{ComplexF64}, dims)
|
28 | 28 |
|
| 29 | + slice = (1:rand(1:dims[1]), rand(1:dims[2]), rand(1:dims[3]):dims[3], rand(1:dims[4])) |
| 30 | + @test ar[slice...] == Array(ar)[slice...] |
| 31 | + |
| 32 | + |
29 | 33 | α = randn(ComplexF64)
|
30 | 34 | β = randn(Float64)
|
31 | 35 | γ = 2
|
|
34 | 38 | @test @constinferred(γ*ar) == γ*Array(ar)
|
35 | 39 | @test @constinferred(ac*β) == Array(ac)*β
|
36 | 40 | @test @constinferred(ar + ac) == Array(ar) + Array(ac)
|
| 41 | + @test @constinferred(ac - ar) == Array(ac) - Array(ar) |
| 42 | + @test @constinferred(zero(ar)) + ac == ac |
37 | 43 |
|
38 | 44 | @test norm(ar + @constinferred(α*ar)) ≈ norm(ar)*abs(1+α)
|
39 | 45 | @test @constinferred(norm(ac + ac*α)) ≈ norm(ac)*abs(1+α)
|
|
63 | 69 |
|
64 | 70 | @timedtestset "Basic matrix algebra" for arraytype in (SparseCOOArray, SparseDOKArray)
|
65 | 71 | using SparseArrays
|
66 |
| - a = sprandn(ComplexF64, 100, 100, 0.1) |
67 |
| - b = sprandn(100, 100, 0.1) |
| 72 | + N = 100 |
| 73 | + a = sprandn(ComplexF64, N, N, 0.1) |
| 74 | + b = sprandn(N, N, 0.1) |
68 | 75 | aa = @constinferred(arraytype(a))
|
69 | 76 | bb = arraytype(b)
|
70 | 77 | @test aa == a
|
|
75 | 82 | @test aa'*bb ≈ Array(aa)'*Array(bb)
|
76 | 83 | @test aa'*bb' ≈ Array(aa)'*Array(bb)'
|
77 | 84 | @test aa*bb' ≈ Array(aa)*Array(bb)'
|
| 85 | + @test @constinferred(one(aa)) == one(Array(aa)) |
| 86 | + @test norm(one(aa)) ≈ sqrt(N) |
| 87 | + @test one(aa) + zero(aa) == one(bb) |
| 88 | + @test adjoint!(copy(aa), bb) == SparseArray(adjoint(bb)) == adjoint(Array(bb)) |
| 89 | + @test transpose!(copy(aa), bb) == SparseArray(transpose(bb)) == transpose(Array(bb)) |
78 | 90 | end
|
79 | 91 |
|
80 | 92 | @timedtestset "random contractions" for (eltype,arraytype) in
|
|
0 commit comments