From 6ab5523fc4481473b0c4657cc1ed0aa3ec8efa49 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 May 2024 21:53:02 -0400 Subject: [PATCH 1/6] CompatHelper: add new compat entry for Observers in [weakdeps] at version 0.2, (keep existing compat) (#1460) Co-authored-by: CompatHelper Julia --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 22fe3200e3..ddc19cb8df 100644 --- a/Project.toml +++ b/Project.toml @@ -57,6 +57,7 @@ KrylovKit = "0.4.2, 0.5, 0.6, 0.7" LinearAlgebra = "1.6" LinearMaps = "3" NDTensors = "0.3.0" +Observers = "0.2" PackageCompiler = "1, 2" PackageExtensionCompat = "1" Pkg = "1.6" From f4b6f3b1837af08509ab14583e4c7acca2be812f Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Sat, 25 May 2024 07:59:12 -0400 Subject: [PATCH 2/6] [ITensors] Remove Observers compat entry --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index ddc19cb8df..22fe3200e3 100644 --- a/Project.toml +++ b/Project.toml @@ -57,7 +57,6 @@ KrylovKit = "0.4.2, 0.5, 0.6, 0.7" LinearAlgebra = "1.6" LinearMaps = "3" NDTensors = "0.3.0" -Observers = "0.2" PackageCompiler = "1, 2" PackageExtensionCompat = "1" Pkg = "1.6" From 1269d891d27e55d0e71777d3d3a22985f3ddc42e Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Sat, 25 May 2024 17:17:19 -0400 Subject: [PATCH 3/6] [GradedAxes] Fix iterate (#1468) * [GradedAxes] Fix iterate * Bump to v0.3.9 --- NDTensors/Project.toml | 2 +- .../src/lib/GradedAxes/src/gradedunitrange.jl | 7 ++++++ .../src/lib/GradedAxes/test/test_basics.jl | 25 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index 80d7a38a09..b1a56aa106 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.8" +version = "0.3.9" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/NDTensors/src/lib/GradedAxes/src/gradedunitrange.jl b/NDTensors/src/lib/GradedAxes/src/gradedunitrange.jl index c10d5052e3..8a19b6e04f 100644 --- a/NDTensors/src/lib/GradedAxes/src/gradedunitrange.jl +++ b/NDTensors/src/lib/GradedAxes/src/gradedunitrange.jl @@ -161,6 +161,13 @@ function Base.first(a::GradedUnitRange) return labelled(first(unlabel_blocks(a)), label(a[Block(1)])) end +Base.iterate(a::GradedUnitRange) = isempty(a) ? nothing : (first(a), first(a)) +function Base.iterate(a::GradedUnitRange, i) + i == last(a) && return nothing + next = a[i + step(a)] + return (next, next) +end + function firstblockindices(a::GradedUnitRange) return labelled.(firstblockindices(unlabel_blocks(a)), blocklabels(a)) end diff --git a/NDTensors/src/lib/GradedAxes/test/test_basics.jl b/NDTensors/src/lib/GradedAxes/test/test_basics.jl index aa3a9d7560..41815db4d1 100644 --- a/NDTensors/src/lib/GradedAxes/test/test_basics.jl +++ b/NDTensors/src/lib/GradedAxes/test/test_basics.jl @@ -9,7 +9,7 @@ using BlockArrays: blocklengths, blocks using NDTensors.GradedAxes: GradedUnitRange, blocklabels, gradedrange -using NDTensors.LabelledNumbers: LabelledUnitRange, label, labelled, unlabel +using NDTensors.LabelledNumbers: LabelledUnitRange, islabelled, label, labelled, unlabel using Test: @test, @test_broken, @testset @testset "GradedAxes basics" begin for a in ( @@ -18,7 +18,30 @@ using Test: @test, @test_broken, @testset gradedrange(["x" => 2, "y" => 3]), ) @test a isa GradedUnitRange + for x in iterate(a) + @test x == 1 + @test label(x) == "x" + end + for x in iterate(a, labelled(1, "x")) + @test x == 2 + @test label(x) == "x" + end + for x in iterate(a, labelled(2, "x")) + @test x == 3 + @test label(x) == "y" + end + for x in iterate(a, labelled(3, "y")) + @test x == 4 + @test label(x) == "y" + end + for x in iterate(a, labelled(4, "y")) + @test x == 5 + @test label(x) == "y" + end + @test isnothing(iterate(a, labelled(5, "y"))) @test length(a) == 5 + @test step(a) == 1 + @test !islabelled(step(a)) @test length(blocks(a)) == 2 @test blocks(a)[1] == 1:2 @test label(blocks(a)[1]) == "x" From cd766a2379eff9583cdfc830a11d74e0ab594e8b Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Sat, 25 May 2024 18:05:22 -0400 Subject: [PATCH 4/6] [BlockSparseArrays] Allow more general axes (#1467) * [BlockSparseArrays] Allow more general axes * [NDTensors] Bump to v0.3.10 --- NDTensors/Project.toml | 2 +- .../BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index b1a56aa106..b4e21b6198 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.9" +version = "0.3.10" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl index 4ecde33381..3f563f9070 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl @@ -10,7 +10,7 @@ struct BlockSparseArray{ N, A<:AbstractArray{T,N}, Blocks<:AbstractArray{A,N}, - Axes<:NTuple{N,AbstractUnitRange{Int}}, + Axes<:Tuple{Vararg{AbstractUnitRange,N}}, } <: AbstractBlockSparseArray{T,N} blocks::Blocks axes::Axes From 4c70aff42df52528ee2316c3f85fa7892ecc7741 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Mon, 27 May 2024 11:41:45 -0400 Subject: [PATCH 5/6] [BlockSparseArrays] Fix adjoint and transpose (#1470) * [BlockSparseArrays] Fix adjoint and transpose * [NDTensors] Bump to v0.3.11 --- NDTensors/Project.toml | 2 +- .../src/abstractblocksparsearray/map.jl | 15 +++ .../wrappedabstractblocksparsearray.jl | 4 +- .../blocksparsearrayinterface.jl | 92 +++++++++++++++--- .../lib/BlockSparseArrays/test/test_basics.jl | 93 +++++++++++++++++-- 5 files changed, 184 insertions(+), 22 deletions(-) diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index b4e21b6198..7e09c978b3 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.10" +version = "0.3.11" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl index 2d22efd277..22f9350605 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl @@ -1,5 +1,6 @@ using ArrayLayouts: LayoutArray using BlockArrays: blockisequal +using LinearAlgebra: Adjoint, Transpose using ..SparseArrayInterface: SparseArrayInterface, SparseArrayStyle, @@ -73,6 +74,20 @@ function Base.copyto!(a_dest::LayoutArray, a_src::BlockSparseArrayLike) return a_dest end +function Base.copyto!( + a_dest::AbstractMatrix, a_src::Transpose{T,<:AbstractBlockSparseMatrix{T}} +) where {T} + sparse_copyto!(a_dest, a_src) + return a_dest +end + +function Base.copyto!( + a_dest::AbstractMatrix, a_src::Adjoint{T,<:AbstractBlockSparseMatrix{T}} +) where {T} + sparse_copyto!(a_dest, a_src) + return a_dest +end + function Base.permutedims!(a_dest, a_src::BlockSparseArrayLike, perm) sparse_permutedims!(a_dest, a_src, perm) return a_dest diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl index dc40010526..784b4e27c8 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl @@ -3,8 +3,8 @@ using SplitApplyCombine: groupcount using Adapt: Adapt, WrappedArray -const WrappedAbstractBlockSparseArray{T,N,A} = WrappedArray{ - T,N,<:AbstractBlockSparseArray,<:AbstractBlockSparseArray{T,N} +const WrappedAbstractBlockSparseArray{T,N} = WrappedArray{ + T,N,AbstractBlockSparseArray,AbstractBlockSparseArray{T,N} } # TODO: Rename `AnyBlockSparseArray`. diff --git a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl index 5fe63e9804..56e6e7c96b 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl @@ -8,6 +8,7 @@ using BlockArrays: blocks, blocklengths, findblockindex +using LinearAlgebra: Adjoint, Transpose using ..SparseArrayInterface: perm, iperm, nstored ## using MappedArrays: mappedarray @@ -86,10 +87,15 @@ end # BlockArrays -using ..SparseArrayInterface: SparseArrayInterface, AbstractSparseArray +using ..SparseArrayInterface: + SparseArrayInterface, AbstractSparseArray, AbstractSparseMatrix -# Represents the array of arrays of a `SubArray` -# wrapping a block spare array, i.e. `blocks(array)` where `a` is a `SubArray`. +_perm(::PermutedDimsArray{<:Any,<:Any,P}) where {P} = P +_getindices(t::Tuple, indices) = map(i -> t[i], indices) +_getindices(i::CartesianIndex, indices) = CartesianIndex(_getindices(Tuple(i), indices)) + +# Represents the array of arrays of a `PermutedDimsArray` +# wrapping a block spare array, i.e. `blocks(array)` where `a` is a `PermutedDimsArray`. struct SparsePermutedDimsArrayBlocks{T,N,Array<:PermutedDimsArray{T,N}} <: AbstractSparseArray{T,N} array::Array @@ -97,24 +103,80 @@ end function blocksparse_blocks(a::PermutedDimsArray) return SparsePermutedDimsArrayBlocks(a) end -_perm(::PermutedDimsArray{<:Any,<:Any,P}) where {P} = P -_getindices(t::Tuple, indices) = map(i -> t[i], indices) -_getindices(i::CartesianIndex, indices) = CartesianIndex(_getindices(Tuple(i), indices)) -function SparseArrayInterface.stored_indices(a::SparsePermutedDimsArrayBlocks) - return map(I -> _getindices(I, _perm(a.array)), stored_indices(blocks(parent(a.array)))) -end function Base.size(a::SparsePermutedDimsArrayBlocks) return _getindices(size(blocks(parent(a.array))), _perm(a.array)) end -function Base.getindex(a::SparsePermutedDimsArrayBlocks, index::Vararg{Int}) +function Base.getindex( + a::SparsePermutedDimsArrayBlocks{<:Any,N}, index::Vararg{Int,N} +) where {N} return PermutedDimsArray( blocks(parent(a.array))[_getindices(index, _perm(a.array))...], _perm(a.array) ) end +function SparseArrayInterface.stored_indices(a::SparsePermutedDimsArrayBlocks) + return map(I -> _getindices(I, _perm(a.array)), stored_indices(blocks(parent(a.array)))) +end +# TODO: Either make this the generic interface or define +# `SparseArrayInterface.sparse_storage`, which is used +# to defined this. +SparseArrayInterface.nstored(a::SparsePermutedDimsArrayBlocks) = length(stored_indices(a)) function SparseArrayInterface.sparse_storage(a::SparsePermutedDimsArrayBlocks) return error("Not implemented") end +reverse_index(index) = reverse(index) +reverse_index(index::CartesianIndex) = CartesianIndex(reverse(Tuple(index))) + +# Represents the array of arrays of a `Transpose` +# wrapping a block spare array, i.e. `blocks(array)` where `a` is a `Transpose`. +struct SparseTransposeBlocks{T,Array<:Transpose{T}} <: AbstractSparseMatrix{T} + array::Array +end +function blocksparse_blocks(a::Transpose) + return SparseTransposeBlocks(a) +end +function Base.size(a::SparseTransposeBlocks) + return reverse(size(blocks(parent(a.array)))) +end +function Base.getindex(a::SparseTransposeBlocks, index::Vararg{Int,2}) + return transpose(blocks(parent(a.array))[reverse(index)...]) +end +function SparseArrayInterface.stored_indices(a::SparseTransposeBlocks) + return map(reverse_index, stored_indices(blocks(parent(a.array)))) +end +# TODO: Either make this the generic interface or define +# `SparseArrayInterface.sparse_storage`, which is used +# to defined this. +SparseArrayInterface.nstored(a::SparseTransposeBlocks) = length(stored_indices(a)) +function SparseArrayInterface.sparse_storage(a::SparseTransposeBlocks) + return error("Not implemented") +end + +# Represents the array of arrays of a `Adjoint` +# wrapping a block spare array, i.e. `blocks(array)` where `a` is a `Adjoint`. +struct SparseAdjointBlocks{T,Array<:Adjoint{T}} <: AbstractSparseMatrix{T} + array::Array +end +function blocksparse_blocks(a::Adjoint) + return SparseAdjointBlocks(a) +end +function Base.size(a::SparseAdjointBlocks) + return reverse(size(blocks(parent(a.array)))) +end +function Base.getindex(a::SparseAdjointBlocks, index::Vararg{Int,2}) + return blocks(parent(a.array))[reverse(index)...]' +end +function SparseArrayInterface.stored_indices(a::SparseAdjointBlocks) + return map(reverse_index, stored_indices(blocks(parent(a.array)))) +end +# TODO: Either make this the generic interface or define +# `SparseArrayInterface.sparse_storage`, which is used +# to defined this. +SparseArrayInterface.nstored(a::SparseAdjointBlocks) = length(stored_indices(a)) +function SparseArrayInterface.sparse_storage(a::SparseAdjointBlocks) + return error("Not implemented") +end + # TODO: Move to `BlockArraysExtensions`. # This takes a range of indices `indices` of array `a` # and maps it to the range of indices within block `block`. @@ -167,9 +229,6 @@ end function Base.size(a::SparseSubArrayBlocks) return length.(axes(a)) end -function SparseArrayInterface.stored_indices(a::SparseSubArrayBlocks) - return stored_indices(view(blocks(parent(a.array)), axes(a)...)) -end function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::CartesianIndex{N}) where {N} return a[Tuple(I)...] end @@ -192,6 +251,13 @@ function Base.isassigned(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) whe # TODO: Implement this properly. return true end +function SparseArrayInterface.stored_indices(a::SparseSubArrayBlocks) + return stored_indices(view(blocks(parent(a.array)), axes(a)...)) +end +# TODO: Either make this the generic interface or define +# `SparseArrayInterface.sparse_storage`, which is used +# to defined this. +SparseArrayInterface.nstored(a::SparseSubArrayBlocks) = length(stored_indices(a)) function SparseArrayInterface.sparse_storage(a::SparseSubArrayBlocks) return error("Not implemented") end diff --git a/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl b/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl index c9d982a6cc..62cc23d9db 100644 --- a/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl +++ b/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl @@ -48,6 +48,9 @@ include("TestBlockSparseArraysUtils.jl") @test block_nstored(a) == 2 @test nstored(a) == 2 * 4 + 3 * 3 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = similar(a, complex(elt)) @test eltype(b) == complex(eltype(a)) @test iszero(b) @@ -56,37 +59,58 @@ include("TestBlockSparseArraysUtils.jl") @test size(b) == size(a) @test blocksize(b) == blocksize(a) + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = copy(a) b[1, 1] = 11 @test b[1, 1] == 11 @test a[1, 1] ≠ 11 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = copy(a) b .*= 2 @test b ≈ 2a + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = copy(a) b ./= 2 @test b ≈ a / 2 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = 2 * a @test Array(b) ≈ 2 * Array(a) @test eltype(b) == elt @test block_nstored(b) == 2 @test nstored(b) == 2 * 4 + 3 * 3 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = (2 + 3im) * a @test Array(b) ≈ (2 + 3im) * Array(a) @test eltype(b) == complex(elt) @test block_nstored(b) == 2 @test nstored(b) == 2 * 4 + 3 * 3 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = a + a @test Array(b) ≈ 2 * Array(a) @test eltype(b) == elt @test block_nstored(b) == 2 @test nstored(b) == 2 * 4 + 3 * 3 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) x = BlockSparseArray{elt}(undef, ([3, 4], [2, 3])) x[Block(1, 2)] = randn(elt, size(@view(x[Block(1, 2)]))) x[Block(2, 1)] = randn(elt, size(@view(x[Block(2, 1)]))) @@ -96,12 +120,18 @@ include("TestBlockSparseArraysUtils.jl") @test block_nstored(b) == 2 @test nstored(b) == 2 * 4 + 3 * 3 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = permutedims(a, (2, 1)) @test Array(b) ≈ permutedims(Array(a), (2, 1)) @test eltype(b) == elt @test block_nstored(b) == 2 @test nstored(b) == 2 * 4 + 3 * 3 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = map(x -> 2x, a) @test Array(b) ≈ 2 * Array(a) @test eltype(b) == elt @@ -110,6 +140,9 @@ include("TestBlockSparseArraysUtils.jl") @test block_nstored(b) == 2 @test nstored(b) == 2 * 4 + 3 * 3 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = a[[Block(2), Block(1)], [Block(2), Block(1)]] @test b[Block(1, 1)] == a[Block(2, 2)] @test b[Block(1, 2)] == a[Block(2, 1)] @@ -120,6 +153,9 @@ include("TestBlockSparseArraysUtils.jl") @test nstored(b) == nstored(a) @test block_nstored(b) == 2 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = a[Block(1):Block(2), Block(1):Block(2)] @test b == a @test size(b) == size(a) @@ -127,6 +163,9 @@ include("TestBlockSparseArraysUtils.jl") @test nstored(b) == nstored(a) @test block_nstored(b) == 2 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = a[Block(1):Block(1), Block(1):Block(2)] @test b == Array(a)[1:2, 1:end] @test b[Block(1, 1)] == a[Block(1, 1)] @@ -136,6 +175,9 @@ include("TestBlockSparseArraysUtils.jl") @test nstored(b) == nstored(a[Block(1, 2)]) @test block_nstored(b) == 1 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = a[2:4, 2:4] @test b == Array(a)[2:4, 2:4] @test size(b) == (3, 3) @@ -143,6 +185,9 @@ include("TestBlockSparseArraysUtils.jl") @test nstored(b) == 1 * 1 + 2 * 2 @test block_nstored(b) == 2 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = a[Block(2, 1)[1:2, 2:3]] @test b == Array(a)[3:4, 2:3] @test size(b) == (2, 2) @@ -150,27 +195,63 @@ include("TestBlockSparseArraysUtils.jl") @test nstored(b) == 2 * 2 @test block_nstored(b) == 1 + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) + b = PermutedDimsArray(a, (2, 1)) + @test block_nstored(b) == 2 + @test Array(b) == permutedims(Array(a), (2, 1)) + c = 2 * b + @test block_nstored(c) == 2 + @test Array(c) == 2 * permutedims(Array(a), (2, 1)) + + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) + b = a' + @test block_nstored(b) == 2 + @test Array(b) == Array(a)' + c = 2 * b + @test block_nstored(c) == 2 + @test Array(c) == 2 * Array(a)' + + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) + b = transpose(a) + @test block_nstored(b) == 2 + @test Array(b) == transpose(Array(a)) + c = 2 * b + @test block_nstored(c) == 2 + @test Array(c) == 2 * transpose(Array(a)) + ## Broken, need to fix. + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) @test_broken a[Block(1), Block(1):Block(2)] # This is outputting only zero blocks. + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = a[Block(2):Block(2), Block(1):Block(2)] @test_broken block_nstored(b) == 1 @test_broken b == Array(a)[3:5, 1:end] - b = a' - @test_broken block_nstored(b) == 2 - - b = transpose(a) - @test_broken block_nstored(b) == 2 - + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = copy(a) x = randn(size(@view(a[Block(2, 2)]))) b[Block(2), Block(2)] = x @test_broken b[Block(2, 2)] == x # Doesnt' set the block + a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) + a[Block(1, 2)] = randn(elt, size(@view(a[Block(1, 2)]))) + a[Block(2, 1)] = randn(elt, size(@view(a[Block(2, 1)]))) b = copy(a) b[Block(1, 1)] .= 1 @test_broken b[1, 1] == trues(size(@view(b[1, 1]))) From b4a688096ba4fa0892a5dcbc055859dd27538930 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Mon, 27 May 2024 15:56:10 -0400 Subject: [PATCH 6/6] [NDTensors] [ITensors] Add compat entries for weakdeps (#1471) * [NDTensors] [ITensors] Add compat entries for weakdeps * [NDTensors] Bump to v0.3.12 * [ITensors] Bump to v0.6.11 --- NDTensors/Project.toml | 14 +++++++++++++- Project.toml | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index 7e09c978b3..e25bea22a2 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.11" +version = "0.3.12" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" @@ -51,11 +51,14 @@ NDTensorsTBLISExt = "TBLIS" NDTensorscuTENSORExt = "cuTENSOR" [compat] +AMDGPU = "0.9" Accessors = "0.1.33" Adapt = "3.7, 4" ArrayLayouts = "1.4" BlockArrays = "0.16" +CUDA = "5" Compat = "4.9" +cuTENSOR = "2" Dictionaries = "0.4" EllipsisNotation = "1.8" FillArrays = "1" @@ -68,6 +71,8 @@ InlineStrings = "1" LinearAlgebra = "1.6" MacroTools = "0.5" MappedArrays = "0.4" +Metal = "1" +Octavian = "0.3" PackageExtensionCompat = "1" Random = "1.6" SimpleTraits = "0.9.4" @@ -76,10 +81,17 @@ SplitApplyCombine = "1.2.2" StaticArrays = "0.12, 1.0" Strided = "2" StridedViews = "0.2.2" +TBLIS = "0.2" TimerOutputs = "0.5.5" TupleTools = "1.2.0" VectorInterface = "0.4.2" julia = "1.6" [extras] +AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" +Metal = "dde4c033-4e86-420c-a63e-0dd931031962" +Octavian = "6fd5a793-0b7e-452c-907f-f8bfe9c57db4" +TBLIS = "48530278-0828-4a49-9772-0f3830dfa1e9" +cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1" diff --git a/Project.toml b/Project.toml index 22fe3200e3..1f8c37ffe2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensors" uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.6.10" +version = "0.6.11" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -57,6 +57,7 @@ KrylovKit = "0.4.2, 0.5, 0.6, 0.7" LinearAlgebra = "1.6" LinearMaps = "3" NDTensors = "0.3.0" +Observers = "0.2" PackageCompiler = "1, 2" PackageExtensionCompat = "1" Pkg = "1.6"