Mercurial > repos > public > sbplib_julia
comparison TensorMappings.jl @ 157:63b495d5dbc7 boundary_conditions
Add *-operator for tensor application
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 29 Apr 2019 11:47:26 +0200 |
parents | ef3e6c70b6f9 |
children | a3fac8298e3c |
comparison
equal
deleted
inserted
replaced
156:ef3e6c70b6f9 | 157:63b495d5dbc7 |
---|---|
34 apply(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,R}, I::Vararg) where {T,R,D} = apply_transpose(tm.tm, v, I...) | 34 apply(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,R}, I::Vararg) where {T,R,D} = apply_transpose(tm.tm, v, I...) |
35 apply_transpose(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,D} = apply(tm.tm, v, I...) | 35 apply_transpose(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,D} = apply(tm.tm, v, I...) |
36 | 36 |
37 # range_size(::TensorMappingTranspose{T,R,D}, domain_size::NTuple{}) = range_size_of_transpose??? | 37 # range_size(::TensorMappingTranspose{T,R,D}, domain_size::NTuple{}) = range_size_of_transpose??? |
38 | 38 |
39 | |
40 | |
39 struct TensorApplication{T,R,D} <: AbstractArray{T,R} | 41 struct TensorApplication{T,R,D} <: AbstractArray{T,R} |
40 t::TensorMapping{R,D} | 42 t::TensorMapping{R,D} |
41 o::AbstractArray{T,D} | 43 o::AbstractArray{T,D} |
42 end | 44 end |
43 | 45 |
50 # Should we overload some other infix binary operator? | 52 # Should we overload some other infix binary operator? |
51 # * has the wrong parsing properties... a*b*c is parsed to (a*b)*c (through a*b*c = *(a,b,c)) | 53 # * has the wrong parsing properties... a*b*c is parsed to (a*b)*c (through a*b*c = *(a,b,c)) |
52 # while a→b→c is parsed as a→(b→c) | 54 # while a→b→c is parsed as a→(b→c) |
53 # The associativity of the operators might be fixed somehow... (rfold/lfold?) | 55 # The associativity of the operators might be fixed somehow... (rfold/lfold?) |
54 # ∘ also is an option but that has the same problem as * (but is not n-ary) (or is this best used for composition of Mappings?) | 56 # ∘ also is an option but that has the same problem as * (but is not n-ary) (or is this best used for composition of Mappings?) |
57 | |
58 # If we want to use * it would be something like this: | |
59 import Base.* | |
60 *(args::Union{TensorMapping{T}, AbstractArray{T}}...) where T = foldr(*,args) | |
61 *(t::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(t,o) | |
62 # We need to be really careful about good error messages. | |
63 # For example what happens if you try to multiply TensorApplication with a TensorMapping(wrong order)? | |
64 | |
65 | |
55 | 66 |
56 struct TensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D} | 67 struct TensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D} |
57 t1::TensorMapping{T,R,K} | 68 t1::TensorMapping{T,R,K} |
58 t2::TensorMapping{T,K,D} | 69 t2::TensorMapping{T,K,D} |
59 end | 70 end |