Skip to content

use BlockedTuple in splitdims #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BlockSparseArrays"
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.21"
version = "0.2.22"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module BlockSparseArraysTensorAlgebraExt
using BlockArrays: AbstractBlockedUnitRange
using GradedUnitRanges: tensor_product
using TensorAlgebra: TensorAlgebra, FusionStyle, BlockReshapeFusion
using TensorAlgebra: TensorAlgebra, BlockedTuple, BlockReshapeFusion, FusionStyle

function TensorAlgebra.:⊗(a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange)
return tensor_product(a1, a2)
Expand All @@ -19,10 +19,8 @@
return blockreshape(a, axes)
end

function TensorAlgebra.splitdims(
::BlockReshapeFusion, a::AbstractArray, axes::AbstractUnitRange...
)
return blockreshape(a, axes)
function TensorAlgebra.splitdims(::BlockReshapeFusion, a::AbstractArray, bt::BlockedTuple)
return blockreshape(a, Tuple(bt)...)

Check warning on line 23 in ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl#L22-L23

Added lines #L22 - L23 were not covered by tests
end

using BlockArrays:
Expand Down Expand Up @@ -58,7 +56,6 @@
TensorAlgebra, FusionStyle, BlockReshapeFusion, SectorFusion, fusedims, splitdims

# TODO: Make a `ReduceWhile` library.
include("reducewhile.jl")

TensorAlgebra.FusionStyle(::AbstractGradedUnitRange) = SectorFusion()

Expand All @@ -85,15 +82,10 @@
return block_mergesort(a_reshaped)
end

function TensorAlgebra.splitdims(
::SectorFusion, a::AbstractArray, split_axes::AbstractUnitRange...
)
function TensorAlgebra.splitdims(::SectorFusion, a::AbstractArray, split_axes::BlockedTuple)

Check warning on line 85 in ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl#L85

Added line #L85 was not covered by tests
# First, fuse axes to get `blockmergesortperm`.
# Then unpermute the blocks.
axes_prod =
groupreducewhile(tensor_product, split_axes, ndims(a); init=OneToOne()) do i, axis
return length(axis) ≤ length(axes(a, i))
end
axes_prod = map(t -> tensor_product(t...), blocks(split_axes))

Check warning on line 88 in ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl#L88

Added line #L88 was not covered by tests
blockperms = blocksortperm.(axes_prod)
sorted_axes = map((r, I) -> only(axes(r[I])), axes_prod, blockperms)

Expand All @@ -103,7 +95,7 @@
# for this combination of slicing.
a_unblocked = a[sorted_axes...]
a_blockpermed = a_unblocked[invblockperm.(blockperms)...]
return splitdims(BlockReshapeFusion(), a_blockpermed, split_axes...)
return splitdims(BlockReshapeFusion(), a_blockpermed, split_axes)

Check warning on line 98 in ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl#L98

Added line #L98 was not covered by tests
end

# This is a temporary fix for `eachindex` being broken for BlockSparseArrays
Expand Down
Loading