Skip to content

Commit 32c11b6

Browse files
committed
Fix some warnings and errors from partial tests
1 parent a32f81c commit 32c11b6

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

mpnum/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def random_mpa(sites, ldim, rank, randstate=None, normalized=False,
228228
[-0.17262967, 2.4505633 ]])
229229
>>> random_mpa(2, 2, 3, rng, dtype=np.complex_).to_array()
230230
array([[-0.53552415+1.39701566j, -2.12128866+0.57913253j],
231-
[-0.32652114+0.51490923j, -0.32222320-0.32675463j]])
231+
[-0.32652114+0.51490923j, -0.3222232 -0.32675463j]])
232232
233233
"""
234234
randfun = ft.partial(_randfuncs[dtype], randstate=randstate)

mpnum/utils/extmath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def block_diag(summands, axes=(0, 1)):
9595

9696
for array, shape in zip(summands, shapes):
9797
endpos = startpos + shape
98-
pos = [slice(start, end) for start, end in zip(startpos, endpos)]
98+
pos = tuple(slice(start, end) for start, end in zip(startpos, endpos))
9999
res[pos] += array
100100
startpos = endpos
101101

@@ -248,8 +248,8 @@ def randomized_svd(M, n_components, n_oversamples=10, n_iter='auto',
248248
``n_components`` is small (``< .1 * min(X.shape)``). Then,
249249
``n_iter`` is set to 7. This improves precision with few
250250
components. (default ``'auto'``)
251-
:param str piter_normalizer: ``'auto'`` (default), ``'QR'``\ , ``'LU'``\ ,
252-
``'none'``\ . Whether the power iterations are normalized with
251+
:param str piter_normalizer: ``'auto'`` (default), ``'QR'``, ``'LU'``,
252+
``'none'``. Whether the power iterations are normalized with
253253
step-by-step QR factorization (the slowest but most accurate),
254254
``'none'`` (the fastest but numerically unstable when `n_iter` is
255255
large, e.g. typically 5 or larger), or ``'LU'`` factorization

tests/extmath_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_block_diag(rgen):
7373
@pt.mark.parametrize('piter_normalizer', [None, 'qr', 'lu', 'auto'])
7474
def test_approximate_range_finder(rows, cols, rank, dtype, piter_normalizer, rgen):
7575
# only guaranteed to work for low-rank matrices
76-
if rank is 'fullrank':
76+
if rank == 'fullrank':
7777
return
7878

7979
rf_size = rank + 10
@@ -84,9 +84,8 @@ def test_approximate_range_finder(rows, cols, rank, dtype, piter_normalizer, rge
8484
Q = em.approx_range_finder(A, rf_size, 7, randstate=rgen,
8585
piter_normalizer=piter_normalizer)
8686

87-
Q = np.asmatrix(Q)
8887
assert Q.shape == (rows, rf_size)
89-
normdist = np.linalg.norm(A - Q * (Q.H * A), ord='fro')
88+
normdist = np.linalg.norm(A - Q @ (Q.T.conj() @ A), ord='fro')
9089
assert normdist < 1e-7
9190

9291

@@ -98,7 +97,7 @@ def test_approximate_range_finder(rows, cols, rank, dtype, piter_normalizer, rge
9897
(20, mptest.random_fullrank)])
9998
def test_randomized_svd(rows, cols, rank, dtype, transpose, n_iter, target_gen,
10099
rgen):
101-
rank = min(rows, cols) - 2 if rank is 'fullrank' else rank
100+
rank = min(rows, cols) - 2 if rank == 'fullrank' else rank
102101
A = target_gen(rows, cols, rank=rank, randstate=rgen, dtype=dtype)
103102

104103
U_ref, s_ref, V_ref = utils.truncated_svd(A, k=rank)

0 commit comments

Comments
 (0)