-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move kp_norm * pylint bug * add tests * use black * pylint kp_norm * Revert "pylint bug" This reverts commit 495c6a0. * vincent's feedback: pylint schmidt rank * vincent' feedback: kp_norm pytest parametrize
- Loading branch information
1 parent
1df0eb6
commit d7c317f
Showing
7 changed files
with
39 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Tests for the S(k)-norm of a matrix.""" | ||
# Tests in this file, follow the discussion of the characteristics of kp_norm at https://qetlab.com/kpNorm | ||
|
||
import re | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from toqito.matrix_props import kp_norm | ||
from toqito.random import random_unitary | ||
from toqito.states import bell | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"vector, k, p, norm_to_compare", | ||
[ | ||
# When (k=1, p= Inf)the kp_norm(vector) is the same as the trace norm (the 1-norm). | ||
(bell(0), 1, np.inf, 1), | ||
# When p=2 and k is greater than or equal to one of the input matrix dimensions, the value calculated is the frobenius norm. | ||
(random_unitary(5), 5, 2, np.linalg.norm(random_unitary(5), "fro")), | ||
], | ||
) | ||
def test_kp_norm(vector, k, p, norm_to_compare): | ||
calculated_kp_norm = kp_norm(vector, k, p) | ||
assert calculated_kp_norm == pytest.approx(norm_to_compare) | ||
|
||
|
||
def test_no_default_kp_values(): | ||
"""kp_norm does not have any default values for k or p.""" | ||
with pytest.raises( | ||
TypeError, match=re.escape("kp_norm() missing 2 required positional arguments: 'k' and 'p'") | ||
): | ||
kp_norm(bell(0)) # pylint: disable=no-value-for-parameter |
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
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