@@ -31,9 +31,8 @@ def state_vector_ket_shape(sv: npt.NDArray[np.complex64]) -> str:
31
31
)[2 :]
32
32
33
33
34
- # @typechecked
35
- # FIXME: Resolve type-checking errors encountered during test execution.
36
- def with_sign (val : np .complex64 ) -> str :
34
+ @typechecked
35
+ def with_sign (val : Union [np .complex64 , np .complex128 ]) -> str :
37
36
"""Sometimes, we want values under a specific format, in particular
38
37
``<sign> <value>``. Where value is as simple as possible (*e.g.* no period
39
38
or no imaginary part if there is no need).
@@ -57,18 +56,20 @@ def with_sign(val: np.complex64) -> str:
57
56
return "+ " + str_rounded
58
57
59
58
60
- # @typechecked
61
- # FIXME: Resolve type-checking errors encountered during test execution.
62
- def _remove_null_imag (val : np .complex64 ) -> np .complex64 | np .float32 | int :
59
+ @typechecked
60
+ def _remove_null_imag (
61
+ val : np .complex64 | np .complex128 ,
62
+ ) -> np .complex64 | np .complex128 | np .float32 | int :
63
63
val = np .round (val , 3 )
64
64
if val .imag != 0 :
65
65
return val
66
66
return _remove_unnecessary_decimals (val .real )
67
67
68
68
69
- # @typechecked
70
- # FIXME: Resolve type-checking errors encountered during test execution.
71
- def _remove_unnecessary_decimals (val : np .float32 | int ) -> np .float32 | int :
69
+ @typechecked
70
+ def _remove_unnecessary_decimals (
71
+ val : np .float32 | np .float64 | int ,
72
+ ) -> np .float32 | int :
72
73
val = np .float32 (val )
73
74
if val .is_integer ():
74
75
return int (val )
@@ -190,9 +191,8 @@ def clean_1D_array(
190
191
)
191
192
192
193
193
- # @typechecked
194
- # FIXME: Resolve type-checking errors encountered during test execution.
195
- def clean_number_repr (number : complex , round : int = 7 ):
194
+ @typechecked
195
+ def clean_number_repr (number : Union [complex , np .complex64 ], round : int = 7 ):
196
196
"""Cleans and formats a number. This function rounds the parts of
197
197
complex numbers and formats them as integers if appropriate. It returns a
198
198
string representation of the number.
@@ -234,8 +234,7 @@ def clean_number_repr(number: complex, round: int = 7):
234
234
return f"{ str (real_part )} { str (imag_part )} "
235
235
236
236
237
- # @typechecked
238
- # FIXME: Resolve type-checking errors encountered during test execution.
237
+ @typechecked
239
238
def clean_matrix (matrix : Matrix , round : int = 5 , align : bool = True ):
240
239
"""Cleans and formats elements of a 2D matrix. This function rounds the
241
240
parts of the numbers in the matrix and formats them as integers if
@@ -250,9 +249,9 @@ def clean_matrix(matrix: Matrix, round: int = 5, align: bool = True):
250
249
A string representation of the cleaned matrix.
251
250
252
251
Examples:
253
- >>> print(clean_matrix([[1.234567895546, 2.3456789645645, 3.45678945645],
254
- ... [1+5j, 0+1j, 5.],
255
- ... [1.223123425+0.95113462364j, 2.0, 3.0]]))
252
+ >>> print(clean_matrix(np.array( [[1.234567895546, 2.3456789645645, 3.45678945645],
253
+ ... [1+5j, 0+1j, 5.],
254
+ ... [1.223123425+0.95113462364j, 2.0, 3.0]]) ))
256
255
[[1.23457 , 2.34568, 3.45679],
257
256
[1+5j , 1j , 5 ],
258
257
[1.22312+0.95113j, 2 , 3 ]]
@@ -280,8 +279,7 @@ def clean_matrix(matrix: Matrix, round: int = 5, align: bool = True):
280
279
)
281
280
282
281
283
- # @typechecked
284
- # FIXME: Resolve type-checking errors encountered during test execution.
282
+ @typechecked
285
283
def pprint (matrix : Matrix , round : int = 5 , align : bool = True ):
286
284
"""Print a cleans and formats elements of a matrix. It rounds the real parts of complex numbers
287
285
in the matrix places and formats them as integers if they are whole numbers. It returns a
@@ -293,9 +291,9 @@ def pprint(matrix: Matrix, round: int = 5, align: bool = True):
293
291
align: Whether to align the elements for a cleaner output.
294
292
295
293
Example:
296
- >>> pprint([[1.234567895546, 2.3456789645645, 3.45678945645],
297
- ... [1+5j, 0+1j, 5.],
298
- ... [1.223123425+0.95113462364j, 2.0, 3.0]])
294
+ >>> pprint(np.array( [[1.234567895546, 2.3456789645645, 3.45678945645],
295
+ ... [1+5j, 0+1j, 5.],
296
+ ... [1.223123425+0.95113462364j, 2.0, 3.0]]) )
299
297
[[1.23457 , 2.34568, 3.45679],
300
298
[1+5j , 1j , 5 ],
301
299
[1.22312+0.95113j, 2 , 3 ]]
0 commit comments