Skip to content

Conversation

@Tuna2222
Copy link
Contributor

@Tuna2222 Tuna2222 commented Jan 30, 2026

Description

Implement the distribution in the paper "A randomized Kaczmarz algorithm with exponential convergence". The distribution of each row (or column) of the matrix to be sketched is proportional to the row (or column) norms of the matrix.

Motivation and Context

Add another distribution can be used in compressor.

How has this been tested

The tests are implemented in "test\Compressors\Distributions\Strohmer-Vershynin.jl".
Please run the following codes in the folder of RLinearAlgebra.jl to see the test results:

] activate .
test

Types of changes

  • CI
  • Docs
  • Feature
  • Fix
  • Performance
  • Refactor
  • Style
  • Test
  • Other (use sparingly):

Checklists:

Code and Comments
If this PR includes modification to the code base, please select all that apply.

  • My code follows the code style of this project.
  • I have updated all package dependencies (if any).
  • I have included all relevant files to realize the functionality of the PR.
  • I have exported relevant functionality (if any).

API Documentation

  • For every exported function (if any), I have included a detailed docstring.
  • I have checked the spelling and grammar of all docstring updates through an external tool.
  • I have checked that the docstring's function signature is correctly formatted and has all arguments.
  • I have checked that the docstring's list of arguments, fields, or return values match the function.
  • I have compiled the docs locally and read through all docstring updates to check for errors.

Manual Documentation

  • I have checked the spelling and grammar of all manual updates through an external tool.
  • Any code included in the docstring is tested using doc tests to ensure consistency.
  • I have compiled the docs locally and read through all manual updates to check for errors.

Testing

  • I have added unit tests to cover my changes. (For Macros, be sure to check
    @code_lowered and
    @code_typed)
  • All new and existing tests passed.
  • I have achieved sufficient code coverage.

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the L2Norm distribution (Strohmer-Vershynin) for weighted sampling in compressors, where row or column selection probability is proportional to their squared L2 norms.

Changes:

  • Added L2Norm and L2NormRecipe structs with complete implementation of distribution interface
  • Comprehensive test suite covering all distribution functions and edge cases
  • Documentation updates for API reference

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Compressors/Distributions/Strohmer-Vershynin.jl Implements L2Norm distribution with probability proportional to row/column norms squared
test/Compressors/Distributions/Strohmer-Vershynin.jl Comprehensive test suite covering constructors, distribution completion, updates, and sampling
src/Compressors/Distributions.jl Includes the new distribution file in the module
src/RLinearAlgebra.jl Exports L2Norm and L2NormRecipe types
docs/src/api/distributions.md Adds L2Norm and L2NormRecipe to API documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI commented Jan 30, 2026

@Tuna2222 I've opened a new pull request, #157, to work on those changes. Once the pull request is ready, I'll request review from you.

@Tuna2222 Tuna2222 marked this pull request as ready for review January 30, 2026 15:31

Distribution where the probability of selecting a row (or column) is proportional
to its squared Euclidean norm, as proposed by
Strohmer and Vershynin (2009) [strohmer2009randomized](@cite).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be converted to [strohmer2009randomized](@citet)

Comment on lines 22 to 36
then the sampling occurs without replacement. The default value is `true`.

# Constructor

L2Norm(;cardinality=Undef(), replace = true)

## Returns
- A `L2Norm` object.
"""
mutable struct L2Norm <: Distribution
cardinality::Cardinality
replace::Bool
end

function L2Norm(; cardinality = Undef(), replace = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest making the default value to replace = false

- `replace::Bool`, an option to replace or not during the sampling process based
on the given weights.
- `state_space::Vector{Int64}`, the row/column index set.
- `weights::ProbabilityWeights`, the weights of each element in the state space,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the weights of..." --> "the probability of..."

Comment on lines 75 to 76
throw(ArgumentError("`L2Norm` cardinality must be specified as `Left()` or `Right()`.\
`Undef()` is not allowed in `complete_distribution`."))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw(ArgumentError("`L2Norm` cardinality must be specified as `Left()` or `Right()`.\
`Undef()` is not allowed in `complete_distribution`."))
throw(
ArgumentError(
"`L2Norm` cardinality must be specified as `Left()` or `Right()`.\
`Undef()` is not allowed in `complete_distribution`."
)
)

Comment on lines 94 to 95
throw(ArgumentError("`L2Norm` cardinality must be specified as `Left()` or `Right()`.\
`Undef()` is not allowed in `update_distribution!`."))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust this throw statement to match the other.

@test fieldtypes(L2Norm) == (Cardinality, Bool)

# Default
let u = L2Norm()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put u = L2Norm() on the next line

@test u.replace == true
end

let u2 = L2Norm(cardinality = Left(), replace = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only put parameters of the test on the let line or separated by commas

Comment on lines 144 to 145
# Verify that index 2 (the zero row) is NEVER sampled
@test 2 ∉ x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test needs to be fixed

# Perform sampling
sample_distribution!(x, ur)

# Verify that index 2 (the zero col) is NEVER sampled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not doing what we want it to do


sample_distribution!(x, ur)
@test ur.cardinality == Right()
@test all(s -> 1 <= s <= 5, x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a good idea as well, but it is not clear to me how we know it is working all the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants