Mercurial > repos > public > sbplib_julia
comparison LazyTensors/test/runtests.jl @ 184:6945c15a6a7a boundary_conditions
Rename package LazyTensor to LazyTensors
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 20 Jun 2019 21:14:20 +0200 |
| parents | LazyTensor/test/runtests.jl@b7397ae8afaf |
| children | 715ff09bb2ce |
comparison
equal
deleted
inserted
replaced
| 183:b78548f98a75 | 184:6945c15a6a7a |
|---|---|
| 1 using Test | |
| 2 using LazyTensors | |
| 3 | |
| 4 | |
| 5 | |
| 6 @testset "Generic Mapping methods" begin | |
| 7 struct DummyMapping{T,R,D} <: LazyTensors.Mapping{T,R,D} end | |
| 8 LazyTensors.apply(m::DummyMapping{T,R,D}, v, i) where {T,R,D} = :apply | |
| 9 @test range_dim(DummyMapping{Int,2,3}()) == 2 | |
| 10 @test domain_dim(DummyMapping{Int,2,3}()) == 3 | |
| 11 @test apply(DummyMapping{Int,2,3}(), zeros(Int, (0,0,0)),0) == :apply | |
| 12 end | |
| 13 | |
| 14 struct DummyOperator{T,D} <: LazyTensors.Operator{T,D} end | |
| 15 @testset "Generic Operator methods" begin | |
| 16 @test range_size(DummyOperator{Int,2}(), (3,5)) == (3,5) | |
| 17 @test domain_size(DummyOperator{Float64, 3}(), (3,3,1)) == (3,3,1) | |
| 18 end | |
| 19 | |
| 20 @testset "Mapping transpose" begin | |
| 21 struct DummyMapping{T,R,D} <: LazyTensors.Mapping{T,R,D} end | |
| 22 | |
| 23 LazyTensors.apply(m::DummyMapping{T,R,D}, v, i) where {T,R,D} = :apply | |
| 24 LazyTensors.apply_transpose(m::DummyMapping{T,R,D}, v, i) where {T,R,D} = :apply_transpose | |
| 25 | |
| 26 LazyTensors.range_size(m::DummyMapping{T,R,D}, domain_size) where {T,R,D} = :range_size | |
| 27 LazyTensors.domain_size(m::DummyMapping{T,R,D}, range_size) where {T,R,D} = :domain_size | |
| 28 | |
| 29 m = DummyMapping{Float64,2,3}() | |
| 30 @test m'' == m | |
| 31 @test apply(m',zeros(Float64,(0,0)),0) == :apply_transpose | |
| 32 @test apply(m'',zeros(Float64,(0,0,0)),0) == :apply | |
| 33 @test apply_transpose(m', zeros(Float64,(0,0,0)),0) == :apply | |
| 34 | |
| 35 @test range_size(m', (0,0)) == :domain_size | |
| 36 @test domain_size(m', (0,0,0)) == :range_size | |
| 37 end | |
| 38 | |
| 39 @testset "TensorApplication" begin | |
| 40 struct DummyMapping{T,R,D} <: LazyTensors.Mapping{T,R,D} end | |
| 41 | |
| 42 LazyTensors.apply(m::DummyMapping{T,R,D}, v, i) where {T,R,D} = (:apply,v,i) | |
| 43 LazyTensors.apply_transpose(m::DummyMapping{T,R,D}, v, i) where {T,R,D} = :apply_transpose | |
| 44 | |
| 45 LazyTensors.range_size(m::DummyMapping{T,R,D}, domain_size) where {T,R,D} = 2 .* domain_size | |
| 46 LazyTensors.domain_size(m::DummyMapping{T,R,D}, range_size) where {T,R,D} = range_size.รท2 | |
| 47 | |
| 48 | |
| 49 m = DummyMapping{Int, 1, 1}() | |
| 50 v = [0,1,2] | |
| 51 @test m*v isa AbstractVector{Int} | |
| 52 @test size(m*v) == 2 .*size(v) | |
| 53 @test (m*v)[0] == (:apply,v,0) | |
| 54 @test m*m*v isa AbstractVector{Int} | |
| 55 @test (m*m*v)[0] == (:apply,m*v,0) | |
| 56 end |
