-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to Derive and SparseArraysBase v0.2 (#3)
- Loading branch information
Showing
7 changed files
with
175 additions
and
65 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,19 +1,19 @@ | ||
name = "DiagonalArrays" | ||
uuid = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" | ||
authors = ["ITensor developers <[email protected]> and contributors"] | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" | ||
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2" | ||
NestedPermutedDimsArrays = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58" | ||
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a" | ||
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" | ||
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138" | ||
|
||
[compat] | ||
ArrayLayouts = "1.10.4" | ||
BroadcastMapConversion = "0.1" | ||
NestedPermutedDimsArrays = "0.1" | ||
SparseArraysBase = "0.1" | ||
TypeParameterAccessors = "0.1" | ||
Derive = "0.3.6" | ||
SparseArraysBase = "0.2.1" | ||
TypeParameterAccessors = "0.2" | ||
julia = "1.10" |
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,6 +1,4 @@ | ||
[deps] | ||
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2" | ||
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a" | ||
DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" | ||
NestedPermutedDimsArrays = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58" | ||
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" | ||
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138" |
100 changes: 86 additions & 14 deletions
100
src/abstractdiagonalarray/diagonalarraydiaginterface.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,95 @@ | ||
using SparseArraysBase: SparseArraysBase, StorageIndex, StorageIndices | ||
# TODO: Turn these into `@interface ::AbstractDiagonalArrayInterface` functions. | ||
|
||
SparseArraysBase.StorageIndex(i::DiagIndex) = StorageIndex(index(i)) | ||
diagview(a::AbstractDiagonalArray) = throw(MethodError(diagview, Tuple{typeof(a)})) | ||
|
||
function Base.getindex(a::AbstractDiagonalArray, i::DiagIndex) | ||
return a[StorageIndex(i)] | ||
end | ||
using Derive: Derive, @interface | ||
using SparseArraysBase: | ||
SparseArraysBase, AbstractSparseArrayInterface, AbstractSparseArrayStyle ## , StorageIndex, StorageIndices | ||
|
||
function Base.setindex!(a::AbstractDiagonalArray, value, i::DiagIndex) | ||
a[StorageIndex(i)] = value | ||
return a | ||
end | ||
abstract type AbstractDiagonalArrayInterface <: AbstractSparseArrayInterface end | ||
|
||
struct DiagonalArrayInterface <: AbstractDiagonalArrayInterface end | ||
|
||
Derive.arraytype(::AbstractDiagonalArrayInterface, elt::Type) = DiagonalArray{elt} | ||
Derive.interface(::Type{<:AbstractDiagonalArray}) = DiagonalArrayInterface() | ||
|
||
abstract type AbstractDiagonalArrayStyle{N} <: AbstractSparseArrayStyle{N} end | ||
|
||
SparseArraysBase.StorageIndices(i::DiagIndices) = StorageIndices(indices(i)) | ||
Derive.interface(::Type{<:AbstractDiagonalArrayStyle}) = DiagonalArrayInterface() | ||
|
||
function Base.getindex(a::AbstractDiagonalArray, i::DiagIndices) | ||
return a[StorageIndices(i)] | ||
struct DiagonalArrayStyle{N} <: AbstractDiagonalArrayStyle{N} end | ||
|
||
DiagonalArrayStyle{M}(::Val{N}) where {M,N} = DiagonalArrayStyle{N}() | ||
|
||
@interface ::AbstractDiagonalArrayInterface function Broadcast.BroadcastStyle(type::Type) | ||
return DiagonalArrayStyle{ndims(type)}() | ||
end | ||
|
||
function Base.setindex!(a::AbstractDiagonalArray, value, i::DiagIndices) | ||
a[StorageIndices(i)] = value | ||
function SparseArraysBase.isstored( | ||
a::AbstractDiagonalArray{<:Any,N}, I::Vararg{Int,N} | ||
) where {N} | ||
return allequal(I) | ||
end | ||
function SparseArraysBase.getstoredindex( | ||
a::AbstractDiagonalArray{<:Any,N}, I::Vararg{Int,N} | ||
) where {N} | ||
# TODO: Make this check optional, define `checkstored` like `checkbounds` | ||
# in SparseArraysBase.jl. | ||
# allequal(I) || error("Not a diagonal index.") | ||
return getdiagindex(a, first(I)) | ||
end | ||
function SparseArraysBase.setstoredindex!( | ||
a::AbstractDiagonalArray{<:Any,N}, value, I::Vararg{Int,N} | ||
) where {N} | ||
# TODO: Make this check optional, define `checkstored` like `checkbounds` | ||
# in SparseArraysBase.jl. | ||
# allequal(I) || error("Not a diagonal index.") | ||
setdiagindex!(a, value, first(I)) | ||
return a | ||
end | ||
function SparseArraysBase.eachstoredindex(a::AbstractDiagonalArray) | ||
return diagindices(a) | ||
end | ||
|
||
# Fix ambiguity error with SparseArraysBase. | ||
function Base.getindex(a::AbstractDiagonalArray, I::DiagIndices) | ||
# TODO: Use `@interface` rather than `invoke`. | ||
return invoke(getindex, Tuple{AbstractArray,DiagIndices}, a, I) | ||
end | ||
# Fix ambiguity error with SparseArraysBase. | ||
function Base.getindex(a::AbstractDiagonalArray, I::DiagIndex) | ||
# TODO: Use `@interface` rather than `invoke`. | ||
return invoke(getindex, Tuple{AbstractArray,DiagIndex}, a, I) | ||
end | ||
# Fix ambiguity error with SparseArraysBase. | ||
function Base.setindex!(a::AbstractDiagonalArray, value, I::DiagIndices) | ||
# TODO: Use `@interface` rather than `invoke`. | ||
return invoke(setindex!, Tuple{AbstractArray,Any,DiagIndices}, a, value, I) | ||
end | ||
# Fix ambiguity error with SparseArraysBase. | ||
function Base.setindex!(a::AbstractDiagonalArray, value, I::DiagIndex) | ||
# TODO: Use `@interface` rather than `invoke`. | ||
return invoke(setindex!, Tuple{AbstractArray,Any,DiagIndex}, a, value, I) | ||
end | ||
|
||
## SparseArraysBase.StorageIndex(i::DiagIndex) = StorageIndex(index(i)) | ||
|
||
## function Base.getindex(a::AbstractDiagonalArray, i::DiagIndex) | ||
## return a[StorageIndex(i)] | ||
## end | ||
|
||
## function Base.setindex!(a::AbstractDiagonalArray, value, i::DiagIndex) | ||
## a[StorageIndex(i)] = value | ||
## return a | ||
## end | ||
|
||
## SparseArraysBase.StorageIndices(i::DiagIndices) = StorageIndices(indices(i)) | ||
|
||
## function Base.getindex(a::AbstractDiagonalArray, i::DiagIndices) | ||
## return a[StorageIndices(i)] | ||
## end | ||
|
||
## function Base.setindex!(a::AbstractDiagonalArray, value, i::DiagIndices) | ||
## a[StorageIndices(i)] = value | ||
## return a | ||
## 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