Skip to content

Commit

Permalink
Aqua tests (#18)
Browse files Browse the repository at this point in the history
* Add and fix Aqua tests

* update readme

* fix undefined variables
  • Loading branch information
lkdvos authored Dec 3, 2024
1 parent ca5d6f5 commit 433319c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 49 deletions.
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"

[compat]
Aqua = "0.8"
BlockArrays = "1"
Combinatorics = "1"
LinearAlgebra = "1"
Random = "1"
Strided = "2"
SafeTestsets = "0.1"
TensorKit = "0.13.2"
TensorOperations = "5"
Test = "1"
Expand All @@ -28,11 +30,12 @@ VectorInterface = "0.4.8"
julia = "1.8"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"

[targets]
test = ["Test", "TestExtras", "Random", "Combinatorics", "SafeTestsets"]
test = ["Test", "TestExtras", "Random", "Combinatorics", "SafeTestsets", "Aqua"]
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@

# BlockTensorKit

![CI][ci-url] [![codecov][codecov-img]][codecov-url]
Contains code for handling `BlockTensorMaps`, which are the [TensorKit.jl](https://github.com/jutho/TensorKit.jl) equivalent of BlockArrays.

| **Documentation** | **Build Status** | **Coverage** | **Quality assurance** |
|:-----------------:|:----------------:|:------------:|:---------------------:|
| [![][docs-stable-img]][docs-stable-url] [![][docs-dev-img]][docs-dev-url] | [![CI][ci-img]][ci-url] | [![Codecov][codecov-img]][codecov-url] | [![Aqua QA][aqua-img]][aqua-url] |


[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
[docs-stable-url]: https://lkdvos.github.io/BlockTensorKit.jl/stable

[docs-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg
[docs-dev-url]: https://lkdvos.github.io/BlockTensorKit.jl/latest

[ci-img]: https://github.com/lkdvos/BlockTensorKit.jl/actions/workflows/CI.yml/badge.svg
[ci-url]: https://github.com/lkdvos/BlockTensorKit.jl/actions/workflows/CI.yml

[codecov-img]: https://codecov.io/gh/lkdvos/BlockTensorKit.jl/graph/badge.svg?token=C1QPCRT1NT
[codecov-url]: https://codecov.io/gh/lkdvos/BlockTensorKit.jl

[ci-url]: https://github.com/QuantumKitHub/PEPSKit.jl/workflows/CI/badge.svg
[aqua-img]: https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg
[aqua-url]: https://github.com/JuliaTesting/Aqua.jl



Contains code for handling BlockTensorMaps, which are the TensorKit equivalent of
BlockArrays.
4 changes: 2 additions & 2 deletions src/BlockTensorKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module BlockTensorKit
export SumSpace, ProductSumSpace
export eachspace, SumSpaceIndices, sumspacetype

export AbstractBlockTensorMap, BlockTensorMap, SparseBlockTensorMap, PseudoBlockTensorMap
export AbstractBlockTensorMap, BlockTensorMap, SparseBlockTensorMap
export blocktensormaptype, sparseblocktensormaptype

export SparseTensorArray

export sprand, sprandn, spzeros
export sprand, spzeros
export nonzero_keys, nonzero_values, nonzero_pairs, nonzero_length
export sparse
export dropzeros!, droptol!
Expand Down
4 changes: 2 additions & 2 deletions src/tensors/abstractblocktensor/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ Base.@propagate_inbounds function Base.getindex(
end

# TODO: check if this fallback is fair
@inline Base.setindex!(t::AbstractBlockTensorMap, args...) = (
setindex!(parent(t), args...); t
@inline Base.setindex!(t::AbstractBlockTensorMap, v::AbstractTensorMap, args...) = (
setindex!(parent(t), v, args...); t
)

# setindex verifies structure is correct
Expand Down
11 changes: 11 additions & 0 deletions src/tensors/abstractblocktensor/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ function Base.convert(
return tdst
end

function Base.convert(::Type{TT}, t::AbstractTensorMap) where {TT<:AbstractBlockTensorMap}
S = spacetype(t)
tdst = TT(
undef,
convert(ProductSumSpace{S,numout(t)}, codomain(t)),
convert(ProductSumSpace{S,numin(t)}, domain(t)),
)
tdst[1] = t
return tdst
end

TensorKit.TensorMap(t::AbstractBlockTensorMap) = convert(TensorMap, t)
34 changes: 0 additions & 34 deletions src/tensors/blocktensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,40 +195,6 @@ function Base.promote_rule(
return BlockTensorMap{TT}
end

function Base.convert(::Type{<:BlockTensorMap{TT₁}}, t::BlockTensorMap{TT₂}) where {TT₁,TT₂}
TT₁ === TT₂ && return t
tdst = BlockTensorMap{TT₁}(undef, space(t))
for I in eachindex(t)
tdst[I] = t[I]
end
return tdst
end

function Base.convert(::Type{BlockTensorMap}, t::AbstractTensorMap)
t isa BlockTensorMap && return t
S = spacetype(t)
N₁ = numout(t)
N₂ = numin(t)
TT = blocktensormaptype(S, N₁, N₂, storagetype(t))
tdst = TT(
undef,
convert(ProductSumSpace{S,N₁}, codomain(t)),
convert(ProductSumSpace{S,N₂}, domain(t)),
)
tdst[1] = t
return tdst
end

function Base.convert(::Type{TT}, t::BlockTensorMap) where {TT<:BlockTensorMap}
t isa TT && return t

tdst = TT(undef_blocks, space(t))
for I in CartesianIndices(t)
tdst[I] = t[I]
end
return tdst
end

# Utility
# -------
Base.haskey(t::BlockTensorMap, I::CartesianIndex) = checkbounds(Bool, t.data, I)
Expand Down
16 changes: 10 additions & 6 deletions src/vectorspaces/sumspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ TensorKit.compose(V, W) = TensorKit.compose(promote(V, W)...)
# bit of a hack to make spacechecks happy?
Base.:(==)(V::SumSpace{S}, W::S) where {S} = ==(promote(V, W)...)
Base.:(==)(V::S, W::SumSpace{S}) where {S} = ==(promote(V, W)...)
Base.:(==)(V::TensorMapSumSpace{S}, W::TensorMapSpace{S}) where {S} = ==(promote(V, W)...)
Base.:(==)(V::TensorMapSpace{S}, W::TensorMapSumSpace{S}) where {S} = ==(promote(V, W)...)
function Base.:(==)(V::TensorMapSumSpace{S}, W::TensorMapSpace{S}) where {S<:IndexSpace}
return ==(promote(V, W)...)
end
function Base.:(==)(V::TensorMapSpace{S}, W::TensorMapSumSpace{S}) where {S<:IndexSpace}
return ==(promote(V, W)...)
end
# disambiguate
function Base.:(==)(V::TensorMapSumSpace, W::TensorMapSumSpace)
function Base.:(==)(V::TensorMapSumSpace{S}, W::TensorMapSumSpace{S}) where {S<:IndexSpace}
@invoke ==(V::HomSpace, W::HomSpace)
end
# this conflicts with the definition in TensorKit, so users always need to specify
Expand Down Expand Up @@ -151,7 +155,7 @@ Base.oneunit(S::Type{<:SumSpace}) = SumSpace(oneunit(eltype(S)))

# Promotion and conversion
# ------------------------
Base.promote_rule(::Type{S}, ::Type{SumSpace{S}}) where {S} = SumSpace{S}
Base.promote_rule(::Type{S}, ::Type{SumSpace{S}}) where {S<:ElementarySpace} = SumSpace{S}
function Base.promote_rule(
::Type{S1}, ::Type{<:ProductSpace{S2}}
) where {S1<:ElementarySpace,S2<:ElementarySpace}
Expand All @@ -168,8 +172,8 @@ function Base.promote_rule(
return TensorMapSumSpace{S}
end

Base.convert(::Type{I}, S::SumSpace{I}) where {I} = TensorKit.oplus(S)
Base.convert(::Type{SumSpace{S}}, V::S) where {S} = SumSpace(V)
Base.convert(::Type{I}, S::SumSpace{I}) where {I<:ElementarySpace} = TensorKit.oplus(S)
Base.convert(::Type{SumSpace{S}}, V::S) where {S<:ElementarySpace} = SumSpace(V)
function Base.convert(::Type{<:ProductSumSpace{S,N}}, V::ProductSpace{S,N}) where {S,N}
return ProductSumSpace{S,N}(SumSpace.(V.spaces)...)
end
Expand Down
8 changes: 8 additions & 0 deletions src/vectorspaces/sumspaceindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ end
end
return Base._getindex(IndexCartesian(), iter, I′...)
end
# disambiguate:
@inline function Base._getindex(
::IndexCartesian, iter::SumSpaceIndices{S,N₁,N₂,1}, I::Union{Real,AbstractVector}
) where {S,N₁,N₂}
@boundscheck checkbounds(iter, I)
return SumSpaceIndices{S,N₁,N₂}(map(getindex, iter.sumspaces, (I,)))
end

@inline Base._getindex(::IndexCartesian, iter::SumSpaceIndices, ::Colon) = iter

# disambiguation of base methods
Expand Down
4 changes: 4 additions & 0 deletions test/aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Aqua: Aqua
using BlockTensorKit: BlockTensorKit
# dont test for piracies right now, these are deliberate.
Aqua.test_all(BlockTensorKit; piracies=false)
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ const GROUP = uppercase(
include("linalg/factorizations.jl")
end
end

@time @safetestset "aqua" begin
include("aqua.jl")
end
end

0 comments on commit 433319c

Please sign in to comment.