Skip to content
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

feat: add rand_circulant_gram func #389

Merged
merged 19 commits into from
Jan 10, 2024
Merged

feat: add rand_circulant_gram func #389

merged 19 commits into from
Jan 10, 2024

Conversation

ankit-pn
Copy link
Contributor

@ankit-pn ankit-pn commented Dec 22, 2023

Description

add feat described in Fixes #379

Status

  • Ready to go

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cbd1575) 97.6% compared to head (2ac70b4) 98.0%.
Report is 29 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #389     +/-   ##
========================================
+ Coverage    97.6%   98.0%   +0.4%     
========================================
  Files         154     156      +2     
  Lines        3059    3065      +6     
  Branches      744     742      -2     
========================================
+ Hits         2987    3006     +19     
+ Misses         45      37      -8     
+ Partials       27      22      -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

def random_circulant_gram(dim: int) -> np.ndarray:
r"""Generate a random circulant Gram matrix of specified dimension.

This function creates a circulant matrix based on a random diagonal matrix and the normalized Discrete
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be better to add some details/ref on what a circulant matrix is in this docstring + more details on what a normalized DFT is.

https://en.wikipedia.org/wiki/Circulant_matrix
https://ccrma.stanford.edu/~jos/st/Normalized_DFT.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the changes, please review it and let me know if further modification is required.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Might want to double-check how references are added. Other docstrings might be helpful for you.

Copy link
Owner

Choose a reason for hiding this comment

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

@ankit-pn I think you'll want to add the links you provided within the references in docs/articles.bib. So for instance,

@misc{WikiCirculantMat,
  author  = "Wikipedia",
  title   = "Circulant matrix",
  howpublished = {https://en.wikipedia.org/wiki/Circulant_matrix}
  
}

And then use the :cite: command in the docstring (as done elsewhere in toqito) instead of putting the whole link there. Similarly for your other link as well.

@ankit-pn
Copy link
Contributor Author

I have done the changes that you have recommended. Please review it.
Thanks.

def random_circulant_gram(dim: int) -> np.ndarray:
r"""Generate a random circulant Gram matrix of specified dimension.

This function creates a circulant matrix based on a random diagonal matrix and the normalized Discrete
Copy link
Owner

Choose a reason for hiding this comment

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

@ankit-pn I think you'll want to add the links you provided within the references in docs/articles.bib. So for instance,

@misc{WikiCirculantMat,
  author  = "Wikipedia",
  title   = "Circulant matrix",
  howpublished = {https://en.wikipedia.org/wiki/Circulant_matrix}
  
}

And then use the :cite: command in the docstring (as done elsewhere in toqito) instead of putting the whole link there. Similarly for your other link as well.

def random_circulant_gram(dim: int) -> np.ndarray:
r"""Generate a random circulant Gram matrix of specified dimension.

A circulant matrix is a square matrix where each row is a shifted version of the one above,
Copy link
Owner

Choose a reason for hiding this comment

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

Something seems a bit off with the formatting of these lines. They should have a length of 120, but these look like they are around 80.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably because black was used for formatting issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it was because i was using formatter in wrong way. i have corrected it and do let me know if any other further changes is required.

circulant_matrix = random_circulant_gram(dim)

# Ensure the matrix has the correct shape.
assert circulant_matrix.shape == (dim, dim)
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of using assert here we should be using np.testing.assert_equal (check out the other tests for reference)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

docs/rand.rst Outdated
@@ -17,3 +17,4 @@ Random
toqito.rand.random_state_vector
toqito.rand.random_states
toqito.rand.random_unitary
toqito.rand.random_circulant_gram
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor nit: might want to move this addition up (alphabetical order)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ankit-pn and others added 2 commits December 29, 2023 19:51
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
Comment on lines 14 to 22
This function utilizes the normalized DFT, a variation of DFT with normalized basis vectors. This
variation alters computational requirements and offers a different view on signal transformations.

:cite:`StanfordNormDFT`.

The function creates a circulant matrix from a random diagonal matrix and the normalized DFT matrix.
First, it generates a diagonal matrix with random non-negative entries. Next, it constructs the
normalized DFT matrix. Finally, it computes the circulant matrix, which is real due to its origin
from the DFT of a real diagonal matrix.
Copy link
Collaborator

@purva-thakre purva-thakre Dec 29, 2023

Choose a reason for hiding this comment

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

It might be just me, but this part seems vague: This variation alters computational requirements and offers a different view on signal transformations

Could this be re-worded differently?

ankit-pn and others added 5 commits December 29, 2023 19:59
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
@ankit-pn
Copy link
Contributor Author

@purva-thakre i have pushed the changes, error was because of ruff check. do let me know know if any further changes required. thanks.

ankit-pn and others added 2 commits December 29, 2023 20:25
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
@vprusso
Copy link
Owner

vprusso commented Jan 7, 2024

I think this is good to go, nice job, @ankit-pn !

Anything additional to address before merging, @purva-thakre ?

@purva-thakre
Copy link
Collaborator

I think this is good to go, nice job, @ankit-pn !

Anything additional to address before merging, @purva-thakre ?

I think one of the lines in the docstring is vague. I don't think it is related to what the function is intended to do. #389 (comment)

But besides this, LGTM.

Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
@vprusso
Copy link
Owner

vprusso commented Jan 10, 2024

Thanks for pushing this over the line, @purva-thakre

And thank you as well to @ankit-pn for putting this feature into toqito!

@vprusso vprusso merged commit 4f75605 into vprusso:master Jan 10, 2024
13 checks passed
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.

Generate random circulant Gram matrix of specified dimension.
3 participants