Mercurial > repos > public > sbplib_julia
changeset 1017:6abbb2c6c3e4 refactor/lazy_tensors
Remove the Lazy prefix on some types
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 21 Mar 2022 15:22:22 +0100 |
parents | 5c8c148c56a3 |
children | 9e76bf19904c |
files | TODO.md src/LazyTensors/LazyTensors.jl src/LazyTensors/lazy_tensor_operations.jl src/LazyTensors/tensor_types.jl test/LazyTensors/lazy_tensor_operations_test.jl test/LazyTensors/tensor_types_test.jl test/SbpOperators/boundaryops/boundary_operator_test.jl test/SbpOperators/boundaryops/boundary_restriction_test.jl |
diffstat | 8 files changed, 115 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/TODO.md Mon Mar 21 13:19:53 2022 +0100 +++ b/TODO.md Mon Mar 21 15:22:22 2022 +0100 @@ -12,7 +12,7 @@ - [ ] Make sure we are setting tolerances in tests in a consistent way - [ ] Add check for correct domain sizes to lazy tensor operations using SizeMismatch - [ ] Write down some coding guideline or checklist for code conventions. For example i,j,... for indices and I for multi-index - - [ ] Add boundschecking in LazyTensorApplication + - [ ] Add boundschecking in TensorApplication - [ ] Start renaming things in LazyTensors - [ ] Clean up RegionIndices 1. [ ] Write tests for how things should work
--- a/src/LazyTensors/LazyTensors.jl Mon Mar 21 13:19:53 2022 +0100 +++ b/src/LazyTensors/LazyTensors.jl Mon Mar 21 15:22:22 2022 +0100 @@ -1,12 +1,12 @@ module LazyTensors -export LazyTensorApplication +export TensorApplication export LazyTensorTranspose -export LazyTensorComposition -export LazyLinearMap +export TensorComposition +export DenseTensor export IdentityTensor export ScalingTensor -export InflatedLazyTensor +export InflatedTensor export LazyOuterProduct export ⊗ export DomainSizeMismatch @@ -19,7 +19,7 @@ include("tuple_manipulation.jl") # Applying lazy tensors to vectors -Base.:*(a::LazyTensor, v::AbstractArray) = LazyTensorApplication(a,v) +Base.:*(a::LazyTensor, v::AbstractArray) = TensorApplication(a,v) Base.:*(a::LazyTensor, b::LazyTensor) = throw(MethodError(Base.:*,(a,b))) Base.:*(a::LazyTensor, args::Union{LazyTensor, AbstractArray}...) = foldr(*,(a,args...)) @@ -28,7 +28,7 @@ Base.:-(s::LazyTensor, t::LazyTensor) = LazyTensorBinaryOperation{:-}(s,t) # Composing lazy tensors -Base.:∘(s::LazyTensor, t::LazyTensor) = LazyTensorComposition(s,t) +Base.:∘(s::LazyTensor, t::LazyTensor) = TensorComposition(s,t) # Outer products of tensors ⊗(a::LazyTensor, b::LazyTensor) = LazyOuterProduct(a,b)
--- a/src/LazyTensors/lazy_tensor_operations.jl Mon Mar 21 13:19:53 2022 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Mon Mar 21 15:22:22 2022 +0100 @@ -1,17 +1,17 @@ """ - LazyTensorApplication{T,R,D} <: LazyArray{T,R} + TensorApplication{T,R,D} <: LazyArray{T,R} Struct for lazy application of a LazyTensor. Created using `*`. Allows the result of a `LazyTensor` applied to a vector to be treated as an `AbstractArray`. -With a mapping `m` and a vector `v` the LazyTensorApplication object can be created by `m*v`. +With a mapping `m` and a vector `v` the TensorApplication object can be created by `m*v`. The actual result will be calcualted when indexing into `m*v`. """ -struct LazyTensorApplication{T,R,D, TM<:LazyTensor{<:Any,R,D}, AA<:AbstractArray{<:Any,D}} <: LazyArray{T,R} +struct TensorApplication{T,R,D, TM<:LazyTensor{<:Any,R,D}, AA<:AbstractArray{<:Any,D}} <: LazyArray{T,R} t::TM o::AA - function LazyTensorApplication(t::LazyTensor{<:Any,R,D}, o::AbstractArray{<:Any,D}) where {R,D} + function TensorApplication(t::LazyTensor{<:Any,R,D}, o::AbstractArray{<:Any,D}) where {R,D} @boundscheck check_domain_size(t, size(o)) I = ntuple(i->1, range_dim(t)) T = typeof(apply(t,o,I...)) @@ -19,12 +19,12 @@ end end -function Base.getindex(ta::LazyTensorApplication{T,R}, I::Vararg{Any,R}) where {T,R} +function Base.getindex(ta::TensorApplication{T,R}, I::Vararg{Any,R}) where {T,R} @boundscheck checkbounds(ta, Int.(I)...) return @inbounds apply(ta.t, ta.o, I...) end -Base.@propagate_inbounds Base.getindex(ta::LazyTensorApplication{T,1} where T, I::CartesianIndex{1}) = ta[Tuple(I)...] # Would otherwise be caught in the previous method. -Base.size(ta::LazyTensorApplication) = range_size(ta.t) +Base.@propagate_inbounds Base.getindex(ta::TensorApplication{T,1} where T, I::CartesianIndex{1}) = ta[Tuple(I)...] # Would otherwise be caught in the previous method. +Base.size(ta::TensorApplication) = range_size(ta.t) """ @@ -73,65 +73,65 @@ """ - LazyTensorComposition{T,R,K,D} + TensorComposition{T,R,K,D} Lazily compose two `LazyTensor`s, so that they can be handled as a single `LazyTensor`. """ -struct LazyTensorComposition{T,R,K,D, TM1<:LazyTensor{T,R,K}, TM2<:LazyTensor{T,K,D}} <: LazyTensor{T,R,D} +struct TensorComposition{T,R,K,D, TM1<:LazyTensor{T,R,K}, TM2<:LazyTensor{T,K,D}} <: LazyTensor{T,R,D} t1::TM1 t2::TM2 - function LazyTensorComposition(t1::LazyTensor{T,R,K}, t2::LazyTensor{T,K,D}) where {T,R,K,D} + function TensorComposition(t1::LazyTensor{T,R,K}, t2::LazyTensor{T,K,D}) where {T,R,K,D} @boundscheck check_domain_size(t1, range_size(t2)) return new{T,R,K,D, typeof(t1), typeof(t2)}(t1,t2) end end -range_size(tm::LazyTensorComposition) = range_size(tm.t1) -domain_size(tm::LazyTensorComposition) = domain_size(tm.t2) +range_size(tm::TensorComposition) = range_size(tm.t1) +domain_size(tm::TensorComposition) = domain_size(tm.t2) -function apply(c::LazyTensorComposition{T,R,K,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,K,D} +function apply(c::TensorComposition{T,R,K,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,K,D} apply(c.t1, c.t2*v, I...) end -function apply_transpose(c::LazyTensorComposition{T,R,K,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,K,D} +function apply_transpose(c::TensorComposition{T,R,K,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,K,D} apply_transpose(c.t2, c.t1'*v, I...) end """ - LazyTensorComposition(tm, tmi::IdentityTensor) - LazyTensorComposition(tmi::IdentityTensor, tm) + TensorComposition(tm, tmi::IdentityTensor) + TensorComposition(tmi::IdentityTensor, tm) Composes a `Tensormapping` `tm` with an `IdentityTensor` `tmi`, by returning `tm` """ -function LazyTensorComposition(tm::LazyTensor{T,R,D}, tmi::IdentityTensor{T,D}) where {T,R,D} +function TensorComposition(tm::LazyTensor{T,R,D}, tmi::IdentityTensor{T,D}) where {T,R,D} @boundscheck check_domain_size(tm, range_size(tmi)) return tm end -function LazyTensorComposition(tmi::IdentityTensor{T,R}, tm::LazyTensor{T,R,D}) where {T,R,D} +function TensorComposition(tmi::IdentityTensor{T,R}, tm::LazyTensor{T,R,D}) where {T,R,D} @boundscheck check_domain_size(tmi, range_size(tm)) return tm end # Specialization for the case where tm is an IdentityTensor. Required to resolve ambiguity. -function LazyTensorComposition(tm::IdentityTensor{T,D}, tmi::IdentityTensor{T,D}) where {T,D} +function TensorComposition(tm::IdentityTensor{T,D}, tmi::IdentityTensor{T,D}) where {T,D} @boundscheck check_domain_size(tm, range_size(tmi)) return tmi end """ - InflatedLazyTensor{T,R,D} <: LazyTensor{T,R,D} + InflatedTensor{T,R,D} <: LazyTensor{T,R,D} An inflated `LazyTensor` with dimensions added before and afer its actual dimensions. """ -struct InflatedLazyTensor{T,R,D,D_before,R_middle,D_middle,D_after, TM<:LazyTensor{T,R_middle,D_middle}} <: LazyTensor{T,R,D} +struct InflatedTensor{T,R,D,D_before,R_middle,D_middle,D_after, TM<:LazyTensor{T,R_middle,D_middle}} <: LazyTensor{T,R,D} before::IdentityTensor{T,D_before} tm::TM after::IdentityTensor{T,D_after} - function InflatedLazyTensor(before, tm::LazyTensor{T}, after) where T + function InflatedTensor(before, tm::LazyTensor{T}, after) where T R_before = range_dim(before) R_middle = range_dim(tm) R_after = range_dim(after) @@ -146,35 +146,35 @@ end """ - InflatedLazyTensor(before, tm, after) - InflatedLazyTensor(before,tm) - InflatedLazyTensor(tm,after) + InflatedTensor(before, tm, after) + InflatedTensor(before,tm) + InflatedTensor(tm,after) The outer product of `before`, `tm` and `after`, where `before` and `after` are `IdentityTensor`s. If one of `before` or `after` is left out, a 0-dimensional `IdentityTensor` is used as the default value. -If `tm` already is an `InflatedLazyTensor`, `before` and `after` will be extended instead of -creating a nested `InflatedLazyTensor`. +If `tm` already is an `InflatedTensor`, `before` and `after` will be extended instead of +creating a nested `InflatedTensor`. """ -InflatedLazyTensor(::IdentityTensor, ::LazyTensor, ::IdentityTensor) +InflatedTensor(::IdentityTensor, ::LazyTensor, ::IdentityTensor) -function InflatedLazyTensor(before, itm::InflatedLazyTensor, after) - return InflatedLazyTensor( +function InflatedTensor(before, itm::InflatedTensor, after) + return InflatedTensor( IdentityTensor(before.size..., itm.before.size...), itm.tm, IdentityTensor(itm.after.size..., after.size...), ) end -InflatedLazyTensor(before::IdentityTensor, tm::LazyTensor{T}) where T = InflatedLazyTensor(before,tm,IdentityTensor{T}()) -InflatedLazyTensor(tm::LazyTensor{T}, after::IdentityTensor) where T = InflatedLazyTensor(IdentityTensor{T}(),tm,after) +InflatedTensor(before::IdentityTensor, tm::LazyTensor{T}) where T = InflatedTensor(before,tm,IdentityTensor{T}()) +InflatedTensor(tm::LazyTensor{T}, after::IdentityTensor) where T = InflatedTensor(IdentityTensor{T}(),tm,after) # Resolve ambiguity between the two previous methods -InflatedLazyTensor(I1::IdentityTensor{T}, I2::IdentityTensor{T}) where T = InflatedLazyTensor(I1,I2,IdentityTensor{T}()) +InflatedTensor(I1::IdentityTensor{T}, I2::IdentityTensor{T}) where T = InflatedTensor(I1,I2,IdentityTensor{T}()) -# TODO: Implement some pretty printing in terms of ⊗. E.g InflatedLazyTensor(I(3),B,I(2)) -> I(3)⊗B⊗I(2) +# TODO: Implement some pretty printing in terms of ⊗. E.g InflatedTensor(I(3),B,I(2)) -> I(3)⊗B⊗I(2) -function range_size(itm::InflatedLazyTensor) +function range_size(itm::InflatedTensor) return flatten_tuple( range_size(itm.before), range_size(itm.tm), @@ -182,7 +182,7 @@ ) end -function domain_size(itm::InflatedLazyTensor) +function domain_size(itm::InflatedTensor) return flatten_tuple( domain_size(itm.before), domain_size(itm.tm), @@ -190,7 +190,7 @@ ) end -function apply(itm::InflatedLazyTensor{T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} +function apply(itm::InflatedTensor{T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} dim_before = range_dim(itm.before) dim_domain = domain_dim(itm.tm) dim_range = range_dim(itm.tm) @@ -202,7 +202,7 @@ return apply(itm.tm, v_inner, inner_index...) end -function apply_transpose(itm::InflatedLazyTensor{T,R,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,D} +function apply_transpose(itm::InflatedTensor{T,R,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,D} dim_before = range_dim(itm.before) dim_domain = domain_dim(itm.tm) dim_range = range_dim(itm.tm) @@ -218,7 +218,7 @@ @doc raw""" LazyOuterProduct(tms...) -Creates a `LazyTensorComposition` for the outerproduct of `tms...`. +Creates a `TensorComposition` for the outerproduct of `tms...`. This is done by separating the outer product into regular products of outer products involving only identity mappings and one non-identity mapping. First let @@ -255,15 +255,15 @@ function LazyOuterProduct end function LazyOuterProduct(tm1::LazyTensor{T}, tm2::LazyTensor{T}) where T - itm1 = InflatedLazyTensor(tm1, IdentityTensor{T}(range_size(tm2))) - itm2 = InflatedLazyTensor(IdentityTensor{T}(domain_size(tm1)),tm2) + itm1 = InflatedTensor(tm1, IdentityTensor{T}(range_size(tm2))) + itm2 = InflatedTensor(IdentityTensor{T}(domain_size(tm1)),tm2) return itm1∘itm2 end LazyOuterProduct(t1::IdentityTensor{T}, t2::IdentityTensor{T}) where T = IdentityTensor{T}(t1.size...,t2.size...) -LazyOuterProduct(t1::LazyTensor, t2::IdentityTensor) = InflatedLazyTensor(t1, t2) -LazyOuterProduct(t1::IdentityTensor, t2::LazyTensor) = InflatedLazyTensor(t1, t2) +LazyOuterProduct(t1::LazyTensor, t2::IdentityTensor) = InflatedTensor(t1, t2) +LazyOuterProduct(t1::IdentityTensor, t2::LazyTensor) = InflatedTensor(t1, t2) LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms)
--- a/src/LazyTensors/tensor_types.jl Mon Mar 21 13:19:53 2022 +0100 +++ b/src/LazyTensors/tensor_types.jl Mon Mar 21 15:22:22 2022 +0100 @@ -2,7 +2,7 @@ IdentityTensor{T,D} <: LazyTensor{T,D,D} The lazy identity LazyTensor for a given size. Usefull for building up higher dimensional tensor mappings from lower -dimensional ones through outer products. Also used in the Implementation for InflatedLazyTensor. +dimensional ones through outer products. Also used in the Implementation for InflatedTensor. """ struct IdentityTensor{T,D} <: LazyTensor{T,D,D} size::NTuple{D,Int} @@ -37,20 +37,20 @@ """ - LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies) + DenseTensor{T,R,D,...}(A, range_indicies, domain_indicies) LazyTensor defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should be considerd the range and domain of the LazyTensor. Each set of indices must be ordered in ascending order. -For instance, if A is a m x n matrix, and range_size = (1,), domain_size = (2,), then the LazyLinearMap performs the +For instance, if A is a m x n matrix, and range_size = (1,), domain_size = (2,), then the DenseTensor performs the standard matrix-vector product on vectors of size n. """ -struct LazyLinearMap{T,R,D, RD, AA<:AbstractArray{T,RD}} <: LazyTensor{T,R,D} +struct DenseTensor{T,R,D, RD, AA<:AbstractArray{T,RD}} <: LazyTensor{T,R,D} A::AA range_indicies::NTuple{R,Int} domain_indicies::NTuple{D,Int} - function LazyLinearMap(A::AA, range_indicies::NTuple{R,Int}, domain_indicies::NTuple{D,Int}) where {T,R,D, RD, AA<:AbstractArray{T,RD}} + function DenseTensor(A::AA, range_indicies::NTuple{R,Int}, domain_indicies::NTuple{D,Int}) where {T,R,D, RD, AA<:AbstractArray{T,RD}} if !issorted(range_indicies) || !issorted(domain_indicies) throw(DomainError("range_indicies and domain_indicies must be sorted in ascending order")) end @@ -59,10 +59,10 @@ end end -range_size(llm::LazyLinearMap) = size(llm.A)[[llm.range_indicies...]] -domain_size(llm::LazyLinearMap) = size(llm.A)[[llm.domain_indicies...]] +range_size(llm::DenseTensor) = size(llm.A)[[llm.range_indicies...]] +domain_size(llm::DenseTensor) = size(llm.A)[[llm.domain_indicies...]] -function apply(llm::LazyLinearMap{T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} +function apply(llm::DenseTensor{T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} view_index = ntuple(i->:,ndims(llm.A)) for i ∈ 1:R view_index = Base.setindex(view_index, Int(I[i]), llm.range_indicies[i]) @@ -71,6 +71,6 @@ return sum(A_view.*v) end -function apply_transpose(llm::LazyLinearMap{T,R,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,D} - apply(LazyLinearMap(llm.A, llm.domain_indicies, llm.range_indicies), v, I...) +function apply_transpose(llm::DenseTensor{T,R,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,D} + apply(DenseTensor(llm.A, llm.domain_indicies, llm.range_indicies), v, I...) end
--- a/test/LazyTensors/lazy_tensor_operations_test.jl Mon Mar 21 13:19:53 2022 +0100 +++ b/test/LazyTensors/lazy_tensor_operations_test.jl Mon Mar 21 15:22:22 2022 +0100 @@ -36,7 +36,7 @@ end -@testset "LazyTensorApplication" begin +@testset "TensorApplication" begin m = SizeDoublingMapping{Int, 1, 1}((3,)) mm = SizeDoublingMapping{Int, 1, 1}((6,)) v = [0,1,2] @@ -159,14 +159,14 @@ end -@testset "LazyTensorComposition" begin +@testset "TensorComposition" begin A = rand(2,3) B = rand(3,4) - Ã = LazyLinearMap(A, (1,), (2,)) - B̃ = LazyLinearMap(B, (1,), (2,)) + Ã = DenseTensor(A, (1,), (2,)) + B̃ = DenseTensor(B, (1,), (2,)) - @test Ã∘B̃ isa LazyTensorComposition + @test Ã∘B̃ isa TensorComposition @test range_size(Ã∘B̃) == (2,) @test domain_size(Ã∘B̃) == (4,) @test_throws DomainSizeMismatch B̃∘Ã @@ -184,38 +184,38 @@ end -@testset "InflatedLazyTensor" begin +@testset "InflatedTensor" begin I(sz...) = IdentityTensor(sz...) Ã = rand(4,2) B̃ = rand(4,2,3) C̃ = rand(4,2,3) - A = LazyLinearMap(Ã,(1,),(2,)) - B = LazyLinearMap(B̃,(1,2),(3,)) - C = LazyLinearMap(C̃,(1,),(2,3)) + A = DenseTensor(Ã,(1,),(2,)) + B = DenseTensor(B̃,(1,2),(3,)) + C = DenseTensor(C̃,(1,),(2,3)) @testset "Constructors" begin - @test InflatedLazyTensor(I(3,2), A, I(4)) isa LazyTensor{Float64, 4, 4} - @test InflatedLazyTensor(I(3,2), B, I(4)) isa LazyTensor{Float64, 5, 4} - @test InflatedLazyTensor(I(3), C, I(2,3)) isa LazyTensor{Float64, 4, 5} - @test InflatedLazyTensor(C, I(2,3)) isa LazyTensor{Float64, 3, 4} - @test InflatedLazyTensor(I(3), C) isa LazyTensor{Float64, 2, 3} - @test InflatedLazyTensor(I(3), I(2,3)) isa LazyTensor{Float64, 3, 3} + @test InflatedTensor(I(3,2), A, I(4)) isa LazyTensor{Float64, 4, 4} + @test InflatedTensor(I(3,2), B, I(4)) isa LazyTensor{Float64, 5, 4} + @test InflatedTensor(I(3), C, I(2,3)) isa LazyTensor{Float64, 4, 5} + @test InflatedTensor(C, I(2,3)) isa LazyTensor{Float64, 3, 4} + @test InflatedTensor(I(3), C) isa LazyTensor{Float64, 2, 3} + @test InflatedTensor(I(3), I(2,3)) isa LazyTensor{Float64, 3, 3} end @testset "Range and domain size" begin - @test range_size(InflatedLazyTensor(I(3,2), A, I(4))) == (3,2,4,4) - @test domain_size(InflatedLazyTensor(I(3,2), A, I(4))) == (3,2,2,4) + @test range_size(InflatedTensor(I(3,2), A, I(4))) == (3,2,4,4) + @test domain_size(InflatedTensor(I(3,2), A, I(4))) == (3,2,2,4) - @test range_size(InflatedLazyTensor(I(3,2), B, I(4))) == (3,2,4,2,4) - @test domain_size(InflatedLazyTensor(I(3,2), B, I(4))) == (3,2,3,4) + @test range_size(InflatedTensor(I(3,2), B, I(4))) == (3,2,4,2,4) + @test domain_size(InflatedTensor(I(3,2), B, I(4))) == (3,2,3,4) - @test range_size(InflatedLazyTensor(I(3), C, I(2,3))) == (3,4,2,3) - @test domain_size(InflatedLazyTensor(I(3), C, I(2,3))) == (3,2,3,2,3) + @test range_size(InflatedTensor(I(3), C, I(2,3))) == (3,4,2,3) + @test domain_size(InflatedTensor(I(3), C, I(2,3))) == (3,2,3,2,3) - @inferred range_size(InflatedLazyTensor(I(3,2), A, I(4))) == (3,2,4,4) - @inferred domain_size(InflatedLazyTensor(I(3,2), A, I(4))) == (3,2,2,4) + @inferred range_size(InflatedTensor(I(3,2), A, I(4))) == (3,2,4,4) + @inferred domain_size(InflatedTensor(I(3,2), A, I(4))) == (3,2,2,4) end @testset "Application" begin @@ -223,47 +223,47 @@ # The inflated tensor mappings are chosen to preserve, reduce and increase the dimension of the result compared to the input. cases = [ ( - InflatedLazyTensor(I(3,2), A, I(4)), + InflatedTensor(I(3,2), A, I(4)), (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]), # Expected result of apply (v-> @tullio res[a,b,c,d] := Ã[i,c]*v[a,b,i,d]), # Expected result of apply_transpose ), ( - InflatedLazyTensor(I(3,2), B, I(4)), + InflatedTensor(I(3,2), B, I(4)), (v-> @tullio res[a,b,c,d,e] := B̃[c,d,i]*v[a,b,i,e]), (v-> @tullio res[a,b,c,d] := B̃[i,j,c]*v[a,b,i,j,d]), ), ( - InflatedLazyTensor(I(3,2), C, I(4)), + InflatedTensor(I(3,2), C, I(4)), (v-> @tullio res[a,b,c,d] := C̃[c,i,j]*v[a,b,i,j,d]), (v-> @tullio res[a,b,c,d,e] := C̃[i,c,d]*v[a,b,i,e]), ), ( - InflatedLazyTensor(I(3,2), A), + InflatedTensor(I(3,2), A), (v-> @tullio res[a,b,c] := Ã[c,i]*v[a,b,i]), (v-> @tullio res[a,b,c] := Ã[i,c]*v[a,b,i]), ), ( - InflatedLazyTensor(I(3,2), B), + InflatedTensor(I(3,2), B), (v-> @tullio res[a,b,c,d] := B̃[c,d,i]*v[a,b,i]), (v-> @tullio res[a,b,c] := B̃[i,j,c]*v[a,b,i,j]), ), ( - InflatedLazyTensor(I(3,2), C), + InflatedTensor(I(3,2), C), (v-> @tullio res[a,b,c] := C̃[c,i,j]*v[a,b,i,j]), (v-> @tullio res[a,b,c,d] := C̃[i,c,d]*v[a,b,i]), ), ( - InflatedLazyTensor(A,I(4)), + InflatedTensor(A,I(4)), (v-> @tullio res[a,b] := Ã[a,i]*v[i,b]), (v-> @tullio res[a,b] := Ã[i,a]*v[i,b]), ), ( - InflatedLazyTensor(B,I(4)), + InflatedTensor(B,I(4)), (v-> @tullio res[a,b,c] := B̃[a,b,i]*v[i,c]), (v-> @tullio res[a,b] := B̃[i,j,a]*v[i,j,b]), ), ( - InflatedLazyTensor(C,I(4)), + InflatedTensor(C,I(4)), (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]), (v-> @tullio res[a,b,c] := C̃[i,a,b]*v[i,c]), ), @@ -278,7 +278,7 @@ end @testset "application to other type" begin - tm = InflatedLazyTensor(I(3,2), A, I(4)) + tm = InflatedTensor(I(3,2), A, I(4)) v = rand(ComplexF64, domain_size(tm)...) @test (tm*v)[1,2,3,1] isa ComplexF64 @@ -288,7 +288,7 @@ end @testset "Inference of application" begin - tm = InflatedLazyTensor(I(2,3),ScalingTensor(2.0, (3,2)),I(3,4)) + tm = InflatedTensor(I(2,3),ScalingTensor(2.0, (3,2)),I(3,4)) v = rand(domain_size(tm)...) @inferred apply(tm,v,1,2,3,2,2,4) @@ -296,14 +296,14 @@ end end - @testset "InflatedLazyTensor of InflatedLazyTensor" begin + @testset "InflatedTensor of InflatedTensor" begin A = ScalingTensor(2.0,(2,3)) - itm = InflatedLazyTensor(I(3,2), A, I(4)) - @test InflatedLazyTensor(I(4), itm, I(2)) == InflatedLazyTensor(I(4,3,2), A, I(4,2)) - @test InflatedLazyTensor(itm, I(2)) == InflatedLazyTensor(I(3,2), A, I(4,2)) - @test InflatedLazyTensor(I(4), itm) == InflatedLazyTensor(I(4,3,2), A, I(4)) + itm = InflatedTensor(I(3,2), A, I(4)) + @test InflatedTensor(I(4), itm, I(2)) == InflatedTensor(I(4,3,2), A, I(4,2)) + @test InflatedTensor(itm, I(2)) == InflatedTensor(I(3,2), A, I(4,2)) + @test InflatedTensor(I(4), itm) == InflatedTensor(I(4,3,2), A, I(4)) - @test InflatedLazyTensor(I(2), I(2), I(2)) isa InflatedLazyTensor # The constructor should always return its type. + @test InflatedTensor(I(2), I(2), I(2)) isa InflatedTensor # The constructor should always return its type. end end @@ -335,8 +335,8 @@ v₁ = rand(2,4,3) v₂ = rand(4,3,2) - Ã = LazyLinearMap(A,(1,),(2,)) - B̃ = LazyLinearMap(B,(1,),(2,3)) + Ã = DenseTensor(A,(1,),(2,)) + B̃ = DenseTensor(B,(1,),(2,3)) ÃB̃ = LazyOuterProduct(Ã,B̃) @tullio ABv[i,k] := A[i,j]*B[k,l,m]*v₁[j,l,m] @@ -349,12 +349,12 @@ @testset "Indentity mapping arguments" begin @test LazyOuterProduct(IdentityTensor(3,2), IdentityTensor(1,2)) == IdentityTensor(3,2,1,2) - Ã = LazyLinearMap(A,(1,),(2,)) - @test LazyOuterProduct(IdentityTensor(3,2), Ã) == InflatedLazyTensor(IdentityTensor(3,2),Ã) - @test LazyOuterProduct(Ã, IdentityTensor(3,2)) == InflatedLazyTensor(Ã,IdentityTensor(3,2)) + Ã = DenseTensor(A,(1,),(2,)) + @test LazyOuterProduct(IdentityTensor(3,2), Ã) == InflatedTensor(IdentityTensor(3,2),Ã) + @test LazyOuterProduct(Ã, IdentityTensor(3,2)) == InflatedTensor(Ã,IdentityTensor(3,2)) I1 = IdentityTensor(3,2) I2 = IdentityTensor(4) - @test I1⊗Ã⊗I2 == InflatedLazyTensor(I1, Ã, I2) + @test I1⊗Ã⊗I2 == InflatedTensor(I1, Ã, I2) end end
--- a/test/LazyTensors/tensor_types_test.jl Mon Mar 21 13:19:53 2022 +0100 +++ b/test/LazyTensors/tensor_types_test.jl Mon Mar 21 15:22:22 2022 +0100 @@ -32,7 +32,7 @@ @inferred domain_dim(I) à = rand(4,2) - A = LazyLinearMap(Ã,(1,),(2,)) + A = DenseTensor(Ã,(1,),(2,)) I1 = IdentityTensor{Float64}(2) I2 = IdentityTensor{Float64}(4) @test A∘I1 == A @@ -59,15 +59,15 @@ end -@testset "LazyLinearMap" begin +@testset "DenseTensor" begin # Test a standard matrix-vector product # mapping vectors of size 4 to vectors of size 3. A = rand(3,4) - à = LazyLinearMap(A, (1,), (2,)) + à = DenseTensor(A, (1,), (2,)) v = rand(4) w = rand(3) - @test à isa LazyLinearMap{T,1,1} where T + @test à isa DenseTensor{T,1,1} where T @test à isa LazyTensor{T,1,1} where T @test range_size(Ã) == (3,) @test domain_size(Ã) == (4,) @@ -77,12 +77,12 @@ @test Ã'*w ≈ A'*w A = rand(2,3,4) - @test_throws DomainError LazyLinearMap(A, (3,1), (2,)) + @test_throws DomainError DenseTensor(A, (3,1), (2,)) # Test more exotic mappings B = rand(3,4,2) # Map vectors of size 2 to matrices of size (3,4) - B̃ = LazyLinearMap(B, (1,2), (3,)) + B̃ = DenseTensor(B, (1,2), (3,)) v = rand(2) @test range_size(B̃) == (3,4) @@ -92,7 +92,7 @@ @test B̃*v ≈ B[:,:,1]*v[1] + B[:,:,2]*v[2] atol=5e-13 # Map matrices of size (3,2) to vectors of size 4 - B̃ = LazyLinearMap(B, (2,), (1,3)) + B̃ = DenseTensor(B, (2,), (1,3)) v = rand(3,2) @test range_size(B̃) == (4,)
--- a/test/SbpOperators/boundaryops/boundary_operator_test.jl Mon Mar 21 13:19:53 2022 +0100 +++ b/test/SbpOperators/boundaryops/boundary_operator_test.jl Mon Mar 21 15:22:22 2022 +0100 @@ -28,7 +28,7 @@ @testset "2D" begin e_w = boundary_operator(g_2D,closure_stencil,CartesianBoundary{1,Upper}()) - @test e_w isa InflatedLazyTensor + @test e_w isa InflatedTensor @test e_w isa LazyTensor{T,1,2} where T end end
--- a/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Mar 21 13:19:53 2022 +0100 +++ b/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Mar 21 15:22:22 2022 +0100 @@ -30,7 +30,7 @@ @testset "2D" begin e_w = boundary_restriction(g_2D,e_closure,CartesianBoundary{1,Upper}()) @test e_w == boundary_restriction(g_2D,stencil_set,CartesianBoundary{1,Upper}()) - @test e_w isa InflatedLazyTensor + @test e_w isa InflatedTensor @test e_w isa LazyTensor{T,1,2} where T end end