TruncationStrategy types and constructors: consistency in names and implementations#56
TruncationStrategy types and constructors: consistency in names and implementations#56
TruncationStrategy types and constructors: consistency in names and implementations#56Conversation
8bb7f87 to
94d62d2
Compare
|
@kshyatt , I think the GPU tests for |
|
If you're ok with pulling in another dependency, |
|
I'm not sure if that is really warranted here, for such a small use. I also am not sure how to make that work with the conditional loading with the GPU package extensions, since it also seems somewhat wrong to only load the CUDA code if AccelleratedKernels is loaded? I guess |
|
Yes a map + findfirst should work too.
…On Sun, Sep 21, 2025 at 5:07 PM Lukas Devos ***@***.***> wrote:
*lkdvos* left a comment (QuantumKitHub/MatrixAlgebraKit.jl#56)
<#56 (comment)>
I'm not sure if that is really warranted here, for such a small use. I
also am not sure how to make that work with the conditional loading with
the GPU package extensions, since it also seems somewhat wrong to only load
the CUDA code if AccelleratedKernels is loaded?
I guess findfirst is fine, I think the overall performance impact of a
scan of a vector of length m should probably be dwarfed by the m x m SVD?
—
Reply to this email directly, view it on GitHub
<#56 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGKJY54P7WHWAX6UWRVWTT3T25JVAVCNFSM6AAAAACHCQ7RX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMJWGA2TIMZRGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
4dabf1a to
f2ee14c
Compare
f2ee14c to
6ce4bf5
Compare
6ce4bf5 to
6f994a4
Compare
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
|
@lkdvos I lost track, is the plan to replace all uses of |
86e1fe3 to
c364ba7
Compare
|
Sorry, my bad, I wasn't fully finished incorporating the things we discussed, and apparently also accidentally committed some of the doodles I wrote during our discussion. I think I got most things figured out now |
88193d9 to
73d74ac
Compare
73d74ac to
5e5a532
Compare
4230365 to
fdb3657
Compare
src/implementations/truncation.jl
Outdated
| ind = findall(strategy.filter, values) | ||
| return ind | ||
| function findtruncated(values::AbstractVector, strategy::TruncationByFilter) | ||
| return strategy.filter.(values)::AbstractVector{Bool} |
There was a problem hiding this comment.
Is it really worth returning a bool vector here, instead of just indices? Is findall(strategy.filter, values) so much worse? Or is that for GPU compatibility?
There was a problem hiding this comment.
Also, is the type annotation really useful? Is this a JET thing again?
There was a problem hiding this comment.
I really don't have any opinion here. @mtfishman, what do you think? I am fine with either way.
There was a problem hiding this comment.
I'm fine either way, I think the main considerations were:
- It expresses the output better, since it encodes that the output indices don't repeat and don't have a specified ordering (i.e. they preserve the ordering).
- We've found it helpful to use bool vectors for slicing block sparse arrays since they make it easier to preserve the block structure, but since some strategies output bool vectors and some don't, we have to convert them all anyway.
Jutho
left a comment
There was a problem hiding this comment.
After reading through the whole code, I think it would be nice if findtruncated has a well defined return type: either a list of indices, in which case a range in certain cases might be acceptable, or a Bool vector.
src/implementations/truncation.jl
Outdated
| ind = findall(strategy.filter, values) | ||
| return ind | ||
| function findtruncated(values::AbstractVector, strategy::TruncationByFilter) | ||
| return strategy.filter.(values)::AbstractVector{Bool} |
There was a problem hiding this comment.
Also, is the type annotation really useful? Is this a JET thing again?
This was mostly just a check since we don't have any input sanitation on the
Great idea, I've implemented this now
I'm not sure it is really necessary to restrict this. I think both options should work and have their merit, and if you implement a new truncation type it might be convenient to not have to be forced one way or the other. It's not that much extra complexity for now, and it is quite easy to go from one to the other so we can always post-process if needed? |
|
I would favour a consistent return type, at least functionally. I know that both boolean vector and list of indices can be used for indexing, but they do behave very different for other purposes. If I want to know the number of values kept, I would need to do I am fine with either choice. I can see some benefits to the boolean vector return type, so if this is easier for @mtfishman that could be a good choice as well. The only consideration that comes to mind is that Julia Hence, I definitely support and approve of the current state of this PR. |
|
Maybe a better way to support bool vectors would be to have julia> to_indices(randn(3), ([true, false, true],))[1]
2-element Base.LogicalIndex{Int64, Vector{Bool}}:
1
3EDIT: Or if we don't want to require that from |
This is a (breaking) change that attempts to make the truncation structs and their derived (lowercase) constructors a bit more uniform, while also removing some of them.
We previously had the following structs and constructors:
where both
trunctolandtruncabovewould actually be equivalent to theTruncationKeepAboveandTruncationKeepBelowwith an absolute tolerance, while not making use of the sorted implementations because they were implemented using filters.Here, I merged
TruncationKeepBelowandTruncationKeepAboveintoTruncationByValueby adding an additional boolean flag to select between the two, while trying to be more consistent in the other names as well.The updated scheme consists of:
Additionally, I exported all the lowercase constructors, and updated the docs accordingly.
PS: before actually tagging a 0.4 release, I would additionally like to change the formatter to runic (in a separate PR), to be consistent with the other packages in the organization.