comparison TensorMappings.jl @ 179:39d3a837bc6b boundary_conditions

Remove imports of Base operators
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 17 Jun 2019 10:57:57 +0200
parents 87747870441e
children
comparison
equal deleted inserted replaced
177:87747870441e 179:39d3a837bc6b
42 end 42 end
43 43
44 Base.size(ta::TensorApplication{T,R,D}) where {T,R,D} = range_size(ta.t,size(ta.o)) 44 Base.size(ta::TensorApplication{T,R,D}) where {T,R,D} = range_size(ta.t,size(ta.o))
45 Base.getindex(ta::TensorApplication{T,R,D}, I::Vararg) where {T,R,D} = apply(ta.t, ta.o, I...) 45 Base.getindex(ta::TensorApplication{T,R,D}, I::Vararg) where {T,R,D} = apply(ta.t, ta.o, I...)
46 # TODO: What else is needed to implement the AbstractArray interface? 46 # TODO: What else is needed to implement the AbstractArray interface?
47 import Base.*
48 →(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(tm,o) 47 →(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(tm,o)
49 # Should we overload some other infix binary operator? 48 # Should we overload some other infix binary operator?
50 # We need the associativity to be a→b→c = a→(b→c), which is the case for '→' 49 # We need the associativity to be a→b→c = a→(b→c), which is the case for '→'
51 *(args::Union{TensorMapping{T}, AbstractArray{T}}...) where T = foldr(*,args) 50 Base.:*(args::Union{TensorMapping{T}, AbstractArray{T}}...) where T = foldr(*,args)
52 *(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(tm,o) 51 Base.:*(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(tm,o)
53 # We need to be really careful about good error messages. 52 # We need to be really careful about good error messages.
54 # For example what happens if you try to multiply TensorApplication with a TensorMapping(wrong order)? 53 # For example what happens if you try to multiply TensorApplication with a TensorMapping(wrong order)?
55 54
56 55
57 56
58 struct TensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D} 57 struct TensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D}
59 t1::TensorMapping{T,R,K} 58 t1::TensorMapping{T,R,K}
60 t2::TensorMapping{T,K,D} 59 t2::TensorMapping{T,K,D}
61 end 60 end
62 61
63 import Base.∘ 62 Base.:∘(s::TensorMapping{T,R,K}, t::TensorMapping{T,K,D}) where {T,R,K,D} = TensorMappingComposition(s,t)
64 ∘(s::TensorMapping{T,R,K}, t::TensorMapping{T,K,D}) where {T,R,K,D} = TensorMappingComposition(s,t)
65 63
66 function range_size(tm::TensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,K,D} 64 function range_size(tm::TensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,K,D}
67 range_size(tm.t1, domain_size(tm.t2, domain_size)) 65 range_size(tm.t1, domain_size(tm.t2, domain_size))
68 end 66 end
69 67