Mercurial > repos > public > sbplib_julia
comparison TensorMappings.jl @ 177:87747870441e boundary_conditions
Steal Vidars changes from 24779d423243 that make TensorMappings.jl compile
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 17 Jun 2019 09:43:35 +0200 |
parents | 766403c677b1 |
children | 39d3a837bc6b |
comparison
equal
deleted
inserted
replaced
175:bcd2029c590d | 177:87747870441e |
---|---|
29 Base.adjoint(t::TensorMappingTranspose) = t.tm | 29 Base.adjoint(t::TensorMappingTranspose) = t.tm |
30 | 30 |
31 apply(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,R}, I::Vararg) where {T,R,D} = apply_transpose(tm.tm, v, I...) | 31 apply(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,R}, I::Vararg) where {T,R,D} = apply_transpose(tm.tm, v, I...) |
32 apply_transpose(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,D} = apply(tm.tm, v, I...) | 32 apply_transpose(tm::TensorMappingTranspose{T,R,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,D} = apply(tm.tm, v, I...) |
33 | 33 |
34 range_size(tmt::TensorMappingTranspose{T,R,D}, domain_size::NTuple{D,Integer}) = domain_size(tmt.tm, domain_size) | 34 range_size(tmt::TensorMappingTranspose{T,R,D}, domain_size::NTuple{D,Integer}) where {T,R,D} = domain_size(tmt.tm, domain_size) |
35 domain_size(tmt::TensorMappingTranspose{T,R,D}, range_size::NTuple{D,Integer}) = range_size(tmt.tm, range_size) | 35 domain_size(tmt::TensorMappingTranspose{T,R,D}, range_size::NTuple{D,Integer}) where {T,R,D} = range_size(tmt.tm, range_size) |
36 | 36 |
37 | 37 |
38 | 38 |
39 struct TensorApplication{T,R,D} <: AbstractArray{T,R} | 39 struct TensorApplication{T,R,D} <: AbstractArray{T,R} |
40 t::TensorMapping{R,D} | 40 t::TensorMapping{R,D} |
41 o::AbstractArray{T,D} | 41 o::AbstractArray{T,D} |
42 end | 42 end |
43 | 43 |
44 Base.size(ta::TensorApplication) = 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(tm::TensorApplication, I::Vararg) = apply(tm.t, tm.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 | 47 import Base.* |
48 →(t::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(t,o) | 48 →(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? | 49 # 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 '→' | 50 # We need the associativity to be a→b→c = a→(b→c), which is the case for '→' |
51 | |
52 import Base.* | |
53 *(args::Union{TensorMapping{T}, AbstractArray{T}}...) where T = foldr(*,args) | 51 *(args::Union{TensorMapping{T}, AbstractArray{T}}...) where T = foldr(*,args) |
54 *(t::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(t,o) | 52 *(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = TensorApplication(tm,o) |
55 # We need to be really careful about good error messages. | 53 # We need to be really careful about good error messages. |
56 # For example what happens if you try to multiply TensorApplication with a TensorMapping(wrong order)? | 54 # For example what happens if you try to multiply TensorApplication with a TensorMapping(wrong order)? |
57 | 55 |
58 | 56 |
59 | 57 |
63 end | 61 end |
64 | 62 |
65 import Base.∘ | 63 import Base.∘ |
66 ∘(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) |
67 | 65 |
68 function range_size(tm::TensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,D} | 66 function range_size(tm::TensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,K,D} |
69 range_size(tm.t1, domain_size(tm.t2, domain_size)) | 67 range_size(tm.t1, domain_size(tm.t2, domain_size)) |
70 end | 68 end |
71 | 69 |
72 function domain_size(tm::TensorMappingComposition{T,R,K,D}, range_size::NTuple{R,Integer}) where {T,R,D} | 70 function domain_size(tm::TensorMappingComposition{T,R,K,D}, range_size::NTuple{R,Integer}) where {T,R,K,D} |
73 domain_size(tm.t1, domain_size(tm.t2, range_size)) | 71 domain_size(tm.t1, domain_size(tm.t2, range_size)) |
74 end | 72 end |
75 | 73 |
76 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,K,D} | 74 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,K,D} |
77 apply(c.t1, TensorApplication(c.t2,v), I...) | 75 apply(c.t1, TensorApplication(c.t2,v), I...) |