-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_linearalgebraext.jl
50 lines (44 loc) · 1.35 KB
/
test_linearalgebraext.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using JLArrays: JLArray
using LinearAlgebra: eigen, qr, svd
using SerializedArrays: SerializedArray
using StableRNGs: StableRNG
using Test: @test, @testset
using TestExtras: @constinferred
elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
arrayts = (Array, JLArray)
@testset "SerializedArraysLinearAlgebraExt (eltype=$elt, arraytype=$arrayt)" for elt in
elts,
arrayt in arrayts
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
y = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
b = SerializedArray(y)
c = @constinferred(a * b)
@test c == x * y
@test c isa arrayt{elt,2}
c = @constinferred(x * b)
@test c == x * y
@test c isa arrayt{elt,2}
c = @constinferred(a * y)
@test c == x * y
@test c isa arrayt{elt,2}
a = permutedims(SerializedArray(x), (2, 1))
b = permutedims(SerializedArray(y), (2, 1))
c = @constinferred(a * b)
@test c == permutedims(x, (2, 1)) * permutedims(y, (2, 1))
@test c isa arrayt{elt,2}
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
# `LinearAlgebra.eigen(::JLArray)` is broken with
# a scalar indexing issue.
if arrayt ≠ JLArray
@test eigen(a) == eigen(x)
end
Q, R = qr(a)
Qₓ, Rₓ = qr(x)
@test Q == Qₓ
@test R == Rₓ
@test svd(a) == svd(x)
end