Remove SimPEGLinearOperator as Scipy 16 has implemented this feature.

This commit is contained in:
Rowan Cockett
2015-09-14 15:14:33 -07:00
parent 7cd4ba7d61
commit 7f74f7ee82
4 changed files with 15 additions and 20 deletions
+5 -4
View File
@@ -1,4 +1,5 @@
import Utils, numpy as np, scipy.sparse as sp
from scipy.sparse.linalg import LinearOperator
from Tests import checkDerivative
from PropMaps import PropMap, Property
@@ -289,7 +290,7 @@ class FullMap(IdentityMap):
"""
FullMap
Given a scalar, the FullMap maps the value to the
Given a scalar, the FullMap maps the value to the
full model space.
"""
@@ -314,8 +315,8 @@ class FullMap(IdentityMap):
:rtype: numpy.array
:return: derivative of transformed model
"""
return np.ones([self.mesh.nC,1])
return np.ones([self.mesh.nC,1])
class Vertical1DMap(IdentityMap):
"""Vertical1DMap
@@ -639,7 +640,7 @@ class ComplexMap(IdentityMap):
return v[:nC] + v[nC:]*1j
def adj(v):
return np.r_[v.real,v.imag]
return Utils.SimPEGLinearOperator(shp,fwd,adj)
return LinearOperator(shp,matvec=fwd,rmatvec=adj)
inverse = deriv
+3 -3
View File
@@ -8,9 +8,9 @@ class MyPropMap(Maps.PropMap):
mu = Maps.Property("Mu", defaultVal=mu_0)
class MyReciprocalPropMap(Maps.PropMap):
sigma = Maps.Property("Electrical Conductivity", defaultInvProp=True, propertyLink=('rho', Maps.ReciprocalMap))
rho = Maps.Property("Electrical Resistivity", propertyLink=('sigma', Maps.ReciprocalMap))
mu = Maps.Property("Mu", defaultVal=mu_0, propertyLink=('mui', Maps.ReciprocalMap))
sigma = Maps.Property("Electrical Conductivity", defaultInvProp=True, propertyLink=('rho', Maps.ReciprocalMap))
rho = Maps.Property("Electrical Resistivity", propertyLink=('sigma', Maps.ReciprocalMap))
mu = Maps.Property("Mu", defaultVal=mu_0, propertyLink=('mui', Maps.ReciprocalMap))
mui = Maps.Property("Mu", defaultVal=1./mu_0, propertyLink=('mu', Maps.ReciprocalMap))
+4 -3
View File
@@ -110,9 +110,10 @@ def SolverWrapI(fun, checkAccuracy=True, accuracyTol=1e-5):
return type(fun.__name__+'_Wrapped', (object,), {"__init__": __init__, "clean": clean, "__mul__": __mul__})
Solver = SolverWrapD(sp.linalg.spsolve, factorize=False)
SolverLU = SolverWrapD(sp.linalg.splu, factorize=True)
SolverCG = SolverWrapI(sp.linalg.cg)
from scipy.sparse import linalg
Solver = SolverWrapD(linalg.spsolve, factorize=False)
SolverLU = SolverWrapD(linalg.splu, factorize=True)
SolverCG = SolverWrapI(linalg.cg)
class SolverDiag(object):
+3 -10
View File
@@ -342,10 +342,10 @@ def invPropertyTensor(M, tensor, returnMatrix=False):
def diagEst(matFun, n, k=None, approach='Probing'):
"""
"""
Estimate the diagonal of a matrix, A. Note that the matrix may be a function which returns A times a vector.
Three different approaches have been implemented,
Three different approaches have been implemented,
1. Probing : uses cyclic permutations of vectors with ones and zeros (default)
2. Ones : random +/- 1 entries
3. Random : random vectors
@@ -362,7 +362,7 @@ def diagEst(matFun, n, k=None, approach='Probing'):
if type(matFun).__name__=='ndarray':
A = matFun
matFun = lambda v: A.dot(v)
matFun = lambda v: A.dot(v)
if k is None:
k = np.floor(n/10.)
@@ -397,10 +397,3 @@ def diagEst(matFun, n, k=None, approach='Probing'):
return d
from scipy.sparse.linalg import LinearOperator
class SimPEGLinearOperator(LinearOperator):
"""Extends scipy.sparse.linalg.LinearOperator to have a .T function."""
@property
def T(self):
return self.__class__((self.shape[1],self.shape[0]),self.rmatvec,rmatvec=self.matvec,matmat=self.matmat)