-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SparseArrayInterface] [BlockSparseArrays] Sparse and block sparse do…
…t products (#1577) * [SparseArrayInterface] [BlockSparseArrays] Sparse and block sparse dot products * [NDTensors] Bump to v0.3.62
- Loading branch information
Showing
12 changed files
with
175 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "NDTensors" | ||
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" | ||
authors = ["Matthew Fishman <[email protected]>"] | ||
version = "0.3.61" | ||
version = "0.3.62" | ||
|
||
[deps] | ||
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" | ||
|
17 changes: 15 additions & 2 deletions
17
NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 31 additions & 6 deletions
37
NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/arraylayouts.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
using ArrayLayouts: ArrayLayouts, MatMulMatAdd | ||
using ArrayLayouts: ArrayLayouts, Dot, MatMulMatAdd, MatMulVecAdd, MulAdd | ||
using BlockArrays: BlockLayout | ||
using ..SparseArrayInterface: SparseLayout | ||
using LinearAlgebra: mul! | ||
using LinearAlgebra: dot, mul! | ||
|
||
function blocksparse_muladd!( | ||
α::Number, a1::AbstractMatrix, a2::AbstractMatrix, β::Number, a_dest::AbstractMatrix | ||
α::Number, a1::AbstractArray, a2::AbstractArray, β::Number, a_dest::AbstractArray | ||
) | ||
mul!(blocks(a_dest), blocks(a1), blocks(a2), α, β) | ||
return a_dest | ||
end | ||
|
||
function blocksparse_matmul!(m::MulAdd) | ||
α, a1, a2, β, a_dest = m.α, m.A, m.B, m.β, m.C | ||
blocksparse_muladd!(α, a1, a2, β, a_dest) | ||
return a_dest | ||
end | ||
|
||
function ArrayLayouts.materialize!( | ||
m::MatMulMatAdd{ | ||
<:BlockLayout{<:SparseLayout}, | ||
<:BlockLayout{<:SparseLayout}, | ||
<:BlockLayout{<:SparseLayout}, | ||
}, | ||
) | ||
α, a1, a2, β, a_dest = m.α, m.A, m.B, m.β, m.C | ||
blocksparse_muladd!(α, a1, a2, β, a_dest) | ||
return a_dest | ||
blocksparse_matmul!(m) | ||
return m.C | ||
end | ||
function ArrayLayouts.materialize!( | ||
m::MatMulVecAdd{ | ||
<:BlockLayout{<:SparseLayout}, | ||
<:BlockLayout{<:SparseLayout}, | ||
<:BlockLayout{<:SparseLayout}, | ||
}, | ||
) | ||
blocksparse_matmul!(m) | ||
return m.C | ||
end | ||
|
||
function blocksparse_dot(a1::AbstractArray, a2::AbstractArray) | ||
# TODO: Add a check that the blocking of `a1` and `a2` are | ||
# the same, or the same up to a reshape. | ||
return dot(blocks(a1), blocks(a2)) | ||
end | ||
|
||
function Base.copy(d::Dot{<:BlockLayout{<:SparseLayout},<:BlockLayout{<:SparseLayout}}) | ||
return blocksparse_dot(d.A, d.B) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 31 additions & 3 deletions
34
NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/arraylayouts.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
using ArrayLayouts: ArrayLayouts, MatMulMatAdd | ||
using ArrayLayouts: ArrayLayouts, Dot, DualLayout, MatMulMatAdd, MatMulVecAdd, MulAdd | ||
using LinearAlgebra: Adjoint, Transpose | ||
using ..TypeParameterAccessors: parenttype | ||
|
||
function ArrayLayouts.MemoryLayout(arraytype::Type{<:SparseArrayLike}) | ||
return SparseLayout() | ||
end | ||
|
||
function ArrayLayouts.materialize!( | ||
m::MatMulMatAdd{<:AbstractSparseLayout,<:AbstractSparseLayout,<:AbstractSparseLayout} | ||
# TODO: Generalize to `SparseVectorLike`/`AnySparseVector`. | ||
function ArrayLayouts.MemoryLayout(arraytype::Type{<:Adjoint{<:Any,<:AbstractSparseVector}}) | ||
return DualLayout{typeof(MemoryLayout(parenttype(arraytype)))}() | ||
end | ||
# TODO: Generalize to `SparseVectorLike`/`AnySparseVector`. | ||
function ArrayLayouts.MemoryLayout( | ||
arraytype::Type{<:Transpose{<:Any,<:AbstractSparseVector}} | ||
) | ||
return DualLayout{typeof(MemoryLayout(parenttype(arraytype)))}() | ||
end | ||
|
||
function sparse_matmul!(m::MulAdd) | ||
α, a1, a2, β, a_dest = m.α, m.A, m.B, m.β, m.C | ||
sparse_mul!(a_dest, a1, a2, α, β) | ||
return a_dest | ||
end | ||
|
||
function ArrayLayouts.materialize!( | ||
m::MatMulMatAdd{<:AbstractSparseLayout,<:AbstractSparseLayout,<:AbstractSparseLayout} | ||
) | ||
sparse_matmul!(m) | ||
return m.C | ||
end | ||
function ArrayLayouts.materialize!( | ||
m::MatMulVecAdd{<:AbstractSparseLayout,<:AbstractSparseLayout,<:AbstractSparseLayout} | ||
) | ||
sparse_matmul!(m) | ||
return m.C | ||
end | ||
|
||
function Base.copy(d::Dot{<:SparseLayout,<:SparseLayout}) | ||
return sparse_dot(d.A, d.B) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4996dca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register subdir=NDTensors
4996dca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/119277
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: