@@ -77,7 +77,7 @@ def empty(cls, shape):
7777 @classmethod
7878 def from_lists (cls , shape , rows , cols , is_sorted = False , no_duplicates = False ):
7979 """
80- Build matrix from provided `shape` and non-zero values data.
80+ Create matrix from provided `shape` and non-zero values data.
8181
8282 >>> matrix = Matrix.from_lists((4, 4), [0, 1, 2, 3], [0, 1, 2, 0], is_sorted=True, no_duplicates=True)
8383 >>> print(matrix)
@@ -260,7 +260,7 @@ def set_marker(self, marker: str):
260260 'meow (0x1a767b0)'
261261
262262 :param marker: String marker to set
263- :return: None
263+ :return:
264264 """
265265
266266 assert marker is not None
@@ -492,6 +492,23 @@ def extract_matrix(self, i, j, shape, out=None, time_check=False):
492492 return out
493493
494494 def extract_row (self , i , out = None ):
495+ """
496+ Extract specified `self` matrix row as sparse vector.
497+
498+ >>> matrix = Matrix.from_lists((5, 4), [0, 1, 2, 4], [0, 1, 1, 3])
499+ >>> print(matrix.extract_row(1))
500+ '
501+ 0 | . | 0
502+ 1 | 1 | 1
503+ 2 | . | 2
504+ 3 | . | 3
505+ '
506+
507+ :param i: Row index to extract
508+ :param out: Optional out vector to store result
509+ :return: Return extracted row
510+ """
511+
495512 if out is None :
496513 out = vector .Vector .empty (self .ncols )
497514
@@ -506,6 +523,24 @@ def extract_row(self, i, out=None):
506523 return out
507524
508525 def extract_col (self , j , out = None ):
526+ """
527+ Extract specified `self` matrix column as sparse vector.
528+
529+ >>> matrix = Matrix.from_lists((5, 4), [0, 1, 2, 4], [0, 1, 1, 3])
530+ >>> print(matrix.extract_col(1))
531+ '
532+ 0 | . | 0
533+ 1 | 1 | 1
534+ 2 | 1 | 2
535+ 3 | . | 3
536+ 4 | . | 4
537+ '
538+
539+ :param j: Column index to extract
540+ :param out: Optional out vector to store result
541+ :return: Return extracted column
542+ """
543+
509544 if out is None :
510545 out = vector .Vector .empty (self .nrows )
511546
@@ -562,6 +597,29 @@ def mxm(self, other, out=None, accumulate=False, time_check=False):
562597 return out
563598
564599 def mxv (self , other , out = None , time_check = False ):
600+ """
601+ Matrix-vector multiply.
602+
603+ Multiply `this` matrix by column `other` vector `on the right`.
604+ For row vector-matrix multiplication "on the left" see `Vector.vxm`.
605+
606+ >>> matrix = Matrix.from_lists((5, 4), [0, 1, 2, 4], [0, 1, 1, 3])
607+ >>> vector = Vector.from_list(4, [0, 1, 2])
608+ >>> print(matrix.mxv(vector))
609+ '
610+ 0 | 1 | 0
611+ 1 | 1 | 1
612+ 2 | 1 | 2
613+ 3 | . | 3
614+ 4 | . | 4
615+ '
616+
617+ :param other: Input matrix for multiplication
618+ :param out: Optional out vector to store result
619+ :param time_check: Pass True to measure and log elapsed time of the operation
620+ :return: Vector-matrix multiplication result
621+ """
622+
565623 if out is None :
566624 out = vector .Vector .empty (self .nrows )
567625
@@ -654,9 +712,9 @@ def ewiseadd(self, other, out=None, time_check=False):
654712 bridge .check (status )
655713 return out
656714
657- def reduce (self , time_check = False ):
715+ def reduce (self , out = None , time_check = False ):
658716 """
659- Reduce matrix to vector with boolean "+ = or" operation.
717+ Reduce matrix to column matrix with boolean "+ = or" operation.
660718 Return `self` reduced matrix.
661719
662720 >>> matrix = Matrix.from_lists((4, 4), [0, 1, 2, 2], [0, 1, 0, 2])
@@ -670,12 +728,14 @@ def reduce(self, time_check=False):
670728 0
671729 '
672730
731+ :param out: Optional out matrix to store result
673732 :param time_check: Pass True to measure and log elapsed time of the operation
674733 :return: Reduced matrix (matrix with M x 1 shape)
675734 """
676735
677- shape = (self .nrows , 1 )
678- out = Matrix .empty (shape )
736+ if out is None :
737+ shape = (self .nrows , 1 )
738+ out = Matrix .empty (shape )
679739
680740 status = wrapper .loaded_dll .cuBool_Matrix_Reduce2 (
681741 out .hnd ,
@@ -687,6 +747,31 @@ def reduce(self, time_check=False):
687747 return out
688748
689749 def reduce_vector (self , out = None , transpose = False , time_check = False ):
750+ """
751+ Reduce matrix to column vector with boolean "+ = or" operation.
752+ Return `self` reduced matrix.
753+
754+ >>> matrix = Matrix.from_lists((5, 4), [0, 1, 2, 4], [0, 1, 1, 3])
755+ >>> print(matrix.reduce_vector(), matrix.reduce_vector(transpose=True), sep="")
756+ '
757+ 0 | 1 | 0
758+ 1 | 1 | 1
759+ 2 | 1 | 2
760+ 3 | . | 3
761+ 4 | 1 | 4
762+
763+ 0 | 1 | 0
764+ 1 | 1 | 1
765+ 2 | . | 2
766+ 3 | 1 | 3
767+ '
768+
769+ :param out: Optional out matrix to store result
770+ :param transpose: Pass True to reduce matrix to row vector
771+ :param time_check: Pass True to measure and log elapsed time of the operation
772+ :return: Reduced matrix (matrix with M x 1 shape)
773+ """
774+
690775 if out is None :
691776 nrows = self .ncols if transpose else self .nrows
692777 out = vector .Vector .empty (nrows )
@@ -795,7 +880,7 @@ def __getitem__(self, item):
795880
796881 def __setitem__ (self , key , value ):
797882 """
798- Sets Sets specified `key` = (i, j) value of the matrix to True.
883+ Sets specified `key` = (i, j) value of the matrix to True.
799884
800885 >>> matrix = Matrix.empty(shape=(4, 4))
801886 >>> matrix[0, 0] = True
0 commit comments