Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 470:0c3decc04649 feature/outer_product
Add some tests and fix some bugs
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 25 Oct 2020 14:01:27 +0100 |
parents | 481e86e77c22 |
children | 1b9af062ba2c |
comparison
equal
deleted
inserted
replaced
469:481e86e77c22 | 470:0c3decc04649 |
---|---|
385 @test LazyTensors.flatten_tuple(((1,2),(3,4),(5,),6)) == (1,2,3,4,5,6) | 385 @test LazyTensors.flatten_tuple(((1,2),(3,4),(5,),6)) == (1,2,3,4,5,6) |
386 end | 386 end |
387 | 387 |
388 | 388 |
389 @testset "LazyIdentityOuterProduct" begin | 389 @testset "LazyIdentityOuterProduct" begin |
390 | 390 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} |
391 | 391 λ::T |
392 end | 392 size::NTuple{D,Int} |
393 | 393 end |
394 end | 394 |
395 LazyTensors.apply(m::ScalingOperator{T,D}, v, I::Vararg{Index,D}) where {T,D} = m.λ*v[I] | |
396 LazyTensors.range_size(m::ScalingOperator) = m.size | |
397 LazyTensors.domain_size(m::ScalingOperator) = m.size | |
398 | |
399 A = ScalingOperator(2.0, (5,)) | |
400 B = ScalingOperator(3.0, (3,)) | |
401 C = ScalingOperator(5.0, (3,2)) | |
402 | |
403 AB = LazyOuterProduct(A,B) | |
404 @test AB isa TensorMapping{T,2,2} where T | |
405 @test range_size(AB) == (5,3) | |
406 @test domain_size(AB) == (5,3) | |
407 | |
408 v = rand(range_size(AB)...) | |
409 @test AB*v == 6*v | |
410 | |
411 ABC = LazyOuterProduct(A,B,C) | |
412 | |
413 @test ABC isa TensorMapping{T,4,4} where T | |
414 @test range_size(ABC) == (5,3,3,2) | |
415 @test domain_size(ABC) == (5,3,3,2) | |
416 | |
417 @test A⊗B == AB | |
418 @test A⊗B⊗C == ABC | |
419 | |
420 # TODO: Include some tests where the domain has different size and dimension | |
421 | |
422 end | |
423 | |
424 end |