Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 524:41c1760a7770 feature/inflated_tensormapping_transpose
Merge refactor/inflated_tensormapping_tests
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 25 Nov 2020 15:10:46 +0100 |
parents | fe86ac896377 390901860b0a |
children | be152486d136 |
comparison
equal
deleted
inserted
replaced
520:fe86ac896377 | 524:41c1760a7770 |
---|---|
362 @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) | 362 @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) |
363 @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) | 363 @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) |
364 end | 364 end |
365 | 365 |
366 @testset "Application" begin | 366 @testset "Application" begin |
367 # Test InflatedTensorMapping mapping w. before and after | 367 tests = [ |
368 tm = InflatedTensorMapping(I(3,2), A, I(4)) | 368 ( |
369 v = rand(domain_size(tm)...) | 369 InflatedTensorMapping(I(3,2), A, I(4)), |
370 @tullio IAIv[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]), |
371 @test tm*v ≈ IAIv rtol=1e-14 | 371 ), |
372 | 372 ( |
373 # Test InflatedTensorMapping mapping w. before | 373 InflatedTensorMapping(I(3,2), B, I(4)), |
374 tm = InflatedTensorMapping(I(3,2), A) | 374 (v-> @tullio res[a,b,c,d,e] := B̃[c,d,i]*v[a,b,i,e]), |
375 v = rand(domain_size(tm)...) | 375 ), |
376 @tullio IAIv[a,b,c] := Ã[c,i]*v[a,b,i] | 376 ( |
377 @test tm*v ≈ IAIv rtol=1e-14 | 377 InflatedTensorMapping(I(3,2), C, I(4)), |
378 | 378 (v-> @tullio res[a,b,c,d] := C̃[c,i,j]*v[a,b,i,j,d]), |
379 # Test InflatedTensorMapping mapping w. after | 379 ), |
380 tm = InflatedTensorMapping(A,I(4)) | 380 ( |
381 v = rand(domain_size(tm)...) | 381 InflatedTensorMapping(I(3,2), A), |
382 @tullio IAIv[c,d] := Ã[c,i]*v[i,d] | 382 (v-> @tullio res[a,b,c] := Ã[c,i]*v[a,b,i]), |
383 @test tm*v ≈ IAIv rtol=1e-14 | 383 ), |
384 ( | |
385 InflatedTensorMapping(I(3,2), B), | |
386 (v-> @tullio res[a,b,c,d] := B̃[c,d,i]*v[a,b,i]), | |
387 ), | |
388 ( | |
389 InflatedTensorMapping(I(3,2), C), | |
390 (v-> @tullio res[a,b,c] := C̃[c,i,j]*v[a,b,i,j]), | |
391 ), | |
392 ( | |
393 InflatedTensorMapping(A,I(4)), | |
394 (v-> @tullio res[a,b] := Ã[a,i]*v[i,b]), | |
395 ), | |
396 ( | |
397 InflatedTensorMapping(B,I(4)), | |
398 (v-> @tullio res[a,b,c] := B̃[a,b,i]*v[i,c]), | |
399 ), | |
400 ( | |
401 InflatedTensorMapping(C,I(4)), | |
402 (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]), | |
403 ), | |
404 ] | |
405 | |
406 for i ∈ 1:length(tests) | |
407 tm = tests[i][1] | |
408 v = rand(domain_size(tm)...) | |
409 true_value = tests[i][2](v) | |
410 @test tm*v ≈ true_value rtol=1e-14 | |
411 end | |
384 | 412 |
385 @testset "Inference of application" begin | 413 @testset "Inference of application" begin |
386 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} | 414 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} |
387 λ::T | 415 λ::T |
388 size::NTuple{D,Int} | 416 size::NTuple{D,Int} |