comparison test/testLazyTensors.jl @ 535:b6768d769f46

Merge refactor/inflated_tensormapping_tests
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 26 Nov 2020 17:20:22 +0100
parents dfad4c16bedb
children fc0f942b8792
comparison
equal deleted inserted replaced
521:afdfb027e439 535:b6768d769f46
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 # Testing regular application and transposed application with inflation "before", "after" and "before and after".
368 tm = InflatedTensorMapping(I(3,2), A, I(4)) 368 # The inflated tensor mappings are chosen to preserve, reduce and increase the dimension of the result compared to the input.
369 v = rand(domain_size(tm)...) 369 tests = [
370 @tullio IAIv[a,b,c,d] := Ã[c,i]*v[a,b,i,d] 370 (
371 @test tm*v ≈ IAIv rtol=1e-14 371 InflatedTensorMapping(I(3,2), A, I(4)),
372 @inferred LazyTensors.split_index(tm,1,1,1,1) 372 (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]),
373 373 ),
374 # Test InflatedTensorMapping mapping w. before 374 (
375 tm = InflatedTensorMapping(I(3,2), A) 375 InflatedTensorMapping(I(3,2), B, I(4)),
376 v = rand(domain_size(tm)...) 376 (v-> @tullio res[a,b,c,d,e] := B̃[c,d,i]*v[a,b,i,e]),
377 @tullio IAIv[a,b,c] := Ã[c,i]*v[a,b,i] 377 ),
378 @test tm*v ≈ IAIv rtol=1e-14 378 (
379 @inferred LazyTensors.split_index(tm,1,1,1) 379 InflatedTensorMapping(I(3,2), C, I(4)),
380 380 (v-> @tullio res[a,b,c,d] := C̃[c,i,j]*v[a,b,i,j,d]),
381 # Test InflatedTensorMapping mapping w. after 381 ),
382 tm = InflatedTensorMapping(A,I(4)) 382 (
383 v = rand(domain_size(tm)...) 383 InflatedTensorMapping(I(3,2), A),
384 @tullio IAIv[c,d] := Ã[c,i]*v[i,d] 384 (v-> @tullio res[a,b,c] := Ã[c,i]*v[a,b,i]),
385 @test tm*v ≈ IAIv rtol=1e-14 385 ),
386 @inferred LazyTensors.split_index(tm,1,1) 386 (
387 InflatedTensorMapping(I(3,2), B),
388 (v-> @tullio res[a,b,c,d] := B̃[c,d,i]*v[a,b,i]),
389 ),
390 (
391 InflatedTensorMapping(I(3,2), C),
392 (v-> @tullio res[a,b,c] := C̃[c,i,j]*v[a,b,i,j]),
393 ),
394 (
395 InflatedTensorMapping(A,I(4)),
396 (v-> @tullio res[a,b] := Ã[a,i]*v[i,b]),
397 ),
398 (
399 InflatedTensorMapping(B,I(4)),
400 (v-> @tullio res[a,b,c] := B̃[a,b,i]*v[i,c]),
401 ),
402 (
403 InflatedTensorMapping(C,I(4)),
404 (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]),
405 ),
406 ]
407
408 for i ∈ 1:length(tests)
409 tm = tests[i][1]
410 v = rand(domain_size(tm)...)
411 true_value = tests[i][2](v)
412 @test tm*v ≈ true_value rtol=1e-14
413 end
387 414
388 @testset "Inference of application" begin 415 @testset "Inference of application" begin
389 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} 416 struct ScalingOperator{T,D} <: TensorMapping{T,D,D}
390 λ::T 417 λ::T
391 size::NTuple{D,Int} 418 size::NTuple{D,Int}