Skip to content

Commit

Permalink
[operators] remove remaining apply2 'product' occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrave committed Aug 2, 2016
1 parent b619aac commit cc1e696
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 40 deletions.
12 changes: 6 additions & 6 deletions src/pymor/operators/constructions.py
Expand Up @@ -82,19 +82,19 @@ def apply(self, U, ind=None, mu=None):
R.axpy(c, op.apply(U, ind=ind, mu=mu))
return R

def pairwise_apply2(self, V, U, U_ind=None, V_ind=None, mu=None, product=None):
def pairwise_apply2(self, V, U, U_ind=None, V_ind=None, mu=None):
if hasattr(self, '_assembled_operator'):
if self._defaults_sid == defaults_sid():
return self._assembled_operator.pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind, product=product)
return self._assembled_operator.pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind)
else:
return self.assemble().pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind, product=product)
return self.assemble().pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind)
elif self._try_assemble:
return self.assemble().pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind, product=product)
return self.assemble().pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind)
coeffs = self.evaluate_coefficients(mu)
R = self.operators[0].pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind, mu=mu, product=product)
R = self.operators[0].pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind, mu=mu)
R *= coeffs[0]
for op, c in zip(self.operators[1:], coeffs[1:]):
R += c * op.pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind, mu=mu, product=product)
R += c * op.pairwise_apply2(V, U, V_ind=V_ind, U_ind=U_ind, mu=mu)
return R

def apply2(self, V, U, U_ind=None, V_ind=None, mu=None):
Expand Down
14 changes: 4 additions & 10 deletions src/pymor/operators/interfaces.py
Expand Up @@ -71,10 +71,10 @@ def apply(self, U, ind=None, mu=None):

@abstractmethod
def apply2(self, V, U, U_ind=None, V_ind=None, mu=None):
"""Treat the operator as a 2-form by calculating (V, A(U)).
"""Treat the operator as a 2-form by computing ``V.dot(self.apply(U))``.
In particular, if ( , ) is the Euclidean product and A is a linear operator
given by multiplication with a matrix M, then ::
If A is a linear operator given by multiplication with a matrix M, then
`apply2` is given as::
A.apply2(V, U) = V^T*M*U
Expand All @@ -92,9 +92,6 @@ def apply2(self, V, U, U_ind=None, V_ind=None, mu=None):
applied. (See the |VectorArray| documentation for further details.)
mu
The |Parameter| for which to evaluate the operator.
product
The scalar product used in the expression `(V, A(U))` given as
an |Operator|. If `None`, the euclidean product is chosen.
Returns
-------
Expand All @@ -105,7 +102,7 @@ def apply2(self, V, U, U_ind=None, V_ind=None, mu=None):

@abstractmethod
def pairwise_apply2(self, V, U, U_ind=None, V_ind=None, mu=None):
"""Treat the operator as a 2-form by calculating (V, A(U)).
"""Treat the operator as a 2-form by computing ``V.dot(self.apply(U))``.
Same as :meth:`OperatorInterface.apply2`, except that vectors from `V`
and `U` are applied in pairs.
Expand All @@ -124,9 +121,6 @@ def pairwise_apply2(self, V, U, U_ind=None, V_ind=None, mu=None):
applied. (See the |VectorArray| documentation for further details.)
mu
The |Parameter| for which to evaluate the operator.
product
The scalar product used in the expression `(V, A(U))` given as
an |Operator|. If `None`, the euclidean product is chosen.
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion src/pymor/operators/mpi.py
Expand Up @@ -137,7 +137,7 @@ def pairwise_apply2(self, V, U, U_ind=None, V_ind=None, mu=None):
U = U if self.vector else U.obj_id
V = V if self.functional else V.obj_id
return mpi.call(mpi.method_call, self.obj_id, 'pairwise_apply2',
V, U, U_ind=U_ind, V_ind=V_ind, mu=mu, product=product)
V, U, U_ind=U_ind, V_ind=V_ind, mu=mu)

def apply_adjoint(self, U, ind=None, mu=None, source_product=None, range_product=None):
assert U in self.range
Expand Down
23 changes: 0 additions & 23 deletions src/pymortests/operators.py
Expand Up @@ -101,18 +101,6 @@ def test_apply2(operator_with_arrays):
assert np.allclose(M, M2)


def test_apply2_with_product(operator_with_arrays_and_products):
op, mu, U, V, sp, rp = operator_with_arrays_and_products
for U_ind in valid_inds(U):
for V_ind in valid_inds(V):
M = op.apply2(V, U, U_ind=U_ind, V_ind=V_ind, mu=mu)
assert M.shape == (V.len_ind(V_ind), U.len_ind(U_ind))
M2 = V.dot(rp.apply(op.apply(U, ind=U_ind, mu=mu)), ind=V_ind)
assert np.allclose(M, M2)
with pytest.raises(TypeError):
M = op.apply2(V, U, U_ind=U_ind, V_ind=V_ind, mu=mu, product=rp)


def test_pairwise_apply2(operator_with_arrays):
op, mu, U, V = operator_with_arrays
for U_ind, V_ind in valid_inds_of_same_length(U, V):
Expand All @@ -122,17 +110,6 @@ def test_pairwise_apply2(operator_with_arrays):
assert np.allclose(M, M2)


def test_pairwise_apply2_with_product(operator_with_arrays_and_products):
op, mu, U, V, sp, rp = operator_with_arrays_and_products
for U_ind, V_ind in valid_inds_of_same_length(U, V):
M = op.pairwise_apply2(V, U, U_ind=U_ind, V_ind=V_ind, mu=mu)
assert M.shape == (V.len_ind(V_ind),)
M2 = V.pairwise_dot(rp.apply(op.apply(U, ind=U_ind, mu=mu)), ind=V_ind)
assert np.allclose(M, M2)
with pytest.raises(TypeError):
M = op.apply2(V, U, U_ind=U_ind, V_ind=V_ind, mu=mu, product=rp)


def test_apply_adjoint(operator_with_arrays):
op, mu, _, V = operator_with_arrays
if not op.linear:
Expand Down

0 comments on commit cc1e696

Please sign in to comment.