Skip to content

Commit 754f69c

Browse files
committed
add tests
1 parent c87a1e1 commit 754f69c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/Project.toml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
55
DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
66
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
77
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
8+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
810
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
911
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208"
1012
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"

test/basics/test_linalg.jl

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using SparseArraysBase: SparseArrayDOK
2+
using LinearAlgebra: mul!
3+
using Random
4+
5+
# TODO: add this to main package
6+
function sprand(::Type{T}, sz::Base.Dims; p::Real=0.5) where {T}
7+
A = SparseArrayDOK{T}(undef, sz)
8+
for I in eachindex(A)
9+
if rand() < p
10+
A[I] = rand(T)
11+
end
12+
end
13+
return A
14+
end
15+
16+
@testset "mul!" begin
17+
T = Float64
18+
szA = (2, 2)
19+
szB = (2, 2)
20+
szC = (szA[1], szB[2])
21+
22+
for p in 0.0:0.25:1
23+
C = sprand(T, szC; p)
24+
A = sprand(T, szA; p)
25+
B = sprand(T, szB; p)
26+
27+
check1 = mul!(Array(C), Array(A), Array(B))
28+
@test mul!(copy(C), A, B) check1
29+
30+
α = rand()
31+
β = rand()
32+
check2 = mul!(Array(C), Array(A), Array(B), α, β)
33+
@test mul!(copy(C), A, B, α, β) check2
34+
end
35+
end

0 commit comments

Comments
 (0)