1- using Adapt, CUDA, cuTENSOR
1+ using Adapt, CUDA, CUDA . cuRAND, cuTENSOR
22using Test, TestExtras
33using TensorKit
44using LinearAlgebra: LinearAlgebra
@@ -23,10 +23,10 @@ for V in spacelist
2323 @testset " QR decomposition" begin
2424 for T in eltypes,
2525 t in (
26- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
27- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' )' ,
28- CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5)), CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
29- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
26+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
27+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' )' ,
28+ cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5)), cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
29+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
3030 )
3131
3232 Q, R = @constinferred qr_full (t)
@@ -52,7 +52,7 @@ for V in spacelist
5252
5353 # empty tensor
5454 for T in eltypes
55- t = CUDA . rand (T, V1 ⊗ V2, zerospace (V1))
55+ t = cuRAND . rand (T, V1 ⊗ V2, zerospace (V1))
5656
5757 Q, R = @constinferred qr_full (t)
5858 @test Q * R ≈ t
@@ -78,10 +78,10 @@ for V in spacelist
7878 @testset " LQ decomposition" begin
7979 for T in eltypes,
8080 t in (
81- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
82- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' )' ,
83- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5)), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
84- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
81+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
82+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' )' ,
83+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5)), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
84+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
8585 )
8686
8787 L, Q = @constinferred lq_full (t)
@@ -103,7 +103,7 @@ for V in spacelist
103103
104104 for T in eltypes
105105 # empty tensor
106- t = CUDA . rand (T, zerospace (V1), V1 ⊗ V2)
106+ t = cuRAND . rand (T, zerospace (V1), V1 ⊗ V2)
107107
108108 L, Q = @constinferred lq_full (t)
109109 @test L * Q ≈ t
@@ -129,10 +129,10 @@ for V in spacelist
129129 @testset " Polar decomposition" begin
130130 @testset for T in eltypes,
131131 t in (
132- CUDA . rand (T, W, W),
133- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
134- CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
135- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
132+ cuRAND . rand (T, W, W),
133+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
134+ cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
135+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
136136 )
137137
138138 @assert domain (t) ≾ codomain (t)
@@ -148,10 +148,10 @@ for V in spacelist
148148
149149 @testset for T in eltypes,
150150 t in (
151- CUDA . rand (T, W, W),
152- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ),
153- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
154- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
151+ cuRAND . rand (T, W, W),
152+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ),
153+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
154+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
155155 )
156156
157157 @assert codomain (t) ≾ domain (t)
@@ -169,10 +169,10 @@ for V in spacelist
169169 @testset " SVD" begin
170170 for T in eltypes,
171171 t in (
172- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
173- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
174- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
175- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
172+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
173+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
174+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
175+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
176176 )
177177
178178 u, s, vᴴ = @constinferred svd_full (t)
@@ -220,8 +220,8 @@ for V in spacelist
220220
221221 # empty tensor
222222 for T in eltypes, t in (
223- CUDA . rand (T, W, zerospace (V1)),
224- CUDA . rand (T, zerospace (V1), W),
223+ cuRAND . rand (T, W, zerospace (V1)),
224+ cuRAND . rand (T, zerospace (V1), W),
225225 )
226226 U, S, Vᴴ = @constinferred svd_full (t)
227227 @test U * S * Vᴴ ≈ t
@@ -237,10 +237,10 @@ for V in spacelist
237237 @testset " truncated SVD" begin
238238 for T in eltypes,
239239 t in (
240- CUDA . randn (T, W, W), CUDA . randn (T, W, W)' ,
241- CUDA . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
242- CUDA . randn (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . randn (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
243- DiagonalTensorMap (CUDA . randn (T, reduceddim (V1)), V1),
240+ cuRAND . randn (T, W, W), cuRAND . randn (T, W, W)' ,
241+ cuRAND . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
242+ cuRAND . randn (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . randn (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
243+ DiagonalTensorMap (cuRAND . randn (T, reduceddim (V1)), V1),
244244 )
245245
246246 @constinferred normalize! (t)
@@ -305,10 +305,10 @@ for V in spacelist
305305 @testset " Eigenvalue decomposition" begin
306306 for T in eltypes,
307307 t in (
308- CUDA . rand (T, V1, V1),
309- CUDA . rand (T, W, W),
310- CUDA . rand (T, W, W)' ,
311- # DiagonalTensorMap(CUDA .rand(T, reduceddim(V1)), V1),
308+ cuRAND . rand (T, V1, V1),
309+ cuRAND . rand (T, W, W),
310+ cuRAND . rand (T, W, W)' ,
311+ # DiagonalTensorMap(cuRAND .rand(T, reduceddim(V1)), V1),
312312 )
313313
314314 d, v = @constinferred eig_full (t)
@@ -365,10 +365,10 @@ for V in spacelist
365365 @testset " Condition number and rank" begin
366366 for T in eltypes,
367367 t in (
368- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
369- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
370- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
371- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
368+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
369+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
370+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
371+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
372372 )
373373
374374 d1, d2 = dim (codomain (t)), dim (domain (t))
@@ -385,15 +385,15 @@ for V in spacelist
385385 @test @constinferred (cond (u)) ≈ one (real (T))
386386 @test @constinferred (rank (u)) == dim (V1 ⊗ V2)
387387
388- t = CUDA . rand (T, zerospace (V1), W)
388+ t = cuRAND . rand (T, zerospace (V1), W)
389389 @test rank (t) == 0
390- t2 = CUDA . rand (T, zerospace (V1) * zerospace (V2), zerospace (V1) * zerospace (V2))
390+ t2 = cuRAND . rand (T, zerospace (V1) * zerospace (V2), zerospace (V1) * zerospace (V2))
391391 @test rank (t2) == 0
392392 @test cond (t2) == 0.0
393393 end
394394 for T in eltypes, t in (
395- CUDA . rand (T, W, W),
396- CUDA . rand (T, W, W)' ,
395+ cuRAND . rand (T, W, W),
396+ cuRAND . rand (T, W, W)' ,
397397 )
398398 project_hermitian! (t)
399399 vals = @constinferred LinearAlgebra. eigvals (t)
@@ -406,10 +406,10 @@ for V in spacelist
406406 @testset " Hermitian projections" begin
407407 for T in eltypes,
408408 t in (
409- CUDA . rand (T, V1, V1),
410- CUDA . rand (T, W, W),
411- CUDA . rand (T, W, W)' ,
412- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
409+ cuRAND . rand (T, V1, V1),
410+ cuRAND . rand (T, W, W),
411+ cuRAND . rand (T, W, W)' ,
412+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
413413 )
414414 normalize! (t)
415415 noisefactor = eps (real (T))^ (3 / 4 )
@@ -439,10 +439,10 @@ for V in spacelist
439439 @testset " Isometric projections" begin
440440 for T in eltypes,
441441 t in (
442- CUDA . randn (T, W, W),
443- CUDA . randn (T, W, W)' ,
444- CUDA . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
445- CUDA . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
442+ cuRAND . randn (T, W, W),
443+ cuRAND . randn (T, W, W)' ,
444+ cuRAND . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
445+ cuRAND . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
446446 )
447447 t2 = project_isometric (t)
448448 @test isisometric (t2)
@@ -457,7 +457,7 @@ for V in spacelist
457457
458458 # test that t2 is closer to A then any other isometry
459459 for k in 1 : 10
460- δt = CUDA . randn! (similar (t))
460+ δt = cuRAND . randn! (similar (t))
461461 t3 = project_isometric (t + δt / 100 )
462462 @test norm (t - t3) > norm (t - t2)
463463 end
0 commit comments