Skip to content
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

Sparse matrix multiplication #2

Merged
merged 2 commits into from
Dec 2, 2024
Merged
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
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"
Expand All @@ -13,7 +15,9 @@ BroadcastMapConversion = {url = "https://github.com/ITensor/BroadcastMapConversi
TypeParameterAccessors = {url = "https://github.com/ITensor/TypeParameterAccessors.jl"}

[compat]
Adapt = "4.1.1"
Aqua = "0.8.9"
ArrayLayouts = "1.10.4"
BroadcastMapConversion = "0.1.0"
LinearAlgebra = "1.10"
Test = "1.10"
Expand Down
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,35 @@ julia> Pkg.add(url="https://github.com/ITensor/SparseArraysBaseNext.jl")

````julia
using SparseArraysBaseNext:
SparseArrayDOK, eachstoredindex, isstored, storedlength, storedvalues
SparseArrayDOK, eachstoredindex, isstored, storedlength, storedpairs, storedvalues
using Test: @test

a = SparseArrayDOK{Float64}(2, 2)
a[1, 2] = 12
@show a[1, 1]
@show a[1, 2]
a[2, 1] = 21
@test a[1, 1] == 0
@test a[2, 1] == 21
@test a[1, 2] == 12
@test a[2, 2] == 0

b = a .+ 2 .* a'
@show storedvalues(b)
@show eachstoredindex(b)
@show isstored(b, 1, 1)
@show isstored(b, 2, 1)
@show isstored(b, 1, 2)
@show isstored(b, 2, 2)
@show storedlength(b)
@test b[1, 1] == 0
@test b[2, 1] == 21 + 2 * 12
@test b[1, 2] == 12 + 2 * 21
@test b[2, 2] == 0
@test issetequal(storedvalues(b), [21 + 2 * 12, 12 + 2 * 21])
@test issetequal(eachstoredindex(b), [CartesianIndex(2, 1), CartesianIndex(1, 2)])
@test storedpairs(b) ==
Dict(CartesianIndex(2, 1) => 21 + 2 * 12, CartesianIndex(1, 2) => 12 + 2 * 21)
@test !isstored(b, 1, 1)
@test isstored(b, 2, 1)
@test isstored(b, 1, 2)
@test !isstored(b, 2, 2)
@test storedlength(b) == 2

c = a * a'
@test storedlength(c) == 2
@test c == [12*12 0; 0 21*21]
````

---
Expand Down
35 changes: 25 additions & 10 deletions examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,32 @@ julia> Pkg.add(url="https://github.com/ITensor/SparseArraysBaseNext.jl")
# ## Examples

using SparseArraysBaseNext:
SparseArrayDOK, eachstoredindex, isstored, storedlength, storedvalues
SparseArrayDOK, eachstoredindex, isstored, storedlength, storedpairs, storedvalues
using Test: @test

a = SparseArrayDOK{Float64}(2, 2)
a[1, 2] = 12
@show a[1, 1]
@show a[1, 2]
a[2, 1] = 21
@test a[1, 1] == 0
@test a[2, 1] == 21
@test a[1, 2] == 12
@test a[2, 2] == 0

b = a .+ 2 .* a'
@show storedvalues(b)
@show eachstoredindex(b)
@show isstored(b, 1, 1)
@show isstored(b, 2, 1)
@show isstored(b, 1, 2)
@show isstored(b, 2, 2)
@show storedlength(b)
@test b[1, 1] == 0
@test b[2, 1] == 21 + 2 * 12
@test b[1, 2] == 12 + 2 * 21
@test b[2, 2] == 0
@test issetequal(storedvalues(b), [21 + 2 * 12, 12 + 2 * 21])
@test issetequal(eachstoredindex(b), [CartesianIndex(2, 1), CartesianIndex(1, 2)])
@test storedpairs(b) ==
Dict(CartesianIndex(2, 1) => 21 + 2 * 12, CartesianIndex(1, 2) => 12 + 2 * 21)
@test !isstored(b, 1, 1)
@test isstored(b, 2, 1)
@test isstored(b, 1, 2)
@test !isstored(b, 2, 2)
@test storedlength(b) == 2

c = a * a'
@test storedlength(c) == 2
@test c == [12*12 0; 0 21*21]
7 changes: 2 additions & 5 deletions src/SparseArraysBaseNext.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
module SparseArraysBaseNext

include("derive.jl")
include("wrappedarrays.jl")
include("abstractinterface.jl")
include("abstractarrayinterface.jl")
include("defaultarrayinterface.jl")
include("lib/InterfaceImplementations/InterfaceImplementations.jl")
using .InterfaceImplementations: InterfaceImplementations
include("sparsearrayinterface.jl")
include("sparsearraydok.jl")

Expand Down
85 changes: 0 additions & 85 deletions src/abstractarrayinterface.jl

This file was deleted.

27 changes: 0 additions & 27 deletions src/derive.jl

This file was deleted.

9 changes: 9 additions & 0 deletions src/lib/InterfaceImplementations/InterfaceImplementations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module InterfaceImplementations

include("abstractinterface.jl")
include("derive.jl")
include("wrappedarrays.jl")
include("abstractarrayinterface.jl")
include("defaultarrayinterface.jl")

end
Loading
Loading