-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the generic MA.operate! from ACoeffs to the lib
- Loading branch information
Showing
4 changed files
with
47 additions
and
48 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
struct ACoeffs{T} <: SA.AbstractCoefficients{UInt32,T} | ||
vals::Vector{T} | ||
end | ||
|
||
# convienience: | ||
ACoeffs(v::AbstractVector) = ACoeffs{valtype(v)}(v) | ||
|
||
# AbstractCoefficients API | ||
|
||
## Basic API | ||
Base.keys(ac::ACoeffs) = (k for (k, v) in pairs(ac.vals) if !iszero(v)) | ||
Base.values(ac::ACoeffs) = (v for v in ac.vals if !iszero(v)) | ||
SA.canonical(ac::ACoeffs) = ac | ||
function SA.star(b::SA.AbstractBasis, ac::ACoeffs) | ||
return ACoeffs([ac.vals[star(b, k)] for k in keys(ac)]) | ||
end | ||
|
||
# for preallocation in arithmetic | ||
function Base.similar(ac::ACoeffs, ::Type{T}) where {T} | ||
vals = similar(ac.vals, T) | ||
MA.operate!(zero, vals) | ||
return ACoeffs(vals) | ||
end | ||
|
||
# the default arithmetic implementation uses this access | ||
Base.getindex(ac::ACoeffs, idx) = ac.vals[idx] | ||
Base.setindex!(ac::ACoeffs, val, idx) = ac.vals[idx] = val |