Mercurial > repos > public > sbplib_julia
changeset 981:df562695b1b5 feature/variable_derivatives
Merge feature/tensormapping_application_promotion
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 15 Mar 2022 21:40:31 +0100 |
parents | f885e1de6dc4 (current diff) 043d13ef8898 (diff) |
children | 2a4f36aca2ea |
files | src/LazyTensors/lazy_tensor_operations.jl test/SbpOperators/boundaryops/boundary_operator_test.jl |
diffstat | 3 files changed, 28 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LazyTensors/LazyTensors.jl Tue Mar 15 21:38:55 2022 +0100 +++ b/src/LazyTensors/LazyTensors.jl Tue Mar 15 21:40:31 2022 +0100 @@ -1,5 +1,15 @@ module LazyTensors +export LazyTensorMappingApplication +export LazyTensorMappingTranspose +export TensorMappingComposition +export LazyLinearMap +export IdentityMapping +export InflatedTensorMapping +export LazyOuterProduct +export ⊗ +export SizeMismatch + include("tensor_mapping.jl") include("lazy_array.jl") include("lazy_tensor_operations.jl")
--- a/src/LazyTensors/lazy_tensor_operations.jl Tue Mar 15 21:38:55 2022 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Tue Mar 15 21:40:31 2022 +0100 @@ -1,15 +1,5 @@ using Sbplib.RegionIndices -export LazyTensorMappingApplication -export LazyTensorMappingTranspose -export TensorMappingComposition -export LazyLinearMap -export IdentityMapping -export InflatedTensorMapping -export LazyOuterProduct -export ⊗ -export SizeMismatch - """ LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R} @@ -24,7 +14,8 @@ o::AA function LazyTensorMappingApplication(t::TensorMapping{<:Any,R,D}, o::AbstractArray{<:Any,D}) where {R,D} - T = promote_type(eltype(t), eltype(o)) + I = ntuple(i->1, range_dim(t)) + T = typeof(apply(t,o,I...)) return new{T,R,D,typeof(t), typeof(o)}(t,o) end end
--- a/test/LazyTensors/lazy_tensor_operations_test.jl Tue Mar 15 21:38:55 2022 +0100 +++ b/test/LazyTensors/lazy_tensor_operations_test.jl Tue Mar 15 21:40:31 2022 +0100 @@ -36,10 +36,8 @@ m = SizeDoublingMapping{Int, 1, 1}((3,)) v = [0,1,2] - @test m*v isa AbstractVector{Int} @test size(m*v) == 2 .*size(v) @test (m*v)[0] == (:apply,v,(0,)) - @test m*m*v isa AbstractVector{Int} @test (m*m*v)[1] == (:apply,m*v,(1,)) @test (m*m*v)[3] == (:apply,m*v,(3,)) @test (m*m*v)[6] == (:apply,m*v,(6,)) @@ -81,26 +79,41 @@ @test m*v == [[2 4];[6 8]] @test (m*v)[2,1] == 6 - @testset "Promotion" begin + @testset "Type calculation" begin m = ScalingOperator{Int,1}(2,(3,)) v = [1.,2.,3.] @test m*v isa AbstractVector{Float64} @test m*v == [2.,4.,6.] + @inferred m*v + @inferred (m*v)[1] m = ScalingOperator{Int,2}(2,(2,2)) v = [[1. 2.];[3. 4.]] @test m*v == [[2. 4.];[6. 8.]] @test (m*v)[2,1] == 6. + @inferred m*v + @inferred (m*v)[1] m = ScalingOperator{ComplexF64,1}(2. +2. *im,(3,)) v = [1.,2.,3.] @test m*v isa AbstractVector{ComplexF64} @test m*v == [2. + 2. *im, 4. + 4. *im, 6. + 6. *im] + @inferred m*v + @inferred (m*v)[1] m = ScalingOperator{ComplexF64,1}(1,(3,)) v = [2. + 2. *im, 4. + 4. *im, 6. + 6. *im] @test m*v isa AbstractVector{ComplexF64} @test m*v == [2. + 2. *im, 4. + 4. *im, 6. + 6. *im] + @inferred m*v + @inferred (m*v)[1] + + m = ScalingOperator{Float64,1}(2., (3,)) + v = [[1,2,3], [3,2,1],[1,3,1]] + @test m*v isa AbstractVector{Vector{Float64}} + @test m*v == [[2.,4.,6.], [6.,4.,2.],[2.,6.,2.]] + @inferred m*v + @inferred (m*v)[1] end end