-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement SubBasis #61
Open
kalmarek
wants to merge
5
commits into
main
Choose a base branch
from
mk/subbasis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a42800e
implement SubBasis and SubMStructure
kalmarek baf65a2
test broken: scalar mul @allocated
kalmarek d023e28
rm StarAlgebra from test/Project.toml
kalmarek ad67331
Add broken tests
blegat f0a91dd
store indicies instead of elts
kalmarek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +1,33 @@ | ||
abstract type FiniteSupportBasis{T,I} <: ExplicitBasis{T,I} end | ||
|
||
""" | ||
supp(fb::FiniteSupportBasis) | ||
Return the supporting elements of `fb` as an indexable vector | ||
""" | ||
function supp end | ||
|
||
Base.IteratorSize(::Type{<:FiniteSupportBasis}) = Base.HasLength() | ||
Base.IteratorEltype(::Type{<:FiniteSupportBasis{T}}) where {T} = T | ||
Base.length(b::FiniteSupportBasis) = length(supp(b)) | ||
|
||
Base.iterate(b::FiniteSupportBasis) = iterate(supp(b)) | ||
Base.iterate(b::FiniteSupportBasis, state) = iterate(supp(b), state) | ||
# function Base.IndexStyle(::Type{<:FiniteSupportBasis{T,I,V}}) where {T,I,V} | ||
# return Base.IndexStyle(V) | ||
# end | ||
|
||
# To break ambiguity | ||
# ?? | ||
Base.@propagate_inbounds function Base.getindex( | ||
b::FiniteSupportBasis, | ||
i::Integer, | ||
) | ||
return supp(b)[i] | ||
end | ||
|
||
mutable struct FixedBasis{T,I,V<:AbstractVector{T},M<:MTable{T,I}} <: | ||
ExplicitBasis{T,I} | ||
elts::V | ||
FiniteSupportBasis{T,I} | ||
supporting_elts::V | ||
table::M | ||
end | ||
|
||
|
@@ -21,21 +48,48 @@ | |
return FixedBasis(elts, MTable(elts, mstr, dims)) | ||
end | ||
|
||
supp(fb::FiniteSupportBasis) = fb.supporting_elts | ||
mstructure(fb::FixedBasis) = fb.table | ||
|
||
Base.in(x, b::FixedBasis) = haskey(mstructure(b), x) | ||
Base.getindex(b::FixedBasis{T}, x::T) where {T} = mstructure(b)[x] | ||
Base.getindex(b::FixedBasis, i::Integer) = mstructure(b)[i] | ||
|
||
Base.IteratorSize(::Type{<:FixedBasis}) = Base.HasLength() | ||
Base.length(b::FixedBasis) = length(b.elts) | ||
struct SubBasis{T,I,V,B<:AbstractBasis{T,I}} <: FiniteSupportBasis{T,I} | ||
supporting_elts::V | ||
parent_basis::B | ||
end | ||
|
||
Base.iterate(b::FixedBasis) = iterate(b.elts) | ||
Base.iterate(b::FixedBasis, state) = iterate(b.elts, state) | ||
Base.IndexStyle(::Type{<:FixedBasis{T,I,V}}) where {T,I,V} = Base.IndexStyle(V) | ||
supp(sb::SubBasis) = sb.supporting_elts | ||
Base.parent(sub::SubBasis) = sub.parent_basis | ||
|
||
# To break ambiguity | ||
Base.@propagate_inbounds Base.getindex( | ||
b::FixedBasis{T,I}, | ||
i::I, | ||
) where {T,I<:Integer} = b.elts[i] | ||
Base.in(x, b::SubBasis) = x in supp(b) | ||
function Base.getindex(b::SubBasis{T,I}, x::T) where {T,I<:Integer} | ||
k = findfirst(==(x), supp(b)) | ||
isnothing(k) && throw("x=$x is not supported on SubBasis") | ||
@info T I | ||
return convert(I, k) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
end | ||
|
||
function Base.getindex(b::SubBasis{T,T}, x::T) where {T} | ||
x in supp(b) && return x | ||
throw("x=$x is not supported on SubBasis") | ||
end | ||
|
||
struct SubMStructure{SB<:SubBasis,MS} <: MultiplicativeStructure | ||
basis::SB | ||
mstructure::MS | ||
end | ||
|
||
function mstructure(b::SubBasis) | ||
pb = b.parent_basis | ||
return SubMStructure(b, mstructure(pb)) | ||
end | ||
|
||
function (mstr::SubMStructure)(x::T, y::T) where {T} | ||
b = mstr.basis | ||
xy = mstr.mstructure(b[x], b[y]) | ||
return xy | ||
end | ||
|
||
# this is used for key-lookup in mstructures.jl | ||
# MA.operate!(op::UnsafeAddMul, …) | ||
_key(mstr::SubMStructure, k) = findfirst(==(k), supp(mstr.basis)) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be the list of indices of the
parent_basis
. ForDiracBasis
, since indices are the same as elements, it works as well