Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 526:be152486d136 feature/inflated_tensormapping_transpose
Implement apply_transpose with tests
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 25 Nov 2020 15:59:04 +0100 |
parents | 41c1760a7770 |
children | 588a843907de |
comparison
equal
deleted
inserted
replaced
525:7e6250c51eb2 | 526:be152486d136 |
---|---|
365 | 365 |
366 @testset "Application" begin | 366 @testset "Application" begin |
367 tests = [ | 367 tests = [ |
368 ( | 368 ( |
369 InflatedTensorMapping(I(3,2), A, I(4)), | 369 InflatedTensorMapping(I(3,2), A, I(4)), |
370 (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]), | 370 (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]), # Expected result of apply |
371 (v-> @tullio res[a,b,c,d] := Ã[i,c]*v[a,b,i,d]), # Expected result of apply_transpose | |
371 ), | 372 ), |
372 ( | 373 ( |
373 InflatedTensorMapping(I(3,2), B, I(4)), | 374 InflatedTensorMapping(I(3,2), B, I(4)), |
374 (v-> @tullio res[a,b,c,d,e] := B̃[c,d,i]*v[a,b,i,e]), | 375 (v-> @tullio res[a,b,c,d,e] := B̃[c,d,i]*v[a,b,i,e]), |
376 (v-> @tullio res[a,b,c,d] := B̃[i,j,c]*v[a,b,i,j,d]), | |
375 ), | 377 ), |
376 ( | 378 ( |
377 InflatedTensorMapping(I(3,2), C, I(4)), | 379 InflatedTensorMapping(I(3,2), C, I(4)), |
378 (v-> @tullio res[a,b,c,d] := C̃[c,i,j]*v[a,b,i,j,d]), | 380 (v-> @tullio res[a,b,c,d] := C̃[c,i,j]*v[a,b,i,j,d]), |
381 (v-> @tullio res[a,b,c,d,e] := C̃[i,c,d]*v[a,b,i,e]), | |
379 ), | 382 ), |
380 ( | 383 ( |
381 InflatedTensorMapping(I(3,2), A), | 384 InflatedTensorMapping(I(3,2), A), |
382 (v-> @tullio res[a,b,c] := Ã[c,i]*v[a,b,i]), | 385 (v-> @tullio res[a,b,c] := Ã[c,i]*v[a,b,i]), |
386 (v-> @tullio res[a,b,c] := Ã[i,c]*v[a,b,i]), | |
383 ), | 387 ), |
384 ( | 388 ( |
385 InflatedTensorMapping(I(3,2), B), | 389 InflatedTensorMapping(I(3,2), B), |
386 (v-> @tullio res[a,b,c,d] := B̃[c,d,i]*v[a,b,i]), | 390 (v-> @tullio res[a,b,c,d] := B̃[c,d,i]*v[a,b,i]), |
391 (v-> @tullio res[a,b,c] := B̃[i,j,c]*v[a,b,i,j]), | |
387 ), | 392 ), |
388 ( | 393 ( |
389 InflatedTensorMapping(I(3,2), C), | 394 InflatedTensorMapping(I(3,2), C), |
390 (v-> @tullio res[a,b,c] := C̃[c,i,j]*v[a,b,i,j]), | 395 (v-> @tullio res[a,b,c] := C̃[c,i,j]*v[a,b,i,j]), |
396 (v-> @tullio res[a,b,c,d] := C̃[i,c,d]*v[a,b,i]), | |
391 ), | 397 ), |
392 ( | 398 ( |
393 InflatedTensorMapping(A,I(4)), | 399 InflatedTensorMapping(A,I(4)), |
394 (v-> @tullio res[a,b] := Ã[a,i]*v[i,b]), | 400 (v-> @tullio res[a,b] := Ã[a,i]*v[i,b]), |
401 (v-> @tullio res[a,b] := Ã[i,a]*v[i,b]), | |
395 ), | 402 ), |
396 ( | 403 ( |
397 InflatedTensorMapping(B,I(4)), | 404 InflatedTensorMapping(B,I(4)), |
398 (v-> @tullio res[a,b,c] := B̃[a,b,i]*v[i,c]), | 405 (v-> @tullio res[a,b,c] := B̃[a,b,i]*v[i,c]), |
406 (v-> @tullio res[a,b] := B̃[i,j,a]*v[i,j,b]), | |
399 ), | 407 ), |
400 ( | 408 ( |
401 InflatedTensorMapping(C,I(4)), | 409 InflatedTensorMapping(C,I(4)), |
402 (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]), | 410 (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]), |
411 (v-> @tullio res[a,b,c] := C̃[i,a,b]*v[i,c]), | |
403 ), | 412 ), |
404 ] | 413 ] |
405 | 414 |
406 for i ∈ 1:length(tests) | 415 @testset "apply" begin |
407 tm = tests[i][1] | 416 for i ∈ 1:length(tests) |
408 v = rand(domain_size(tm)...) | 417 tm = tests[i][1] |
409 true_value = tests[i][2](v) | 418 v = rand(domain_size(tm)...) |
410 @test tm*v ≈ true_value rtol=1e-14 | 419 true_value = tests[i][2](v) |
420 @test tm*v ≈ true_value rtol=1e-14 | |
421 end | |
422 end | |
423 | |
424 @testset "apply_transpose" begin | |
425 for i ∈ 1:length(tests) | |
426 tm = tests[i][1] | |
427 v = rand(range_size(tm)...) | |
428 true_value = tests[i][3](v) | |
429 @test tm'*v ≈ true_value rtol=1e-14 | |
430 end | |
411 end | 431 end |
412 | 432 |
413 @testset "Inference of application" begin | 433 @testset "Inference of application" begin |
414 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} | 434 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} |
415 λ::T | 435 λ::T |