Skip to content

Commit c55193b

Browse files
authored
Merge pull request #422 from tkoolen/tk/pass-tests
Another round of fixes
2 parents 0095ad8 + 2e31933 commit c55193b

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

src/lyap.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ _lyap(::Size{(1,1)}, ::Size{(1,1)}, a::StaticMatrix, c::StaticMatrix) = -c/(2a[
88
-(d*c + (a - t*I)*c*(a-t*I)')/(2*d*t) # http://www.nber.org/papers/w8956.pdf
99
end
1010

11-
@inline _lyap(sa::Size, sc::Size, a::StaticMatrix, c::StaticMatrix) = sc(Base.lyap(Array(a),Array(c)))
12-
11+
@inline _lyap(sa::Size, sc::Size, a::StaticMatrix, c::StaticMatrix) = sc(lyap(Array(a),Array(c)))

src/mapreduce.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
## map / map! ##
55
################
66

7-
# The following type signature for map() matches any list of AbstractArrays,
8-
# provided at least one is a static array.
97
if VERSION < v"0.7.0-"
8+
# The following type signature for map() matches any list of AbstractArrays,
9+
# provided at least one is a static array.
1010
@inline function map(f, as::Union{SA,AbstractArray}...) where {SA<:StaticArray}
1111
_map(f, same_size(as...), as...)
1212
end
1313
else
14+
# In 0.7, the above construction can no longer be used due to https://github.com/JuliaLang/julia/pull/23117.
15+
# Instead, only dispatch to StaticArrays._map if one of the first two arguments is a StaticArray.
1416
@inline function map(f, a1::StaticArray, as::AbstractArray...)
1517
_map(f, same_size(a1, as...), a1, as...)
1618
end
19+
@inline function map(f, a1::AbstractArray, a2::StaticArray, as::AbstractArray...)
20+
_map(f, same_size(a1, a2, as...), a1, a2, as...)
21+
end
22+
@inline function map(f, a1::StaticArray, a2::StaticArray, as::AbstractArray...)
23+
_map(f, same_size(a1, a2, as...), a1, a2, as...)
24+
end
1725
end
1826

1927
@generated function _map(f, ::Size{S}, a::AbstractArray...) where {S}

test/linalg.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,23 @@ using StaticArrays, Compat.Test
110110
@test @inferred(conj(SVector(1+im, 2+im))) === SVector(1-im, 2-im)
111111

112112
if VERSION < v"0.7-"
113-
@test @inferred(transpose(@SVector([1, 2, 3]))) === Adjoint(@SVector([1, 2, 3]))
113+
@test @inferred(transpose(@SVector([1, 2, 3]))) === RowVector(@SVector([1, 2, 3]))
114+
@test @inferred(adjoint(@SVector([1, 2, 3]))) === RowVector(@SVector([1, 2, 3]))
114115
else
115116
@test @inferred(transpose(@SVector([1, 2, 3]))) === Transpose(@SVector([1, 2, 3]))
117+
@test @inferred(adjoint(@SVector([1, 2, 3]))) === Adjoint(@SVector([1, 2, 3]))
116118
end
117119
@test @inferred(transpose(@SMatrix([1 2; 0 3]))) === @SMatrix([1 0; 2 3])
118120
@test @inferred(transpose(@SMatrix([1 2 3; 4 5 6]))) === @SMatrix([1 4; 2 5; 3 6])
119121

120-
@test @inferred(adjoint(@SVector([1, 2, 3]))) === Adjoint(@SVector([1, 2, 3]))
121122
@test @inferred(adjoint(@SMatrix([1 2; 0 3]))) === @SMatrix([1 0; 2 3])
122123
@test @inferred(adjoint(@SMatrix([1 2 3; 4 5 6]))) === @SMatrix([1 4; 2 5; 3 6])
123124
@test @inferred(adjoint(@SMatrix([1 2*im 3; 4 5 6]))) === @SMatrix([1 4; -2*im 5; 3 6])
124-
125+
125126
m = [1 2; 3 4] + im*[5 6; 7 8]
126-
@test @inferred(adjoint(@SVector [m,m])) == ctranspose([m,m])
127+
@test @inferred(adjoint(@SVector [m,m])) == adjoint([m,m])
127128
@test @inferred(transpose(@SVector [m,m])) == transpose([m,m])
128-
@test @inferred(adjoint(@SMatrix [m m; m m])) == ctranspose([[m] [m]; [m] [m]])
129+
@test @inferred(adjoint(@SMatrix [m m; m m])) == adjoint([[m] [m]; [m] [m]])
129130
@test @inferred(transpose(@SMatrix [m m; m m])) == transpose([[m] [m]; [m] [m]])
130131

131132
end

test/matrix_multiply.jl

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@
6060
m = @SMatrix [1 2; 3 4]
6161
bm = @SMatrix [m m; m m]
6262
bv = @SVector [v,v]
63-
# Broken only because output turns into a normal array:
64-
@test_broken (bv'*bm)'::SVector{2,SVector{2,Int}} == @SVector [[14,20],[14,20]]
63+
64+
if VERSION < v"0.7-"
65+
# Broken only because output turns into a normal array:
66+
@test_broken (bv'*bm)'::SVector{2,SVector{2,Int}} == @SVector [[14,20],[14,20]]
67+
else
68+
@test (bv'*bm)'::SVector{2,SVector{2,Int}} == @SVector [[14,20],[14,20]]
69+
end
6570

6671
# Outer product
6772
v2 = SVector(1, 2)
@@ -218,25 +223,25 @@
218223
@test_throws DimensionMismatch m*n
219224
end
220225

221-
@testset "A_mul_B!" begin
226+
@testset "mul!" begin
222227
v = @SVector [2, 4]
223228
v2 = [2, 4]
224229
m = @SMatrix [1 2; 3 4]
225230
n = @SMatrix [2 3; 4 5]
226231

227232
outvec = MVector{2,Int}()
228-
A_mul_B!(outvec, m, v)
233+
mul!(outvec, m, v)
229234
@test outvec == @MVector [10,22]
230-
outvec2 = Vector{Int}(2)
231-
A_mul_B!(outvec2, m, v2)
235+
outvec2 = Vector{Int}(undef, 2)
236+
mul!(outvec2, m, v2)
232237
@test outvec2 == [10,22]
233238

234239
# Bad dimensions
235240
outvec_bad = MVector{3,Int}()
236-
@test_throws DimensionMismatch A_mul_B!(outvec_bad, m, v)
241+
@test_throws DimensionMismatch mul!(outvec_bad, m, v)
237242

238243
a = MMatrix{2,2,Int,4}()
239-
A_mul_B!(a, m, n)
244+
mul!(a, m, n)
240245
@test a::MMatrix{2,2,Int,4} == @MMatrix [10 13; 22 29]
241246

242247
a = MMatrix{2,2,Int,4}()
@@ -254,7 +259,7 @@
254259
@test a::MMatrix{2,2,Int,4} == @MMatrix [11 19; 16 28]
255260

256261
a2 = MArray{Tuple{2,2},Int,2,4}()
257-
A_mul_B!(a2, m, n)
262+
mul!(a2, m, n)
258263
@test a2::MArray{Tuple{2,2},Int,2,4} == @MArray [10 13; 22 29]
259264

260265
# Alternative builtin method used for n > 8
@@ -265,7 +270,7 @@
265270
m_2 = MMatrix{10,10}(m_array_2)
266271
n_2 = MMatrix{10,10}(n_array_2)
267272
a_2 = MMatrix{10,10,Int}()
268-
A_mul_B!(a_2, m_2, n_2)
273+
mul!(a_2, m_2, n_2)
269274
@test a_2 == a_array_2
270275

271276
# BLAS used for n > 14
@@ -276,7 +281,7 @@
276281
m_3 = MMatrix{4,4}(m_array_3)
277282
n_3 = MMatrix{4,4}(n_array_3)
278283
a_3 = MMatrix{4,4,Float64}()
279-
A_mul_B!(a_3, m_3, n_3)
284+
mul!(a_3, m_3, n_3)
280285
@test a_3 a_array_3
281286

282287
m_array_4 = randn(10, 10)
@@ -286,7 +291,7 @@
286291
m_4 = MMatrix{10,10}(m_array_4)
287292
n_4 = MMatrix{10,10}(n_array_4)
288293
a_4 = MMatrix{10,10,Float64}()
289-
A_mul_B!(a_4, m_4, n_4)
294+
mul!(a_4, m_4, n_4)
290295
@test a_4 a_array_4
291296

292297
m_array_5 = rand(1:10, 16, 16)
@@ -296,7 +301,7 @@
296301
m_5 = MMatrix{16,16}(m_array_5)
297302
n_5 = MMatrix{16,16}(n_array_5)
298303
a_5 = MMatrix{16,16,Int}()
299-
A_mul_B!(a_5, m_5, n_5)
304+
mul!(a_5, m_5, n_5)
300305
@test a_5 a_array_5
301306

302307
m_array_6 = rand(1:10, 8, 10)
@@ -306,7 +311,7 @@
306311
m_6 = MMatrix{8,10}(m_array_6)
307312
n_6 = MMatrix{10,8}(n_array_6)
308313
a_6 = MMatrix{8,8,Int}()
309-
A_mul_B!(a_6, m_6, n_6)
314+
mul!(a_6, m_6, n_6)
310315
@test a_6 == a_array_6
311316

312317
# Float64
@@ -315,10 +320,10 @@
315320
mf = @SMatrix [1.0 2.0; 3.0 4.0]
316321

317322
outvecf = MVector{2,Float64}()
318-
A_mul_B!(outvecf, mf, vf)
323+
mul!(outvecf, mf, vf)
319324
@test outvecf @MVector [10.0, 22.0]
320325
outvec2f = Vector{Float64}(2)
321-
A_mul_B!(outvec2f, mf, vf2)
326+
mul!(outvec2f, mf, vf2)
322327
@test outvec2f [10.0, 22.0]
323328
end
324329
end

test/runtests.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using StaticArrays, Compat, Compat.Test
1+
using StaticArrays, Compat, Compat.Test, Compat.Random, Compat.LinearAlgebra
22
if VERSION > v"0.7-"
3-
using Random
4-
using LinearAlgebra
53
using InteractiveUtils
64
else
7-
using Base.Random
85
const LinearAlgebra = Base.LinAlg
9-
const Adjoint = RowVector
106
const tr = trace
7+
const mul! = A_mul_B!
118
end
129

1310
# We generate a lot of matrices using rand(), but unit tests should be

0 commit comments

Comments
 (0)