Skip to content
Open
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"
version = "0.10.4"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.10.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
28 changes: 14 additions & 14 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ using BlockSparseArrays: BlockSparseArrays
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(
BlockSparseArrays, :DocTestSetup, quote
using BlockSparseArrays
using LinearAlgebra: Diagonal
end; recursive=true
BlockSparseArrays, :DocTestSetup, quote
using BlockSparseArrays
using LinearAlgebra: Diagonal
end; recursive = true
)

include("make_index.jl")

makedocs(;
modules=[BlockSparseArrays],
authors="ITensor developers <[email protected]> and contributors",
sitename="BlockSparseArrays.jl",
format=Documenter.HTML(;
canonical="https://ITensor.github.io/BlockSparseArrays.jl",
edit_link="main",
assets=["assets/favicon.ico", "assets/extras.css"],
),
pages=["Home" => "index.md", "Reference" => "reference.md"],
modules = [BlockSparseArrays],
authors = "ITensor developers <[email protected]> and contributors",
sitename = "BlockSparseArrays.jl",
format = Documenter.HTML(;
canonical = "https://ITensor.github.io/BlockSparseArrays.jl",
edit_link = "main",
assets = ["assets/favicon.ico", "assets/extras.css"],
),
pages = ["Home" => "index.md", "Reference" => "reference.md"],
)

deploydocs(;
repo="github.com/ITensor/BlockSparseArrays.jl", devbranch="main", push_preview=true
repo = "github.com/ITensor/BlockSparseArrays.jl", devbranch = "main", push_preview = true
)
16 changes: 8 additions & 8 deletions docs/make_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using BlockSparseArrays: BlockSparseArrays

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
```@raw html
<img class="display-light-only" src="assets/CCQ.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
<img class="display-dark-only" src="assets/CCQ-dark.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
```
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
postprocess=ccq_logo,
joinpath(pkgdir(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays), "docs", "src");
flavor = Literate.DocumenterFlavor(),
name = "index",
postprocess = ccq_logo,
)
16 changes: 8 additions & 8 deletions docs/make_readme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using BlockSparseArrays: BlockSparseArrays

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
<picture>
<source media="(prefers-color-scheme: dark)" width="20%" srcset="docs/src/assets/CCQ-dark.png">
<img alt="Flatiron Center for Computational Quantum Physics logo." width="20%" src="docs/src/assets/CCQ.png">
</picture>
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays));
flavor=Literate.CommonMarkFlavor(),
name="README",
postprocess=ccq_logo,
joinpath(pkgdir(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays));
flavor = Literate.CommonMarkFlavor(),
name = "README",
postprocess = ccq_logo,
)
2 changes: 1 addition & 1 deletion examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # BlockSparseArrays.jl
#
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/BlockSparseArrays.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/BlockSparseArrays.jl/dev/)
# [![Build Status](https://github.com/ITensor/BlockSparseArrays.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/BlockSparseArrays.jl/actions/workflows/Tests.yml?query=branch%3Amain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@ module BlockSparseArraysTensorAlgebraExt

using BlockSparseArrays: AbstractBlockSparseArray, blockreshape
using TensorAlgebra:
TensorAlgebra,
BlockedTrivialPermutation,
BlockedTuple,
FusionStyle,
ReshapeFusion,
fuseaxes
TensorAlgebra,
BlockedTrivialPermutation,
BlockedTuple,
FusionStyle,
ReshapeFusion,
fuseaxes

struct BlockReshapeFusion <: FusionStyle end

function TensorAlgebra.FusionStyle(::Type{<:AbstractBlockSparseArray})
return BlockReshapeFusion()
return BlockReshapeFusion()
end

using BlockArrays: Block, blocklength, blocks
using BlockSparseArrays: blocksparse
using SparseArraysBase: eachstoredindex
using TensorAlgebra: TensorAlgebra, matricize, unmatricize
function TensorAlgebra.matricize(
::BlockReshapeFusion, a::AbstractArray, biperm::BlockedTrivialPermutation{2}
)
ax = fuseaxes(axes(a), biperm)
reshaped_blocks_a = reshape(blocks(a), map(blocklength, ax))
key(I) = Block(Tuple(I))
value(I) = matricize(reshaped_blocks_a[I], biperm)
Is = eachstoredindex(reshaped_blocks_a)
bs = if isempty(Is)
# Catch empty case and make sure the type is constrained properly.
# This seems to only be necessary in Julia versions below v1.11,
# try removing it when we drop support for those versions.
keytype = Base.promote_op(key, eltype(Is))
valtype = Base.promote_op(value, eltype(Is))
valtype′ = !isconcretetype(valtype) ? AbstractMatrix{eltype(a)} : valtype
Dict{keytype,valtype′}()
else
Dict(key(I) => value(I) for I in Is)
end
return blocksparse(bs, ax)
::BlockReshapeFusion, a::AbstractArray, biperm::BlockedTrivialPermutation{2}
)
ax = fuseaxes(axes(a), biperm)
reshaped_blocks_a = reshape(blocks(a), map(blocklength, ax))
key(I) = Block(Tuple(I))
value(I) = matricize(reshaped_blocks_a[I], biperm)
Is = eachstoredindex(reshaped_blocks_a)
bs = if isempty(Is)
# Catch empty case and make sure the type is constrained properly.
# This seems to only be necessary in Julia versions below v1.11,
# try removing it when we drop support for those versions.
keytype = Base.promote_op(key, eltype(Is))
valtype = Base.promote_op(value, eltype(Is))
valtype′ = !isconcretetype(valtype) ? AbstractMatrix{eltype(a)} : valtype
Dict{keytype, valtype′}()
else
Dict(key(I) => value(I) for I in Is)
end
return blocksparse(bs, ax)
end

using BlockArrays: blocklengths
function TensorAlgebra.unmatricize(
::BlockReshapeFusion,
m::AbstractMatrix,
blocked_ax::BlockedTuple{2,<:Any,<:Tuple{Vararg{AbstractUnitRange}}},
)
ax = Tuple(blocked_ax)
reshaped_blocks_m = reshape(blocks(m), map(blocklength, ax))
function f(I)
block_axes_I = BlockedTuple(
map(ntuple(identity, length(ax))) do i
return Base.axes1(ax[i][Block(I[i])])
end,
blocklengths(blocked_ax),
::BlockReshapeFusion,
m::AbstractMatrix,
blocked_ax::BlockedTuple{2, <:Any, <:Tuple{Vararg{AbstractUnitRange}}},
)
return unmatricize(reshaped_blocks_m[I], block_axes_I)
end
bs = Dict(Block(Tuple(I)) => f(I) for I in eachstoredindex(reshaped_blocks_m))
return blocksparse(bs, ax)
ax = Tuple(blocked_ax)
reshaped_blocks_m = reshape(blocks(m), map(blocklength, ax))
function f(I)
block_axes_I = BlockedTuple(
map(ntuple(identity, length(ax))) do i
return Base.axes1(ax[i][Block(I[i])])
end,
blocklengths(blocked_ax),
)
return unmatricize(reshaped_blocks_m[I], block_axes_I)
end
bs = Dict(Block(Tuple(I)) => f(I) for I in eachstoredindex(reshaped_blocks_m))
return blocksparse(bs, ax)
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ using TensorProducts: TensorProducts, tensor_product
# TODO: Dispatch on `FusionStyle` to allow different kinds of products,
# for example to allow merging common symmetry sectors.
function TensorProducts.tensor_product(a1::BlockUnitRange, a2::BlockUnitRange)
new_blockaxes = vec(
map(splat(tensor_product), Iterators.product(eachblockaxis(a1), eachblockaxis(a2)))
)
return blockrange(new_blockaxes)
new_blockaxes = vec(
map(splat(tensor_product), Iterators.product(eachblockaxis(a1), eachblockaxis(a2)))
)
return blockrange(new_blockaxes)
end

end
Loading