testing of compressed maps.

This commit is contained in:
Rowan Cockett
2015-06-01 10:15:20 -07:00
parent 8475eadcce
commit 2c48a69fb2
2 changed files with 49 additions and 4 deletions
+15 -1
View File
@@ -73,8 +73,22 @@ class PropModel(object):
def __init__(self, propMap, vector):
self.propMap = propMap
self.vector = vector
assert len(self.vector) == self.nP
@property
def nP(self):
inds = []
if getattr(self, '_nP', None) is None:
for name in self.propMap._properties:
index = getattr(self.propMap, '%sIndex'%name, None)
if index is not None:
if type(index) is slice:
inds += range(*index.indices(len(self.vector)))
else:
inds += list(index)
self._nP = len(set(inds))
return self._nP
# TODO: nP
_PROPMAPCLASSREGISTRY = {}
+34 -3
View File
@@ -1,11 +1,11 @@
import unittest
from SimPEG import *
from scipy.constants import mu_0
class MyPropMap(Maps.PropMap):
sigma = Maps.Property("Electrical Conductivity", defaultInvProp=True)
mu = Maps.Property("Electrical Conductivity", defaultVal=4e-10)
mu = Maps.Property("Electrical Conductivity", defaultVal=mu_0)
class TestPropMaps(unittest.TestCase):
@@ -31,7 +31,7 @@ class TestPropMaps(unittest.TestCase):
assert PM.muIndex is None
m = PM(np.r_[1,2,3])
assert m.mu == 4e-10
assert m.mu == mu_0
assert m.muModel is None
assert m.muMap is None
assert m.muDeriv is None
@@ -41,6 +41,8 @@ class TestPropMaps(unittest.TestCase):
assert np.all(m.sigma == np.exp(np.r_[1,2,3]))
assert m.sigmaDeriv is not None
assert m.nP == 3
def test_slices(self):
expMap = Maps.ExpMap(Mesh.TensorMesh((3,)))
PM = MyPropMap({'maps':[('sigma', expMap)], 'slices':{'sigma':[2,1,0]}})
@@ -49,7 +51,36 @@ class TestPropMaps(unittest.TestCase):
assert np.all(m.sigmaModel == np.r_[3,2,1])
assert np.all(m.sigma == np.exp(np.r_[3,2,1]))
def test_multiMap(self):
m = Mesh.TensorMesh((3,))
expMap = Maps.ExpMap(m)
iMap = Maps.IdentityMap(m)
PM = MyPropMap([('sigma', expMap), ('mu', iMap)])
pm = PM(np.r_[1,2,3,4,5,6])
assert pm.nP == 6
assert np.all(pm.sigmaModel == [1,2,3])
assert np.all(pm.sigma == np.exp([1,2,3]))
assert np.all(pm.muModel == [4,5,6])
assert np.all(pm.mu == [4,5,6])
def test_multiMapCompressed(self):
m = Mesh.TensorMesh((3,))
expMap = Maps.ExpMap(m)
iMap = Maps.IdentityMap(m)
PM = MyPropMap({'maps':[('sigma', expMap), ('mu', iMap)],'slices':{'mu':[0,1,2]}})
pm = PM(np.r_[1,2,3])
assert pm.nP == 3
assert np.all(pm.sigmaModel == [1,2,3])
assert np.all(pm.sigma == np.exp([1,2,3]))
assert np.all(pm.muModel == [1,2,3])
assert np.all(pm.mu == [1,2,3])
if __name__ == '__main__':
unittest.main()