Coverage for src/pymor/tools/inplace : 30%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# -*- coding: utf-8 -*- # This file is part of the pyMOR project (http://www.pymor.org). # Copyright Holders: Rene Milk, Stephan Rave, Felix Schindler # License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
'''Indexed, masked in-place addition.
This is the same as ::
U[U_ind] += V
with two exceptions: 1. Negative indices are skipped. 2. If the same index is repeated, all additions are performed, not only the last one. ''' logger.warn('Call to unoptimized function iadd_masked') assert len(U_ind) == len(V), 'Lengths of U_ind and V must match' assert U.shape[1:] == V.shape[1:], 'U.shape[1:] != V.shape[1:]'
for ind, v in izip(U_ind, V): if ind < 0: continue U[ind] += v
'''Indexed, masked in-place subtraction.
This is the same as ::
U[U_ind] -= V
with two exceptions: 1. Negative indices are skipped. 2. If the same index is repeated, all subtractions are performed, not only the last one. ''' logger.warn('Call to unoptimized function iadd_masked') assert len(U_ind) == len(V), 'Lengths of U_ind and V must match' assert U.shape[1:] == V.shape[1:], 'U.shape[1:] != V.shape[1:]'
for ind, v in izip(U_ind, V): if ind < 0: continue U[ind] -= v |