Skip to content

Commit

Permalink
add a isnull function to really determine if a smrt_matrix is null
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainp committed Aug 27, 2019
1 parent 0191203 commit b17670e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion smrt/core/fresnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import numpy as np
import scipy.sparse
from smrt.core.lib import smrt_matrix, abs2


Expand Down
16 changes: 13 additions & 3 deletions smrt/core/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class smrt_matrix(object):
def __init__(self, mat, mtype=None):

if mat is 0:
self.values = 0
self.values = 0.
self.mtype = "0"
else:
self.values = mat
Expand Down Expand Up @@ -176,7 +176,7 @@ def compress(self, mode=None, auto_reduce_npol=False):
3) convert the format of the matrix to compressed numpy, involving a change of the dimension order (pola and streams are merged).
"""
if self.values is 0:
if self.mtype == "0":
return 0.

if self.mtype == "dense5":
Expand Down Expand Up @@ -264,7 +264,7 @@ def __setitem__(self, key, v):

@property
def diagonal(self):
if self.values is 0:
if self.mtype == "0":
return np.array([0.])
if self.mtype.startswith("diagonal"):
return self.values
Expand Down Expand Up @@ -306,6 +306,16 @@ def __repr__(self):
return str("smrt_matrix %s %s" % (self.mtype, shape)) + "\n" + str(self.values)


def isnull(m):
"""return true if the smrt matrix is null"""

if isinstance(m, scipy.sparse.dia.dia_matrix):
m = m.diagonal()

return (m is 0) or \
(getattr(m, "mtype", None) == "0") or \
(~np.any(m))


def abs2(c):
return c.real**2 + c.imag**2
Expand Down

0 comments on commit b17670e

Please sign in to comment.