Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jutho committed Oct 27, 2017
1 parent 49c5502 commit 6b59f15
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/auxiliary/stridedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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(::Type{T}, indices::NTuple{N,Int}, A::StridedArray, B::StridedArray, ::Type{Val{CA}}=Val{:N}, ::Type{Val{CB}}=Val{:N}) where {T,N,CA,CB}
function similar_from_indices(::Type{T}, indices::IndexTuple{N}, A::StridedArray, B::StridedArray, ::Type{Val{CA}}=Val{:N}, ::Type{Val{CB}}=Val{:N}) where {T,N,CA,CB}
srcdims = tuple(size(A)...,size(B)...)
return similar(A, T, ntuple(n->srcdims[indices[n]], StaticLength(N)))
end
Expand Down
14 changes: 7 additions & 7 deletions src/auxiliary/strideddata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import Base.StridedReshapedArray

StridedSubArray{T,N,A<:Union{DenseArray{T},StridedReshapedArray{T}},I<:Tuple{Vararg{Union{Base.RangeIndex, Base.AbstractCartesianIndex}}}} = SubArray{T,N,A,I}

StridedData(a::Array{T}, strides::NTuple{N,Int} = strides(a), ::Type{Val{C}} = Val{:N}) where {N,T,C} =
StridedData(a::Array{T}, strides::IndexTuple{N} = strides(a), ::Type{Val{C}} = Val{:N}) where {N,T,C} =
StridedData{N,T,C}(vec(a), strides, 1)
StridedData(a::StridedReshapedArray{T}, strides::NTuple{N,Int} = strides(a), ::Type{Val{C}} = Val{:N}) where {N,T,C} =
StridedData(a::StridedReshapedArray{T}, strides::IndexTuple{N} = strides(a), ::Type{Val{C}} = Val{:N}) where {N,T,C} =
StridedData{N,T,C}(vec(a.parent), strides, 1)
StridedData(a::StridedSubArray{T}, strides::NTuple{N,Int} = strides(a), ::Type{Val{C}} = Val{:N}) where {N,T,C} =
StridedData(a::StridedSubArray{T}, strides::IndexTuple{N} = 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]
Expand All @@ -31,16 +31,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(dims::NTuple{N,Int}, a::StridedData{N}) where {N}
@generated function _filterdims(dims::IndexTuple{N}, 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!(C::StridedData{N}, β::One, dims::NTuple{N,Int}, offset::Int=0) where {N} = C
_scale!(C::StridedData{N}, β::One, dims::IndexTuple{N}, offset::Int=0) where {N} = C

@generated function _scale!(C::StridedData{N}, β::Zero, dims::NTuple{N,Int}, offset::Int=0) where {N}
@generated function _scale!(C::StridedData{N}, β::Zero, dims::IndexTuple{N}, offset::Int=0) where {N}
meta = Expr(:meta,:inline)
quote
$meta
Expand All @@ -52,7 +52,7 @@ _scale!(C::StridedData{N}, β::One, dims::NTuple{N,Int}, offset::Int=0) where {N
end
end

@generated function _scale!(C::StridedData{N}, β::Number, dims::NTuple{N,Int}, offset::Int=0) where {N}
@generated function _scale!(C::StridedData{N}, β::Number, dims::IndexTuple{N}, offset::Int=0) where {N}
meta = Expr(:meta,:inline)
quote
$meta
Expand Down
6 changes: 3 additions & 3 deletions src/implementation/kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Implements the microkernels for solving the subproblems of the various problems.

@generated function add_micro!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int) where N
@generated function add_micro!(α, A::StridedData{N}, β, C::StridedData{N}, dims::IndexTuple{N}, offsetA::Int, offsetC::Int) where N
quote
startA = A.start+offsetA
stridesA = A.strides
Expand All @@ -13,7 +13,7 @@
end
end

@generated function trace_micro!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int) where N
@generated function trace_micro!(α, A::StridedData{N}, β, C::StridedData{N}, dims::IndexTuple{N}, offsetA::Int, offsetC::Int) where N
quote
_scale!(C, β, dims, offsetC)
startA = A.start+offsetA
Expand All @@ -25,7 +25,7 @@ end
end
end

@generated function contract_micro!(α, A::StridedData{N}, B::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA, offsetB, offsetC) where N
@generated function contract_micro!(α, A::StridedData{N}, B::StridedData{N}, β, C::StridedData{N}, dims::IndexTuple{N}, offsetA, offsetB, offsetC) where N
quote
_scale!(C, β, dims, offsetC)
startA = A.start+offsetA
Expand Down
6 changes: 3 additions & 3 deletions src/implementation/recursive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const BASELENGTH=2048

function add_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int, minstrides::NTuple{N, Int}) where N
function add_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::IndexTuple{N}, offsetA::Int, offsetC::Int, minstrides::IndexTuple{N}) where N
if 2*prod(dims) <= BASELENGTH
add_micro!(α, A, β, C, dims, offsetA, offsetC)
else
Expand All @@ -24,7 +24,7 @@ function add_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N,
return C
end

function trace_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N, Int}, offsetA::Int, offsetC::Int, minstrides::NTuple{N, Int}) where N
function trace_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::IndexTuple{N}, offsetA::Int, offsetC::Int, minstrides::IndexTuple{N}) where N
if prod(dims) + prod(_filterdims(dims,C)) <= BASELENGTH
trace_micro!(α, A, β, C, dims, offsetA, offsetC)
else
Expand All @@ -46,7 +46,7 @@ function trace_rec!(α, A::StridedData{N}, β, C::StridedData{N}, dims::NTuple{N
end

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
dims::IndexTuple{N}, offsetA::Int, offsetB::Int, offsetC::Int, minstrides::IndexTuple{N}) where N

odimsA = _filterdims(_filterdims(dims, A), C)
odimsB = _filterdims(_filterdims(dims, B), C)
Expand Down
8 changes: 4 additions & 4 deletions src/implementation/strides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Implements the stride calculations of the various problems

@generated function add_strides(dims::NTuple{N,Int}, stridesA::NTuple{N,Int}, stridesC::NTuple{N,Int}) where N
@generated function add_strides(dims::IndexTuple{N}, stridesA::IndexTuple{N}, stridesC::IndexTuple{N}) where N
minstridesex = Expr(:tuple,[:(min(stridesA[$d],stridesC[$d])) for d = 1:N]...)
quote
minstrides = $minstridesex
Expand All @@ -16,7 +16,7 @@
end
end

@generated function trace_strides(dims::NTuple{NA,Int}, stridesA::NTuple{NA,Int}, stridesC::NTuple{NC,Int}) where {NA,NC}
@generated function trace_strides(dims::IndexTuple{NA}, stridesA::IndexTuple{NA}, stridesC::IndexTuple{NC}) 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]...)
Expand All @@ -34,8 +34,8 @@ end
end
end

@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}
@generated function contract_strides(dimsA::IndexTuple{NA}, dimsB::IndexTuple{NB},
stridesA::IndexTuple{NA}, stridesB::IndexTuple{NB}, stridesC::IndexTuple{NC}) where {NA, NB, NC}
meta = Expr(:meta, :inline)
cN = div(NA+NB-NC, 2)
oNA = NA - cN
Expand Down

0 comments on commit 6b59f15

Please sign in to comment.