Mercurial > repos > public > sbplib_julia
changeset 437:c3aa4ede899c
Merge bugfix/tensor_application_multiplication
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 19 Oct 2020 20:55:01 +0200 |
parents | 6737e769a1ca (current diff) cffdac9c612d (diff) |
children | 907b0510699f |
files | |
diffstat | 2 files changed, 5 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl Mon Oct 19 20:42:13 2020 +0200 +++ b/src/LazyTensors/lazy_tensor_operations.jl Mon Oct 19 20:55:01 2020 +0200 @@ -16,14 +16,16 @@ # TODO: Go through and remove unneccerary type parameters on functions -Base.:*(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = LazyTensorMappingApplication(tm,o) Base.getindex(ta::LazyTensorMappingApplication{T,R,D}, I::Vararg{Index,R}) where {T,R,D} = apply(ta.t, ta.o, I...) Base.getindex(ta::LazyTensorMappingApplication{T,R,D}, I::Vararg{Int,R}) where {T,R,D} = apply(ta.t, ta.o, Index{Unknown}.(I)...) Base.size(ta::LazyTensorMappingApplication) = range_size(ta.t) # TODO: What else is needed to implement the AbstractArray interface? +Base.:*(a::TensorMapping, v::AbstractArray) = LazyTensorMappingApplication(a,v) +Base.:*(a::TensorMapping, b::TensorMapping) = throw(MethodError(Base.:*,(a,b))) +Base.:*(a::TensorMapping, args::Union{TensorMapping, AbstractArray}...) = foldr(*,(a,args...)) + # # We need the associativity to be a→b→c = a→(b→c), which is the case for '→' -Base.:*(a::TensorMapping{T,R,D}, b::TensorMapping{T,D,K}, args::Union{TensorMapping{T}, AbstractArray{T}}...) where {T,R,D,K} = foldr(*,(a,b,args...)) # # Should we overload some other infix binary opesrator? # →(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = LazyTensorMappingApplication(tm,o) # TODO: We need to be really careful about good error messages.
--- a/test/testLazyTensors.jl Mon Oct 19 20:42:13 2020 +0200 +++ b/test/testLazyTensors.jl Mon Oct 19 20:55:01 2020 +0200 @@ -58,6 +58,7 @@ @test (m*m*v)[6] == (:apply,m*v,(Index{Unknown}(6),)) @test_broken BoundsError == (m*m*v)[0] @test_broken BoundsError == (m*m*v)[7] + @test_throws MethodError m*m m = SizeDoublingMapping{Int, 2, 1}((3,)) @test_throws MethodError m*ones(Int,2,2)