Mercurial > repos > public > sbplib_julia
changeset 491:2dc2eac27f75 feature/outer_product
Add special methods for Identity mappings
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 05 Nov 2020 12:48:30 +0100 |
parents | 79a88269d7d0 |
children | 5a600ec40ccc |
files | src/LazyTensors/lazy_tensor_operations.jl test/testLazyTensors.jl |
diffstat | 2 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl Mon Nov 02 22:12:24 2020 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Thu Nov 05 12:48:30 2020 +0100 @@ -324,6 +324,10 @@ return itm1∘itm2 end +LazyOuterProduct(t1::IdentityMapping{T}, t2::IdentityMapping{T}) where T = IdentityMapping{T}(t1.size...,t2.size...) +LazyOuterProduct(t1::TensorMapping, t2::IdentityMapping) = InflatedTensorMapping(t1, t2) +LazyOuterProduct(t1::IdentityMapping, t2::TensorMapping) = InflatedTensorMapping(t1, t2) + LazyOuterProduct(tms::Vararg{TensorMapping}) = foldl(LazyOuterProduct, tms) ⊗(a::TensorMapping, b::TensorMapping) = LazyOuterProduct(a,b)
--- a/test/testLazyTensors.jl Mon Nov 02 22:12:24 2020 +0100 +++ b/test/testLazyTensors.jl Thu Nov 05 12:48:30 2020 +0100 @@ -447,6 +447,14 @@ @tullio BAv[k,i] := A[i,j]*B[k,l,m]*v₂[l,m,j] @test B̃Ã*v₂ ≈ BAv + @testset "Indentity mapping arguments" begin + @test LazyOuterProduct(IdentityMapping(3,2), IdentityMapping(1,2)) == IdentityMapping(3,2,1,2) + + Ã = LazyLinearMap(A,(1,),(2,)) + @test LazyOuterProduct(IdentityMapping(3,2), Ã) == InflatedTensorMapping(IdentityMapping(3,2),Ã) + @test LazyOuterProduct(Ã, IdentityMapping(3,2)) == InflatedTensorMapping(Ã,IdentityMapping(3,2)) + end + end end