Skip to content

Commit 36bff38

Browse files
committed
Add method to zero matrix entries
1 parent ecf1f67 commit 36bff38

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

fipy/matrices/pysparseMatrix.py

+4
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ def T(self):
392392

393393
return _PysparseMatrix(matrix=A_T)
394394

395+
def zeroEntries(self):
396+
_, irow, jcol = self.matrix.find()
397+
self.put(0, irow, jcol)
398+
395399
class _PysparseMatrixFromShape(_PysparseMatrix):
396400

397401
def __init__(self, rows, cols,

fipy/matrices/scipyMatrix.py

+4
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ def T(self):
379379
"""
380380
return _ScipyMatrix(matrix=self.matrix.transpose(copy=True))
381381

382+
def zeroEntries(self):
383+
id1, id2 = self.matrix.nonzero()
384+
self.matrix[id1, id2] = 0
385+
382386
class _ScipyMatrixFromShape(_ScipyMatrix):
383387

384388
def __init__(self, rows, cols,

fipy/matrices/sparseMatrix.py

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ def LIL(self):
134134
def T(self):
135135
raise NotImplementedError
136136

137+
def zeroEntries(self):
138+
"""Insert zeros into nonzero matrix entries.
139+
"""
140+
raise NotImplementedError
141+
137142
def _matrix2mesh(self, ids):
138143
"""Convert matrix row indices to mesh cell indices
139144
"""

fipy/matrices/trilinosMatrix.py

+3
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ def T(self):
715715

716716
return _TrilinosMatrix(matrix=A_T_bis)
717717

718+
def zeroEntries(self):
719+
self.matrix.PutScalar(0)
720+
718721
class _TrilinosMatrixFromShape(_TrilinosMatrix):
719722
def __init__(self, rows, cols,
720723
nonZerosPerRow=1, exactNonZeros=False, matrix=None):

0 commit comments

Comments
 (0)