@@ -44,13 +44,14 @@ strides are permuted such that both refer to the same entry. Term `n` then compu
4444`dst[offset_dst[n] .+ rel_dst] = α * coeff[n] * src[offset_src[n] .+ rel_src] + b * dst[offset_dst[n] .+ rel_dst]`,
4545with `b = β` for the first term into every destination subblock and `b = 1` for the groups of
4646further recoupling terms, which have `accumulate` set and are applied after all others.
47- The terms are sorted by `offset_dst`.
47+ The terms are sorted by `offset_dst`. Offsets and relative positions are `Int32`; tensors with more
48+ than `typemax(Int32)` entries are not grouped.
4849"""
4950struct SubblockGroup{T}
50- rel_dst:: Vector{Int }
51- rel_src:: Vector{Int }
52- offset_dst:: Vector{Int }
53- offset_src:: Vector{Int }
51+ rel_dst:: Vector{Int32 }
52+ rel_src:: Vector{Int32 }
53+ offset_dst:: Vector{Int32 }
54+ offset_src:: Vector{Int32 }
5455 coeff:: Vector{T}
5556 accumulate:: Bool
5657end
@@ -229,6 +230,9 @@ accumulating groups last, and return them together with the positions in `data`
229230function subblockgroups (:: Type{T} , data, structure_dst:: Vector{StridedStructure{N}} , structure_src, p) where {T, N}
230231 terms = Tuple{T, Int, Int, Bool}[]
231232 large = Int[]
233+ # positions are stored as `Int32`
234+ (_lastindex (structure_dst) > typemax (Int32) || _lastindex (structure_src) > typemax (Int32)) &&
235+ return SubblockGroup{T}[], collect (eachindex (data))
232236 for (n, (U, inds_dst, inds_src)) in enumerate (data)
233237 if prod (first (structure_dst[first (inds_dst)])) > SUBBLOCKGROUP_MAXLENGTH
234238 push! (large, n)
@@ -246,12 +250,12 @@ function subblockgroups(::Type{T}, data, structure_dst::Vector{StridedStructure{
246250 strides_dst = map ((n, s) -> n == 1 ? 0 : s, sz, strides_dst)
247251 strides_src′ = map ((n, s) -> n == 1 ? 0 : s, sz, TupleTools. getindices (strides_src, p))
248252 group = get! (groups, (accumulate, (sz, strides_dst, strides_src′))) do
249- rel_dst, rel_src = Int [], Int []
253+ rel_dst, rel_src = Int32 [], Int32 []
250254 for I in CartesianIndices (sz)
251255 push! (rel_dst, 1 + sum ((Tuple (I) .- 1 ) .* strides_dst; init = 0 ))
252256 push! (rel_src, 1 + sum ((Tuple (I) .- 1 ) .* strides_src′; init = 0 ))
253257 end
254- return SubblockGroup (rel_dst, rel_src, Int [], Int [], T[], accumulate)
258+ return SubblockGroup (rel_dst, rel_src, Int32 [], Int32 [], T[], accumulate)
255259 end
256260 push! (group. offset_dst, offset_dst)
257261 push! (group. offset_src, offset_src)
@@ -260,6 +264,9 @@ function subblockgroups(::Type{T}, data, structure_dst::Vector{StridedStructure{
260264 return sort! (collect (values (groups)); by = group -> group. accumulate), large
261265end
262266
267+ # the largest position addressed by the subblocks of `structure`
268+ _lastindex (structure) = maximum (((sz, str, offset),) -> offset + sum ((sz .- 1 ) .* str; init = 0 ) + 1 , structure; init = 0 )
269+
263270_push_terms! (terms, coeff:: Number , idst:: Int , isrc:: Int ) = push! (terms, (coeff, idst, isrc, false ))
264271function _push_terms! (terms, U:: AbstractMatrix , inds_dst, inds_src)
265272 for (i, idst) in enumerate (inds_dst)
0 commit comments