@@ -3,7 +3,7 @@ if Sys.iswindows()
33else
44
55using oneAPI
6- using oneAPI. oneMKL: band, bandex, oneSparseMatrixCSR, oneSparseMatrixCOO, oneSparseMatrixCSC
6+ using oneAPI. oneMKL: band, bandex, oneSparseMatrixCSR, oneSparseMatrixCOO, oneSparseMatrixCSC
77
88using SparseArrays
99using LinearAlgebra
@@ -1083,8 +1083,6 @@ end
10831083
10841084@testset " SPARSE" begin
10851085 @testset " $T " for T in intersect (eltypes, [Float32, Float64, ComplexF32, ComplexF64])
1086- ε = sqrt (eps (real (T)))
1087-
10881086 @testset " oneSparseMatrixCSR" begin
10891087 for S in (Int32, Int64)
10901088 A = sprand (T, 20 , 10 , 0.5 )
@@ -1095,16 +1093,16 @@ end
10951093 end
10961094 end
10971095
1098- @testset " oneSparseMatrixCSC" begin
1099- (T isa Complex) && continue
1100- for S in (Int32, Int64)
1101- A = sprand (T, 20 , 10 , 0.5 )
1102- A = SparseMatrixCSC {T, S} (A)
1103- B = oneSparseMatrixCSC (A)
1104- A2 = SparseMatrixCSC (B)
1105- @test A == A2
1096+ @testset " oneSparseMatrixCSC" begin
1097+ (T isa Complex) && continue
1098+ for S in (Int32, Int64)
1099+ A = sprand (T, 20 , 10 , 0.5 )
1100+ A = SparseMatrixCSC {T, S} (A)
1101+ B = oneSparseMatrixCSC (A)
1102+ A2 = SparseMatrixCSC (B)
1103+ @test A == A2
1104+ end
11061105 end
1107- end
11081106
11091107 @testset " oneSparseMatrixCOO" begin
11101108 for S in (Int32, Int64)
@@ -1117,9 +1115,8 @@ end
11171115 end
11181116
11191117 @testset " sparse gemv" begin
1120- @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCOO, oneSparseMatrixCSR, oneSparseMatrixCSC)
1118+ @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCOO, oneSparseMatrixCSR, oneSparseMatrixCSC)
11211119 @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1122- (T <: Complex ) && (SparseMatrix == oneSparseMatrixCSC) && continue
11231120 A = sprand (T, 20 , 10 , 0.5 )
11241121 x = transa == ' N' ? rand (T, 10 ) : rand (T, 20 )
11251122 y = transa == ' N' ? rand (T, 20 ) : rand (T, 10 )
@@ -1132,41 +1129,39 @@ end
11321129 beta = rand (T)
11331130 oneMKL. sparse_optimize_gemv! (transa, dA)
11341131 oneMKL. sparse_gemv! (transa, alpha, dA, dx, beta, dy)
1135- @test isapprox ( alpha * opa (A) * x + beta * y, collect (dy), atol = ε )
1132+ @test alpha * opa (A) * x + beta * y ≈ collect (dy)
11361133 end
11371134 end
11381135 end
11391136
11401137 @testset " sparse gemm" begin
1141- @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR, oneSparseMatrixCSC)
1142- @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1143- @testset " transb = $transb " for (transb, opb) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1144- (transb == ' N' ) || continue
1145- (T <: Complex ) && (SparseMatrix == oneSparseMatrixCSC) && continue
1146- A = sprand (T, 10 , 10 , 0.5 )
1147- B = transb == ' N' ? rand (T, 10 , 2 ) : rand (T, 2 , 10 )
1148- C = rand (T, 10 , 2 )
1149-
1150- dA = SparseMatrix (A)
1151- dB = oneMatrix {T} (B)
1152- dC = oneMatrix {T} (C)
1138+ @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR, oneSparseMatrixCSC)
1139+ @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1140+ @testset " transb = $transb " for (transb, opb) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1141+ (transb == ' N' ) || continue
1142+ A = sprand (T, 10 , 10 , 0.5 )
1143+ B = transb == ' N' ? rand (T, 10 , 2 ) : rand (T, 2 , 10 )
1144+ C = rand (T, 10 , 2 )
1145+
1146+ dA = SparseMatrix (A)
1147+ dB = oneMatrix {T} (B)
1148+ dC = oneMatrix {T} (C)
11531149
1154- alpha = rand (T)
1155- beta = rand (T)
1156- oneMKL. sparse_optimize_gemm! (transa, dA)
1157- oneMKL. sparse_gemm! (transa, transb, alpha, dA, dB, beta, dC)
1158- @test isapprox (alpha * opa (A) * opb (B) + beta * C, collect (dC), atol= ε)
1150+ alpha = rand (T)
1151+ beta = rand (T)
1152+ oneMKL. sparse_optimize_gemm! (transa, dA)
1153+ oneMKL. sparse_gemm! (transa, transb, alpha, dA, dB, beta, dC)
11591154
1160- oneMKL. sparse_optimize_gemm! (transa, transb, 2 , dA)
1161- end
1155+ @test alpha * opa (A) * opb (B) + beta * C ≈ collect (dC)
1156+ oneMKL. sparse_optimize_gemm! (transa, transb, 2 , dA)
1157+ end
11621158 end
11631159 end
11641160 end
11651161
11661162 @testset " sparse symv" begin
1167- @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR, oneSparseMatrixCSC)
1168- @testset " uplo = $uplo " for uplo in (' L' , ' U' )
1169- (T <: Complex ) && (SparseMatrix == oneSparseMatrixCSC) && continue
1163+ @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR, oneSparseMatrixCSC)
1164+ @testset " uplo = $uplo " for uplo in (' L' , ' U' )
11701165 A = sprand (T, 10 , 10 , 0.5 )
11711166 A = A + transpose (A)
11721167 x = rand (T, 10 )
@@ -1179,95 +1174,111 @@ end
11791174 alpha = rand (T)
11801175 beta = rand (T)
11811176 oneMKL. sparse_symv! (uplo, alpha, dA, dx, beta, dy)
1182- @test isapprox ( alpha * A * x + beta * y, collect (dy), atol = ε )
1177+ @test alpha * A * x + beta * y ≈ collect (dy)
11831178 end
11841179 end
11851180 end
11861181
1187- @testset " sparse trmv" begin
1188- @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR,)
1189- @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1190- for (uplo, diag, wrapper) in [(' L' , ' N' , LowerTriangular), (' L' , ' U' , UnitLowerTriangular),
1191- (' U' , ' N' , UpperTriangular), (' U' , ' U' , UnitUpperTriangular)]
1192- (transa == ' N' ) || continue
1193- (T <: Complex ) && (SparseMatrix == oneSparseMatrixCSC) && continue
1194- A = sprand (T, 10 , 10 , 0.5 )
1195- x = rand (T, 10 )
1196- y = rand (T, 10 )
1197-
1198- B = uplo == ' L' ? tril (A) : triu (A)
1199- B = diag == ' U' ? B - Diagonal (B) + I : B
1200- dA = SparseMatrix (B)
1201- dx = oneVector {T} (x)
1202- dy = oneVector {T} (y)
1182+ @testset " sparse trmv" begin
1183+ @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR, oneSparseMatrixCSC)
1184+ @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1185+ for (uplo, diag, wrapper) in [(' L' , ' N' , LowerTriangular), (' L' , ' U' , UnitLowerTriangular),
1186+ (' U' , ' N' , UpperTriangular), (' U' , ' U' , UnitUpperTriangular)]
1187+ (transa == ' N' ) || continue
1188+ A = sprand (T, 10 , 10 , 0.5 )
1189+ x = rand (T, 10 )
1190+ y = rand (T, 10 )
12031191
1204- alpha = rand (T)
1205- beta = rand (T)
1192+ B = uplo == ' L' ? tril (A) : triu (A)
1193+ B = diag == ' U' ? B - Diagonal (B) + I : B
1194+ dA = SparseMatrix (B)
1195+ dx = oneVector {T} (x)
1196+ dy = oneVector {T} (y)
12061197
1207- oneMKL. sparse_optimize_trmv! (uplo, transa, diag, dA)
1208- oneMKL. sparse_trmv! (uplo, transa, diag, alpha, dA, dx, beta, dy)
1209- @test isapprox (alpha * wrapper (opa (A)) * x + beta * y, collect (dy), atol= ε)
1210- end
1198+ alpha = rand (T)
1199+ beta = rand (T)
1200+
1201+ if SparseMatrix == oneSparseMatrixCSC
1202+ @test_broken sparse_optimize_trmv! (uplo, transa, diag, dA) # Intel oneAPI limitation: CSC triangular operations not supported
1203+ @test_throws ArgumentError oneMKL. sparse_optimize_trmv! (uplo, transa, diag, dA)
1204+ @test_throws ArgumentError oneMKL. sparse_trmv! (uplo, transa, diag, alpha, dA, dx, beta, dy)
1205+ else
1206+ oneMKL. sparse_optimize_trmv! (uplo, transa, diag, dA)
1207+ oneMKL. sparse_trmv! (uplo, transa, diag, alpha, dA, dx, beta, dy)
1208+ @test alpha * wrapper (opa (A)) * x + beta * y ≈ collect (dy)
1209+ end
1210+ end
12111211 end
12121212 end
12131213 end
12141214
1215- @testset " sparse trsv" begin
1216- @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR,)
1217- @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1215+ @testset " sparse trsv" begin
1216+ @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR, oneSparseMatrixCSC )
1217+ @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
12181218 for (uplo, diag, wrapper) in [(' L' , ' N' , LowerTriangular), (' L' , ' U' , UnitLowerTriangular),
1219- (' U' , ' N' , UpperTriangular), (' U' , ' U' , UnitUpperTriangular)]
1219+ (' U' , ' N' , UpperTriangular), (' U' , ' U' , UnitUpperTriangular)]
12201220 (transa == ' N' ) || continue
1221- (T <: Complex ) && (SparseMatrix == oneSparseMatrixCSC) && continue
12221221 alpha = rand (T)
12231222 A = rand (T, 10 , 10 ) + I
12241223 A = sparse (A)
1225- x = rand (T, 10 )
1226- y = rand (T, 10 )
1224+ x = rand (T, 10 )
1225+ y = rand (T, 10 )
12271226
12281227 B = uplo == ' L' ? tril (A) : triu (A)
12291228 B = diag == ' U' ? B - Diagonal (B) + I : B
1230- dA = SparseMatrix (B)
1231- dx = oneVector {T} (x)
1232- dy = oneVector {T} (y)
1233-
1234- oneMKL. sparse_optimize_trsv! (uplo, transa, diag, dA)
1235- oneMKL. sparse_trsv! (uplo, transa, diag, alpha, dA, dx, dy)
1236- y = wrapper (opa (A)) \ (alpha * x)
1237- @test isapprox (y, collect (dy), atol= ε)
1229+ dA = SparseMatrix (B)
1230+ dx = oneVector {T} (x)
1231+ dy = oneVector {T} (y)
1232+
1233+ if SparseMatrix == oneSparseMatrixCSC
1234+ @test_broken sparse_optimize_trsv! (uplo, transa, diag, dA) # Intel oneAPI limitation: CSC triangular operations not supported
1235+ @test_throws ArgumentError oneMKL. sparse_optimize_trsv! (uplo, transa, diag, dA)
1236+ @test_throws ArgumentError oneMKL. sparse_trsv! (uplo, transa, diag, alpha, dA, dx, dy)
1237+ else
1238+ oneMKL. sparse_optimize_trsv! (uplo, transa, diag, dA)
1239+ oneMKL. sparse_trsv! (uplo, transa, diag, alpha, dA, dx, dy)
1240+ y = wrapper (opa (A)) \ (alpha * x)
1241+ @test y ≈ collect (dy)
1242+ end
1243+ end
12381244 end
12391245 end
12401246 end
1241- end
12421247
1243- @testset " sparse trsm" begin
1244- @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR,)
1245- @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1246- @testset " transx = $transx " for (transx, opx) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1247- (transx != ' N' ) && continue
1248- for (uplo, diag, wrapper) in [(' L' , ' N' , LowerTriangular), (' L' , ' U' , UnitLowerTriangular),
1249- (' U' , ' N' , UpperTriangular), (' U' , ' U' , UnitUpperTriangular)]
1250- (transa == ' N' ) || continue
1251- (T <: Complex ) && (SparseMatrix == oneSparseMatrixCSC) && continue
1252- alpha = rand (T)
1253- A = rand (T, 10 , 10 ) + I
1254- A = sparse (A)
1255- X = transx == ' N' ? rand (T, 10 , 4 ) : rand (T, 4 , 10 )
1256- Y = rand (T, 10 , 4 )
1257-
1258- B = uplo == ' L' ? tril (A) : triu (A)
1259- B = diag == ' U' ? B - Diagonal (B) + I : B
1260- dA = SparseMatrix (B)
1261- dX = oneMatrix {T} (X)
1262- dY = oneMatrix {T} (Y)
1263-
1264- oneMKL. sparse_optimize_trsm! (uplo, transa, diag, dA)
1265- oneMKL. sparse_trsm! (uplo, transa, transx, diag, alpha, dA, dX, dY)
1266- Y = wrapper (opa (A)) \ (alpha * opx (X))
1267- @test isapprox (Y, collect (dY), atol= ε)
1268-
1269- oneMKL. sparse_optimize_trsm! (uplo, transa, diag, 4 , dA)
1270- end
1248+ @testset " sparse trsm" begin
1249+ @testset " $SparseMatrix " for SparseMatrix in (oneSparseMatrixCSR, oneSparseMatrixCSC)
1250+ @testset " transa = $transa " for (transa, opa) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1251+ @testset " transx = $transx " for (transx, opx) in [(' N' , identity), (' T' , transpose), (' C' , adjoint)]
1252+ (transx != ' N' ) && continue
1253+ for (uplo, diag, wrapper) in [(' L' , ' N' , LowerTriangular), (' L' , ' U' , UnitLowerTriangular),
1254+ (' U' , ' N' , UpperTriangular), (' U' , ' U' , UnitUpperTriangular)]
1255+ (transa == ' N' ) || continue
1256+ alpha = rand (T)
1257+ A = rand (T, 10 , 10 ) + I
1258+ A = sparse (A)
1259+ X = transx == ' N' ? rand (T, 10 , 4 ) : rand (T, 4 , 10 )
1260+ Y = rand (T, 10 , 4 )
1261+
1262+ B = uplo == ' L' ? tril (A) : triu (A)
1263+ B = diag == ' U' ? B - Diagonal (B) + I : B
1264+ dA = SparseMatrix (B)
1265+ dX = oneMatrix {T} (X)
1266+ dY = oneMatrix {T} (Y)
1267+
1268+ if SparseMatrix == oneSparseMatrixCSC
1269+ @test_broken sparse_optimize_trsm! (uplo, transa, diag, dA) # Intel oneAPI limitation: CSC triangular operations not supported
1270+ @test_throws ArgumentError oneMKL. sparse_optimize_trsm! (uplo, transa, diag, dA)
1271+ @test_throws ArgumentError oneMKL. sparse_trsm! (uplo, transa, transx, diag, alpha, dA, dX, dY)
1272+ @test_throws ArgumentError oneMKL. sparse_optimize_trsm! (uplo, transa, diag, 4 , dA)
1273+ else
1274+ oneMKL. sparse_optimize_trsm! (uplo, transa, diag, dA)
1275+ oneMKL. sparse_trsm! (uplo, transa, transx, diag, alpha, dA, dX, dY)
1276+ Y = wrapper (opa (A)) \ (alpha * opx (X))
1277+ @test Y ≈ collect (dY)
1278+
1279+ oneMKL. sparse_optimize_trsm! (uplo, transa, diag, 4 , dA)
1280+ end
1281+ end
12711282 end
12721283 end
12731284 end
0 commit comments