Skip to content

Commit d30660e

Browse files
committed
Add some periods to doc strings
1 parent a7f08f1 commit d30660e

File tree

1 file changed

+53
-51
lines changed

1 file changed

+53
-51
lines changed

src/aspire/utils/blk_diag_matrix.py

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def __init__(self, nblocks, partition=None, dtype=np.float64):
3434
"""
3535
Instantiate a BlkDiagMatrix.
3636
37-
:param nblocks: Number of diagonal matrix blocks
37+
:param nblocks: Number of diagonal matrix blocks.
3838
:param partition: Optionally supply the matrix block partition
3939
in the form of a `nblock`-element list storing all shapes of
4040
diagonal matrix blocks, where `partition[i]` corresponds to
4141
the shape (number of rows and columns) of the `i` matrix block.
42-
:return BlkDiagMatrix instance
42+
:return BlkDiagMatrix instance.
4343
4444
"""
4545

@@ -52,7 +52,7 @@ def __init__(self, nblocks, partition=None, dtype=np.float64):
5252
assert self._cached_blk_sizes.shape[1] == 2
5353

5454
def __repr__(self):
55-
"""String represention describing instance """
55+
"""String represention describing instance. """
5656
return "BlkDiagMatrix({}, {})".format(
5757
repr(self.nblocks), repr(self.dtype))
5858

@@ -67,29 +67,29 @@ def copy(self):
6767
# This is just for syntax which allows us to reference self[i] etc
6868
# instead of writing self.data all the time. You may use either.
6969
def __getitem__(self, key):
70-
""" Convenience wrapper, getter on self.data """
70+
""" Convenience wrapper, getter on self.data. """
7171
return self.data[key]
7272

7373
def __setitem__(self, key, value):
74-
""" Convenience wrapper, setter on self.data """
74+
""" Convenience wrapper, setter on self.data. """
7575
self.data[key] = value
7676

7777
def __len__(self):
78-
""" Convenience function for getting nblocks """
78+
""" Convenience function for getting nblocks. """
7979
return self.nblocks
8080

8181
def _is_scalar_type(self, x):
82-
""" Internal helper function checking scalar-ness for elementwise ops
82+
""" Internal helper function checking scalar-ness for elementwise ops.
8383
84-
:return: bool
84+
:return: bool.
8585
"""
8686
# Implemented as a function in case we need to modify it in future...
8787
return np.isscalar(x)
8888

8989
@staticmethod
9090
def zeros(blk_partition, dtype=np.float64):
9191
"""
92-
Build a BlkDiagMatrix zeros matrix
92+
Build a BlkDiagMatrix zeros matrix.
9393
9494
:param blk_partition: The matrix block partition in the form of a
9595
K-element list storing all shapes of K diagonal matrix blocks,
@@ -109,7 +109,7 @@ def zeros(blk_partition, dtype=np.float64):
109109
@staticmethod
110110
def ones(blk_partition, dtype=np.float64):
111111
"""
112-
Build a BlkDiagMatrix ones matrix
112+
Build a BlkDiagMatrix ones matrix.
113113
114114
:param blk_partition: The matrix block partition in the form of a
115115
K-element list storing all shapes of K diagonal matrix blocks,
@@ -184,7 +184,7 @@ def partition(self):
184184
def check_compatible(self, other):
185185
"""
186186
Sanity check two BlkDiagMatrix matrices are compatible in size.
187-
:para other: The BlkDiagMatrix to compare with self
187+
:para other: The BlkDiagMatrix to compare with self.
188188
:return: Returns True if no error is raised.
189189
"""
190190

@@ -209,9 +209,9 @@ def check_compatible(self, other):
209209
@property
210210
def isnumeric(self):
211211
"""
212-
Check if all blocks in diag matrix are numeric
212+
Check if all blocks in diag matrix are numeric.
213213
214-
:return: Bool
214+
:return: Bool.
215215
"""
216216
# Note Matlab port checked 0 == blk*0 for a single blk.
217217
# However, the only use case I could think of would be for the
@@ -224,9 +224,9 @@ def isnumeric(self):
224224

225225
def add(self, other):
226226
"""
227-
Define the elementwise addition of BlkDiagMatrix matrix
227+
Define the elementwise addition of BlkDiagMatrix matrix.
228228
229-
:param other: The rhs BlkDiagMatrix matrix
229+
:param other: The rhs BlkDiagMatrix matrix.
230230
:return: BlkDiagMatrix matrix with elementwise sum equal
231231
to self + other.
232232
"""
@@ -268,9 +268,9 @@ def __radd__(self, other):
268268

269269
def scalar_add(self, scalar, inplace=False):
270270
"""
271-
Define the element addition of BlkDiagMatrix matrix
271+
Define the element addition of BlkDiagMatrix matrix.
272272
273-
:param scalar: constant addend value
273+
:param scalar: constant addend value.
274274
:param inplace: bool, when false (default) return new instance.
275275
276276
:return: BlkDiagMatrix matrix with elementwise sum equal
@@ -290,9 +290,9 @@ def scalar_add(self, scalar, inplace=False):
290290

291291
def sub(self, other):
292292
"""
293-
Define the element subtraction of BlkDiagMatrix matrix
293+
Define the element subtraction of BlkDiagMatrix matrix.
294294
295-
:param other: The rhs BlkDiagMatrix matrix
295+
:param other: The rhs BlkDiagMatrix matrix.
296296
297297
:return: A BlkDiagMatrix matrix with elementwise subraction equal to
298298
self - other.
@@ -310,11 +310,11 @@ def sub(self, other):
310310
return C
311311

312312
def __sub__(self, other):
313-
""" Operator overloading for subtraction """
313+
""" Operator overloading for subtraction. """
314314
return self.sub(other)
315315

316316
def __isub__(self, other):
317-
""" Operator overloading for in place subtraction """
317+
""" Operator overloading for in place subtraction. """
318318
if self._is_scalar_type(other):
319319
return self.scalar_sub(other, inplace=True)
320320
self.check_compatible(other)
@@ -325,17 +325,17 @@ def __isub__(self, other):
325325
return self
326326

327327
def __rsub__(self, other):
328-
""" Convenient function for elementwise scalar subtraction """
328+
""" Convenient function for elementwise scalar subtraction. """
329329
# Note, the case of BlkDiagMatrix_L - BlkDiagMatrix_R would be
330330
# evaluated as L.sub(R), so this is only for other
331331
# Object - BlkDiagMatrix situations, namely scalars.
332332
return -(self - other)
333333

334334
def scalar_sub(self, scalar, inplace=False):
335335
"""
336-
Define the elementwise subtraction from BlkDiagMatrix matrix
336+
Define the elementwise subtraction from BlkDiagMatrix matrix.
337337
338-
:param scalar: constant subtractend value
338+
:param scalar: constant subtractend value.
339339
:param inplace: bool, when false (default) return new instance.
340340
341341
:return: BlkDiagMatrix matrix with elementwise sum equal to
@@ -355,9 +355,9 @@ def scalar_sub(self, scalar, inplace=False):
355355

356356
def matmul(self, other):
357357
"""
358-
Compute the Matrix multiplication of two BlkDiagMatrix matrices
358+
Compute the Matrix multiplication of two BlkDiagMatrix matrices.
359359
360-
:param other: The rhs BlkDiagMatrix matrix
360+
:param other: The rhs BlkDiagMatrix matrix.
361361
362362
:return: A BlkDiagMatrix of self @ other.
363363
"""
@@ -376,7 +376,7 @@ def matmul(self, other):
376376
return C
377377

378378
def __matmul__(self, other):
379-
""" Operator overload for matrix matrix multiply of BlkDiagMatrixes """
379+
""" Operator overload for matrix matrix multiply of BlkDiagMatrixes. """
380380
return self.matmul(other)
381381

382382
def __imatmul__(self, other):
@@ -395,7 +395,7 @@ def mul(self, val):
395395
Compute the numeric (elementwise) multiplication of a BlkDiagMatrix
396396
matrix and a scalar.
397397
398-
:param other: The rhs BlkDiagMatrix matrix
398+
:param other: The rhs BlkDiagMatrix matrix.
399399
400400
:return: A BlkDiagMatrix of self * other.
401401
"""
@@ -415,11 +415,11 @@ def mul(self, val):
415415
return C
416416

417417
def __mul__(self, val):
418-
""" Operator overload for BlkDiagMatrix scalar multiply"""
418+
""" Operator overload for BlkDiagMatrix scalar multiply. """
419419
return self.mul(val)
420420

421421
def __imul__(self, val):
422-
""" Operator overload for in place BlkDiagMatrix scalar multiply"""
422+
""" Operator overload for in place BlkDiagMatrix scalar multiply. """
423423
if isinstance(val, BlkDiagMatrix):
424424
raise RuntimeError(
425425
"Attempt numeric multiplication (*,mul) of two BlkDiagMatrixs,"
@@ -430,14 +430,14 @@ def __imul__(self, val):
430430
return self
431431

432432
def __rmul__(self, other):
433-
""" Convenience function, elementwise rmul commutes to mul """
433+
""" Convenience function, elementwise rmul commutes to mul. """
434434
return self.mul(other)
435435

436436
def __neg__(self):
437437
"""
438438
Compute the unary negation of BlkDiagMatrix matrix.
439439
440-
:return: A BlkDiagMatrix like self
440+
:return: A BlkDiagMatrix like self.
441441
"""
442442
C = BlkDiagMatrix(self.nblocks, dtype=self.dtype)
443443
for i in range(self.nblocks):
@@ -448,7 +448,7 @@ def __abs__(self):
448448
"""
449449
Compute the elementwise absolute value of BlkDiagMatrix matrix.
450450
451-
:return: A BlkDiagMatrix like self
451+
:return: A BlkDiagMatrix like self.
452452
"""
453453
C = BlkDiagMatrix(self.nblocks, dtype=self.dtype)
454454
for i in range(self.nblocks):
@@ -484,7 +484,7 @@ def norm(self, order=2):
484484
485485
:param order: Norm order, see np.norm. Defaults to order 2 norm.
486486
487-
:return: The norm of the BlkDiagMatrix matrix
487+
:return: The norm of the BlkDiagMatrix matrix.
488488
"""
489489
implimented_orders = (2,)
490490
if order not in implimented_orders:
@@ -496,9 +496,9 @@ def norm(self, order=2):
496496

497497
def transpose(self):
498498
"""
499-
Get the transpose matrix of a BlkDiagMatrix matrix
499+
Get the transpose matrix of a BlkDiagMatrix matrix.
500500
501-
:return: The corresponding transpose form as a BlkDiagMatrix
501+
:return: The corresponding transpose form as a BlkDiagMatrix.
502502
"""
503503

504504
T = BlkDiagMatrix(self.nblocks, dtype=self.dtype)
@@ -510,14 +510,14 @@ def transpose(self):
510510

511511
@property
512512
def T(self):
513-
""" Syntactic sugar for self.transpose() """
513+
""" Syntactic sugar for self.transpose(). """
514514
return self.transpose()
515515

516516
def dense(self):
517517
"""
518-
Convert list representation of BlkDiagMatrix matrix into full matrix
518+
Convert list representation of BlkDiagMatrix matrix into full matrix.
519519
520-
:param blk_diag: The BlkDiagMatrix matrix
520+
:param blk_diag: The BlkDiagMatrix matrix.
521521
522522
:return: The BlkDiagMatrix matrix including the zero elements of
523523
non-diagonal blocks.
@@ -527,14 +527,14 @@ def dense(self):
527527
@staticmethod
528528
def from_blk_diag(blk_diag, dtype=np.float64):
529529
"""
530-
Convert full from list representation into BlkDiagMatrix
530+
Convert full from list representation into BlkDiagMatrix.
531531
532532
:param blk_diag; The blk_diag representation in the form of a
533533
K-element list storing all shapes of K diagonal matrix blocks,
534534
where `blk_partition[i]` corresponds to the shape (number of rows
535535
and columns) of the `i` diagonal matrix block.
536536
537-
:return: The BlkDiagMatrix matrix
537+
:return: The BlkDiagMatrix matrix.
538538
"""
539539

540540
# TODO: maybe can improve implementation
@@ -554,7 +554,7 @@ def from_blk_diag(blk_diag, dtype=np.float64):
554554
@staticmethod
555555
def from_mat(mat, blk_partition, dtype=np.float64):
556556
"""
557-
Convert full block diagonal matrix into list representation
557+
Convert full block diagonal matrix into list representation.
558558
559559
:param mat; The full block diagonal matrix including the zero elements
560560
ofnon-diagonal blocks.
@@ -563,7 +563,7 @@ def from_mat(mat, blk_partition, dtype=np.float64):
563563
where `blk_partition[i]` corresponds to the shape (number rows
564564
and columns) of the `i` diagonal matrix block.
565565
566-
:return: The BlkDiagMatrix matrix
566+
:return: The BlkDiagMatrix matrix.
567567
"""
568568

569569
# TODO: maybe can improve this implementation
@@ -579,7 +579,7 @@ def from_mat(mat, blk_partition, dtype=np.float64):
579579

580580
def solve(self, Y):
581581
"""
582-
Solve a linear system involving a block diagonal matrix
582+
Solve a linear system involving a block diagonal matrix.
583583
584584
:param Y: The right-hand side in the linear system. May be a matrix
585585
consisting of coefficient vectors, in which case each column is
@@ -615,9 +615,10 @@ def apply(self, X):
615615
Define the apply option of a block diagonal matrix with a matrix of
616616
coefficient vectors.
617617
618-
:param X: The coefficient matrix with each col is a coefficient vector
618+
:param X: The coefficient matrix with each column is a coefficient
619+
vector.
619620
620-
:return: A matrix with new coefficient vectors
621+
:return: A matrix with new coefficient vectors.
621622
"""
622623
cols = np.array([np.size(mat, 1) for mat in self])
623624

@@ -646,18 +647,19 @@ def apply(self, X):
646647

647648

648649
def get_partition(blk_diag):
649-
""" Convenience wrapper of BlkDiagMatrix.get_partition"""
650+
""" Convenience wrapper of BlkDiagMatrix.get_partition. """
650651
return BlkDiagMatrix.get_partition(blk_diag)
651652

652653

653654
def filter_to_fb_mat(h_fun, fbasis):
654655
"""
655-
Convert a nonradial function in k space into a basis representation
656+
Convert a nonradial function in k space into a basis representation.
656657
657-
:param h_fun: The function form in k space
658-
:param fbasis: The basis object for expanding
658+
:param h_fun: The function form in k space.
659+
:param fbasis: The basis object for expanding.
659660
660-
:return: a BlkDiagMatrix matrix representation using the `fbasis` expansion
661+
:return: a BlkDiagMatrix matrix representation using the
662+
`fbasis` expansion.
661663
"""
662664
if not isinstance(fbasis, FFBBasis2D):
663665
raise NotImplementedError('Currently only fast FB method is supported')

0 commit comments

Comments
 (0)