-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_basics.jl
153 lines (136 loc) · 3.88 KB
/
test_basics.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using GPUArraysCore: @allowscalar
using JLArrays: JLArray
using SerializedArrays:
AdjointSerializedArray,
PermutedSerializedArray,
ReshapedSerializedArray,
SerializedArray,
SubSerializedArray,
TransposeSerializedArray,
disk,
memory
using StableRNGs: StableRNG
using Test: @test, @testset
using TestExtras: @constinferred
elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
arrayts = (Array, JLArray)
@testset "SerializedArrays (eltype=$elt, arraytype=$arrayt)" for elt in elts,
arrayt in arrayts
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
@test @constinferred(copy(a)) == x
@test typeof(copy(a)) == typeof(x)
@test memory(a) == x
@test memory(a) isa arrayt{elt,2}
@test memory(x) === x
@test disk(a) === a
@test disk(x) == a
@test disk(x) isa SerializedArray{elt,2,<:arrayt{elt,2}}
x = arrayt(zeros(elt, 4, 4))
a = SerializedArray(x)
@allowscalar begin
a[1, 1] = 2
@test @constinferred(a[1, 1]) == 2
end
x = arrayt(zeros(elt, 4, 4))
a = SerializedArray(x)
b = 2a
@test @constinferred(copy(b)) == 2x
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}
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
b = similar(a)
@test b isa arrayt{elt,2}
@test size(b) == size(a) == size(x)
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = permutedims(SerializedArray(x), (2, 1))
@test a isa PermutedSerializedArray{elt,2}
@test similar(a) isa arrayt{elt,2}
@test copy(a) == permutedims(x, (2, 1))
@test copy(2a) == 2permutedims(x, (2, 1))
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = transpose(SerializedArray(x))
@test a isa TransposeSerializedArray{elt}
@test similar(a) isa arrayt{elt,2}
@test copy(a) == transpose(x)
@test copy(2a) == 2transpose(x)
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = adjoint(SerializedArray(x))
@test a isa AdjointSerializedArray{elt}
@test similar(a) isa arrayt{elt,2}
@test copy(a) == adjoint(x)
@test copy(2a) == 2adjoint(x)
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
@test transpose(transpose(a)) === a
@test adjoint(adjoint(a)) === a
if isreal(a)
@test adjoint(transpose(a)) === a
@test transpose(adjoint(a)) === a
end
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = reshape(SerializedArray(x), 16)
@test a isa ReshapedSerializedArray{elt,1}
@test similar(a) isa arrayt{elt,1}
@test copy(a) == reshape(x, 16)
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = reshape(permutedims(SerializedArray(x), (2, 1)), 16)
@test a isa ReshapedSerializedArray{elt,1,<:PermutedSerializedArray{elt,2}}
@test similar(a) isa arrayt{elt,1}
@test copy(a) == reshape(permutedims(x, (2, 1)), 16)
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
@test a == a
@test x == a
@test a == x
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
y = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
b = SerializedArray(y)
copyto!(b, a)
@test b == a
@test b == x
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
y = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
b = SerializedArray(y)
copyto!(b, x)
@test b == a
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
y = arrayt(randn(rng, elt, 4, 4))
a = SerializedArray(x)
copyto!(y, a)
b = SerializedArray(y)
@test b == a
rng = StableRNG(123)
x = arrayt(randn(rng, elt, 4, 4))
y = @view x[2:3, 2:3]
a = SerializedArray(x)
b = @view a[2:3, 2:3]
@test b isa SubSerializedArray{elt,2}
c = 2b
@test 2y == copy(c)
@allowscalar begin
b[1, 1] = 2
@test @constinferred(b[1, 1]) == 2
end
end