From 7f74f7ee82994333266db56780b438e89ba25723 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Mon, 14 Sep 2015 15:14:33 -0700 Subject: [PATCH] Remove SimPEGLinearOperator as Scipy 16 has implemented this feature. --- SimPEG/Maps.py | 9 +++++---- SimPEG/Tests/test_PropMaps.py | 6 +++--- SimPEG/Utils/SolverUtils.py | 7 ++++--- SimPEG/Utils/matutils.py | 13 +++---------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/SimPEG/Maps.py b/SimPEG/Maps.py index 6dca13dd..0472cbf2 100644 --- a/SimPEG/Maps.py +++ b/SimPEG/Maps.py @@ -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 diff --git a/SimPEG/Tests/test_PropMaps.py b/SimPEG/Tests/test_PropMaps.py index b4c0eb8d..ef22aaad 100644 --- a/SimPEG/Tests/test_PropMaps.py +++ b/SimPEG/Tests/test_PropMaps.py @@ -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)) diff --git a/SimPEG/Utils/SolverUtils.py b/SimPEG/Utils/SolverUtils.py index 9c2f73ac..279d2b06 100644 --- a/SimPEG/Utils/SolverUtils.py +++ b/SimPEG/Utils/SolverUtils.py @@ -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): diff --git a/SimPEG/Utils/matutils.py b/SimPEG/Utils/matutils.py index e4ab5700..7ba100a0 100644 --- a/SimPEG/Utils/matutils.py +++ b/SimPEG/Utils/matutils.py @@ -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)