From 71fba9f9fdf9eb241bd70dc30225b91723d5e92a Mon Sep 17 00:00:00 2001 From: Alexander Morley Date: Thu, 24 Aug 2017 23:14:13 +0100 Subject: [PATCH] Drop support for v0.5 + v0.6 updates (#33) --- .travis.yml | 1 - README.md | 2 +- REQUIRE | 3 +-- src/TensorOperations.jl | 2 -- src/auxiliary/axpby.jl | 4 ++-- src/auxiliary/error.jl | 2 +- src/auxiliary/meta.jl | 8 ++++---- src/auxiliary/stridedarray.jl | 6 +++--- src/auxiliary/strideddata.jl | 21 ++++++++++---------- src/implementation/kernels.jl | 6 +++--- src/implementation/recursive.jl | 8 ++++---- src/implementation/stridedarray.jl | 8 ++++---- src/implementation/strides.jl | 8 ++++---- src/indexnotation/indexedobject.jl | 31 +++++++++++++++--------------- src/indexnotation/product.jl | 8 ++++---- src/indexnotation/sum.jl | 8 ++++---- 16 files changed, 62 insertions(+), 64 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20079377..97bd0c61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ os: - linux - osx julia: - - 0.5 - 0.6 - nightly notifications: diff --git a/README.md b/README.md index d72be808..7b514293 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Fast tensor operations using a convenient index notation. ## What's new -- Fully compatible with Julia v0.5. +- Fully compatible with Julia v0.6. (v0.5 no longer supported) ## Installation diff --git a/REQUIRE b/REQUIRE index 6463e31f..137767a4 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1 @@ -julia 0.5 -Compat 0.24.0 +julia 0.6 diff --git a/src/TensorOperations.jl b/src/TensorOperations.jl index 0a714bb7..538265e3 100644 --- a/src/TensorOperations.jl +++ b/src/TensorOperations.jl @@ -1,7 +1,5 @@ module TensorOperations -using Compat - export tensorcopy, tensoradd, tensortrace, tensorcontract, tensorproduct, scalar export tensorcopy!, tensoradd!, tensortrace!, tensorcontract!, tensorproduct! diff --git a/src/auxiliary/axpby.jl b/src/auxiliary/axpby.jl index 35fd4eb2..c1909373 100644 --- a/src/auxiliary/axpby.jl +++ b/src/auxiliary/axpby.jl @@ -4,9 +4,9 @@ # special singleton types (immutables) to remove any overhead of multiplication # by one or addition by zero. -immutable Zero <: Integer +struct Zero <: Integer end -immutable One <: Integer +struct One <: Integer end const _zero = Zero() diff --git a/src/auxiliary/error.jl b/src/auxiliary/error.jl index 2ed8e59f..175a0b1e 100644 --- a/src/auxiliary/error.jl +++ b/src/auxiliary/error.jl @@ -2,7 +2,7 @@ # # An exception type for reporting errors in the index specificatino -immutable IndexError{S<:AbstractString} <: Exception +struct IndexError{S<:AbstractString} <: Exception msg::S end diff --git a/src/auxiliary/meta.jl b/src/auxiliary/meta.jl index 8c94b3c6..8161ba39 100644 --- a/src/auxiliary/meta.jl +++ b/src/auxiliary/meta.jl @@ -2,24 +2,24 @@ # # A bunch of auxiliary metaprogramming tools and generated functions -@generated function _strides{T,N}(A::StridedArray{T,N}) +@generated function _strides(A::StridedArray{T,N}) where {T,N} meta = Expr(:meta,:inline) ex = Expr(:tuple,[:(stride(A,$d)) for d = 1:N]...) Expr(:block, meta, ex) end -@generated function _indmax{N,T}(values::NTuple{N,T}) +@generated function _indmax(values::NTuple{N,T}) where {N,T} meta = Expr(:meta,:inline) Expr(:block, meta, :(dmax = 1), :(max = values[1]), [:(values[$d] > max && (dmax = $d; max = values[$d])) for d = 2:N]..., :(return dmax)) end -@generated function _permute{T,N}(t::NTuple{N,T}, p) +@generated function _permute(t::NTuple{N,T}, p) where {T,N} meta = Expr(:meta,:inline) ex = Expr(:tuple,[:(t[p[$d]]) for d = 1:N]...) Expr(:block, meta, ex) end -@generated function _memjumps{N}(dims::NTuple{N,Int},strides::NTuple{N,Int}) +@generated function _memjumps(dims::NTuple{N,Int},strides::NTuple{N,Int}) where N meta = Expr(:meta,:inline) ex = Expr(:tuple,[:((dims[$d]-1)*strides[$d]) for d = 1:N]...) Expr(:block, meta, ex) diff --git a/src/auxiliary/stridedarray.jl b/src/auxiliary/stridedarray.jl index 193c8365..b1d101e6 100644 --- a/src/auxiliary/stridedarray.jl +++ b/src/auxiliary/stridedarray.jl @@ -8,13 +8,13 @@ Returns the number of indices of a tensor-like object `A`, i.e. for a multidimensional array (`<:AbstractArray`) we have `numind(A) = ndims(A)`. Also works in type domain. """ numind(A::AbstractArray) = ndims(A) -numind{T<:AbstractArray}(::Type{T}) = ndims(T) +numind(::Type{T}) where {T<:AbstractArray} = ndims(T) """`similar_from_indices(T, indices, A, conjA=Val{:N})` Returns an object similar to `A` which has an `eltype` given by `T` and dimensions/sizes corresponding to a selection of those of `op(A)`, where the selection is specified by `indices` (which contains integer between `1` and `numind(A)`) and `op` is `conj` if `conjA=Val{:C}` or does nothing if `conjA=Val{:N}` (default). """ -function similar_from_indices{T,CA}(::Type{T}, indices, A::StridedArray, ::Type{Val{CA}}=Val{:N}) +function similar_from_indices(::Type{T}, indices, A::StridedArray, ::Type{Val{CA}}=Val{:N}) where {T,CA} dims = size(A) return similar(A,T,dims[indices]) end @@ -23,7 +23,7 @@ end Returns an object similar to `A` which has an `eltype` given by `T` and dimensions/sizes corresponding to a selection of those of `op(A)` and `op(B)` concatenated, where the selection is specified by `indices` (which contains integers between `1` and `numind(A)+numind(B)` and `op` is `conj` if `conjA` or `conjB` equal `Val{:C}` or does nothing if `conjA` or `conjB` equal `Val{:N}` (default). """ -function similar_from_indices{T,CA,CB}(::Type{T}, indices, A::StridedArray, B::StridedArray, ::Type{Val{CA}}=Val{:N}, ::Type{Val{CB}}=Val{:N}) +function similar_from_indices(::Type{T}, indices, A::StridedArray, B::StridedArray, ::Type{Val{CA}}=Val{:N}, ::Type{Val{CB}}=Val{:N}) where {T,CA,CB} dims = tuple(size(A)...,size(B)...) return similar(A,T,dims[indices]) end diff --git a/src/auxiliary/strideddata.jl b/src/auxiliary/strideddata.jl index 1c20620d..6bc4c384 100644 --- a/src/auxiliary/strideddata.jl +++ b/src/auxiliary/strideddata.jl @@ -4,19 +4,20 @@ # inside the region and a collection of strides to interpret this memory as a # multidimensional array. -immutable StridedData{N,T,C} +struct StridedData{N,T,C} data::Vector{T} strides::NTuple{N,Int} start::Int end -@compat const NormalStridedData{N,T} = StridedData{N,T,:N} -@compat const ConjugatedStridedData{N,T} = StridedData{N,T,:C} -@compat const StridedSubArray{T,N,A<:Array,I<:Tuple{Vararg{Union{Colon,Range{Int64},Int64}}},LD} = SubArray{T,N,A,I,LD} +NormalStridedData{N,T} = StridedData{N,T,:N} +ConjugatedStridedData{N,T} = StridedData{N,T,:C} -StridedData{N,T,C}(a::Array{T}, strides::NTuple{N,Int} = _strides(a), ::Type{Val{C}} = Val{:N}) = +StridedSubArray{T,N,A<:Array,I<:Tuple{Vararg{Union{Colon,Range{Int64},Int64}}},LD} = SubArray{T,N,A,I,LD} + +StridedData(a::Array{T}, strides::NTuple{N,Int} = _strides(a), ::Type{Val{C}} = Val{:N}) where {N,T,C} = StridedData{N,T,C}(vec(a), strides, 1) -StridedData{N,T,C}(a::StridedSubArray{T}, strides::NTuple{N,Int} = _strides(a), ::Type{Val{C}} = Val{:N}) = +StridedData(a::StridedSubArray{T}, strides::NTuple{N,Int} = _strides(a), ::Type{Val{C}} = Val{:N}) where {N,T,C} = StridedData{N,T,C}(vec(a.parent), strides, Base.first_index(a)) Base.getindex(a::NormalStridedData,i) = a.data[i] @@ -26,16 +27,16 @@ Base.setindex!(a::NormalStridedData,v,i) = (@inbounds a.data[i] = v) Base.setindex!(a::ConjugatedStridedData,v,i) = (@inbounds a.data[i] = conj(v)) # set dimensions dims[d]==1 for all d where a.strides[d] == 0. -@generated function _filterdims{N}(dims::NTuple{N,Int}, a::StridedData{N}) +@generated function _filterdims(dims::NTuple{N,Int}, a::StridedData{N}) where N meta = Expr(:meta,:inline) ex = Expr(:tuple,[:(a.strides[$d]==0 ? 1 : dims[$d]) for d=1:N]...) Expr(:block,meta,ex) end # initial scaling of a block specified by dims -_scale!{N}(C::StridedData{N}, β::One, dims::NTuple{N,Int}, offset::Int=0) = C +_scale!(C::StridedData{N}, β::One, dims::NTuple{N,Int}, offset::Int=0) where {N} = C -@generated function _scale!{N}(C::StridedData{N}, β::Zero, dims::NTuple{N,Int}, offset::Int=0) +@generated function _scale!(C::StridedData{N}, β::Zero, dims::NTuple{N,Int}, offset::Int=0) where N meta = Expr(:meta,:inline) quote $meta @@ -47,7 +48,7 @@ _scale!{N}(C::StridedData{N}, β::One, dims::NTuple{N,Int}, offset::Int=0) = C end end -@generated function _scale!{N}(C::StridedData{N}, β::Number, dims::NTuple{N,Int}, offset::Int=0) +@generated function _scale!(C::StridedData{N}, β::Number, dims::NTuple{N,Int}, offset::Int=0) where N meta = Expr(:meta,:inline) quote $meta diff --git a/src/implementation/kernels.jl b/src/implementation/kernels.jl index 41b6d176..845674e9 100644 --- a/src/implementation/kernels.jl +++ b/src/implementation/kernels.jl @@ -2,7 +2,7 @@ # # Implements the microkernels for solving the subproblems of the various problems. -@generated function add_micro!{N}(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int) +@generated function add_micro!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int) where N quote startA = A.start+offsetA stridesA = A.strides @@ -13,7 +13,7 @@ end end -@generated function trace_micro!{N}(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int) +@generated function trace_micro!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int) where N quote _scale!(C, β, dims, offsetC) startA = A.start+offsetA @@ -25,7 +25,7 @@ end end end -@generated function contract_micro!{N}(α, A::StridedData{N}, B::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA, offsetB, offsetC) +@generated function contract_micro!(α, A::StridedData{N}, B::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA, offsetB, offsetC) where N quote _scale!(C, β, dims, offsetC) startA = A.start+offsetA diff --git a/src/implementation/recursive.jl b/src/implementation/recursive.jl index 9faebd5a..cf30f761 100644 --- a/src/implementation/recursive.jl +++ b/src/implementation/recursive.jl @@ -7,7 +7,7 @@ const BASELENGTH=2048 -@generated function add_rec!{N}(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int, minstrides::NTuple{N, Int}) +@generated function add_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int, minstrides::NTuple{N, Int}) where N quote if 2*prod(dims) <= BASELENGTH add_micro!(α, A, β, C, dims, offsetA, offsetC) @@ -23,7 +23,7 @@ const BASELENGTH=2048 end end -@generated function trace_rec!{N}(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int, minstrides::NTuple{N, Int}) +@generated function trace_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int, minstrides::NTuple{N, Int}) where N quote if prod(dims) + prod(_filterdims(dims,C)) <= BASELENGTH trace_micro!(α, A, β, C, dims, offsetA, offsetC) @@ -43,8 +43,8 @@ end end end -@generated function contract_rec!{N}(α, A::StridedData{N}, B::StridedData{N}, β, C::StridedData{N}, - dims::NTuple{N, Int}, offsetA::Int, offsetB::Int, offsetC::Int, minstrides::NTuple{N, Int}) +@generated function contract_rec!(α, A::StridedData{N}, B::StridedData{N}, β, C::StridedData{N}, + dims::NTuple{N, Int}, offsetA::Int, offsetB::Int, offsetC::Int, minstrides::NTuple{N, Int}) where N quote odimsA = _filterdims(_filterdims(dims, A), C) diff --git a/src/implementation/stridedarray.jl b/src/implementation/stridedarray.jl index 19e1051c..62335a77 100644 --- a/src/implementation/stridedarray.jl +++ b/src/implementation/stridedarray.jl @@ -8,7 +8,7 @@ Implements `C = β*C+α*permute(op(A))` where `A` is permuted according to `indCinA` and `op` is `conj` if `conjA=Val{:C}` or the identity map if `conjA=Val{:N}`. The indexable collection `indCinA` contains as nth entry the dimension of `A` associated with the nth dimension of `C`. """ -function add!{CA}(α, A::StridedArray, ::Type{Val{CA}}, β, C::StridedArray, indCinA) +function add!(α, A::StridedArray, ::Type{Val{CA}}, β, C::StridedArray, indCinA) where CA for i = 1:ndims(C) size(A,indCinA[i]) == size(C,i) || throw(DimensionMismatch()) end @@ -39,7 +39,7 @@ end Implements `C = β*C+α*partialtrace(op(A))` where `A` is permuted and partially traced, according to `indCinA`, `cindA1` and `cindA2`, and `op` is `conj` if `conjA=Val{:C}` or the identity map if `conjA=Val{:N}`. The indexable collection `indCinA` contains as nth entry the dimension of `A` associated with the nth dimension of `C`. The partial trace is performed by contracting dimension `cindA1[i]` of `A` with dimension `cindA2[i]` of `A` for all `i in 1:length(cindA1)`. """ -function trace!{CA}(α, A::StridedArray, ::Type{Val{CA}}, β, C::StridedArray, indCinA, cindA1, cindA2) +function trace!(α, A::StridedArray, ::Type{Val{CA}}, β, C::StridedArray, indCinA, cindA1, cindA2) where CA NC = ndims(C) NA = ndims(A) @@ -79,7 +79,7 @@ Implements `C = β*C+α*contract(op(A),op(B))` where `A` and `B` are contracted The optional argument `method` specifies whether the contraction is performed using BLAS matrix multiplication by specifying `Val{:BLAS}` (default), or using a native algorithm by specifying `Val{:native}`. The native algorithm does not copy the data but is typically slower. """ -function contract!{CA,CB,TC<:Base.LinAlg.BlasFloat}(α, A::StridedArray, ::Type{Val{CA}}, B::StridedArray, ::Type{Val{CB}}, β, C::StridedArray{TC}, oindA, cindA, oindB, cindB, indCinoAB, ::Type{Val{:BLAS}}=Val{:BLAS}) +function contract!(α, A::StridedArray, ::Type{Val{CA}}, B::StridedArray, ::Type{Val{CB}}, β, C::StridedArray{TC}, oindA, cindA, oindB, cindB, indCinoAB, ::Type{Val{:BLAS}}=Val{:BLAS}) where {CA,CB,TC<:Base.LinAlg.BlasFloat} NA = ndims(A) NB = ndims(B) NC = ndims(C) @@ -179,7 +179,7 @@ function contract!{CA,CB,TC<:Base.LinAlg.BlasFloat}(α, A::StridedArray, ::Type{ return C end -function contract!{CA,CB}(α, A::StridedArray, ::Type{Val{CA}}, B::StridedArray, ::Type{Val{CB}}, β, C::StridedArray, oindA, cindA, oindB, cindB, indCinoAB, ::Type{Val{:native}}=Val{:native}) +function contract!(α, A::StridedArray, ::Type{Val{CA}}, B::StridedArray, ::Type{Val{CB}}, β, C::StridedArray, oindA, cindA, oindB, cindB, indCinoAB, ::Type{Val{:native}}=Val{:native}) where {CA,CB} NA = ndims(A) NB = ndims(B) NC = ndims(C) diff --git a/src/implementation/strides.jl b/src/implementation/strides.jl index 090808f0..c7d5e84c 100644 --- a/src/implementation/strides.jl +++ b/src/implementation/strides.jl @@ -2,7 +2,7 @@ # # Implements the stride calculations of the various problems -@generated function add_strides{N}(dims::NTuple{N,Int}, stridesA::NTuple{N,Int}, stridesC::NTuple{N,Int}) +@generated function add_strides(dims::NTuple{N,Int}, stridesA::NTuple{N,Int}, stridesC::NTuple{N,Int}) where N minstridesex = Expr(:tuple,[:(min(stridesA[$d],stridesC[$d])) for d = 1:N]...) quote minstrides = $minstridesex @@ -16,7 +16,7 @@ end end -@generated function trace_strides{NA,NC}(dims::NTuple{NA,Int}, stridesA::NTuple{NA,Int}, stridesC::NTuple{NC,Int}) +@generated function trace_strides(dims::NTuple{NA,Int}, stridesA::NTuple{NA,Int}, stridesC::NTuple{NC,Int}) where {NA,NC} M = div(NA-NC,2) dimsex = Expr(:tuple,[:(dims[$d]) for d=1:(NC+M)]...) stridesAex = Expr(:tuple,[:(stridesA[$d]) for d = 1:NC]...,[:(stridesA[$(NC+d)]+stridesA[$(NC+M+d)]) for d = 1:M]...) @@ -34,8 +34,8 @@ end end end -@generated function contract_strides{NA, NB, NC}(dimsA::NTuple{NA, Int}, dimsB::NTuple{NB, Int}, - stridesA::NTuple{NA, Int}, stridesB::NTuple{NB, Int}, stridesC::NTuple{NC, Int}) +@generated function contract_strides(dimsA::NTuple{NA, Int}, dimsB::NTuple{NB, Int}, + stridesA::NTuple{NA, Int}, stridesB::NTuple{NB, Int}, stridesC::NTuple{NC, Int}) where {NA, NB, NC} meta = Expr(:meta, :inline) cN = div(NA+NB-NC, 2) oNA = NA - cN diff --git a/src/indexnotation/indexedobject.jl b/src/indexnotation/indexedobject.jl index 15f49273..ad4572f5 100644 --- a/src/indexnotation/indexedobject.jl +++ b/src/indexnotation/indexedobject.jl @@ -6,44 +6,45 @@ import Base: +, -, * -immutable Indices{I} +struct Indices{I} end -@compat abstract type AbstractIndexedObject end +abstract type AbstractIndexedObject end + indices(a::AbstractIndexedObject) = indices(typeof(a)) -immutable IndexedObject{I,C,A,T} <: AbstractIndexedObject +struct IndexedObject{I,C,A,T} <: AbstractIndexedObject object::A α::T - function (::Type{IndexedObject{I,C,A,T}}){I,C,A,T}(object::A, α::T) + function IndexedObject{I,C,A,T}(object::A, α::T) where {I,C,A,T} checkindices(object, I) new{I,C,A,T}(object, α) end end -(::Type{IndexedObject{I,C}}){I, C, A, T}(object::A, α::T=1) = IndexedObject{I,C, A, T}(object, α) +IndexedObject{I,C}(object::A, α::T=1) where {I, C, A, T} = IndexedObject{I,C, A, T}(object, α) -Base.conj{I}(a::IndexedObject{I,:N}) = IndexedObject{I,:C}(a.object, conj(a.α)) -Base.conj{I}(a::IndexedObject{I,:C}) = IndexedObject{I,:N}(a.object, conj(a.α)) +Base.conj(a::IndexedObject{I,:N}) where {I} = IndexedObject{I,:C}(a.object, conj(a.α)) +Base.conj(a::IndexedObject{I,:C}) where {I} = IndexedObject{I,:N}(a.object, conj(a.α)) Base.eltype(A::IndexedObject) = promote_type(eltype(A.object), typeof(A.α)) -Base.eltype{I,C, A, T}(::Type{IndexedObject{I,C, A, T}}) = promote_type(eltype(A), T) +Base.eltype(::Type{IndexedObject{I,C, A, T}}) where {I,C, A, T} = promote_type(eltype(A), T) -*{I,C}(a::IndexedObject{I,C}, β::Number) = IndexedObject{I,C}(a.object, a.α*β) +*(a::IndexedObject{I,C}, β::Number) where {I,C} = IndexedObject{I,C}(a.object, a.α*β) *(β::Number, a::IndexedObject) = *(a, β) -(a::IndexedObject) = *(a, -1) -@generated function indices{I,C,A,T}(::Type{IndexedObject{I,C,A,T}}) +@generated function indices(::Type{IndexedObject{I,C,A,T}}) where {I,C,A,T} J = tuple(unique2(I)...) meta = Expr(:meta, :inline) Expr(:block, meta, :($J)) end -indexify{I}(object, ::Indices{I}) = IndexedObject{I,:N}(object) +indexify(object, ::Indices{I}) where {I} = IndexedObject{I,:N}(object) -deindexify{I}(A::IndexedObject{I,:N}, ::Indices{I}) = A.α == 1 ? A.object : A.α*A.object -deindexify{I}(A::IndexedObject{I,:C}, ::Indices{I}) = A.α == 1 ? conj(A.object) : A.α*conj(A.object) +deindexify(A::IndexedObject{I,:N}, ::Indices{I}) where {I} = A.α == 1 ? A.object : A.α*A.object +deindexify(A::IndexedObject{I,:C}, ::Indices{I}) where {I} = A.α == 1 ? conj(A.object) : A.α*conj(A.object) -@generated function deindexify{I,C,J}(A::IndexedObject{I,C}, ::Indices{J}, T::Type = eltype(A)) +@generated function deindexify(A::IndexedObject{I,C}, ::Indices{J}, T::Type = eltype(A)) where {I,C,J} meta = Expr(:meta, :inline) indCinA, = trace_indices(I,J) conj = Val{C} @@ -53,7 +54,7 @@ deindexify{I}(A::IndexedObject{I,:C}, ::Indices{I}) = A.α == 1 ? conj(A.object) end end -@generated function deindexify!{Idst, Isrc, C}(dst, src::IndexedObject{Isrc, C}, ::Indices{Idst}, β=0) +@generated function deindexify!(dst, src::IndexedObject{Isrc, C}, ::Indices{Idst}, β=0) where {Idst, Isrc, C} meta = Expr(:meta, :inline) Jdst = unique2(Idst) length(Jdst) == length(Idst) || throw(IndexError("left-hand side cannot have partial trace: $Idst")) diff --git a/src/indexnotation/product.jl b/src/indexnotation/product.jl index f82a511a..5a696dcb 100644 --- a/src/indexnotation/product.jl +++ b/src/indexnotation/product.jl @@ -3,7 +3,7 @@ # A wrapper to store the contraction (product) of two indexed objects and # evaluate lazily, i.e. evaluate upon calling `deindexify`. -immutable ProductOfIndexedObjects{IA,IB,CA,CB,OA,OB,TA,TB} <: AbstractIndexedObject +struct ProductOfIndexedObjects{IA,IB,CA,CB,OA,OB,TA,TB} <: AbstractIndexedObject A::IndexedObject{IA,CA,OA,TA} B::IndexedObject{IB,CB,OB,TB} end @@ -16,7 +16,7 @@ Base.eltype(P::ProductOfIndexedObjects) = promote_type(eltype(P.A),eltype(P.B)) *(β::Number, P::ProductOfIndexedObjects) = *(P,β) -(P::ProductOfIndexedObjects) = *(-1, P) -@generated function indices{IA,IB,CA,CB,OA,OB,TA,TB}(::Type{ProductOfIndexedObjects{IA,IB,CA,CB,OA,OB,TA,TB}}) +@generated function indices(::Type{ProductOfIndexedObjects{IA,IB,CA,CB,OA,OB,TA,TB}}) where {IA,IB,CA,CB,OA,OB,TA,TB} J = unique2([IA...,IB...]) J = tuple(J...) meta = Expr(:meta, :inline) @@ -49,7 +49,7 @@ end Expr(:block,meta,:(ProductOfIndexedObjects($argA,$argB))) end -@generated function deindexify{IA,IB,CA,CB,IC}(P::ProductOfIndexedObjects{IA,IB,CA,CB}, I::Indices{IC}, T::Type = eltype(P)) +@generated function deindexify(P::ProductOfIndexedObjects{IA,IB,CA,CB}, I::Indices{IC}, T::Type = eltype(P)) where {IA,IB,CA,CB,IC} meta = Expr(:meta, :inline) oindA, cindA, oindB, cindB, indCinoAB = contract_indices(IA, IB, IC) indCinAB = vcat(oindA,length(IA)+oindB)[indCinoAB] @@ -61,7 +61,7 @@ end end end -@generated function deindexify!{IA,IB,CA,CB,IC}(dst, P::ProductOfIndexedObjects{IA,IB,CA,CB}, ::Indices{IC}, β=0) +@generated function deindexify!(dst, P::ProductOfIndexedObjects{IA,IB,CA,CB}, ::Indices{IC}, β=0) where {IA,IB,CA,CB,IC} oindA, cindA, oindB, cindB, indCinoAB = contract_indices(IA, IB, IC) conjA = Val{CA} conjB = Val{CB} diff --git a/src/indexnotation/sum.jl b/src/indexnotation/sum.jl index f7b71453..bdbbdcb0 100644 --- a/src/indexnotation/sum.jl +++ b/src/indexnotation/sum.jl @@ -3,7 +3,7 @@ # A wrapper to store the sum of a set of indexed objects and evaluate lazily, # i.e. evaluate upon calling `deindexify`. -immutable SumOfIndexedObjects{Os<:Tuple{Vararg{AbstractIndexedObject}}} <: AbstractIndexedObject +struct SumOfIndexedObjects{Os<:Tuple{Vararg{AbstractIndexedObject}}} <: AbstractIndexedObject objects::Os end @@ -22,7 +22,7 @@ Base.eltype(A::SumOfIndexedObjects) = _eltypetuple(A.objects) *(β::Number, A::SumOfIndexedObjects) = SumOfIndexedObjects(_multuple(β, A.objects)) -(A::SumOfIndexedObjects) = *(-1, A) -indices{Os}(A::SumOfIndexedObjects{Os}) = indices(Os.parameters[1]) +indices(A::SumOfIndexedObjects{Os}) where {Os} = indices(Os.parameters[1]) function +(A::SumOfIndexedObjects, B::SumOfIndexedObjects) add_indices(indices(A), indices(B)) # performs index check @@ -43,7 +43,7 @@ end -(a::AbstractIndexedObject, b::AbstractIndexedObject) = +(a, -b) -@generated function deindexify{Os}(A::SumOfIndexedObjects{Os}, I::Indices) +@generated function deindexify(A::SumOfIndexedObjects{Os}, I::Indices) where Os addex = Expr(:block, [:(deindexify!(dst, A.objects[$j], I, +1)) for j=2:length(Os.parameters)]...) quote dst = deindexify(A.objects[1], I, eltype(A)) @@ -52,7 +52,7 @@ end end end -@generated function deindexify!{Os}(dst, A::SumOfIndexedObjects{Os}, I::Indices, β=0) +@generated function deindexify!(dst, A::SumOfIndexedObjects{Os}, I::Indices, β=0) where Os addex = Expr(:block, [:(deindexify!(dst, A.objects[$j], I, +1)) for j=2:length(Os.parameters)]...) quote deindexify!(dst, A.objects[1], I, β)