1- using Adapt, CUDA, cuTENSOR
1+ using Adapt, CUDA, CUDA . cuRAND, cuTENSOR
22using Test, TestExtras
33using TensorKit
44using LinearAlgebra: LinearAlgebra
@@ -25,10 +25,10 @@ for V in spacelist
2525 @testset " QR decomposition" begin
2626 for T in eltypes,
2727 t in (
28- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
29- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' )' ,
30- CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5)), CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
31- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
28+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
29+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' )' ,
30+ cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5)), cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
31+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
3232 )
3333
3434 Q, R = @constinferred qr_full (t)
@@ -54,7 +54,7 @@ for V in spacelist
5454
5555 # empty tensor
5656 for T in eltypes
57- t = CUDA . rand (T, V1 ⊗ V2, zerospace (V1))
57+ t = cuRAND . rand (T, V1 ⊗ V2, zerospace (V1))
5858
5959 Q, R = @constinferred qr_full (t)
6060 @test Q * R ≈ t
@@ -80,10 +80,10 @@ for V in spacelist
8080 @testset " LQ decomposition" begin
8181 for T in eltypes,
8282 t in (
83- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
84- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' )' ,
85- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5)), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
86- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
83+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
84+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' )' ,
85+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5)), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
86+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
8787 )
8888
8989 L, Q = @constinferred lq_full (t)
@@ -105,7 +105,7 @@ for V in spacelist
105105
106106 for T in eltypes
107107 # empty tensor
108- t = CUDA . rand (T, zerospace (V1), V1 ⊗ V2)
108+ t = cuRAND . rand (T, zerospace (V1), V1 ⊗ V2)
109109
110110 L, Q = @constinferred lq_full (t)
111111 @test L * Q ≈ t
@@ -131,10 +131,10 @@ for V in spacelist
131131 @testset " Polar decomposition" begin
132132 @testset for T in eltypes,
133133 t in (
134- CUDA . rand (T, W, W),
135- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
136- CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
137- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
134+ cuRAND . rand (T, W, W),
135+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
136+ cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
137+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
138138 )
139139
140140 @assert domain (t) ≾ codomain (t)
@@ -150,10 +150,10 @@ for V in spacelist
150150
151151 @testset for T in eltypes,
152152 t in (
153- CUDA . rand (T, W, W),
154- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ),
155- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
156- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
153+ cuRAND . rand (T, W, W),
154+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ),
155+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
156+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
157157 )
158158
159159 @assert codomain (t) ≾ domain (t)
@@ -171,10 +171,10 @@ for V in spacelist
171171 @testset " SVD" begin
172172 for T in eltypes,
173173 t in (
174- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
175- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
176- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
177- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
174+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
175+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
176+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
177+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
178178 )
179179
180180 u, s, vᴴ = @constinferred svd_full (t)
@@ -222,8 +222,8 @@ for V in spacelist
222222
223223 # empty tensor
224224 for T in eltypes, t in (
225- CUDA . rand (T, W, zerospace (V1)),
226- CUDA . rand (T, zerospace (V1), W),
225+ cuRAND . rand (T, W, zerospace (V1)),
226+ cuRAND . rand (T, zerospace (V1), W),
227227 )
228228 U, S, Vᴴ = @constinferred svd_full (t)
229229 @test U * S * Vᴴ ≈ t
@@ -239,10 +239,10 @@ for V in spacelist
239239 @testset " truncated SVD" begin
240240 for T in eltypes,
241241 t in (
242- CUDA . randn (T, W, W), CUDA . randn (T, W, W)' ,
243- CUDA . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
244- CUDA . randn (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . randn (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
245- DiagonalTensorMap (CUDA . randn (T, reduceddim (V1)), V1),
242+ cuRAND . randn (T, W, W), cuRAND . randn (T, W, W)' ,
243+ cuRAND . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
244+ cuRAND . randn (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . randn (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
245+ DiagonalTensorMap (cuRAND . randn (T, reduceddim (V1)), V1),
246246 )
247247
248248 @constinferred normalize! (t)
@@ -307,10 +307,10 @@ for V in spacelist
307307 @testset " Eigenvalue decomposition" begin
308308 for T in eltypes,
309309 t in (
310- CUDA . rand (T, V1, V1),
311- CUDA . rand (T, W, W),
312- CUDA . rand (T, W, W)' ,
313- # DiagonalTensorMap(CUDA .rand(T, reduceddim(V1)), V1),
310+ cuRAND . rand (T, V1, V1),
311+ cuRAND . rand (T, W, W),
312+ cuRAND . rand (T, W, W)' ,
313+ # DiagonalTensorMap(cuRAND .rand(T, reduceddim(V1)), V1),
314314 )
315315
316316 d, v = @constinferred eig_full (t)
@@ -367,15 +367,15 @@ for V in spacelist
367367 @testset " Condition number and rank" begin
368368 for T in eltypes,
369369 t in (
370- CUDA . rand (T, W, W), CUDA . rand (T, W, W)' ,
371- CUDA . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
372- CUDA . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), CUDA . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
373- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
370+ cuRAND . rand (T, W, W), cuRAND . rand (T, W, W)' ,
371+ cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
372+ cuRAND . rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), cuRAND . rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
373+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
374374 )
375375
376376 d1, d2 = dim (codomain (t)), dim (domain (t))
377377 r = rank (t)
378- @test r == min (d1, d2)
378+ @test r ≈ min (d1, d2)
379379 @test typeof (r) == typeof (d1)
380380 M = left_null (t)
381381 @test @constinferred (rank (M)) + r ≈ d1
@@ -387,15 +387,15 @@ for V in spacelist
387387 @test @constinferred (cond (u)) ≈ one (real (T))
388388 @test @constinferred (rank (u)) == dim (V1 ⊗ V2)
389389
390- t = CUDA . rand (T, zerospace (V1), W)
390+ t = cuRAND . rand (T, zerospace (V1), W)
391391 @test rank (t) == 0
392- t2 = CUDA . rand (T, zerospace (V1) * zerospace (V2), zerospace (V1) * zerospace (V2))
392+ t2 = cuRAND . rand (T, zerospace (V1) * zerospace (V2), zerospace (V1) * zerospace (V2))
393393 @test rank (t2) == 0
394394 @test cond (t2) == 0.0
395395 end
396396 for T in eltypes, t in (
397- CUDA . rand (T, W, W),
398- CUDA . rand (T, W, W)' ,
397+ cuRAND . rand (T, W, W),
398+ cuRAND . rand (T, W, W)' ,
399399 )
400400 project_hermitian! (t)
401401 vals = @constinferred LinearAlgebra. eigvals (t)
@@ -408,10 +408,10 @@ for V in spacelist
408408 @testset " Hermitian projections" begin
409409 for T in eltypes,
410410 t in (
411- CUDA . rand (T, V1, V1),
412- CUDA . rand (T, W, W),
413- CUDA . rand (T, W, W)' ,
414- DiagonalTensorMap (CUDA . rand (T, reduceddim (V1)), V1),
411+ cuRAND . rand (T, V1, V1),
412+ cuRAND . rand (T, W, W),
413+ cuRAND . rand (T, W, W)' ,
414+ DiagonalTensorMap (cuRAND . rand (T, reduceddim (V1)), V1),
415415 )
416416 normalize! (t)
417417 noisefactor = eps (real (T))^ (3 / 4 )
@@ -441,10 +441,10 @@ for V in spacelist
441441 @testset " Isometric projections" begin
442442 for T in eltypes,
443443 t in (
444- CUDA . randn (T, W, W),
445- CUDA . randn (T, W, W)' ,
446- CUDA . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
447- CUDA . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
444+ cuRAND . randn (T, W, W),
445+ cuRAND . randn (T, W, W)' ,
446+ cuRAND . randn (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
447+ cuRAND . randn (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
448448 )
449449 t2 = project_isometric (t)
450450 @test isisometric (t2)
@@ -459,7 +459,7 @@ for V in spacelist
459459
460460 # test that t2 is closer to A then any other isometry
461461 for k in 1 : 10
462- δt = CUDA . randn! (similar (t))
462+ δt = cuRAND . randn! (similar (t))
463463 t3 = project_isometric (t + δt / 100 )
464464 @test norm (t - t3) > norm (t - t2)
465465 end
0 commit comments