From fbe0b714de5450c126adef776bcea3961b0410d7 Mon Sep 17 00:00:00 2001 From: domfournier Date: Fri, 28 Feb 2025 14:36:35 -0800 Subject: [PATCH 1/2] Bring back Projection as input for Wires --- simpeg/maps/_base.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/simpeg/maps/_base.py b/simpeg/maps/_base.py index b2d0def858..cd3336b10b 100644 --- a/simpeg/maps/_base.py +++ b/simpeg/maps/_base.py @@ -1140,20 +1140,24 @@ def __init__(self, *args): and isinstance(arg[0], str) and # TODO: this should be extended to a slice. - isinstance(arg[1], (int, np.integer)) + isinstance(arg[1], (int, np.integer, Projection)) ), ( - "Each wire needs to be a tuple: (name, length). " + "Each wire needs to be a tuple: (name, length) or (name, Projection). " "You provided: {}".format(arg) ) - self._nP = int(np.sum([w[1] for w in args])) start = 0 maps = [] for arg in args: - wire = Projection(self.nP, slice(start, start + arg[1])) + + if isinstance(arg[1], (int, np.integer)): + wire = Projection(self.nP, slice(start, start + arg[1])) + start += arg[1] + else: + wire = arg[1] + setattr(self, arg[0], wire) maps += [(arg[0], wire)] - start += arg[1] self.maps = maps self._tuple = namedtuple("Model", [w[0] for w in args]) From e0adeaff5de0307d3860443d3ffa29489e42cc87 Mon Sep 17 00:00:00 2001 From: domfournier Date: Fri, 28 Feb 2025 14:39:13 -0800 Subject: [PATCH 2/2] Bring back derivs --- simpeg/maps/_base.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/simpeg/maps/_base.py b/simpeg/maps/_base.py index cd3336b10b..2671b2a87f 100644 --- a/simpeg/maps/_base.py +++ b/simpeg/maps/_base.py @@ -1159,8 +1159,9 @@ def __init__(self, *args): setattr(self, arg[0], wire) maps += [(arg[0], wire)] self.maps = maps - - self._tuple = namedtuple("Model", [w[0] for w in args]) + self._nP = maps[0][1].nP + self._tuple = namedtuple("Model", [name for name, _ in args]) + self._projection = sp.vstack([wire.P for _, wire in self.maps]) def __mul__(self, val): assert isinstance(val, np.ndarray) @@ -1180,6 +1181,22 @@ def nP(self): """ return self._nP + def deriv(self, m): + """ + Derivative of the mapping with respect to the input parameters + + Parameters + ---------- + m : (n_param, ) numpy.ndarray + The model for which the gradient is evaluated. + + Returns + ------- + (n_param, ) numpy.ndarray + The Gradient of the mapping function evaluated for the model provided. + """ + return self._projection + class TileMap(IdentityMap): """