Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 508:27e64b3d3efa
Restructure tests for InflatedTensorMapping
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 23 Nov 2020 21:15:04 +0100 |
parents | 1c50b5f1b356 |
children | fe86ac896377 3968210797a9 |
comparison
equal
deleted
inserted
replaced
503:fbbb3733650c | 508:27e64b3d3efa |
---|---|
338 | 338 |
339 A = LazyLinearMap(Ã,(1,),(2,)) | 339 A = LazyLinearMap(Ã,(1,),(2,)) |
340 B = LazyLinearMap(B̃,(1,2),(3,)) | 340 B = LazyLinearMap(B̃,(1,2),(3,)) |
341 C = LazyLinearMap(C̃,(1,),(2,3)) | 341 C = LazyLinearMap(C̃,(1,),(2,3)) |
342 | 342 |
343 @test InflatedTensorMapping(I(3,2), A, I(4)) isa TensorMapping{Float64, 4, 4} | 343 @testset "Constructors" begin |
344 @test InflatedTensorMapping(I(3,2), B, I(4)) isa TensorMapping{Float64, 5, 4} | 344 @test InflatedTensorMapping(I(3,2), A, I(4)) isa TensorMapping{Float64, 4, 4} |
345 @test InflatedTensorMapping(I(3), C, I(2,3)) isa TensorMapping{Float64, 4, 5} | 345 @test InflatedTensorMapping(I(3,2), B, I(4)) isa TensorMapping{Float64, 5, 4} |
346 @test InflatedTensorMapping(C, I(2,3)) isa TensorMapping{Float64, 3, 4} | 346 @test InflatedTensorMapping(I(3), C, I(2,3)) isa TensorMapping{Float64, 4, 5} |
347 @test InflatedTensorMapping(I(3), C) isa TensorMapping{Float64, 2, 3} | 347 @test InflatedTensorMapping(C, I(2,3)) isa TensorMapping{Float64, 3, 4} |
348 @test InflatedTensorMapping(I(3), I(2,3)) isa TensorMapping{Float64, 3, 3} | 348 @test InflatedTensorMapping(I(3), C) isa TensorMapping{Float64, 2, 3} |
349 | 349 @test InflatedTensorMapping(I(3), I(2,3)) isa TensorMapping{Float64, 3, 3} |
350 @test range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) | 350 end |
351 @test domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) | 351 |
352 | 352 @testset "Range and domain size" begin |
353 @test range_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,4,2,4) | 353 @test range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) |
354 @test domain_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,3,4) | 354 @test domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) |
355 | 355 |
356 @test range_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,4,2,3) | 356 @test range_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,4,2,4) |
357 @test domain_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,2,3,2,3) | 357 @test domain_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,3,4) |
358 | 358 |
359 @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) | 359 @test range_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,4,2,3) |
360 @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) | 360 @test domain_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,2,3,2,3) |
361 | 361 |
362 # Test InflatedTensorMapping mapping w. before and after | 362 @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) |
363 tm = InflatedTensorMapping(I(3,2), A, I(4)) | 363 @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) |
364 v = rand(domain_size(tm)...) | 364 end |
365 @tullio IAIv[a,b,c,d] := Ã[c,i]*v[a,b,i,d] | 365 |
366 @test tm*v ≈ IAIv rtol=1e-14 | 366 @testset "Application" begin |
367 @inferred LazyTensors.split_index(tm,1,1,1,1) | 367 # Test InflatedTensorMapping mapping w. before and after |
368 | 368 tm = InflatedTensorMapping(I(3,2), A, I(4)) |
369 # Test InflatedTensorMapping mapping w. before | 369 v = rand(domain_size(tm)...) |
370 tm = InflatedTensorMapping(I(3,2), A) | 370 @tullio IAIv[a,b,c,d] := Ã[c,i]*v[a,b,i,d] |
371 v = rand(domain_size(tm)...) | 371 @test tm*v ≈ IAIv rtol=1e-14 |
372 @tullio IAIv[a,b,c] := Ã[c,i]*v[a,b,i] | 372 @inferred LazyTensors.split_index(tm,1,1,1,1) |
373 @test tm*v ≈ IAIv rtol=1e-14 | 373 |
374 @inferred LazyTensors.split_index(tm,1,1,1) | 374 # Test InflatedTensorMapping mapping w. before |
375 | 375 tm = InflatedTensorMapping(I(3,2), A) |
376 # Test InflatedTensorMapping mapping w. after | 376 v = rand(domain_size(tm)...) |
377 tm = InflatedTensorMapping(A,I(4)) | 377 @tullio IAIv[a,b,c] := Ã[c,i]*v[a,b,i] |
378 v = rand(domain_size(tm)...) | 378 @test tm*v ≈ IAIv rtol=1e-14 |
379 @tullio IAIv[c,d] := Ã[c,i]*v[i,d] | 379 @inferred LazyTensors.split_index(tm,1,1,1) |
380 @test tm*v ≈ IAIv rtol=1e-14 | 380 |
381 @inferred LazyTensors.split_index(tm,1,1) | 381 # Test InflatedTensorMapping mapping w. after |
382 | 382 tm = InflatedTensorMapping(A,I(4)) |
383 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} | 383 v = rand(domain_size(tm)...) |
384 λ::T | 384 @tullio IAIv[c,d] := Ã[c,i]*v[i,d] |
385 size::NTuple{D,Int} | 385 @test tm*v ≈ IAIv rtol=1e-14 |
386 end | 386 @inferred LazyTensors.split_index(tm,1,1) |
387 | 387 |
388 LazyTensors.apply(m::ScalingOperator{T,D}, v, I::Vararg{Index,D}) where {T,D} = m.λ*v[I] | 388 @testset "Inference of application" begin |
389 LazyTensors.range_size(m::ScalingOperator) = m.size | 389 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} |
390 LazyTensors.domain_size(m::ScalingOperator) = m.size | 390 λ::T |
391 | 391 size::NTuple{D,Int} |
392 tm = InflatedTensorMapping(I(2,3),ScalingOperator(2.0, (3,2)),I(3,4)) | 392 end |
393 v = rand(domain_size(tm)...) | 393 |
394 | 394 LazyTensors.apply(m::ScalingOperator{T,D}, v, I::Vararg{Index,D}) where {T,D} = m.λ*v[I] |
395 @inferred LazyTensors.split_index(tm,1,2,3,2,2,4) | 395 LazyTensors.range_size(m::ScalingOperator) = m.size |
396 @inferred apply(tm,v,Index{Unknown}.((1,2,3,2,2,4))...) | 396 LazyTensors.domain_size(m::ScalingOperator) = m.size |
397 @inferred (tm*v)[1,2,3,2,2,4] | 397 |
398 tm = InflatedTensorMapping(I(2,3),ScalingOperator(2.0, (3,2)),I(3,4)) | |
399 v = rand(domain_size(tm)...) | |
400 | |
401 @inferred LazyTensors.split_index(tm,1,2,3,2,2,4) | |
402 @inferred apply(tm,v,Index{Unknown}.((1,2,3,2,2,4))...) | |
403 @inferred (tm*v)[1,2,3,2,2,4] | |
404 end | |
405 end | |
398 | 406 |
399 @testset "InflatedTensorMapping of InflatedTensorMapping" begin | 407 @testset "InflatedTensorMapping of InflatedTensorMapping" begin |
400 A = ScalingOperator(2.0,(2,3)) | 408 A = ScalingOperator(2.0,(2,3)) |
401 itm = InflatedTensorMapping(I(3,2), A, I(4)) | 409 itm = InflatedTensorMapping(I(3,2), A, I(4)) |
402 @test InflatedTensorMapping(I(4), itm, I(2)) == InflatedTensorMapping(I(4,3,2), A, I(4,2)) | 410 @test InflatedTensorMapping(I(4), itm, I(2)) == InflatedTensorMapping(I(4,3,2), A, I(4,2)) |
403 @test InflatedTensorMapping(itm, I(2)) == InflatedTensorMapping(I(3,2), A, I(4,2)) | 411 @test InflatedTensorMapping(itm, I(2)) == InflatedTensorMapping(I(3,2), A, I(4,2)) |
404 @test InflatedTensorMapping(I(4), itm) == InflatedTensorMapping(I(4,3,2), A, I(4)) | 412 @test InflatedTensorMapping(I(4), itm) == InflatedTensorMapping(I(4,3,2), A, I(4)) |
405 | 413 |
406 @test InflatedTensorMapping(I(2), I(2), I(2)) isa InflatedTensorMapping # The constructor should always return its type. | 414 @test InflatedTensorMapping(I(2), I(2), I(2)) isa InflatedTensorMapping # The constructor should always return its type. |
407 end | 415 end |
408 | |
409 end | 416 end |
410 | 417 |
411 @testset "slice_tuple" begin | 418 @testset "slice_tuple" begin |
412 @test LazyTensors.slice_tuple((1,2,3),Val(1), Val(3)) == (1,2,3) | 419 @test LazyTensors.slice_tuple((1,2,3),Val(1), Val(3)) == (1,2,3) |
413 @test LazyTensors.slice_tuple((1,2,3,4,5,6),Val(2), Val(5)) == (2,3,4,5) | 420 @test LazyTensors.slice_tuple((1,2,3,4,5,6),Val(2), Val(5)) == (2,3,4,5) |