Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/scipy/sparse/_matrix.py: 50%
56 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-23 06:43 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-23 06:43 +0000
1class spmatrix:
2 """This class provides a base class for all sparse matrix classes.
4 It cannot be instantiated. Most of the work is provided by subclasses.
5 """
7 @property
8 def _bsr_container(self):
9 from ._bsr import bsr_matrix
10 return bsr_matrix
12 @property
13 def _coo_container(self):
14 from ._coo import coo_matrix
15 return coo_matrix
17 @property
18 def _csc_container(self):
19 from ._csc import csc_matrix
20 return csc_matrix
22 @property
23 def _csr_container(self):
24 from ._csr import csr_matrix
25 return csr_matrix
27 @property
28 def _dia_container(self):
29 from ._dia import dia_matrix
30 return dia_matrix
32 @property
33 def _dok_container(self):
34 from ._dok import dok_matrix
35 return dok_matrix
37 @property
38 def _lil_container(self):
39 from ._lil import lil_matrix
40 return lil_matrix
42 # Restore matrix multiplication
43 def __mul__(self, other):
44 return self._mul_dispatch(other)
46 def __rmul__(self, other):
47 return self._rmul_dispatch(other)
49 # Restore matrix power
50 def __pow__(self, power):
51 from .linalg import matrix_power
53 return matrix_power(self, power)
55 ## Backward compatibility
57 def set_shape(self, shape):
58 """Set the shape of the matrix in-place"""
59 # Make sure copy is False since this is in place
60 # Make sure format is unchanged because we are doing a __dict__ swap
61 new_self = self.reshape(shape, copy=False).asformat(self.format)
62 self.__dict__ = new_self.__dict__
64 def get_shape(self):
65 """Get the shape of the matrix"""
66 return self._shape
68 shape = property(fget=get_shape, fset=set_shape,
69 doc="Shape of the matrix")
71 def asfptype(self):
72 """Upcast matrix to a floating point format (if necessary)"""
73 return self._asfptype()
75 def getmaxprint(self):
76 """Maximum number of elements to display when printed."""
77 return self._getmaxprint()
79 def getformat(self):
80 """Matrix storage format"""
81 return self.format
83 def getnnz(self, axis=None):
84 """Number of stored values, including explicit zeros.
86 Parameters
87 ----------
88 axis : None, 0, or 1
89 Select between the number of values across the whole array, in
90 each column, or in each row.
91 """
92 return self._getnnz(axis=axis)
94 def getH(self):
95 """Return the Hermitian transpose of this matrix.
97 See Also
98 --------
99 numpy.matrix.getH : NumPy's implementation of `getH` for matrices
100 """
101 return self.conjugate().transpose()
103 def getcol(self, j):
104 """Returns a copy of column j of the matrix, as an (m x 1) sparse
105 matrix (column vector).
106 """
107 return self._getcol(j)
109 def getrow(self, i):
110 """Returns a copy of row i of the matrix, as a (1 x n) sparse
111 matrix (row vector).
112 """
113 return self._getrow(i)