Commit c36a2ea5 authored by René Fritze's avatar René Fritze Committed by René Fritze

[alogirhtms] move contains_zero_vector here from float_cmp

parent 9a7c6671
......@@ -9,6 +9,7 @@ import scipy
from pymor.core.defaults import defaults
from pymor.operators.constructions import induced_norm
from pymor.tools.floatcmp import float_cmp
@defaults('rtol', 'atol')
......@@ -101,3 +102,22 @@ def project_array(U, basis, product=None, orthonormal=True):
rhs = basis.inner(U, product)
coeffs = scipy.linalg.solve(gramian, rhs, sym_pos=True, overwrite_a=True, overwrite_b=True).T
return basis.lincomb(coeffs)
def contains_zero_vector(vector_array, rtol=None, atol=None):
"""returns `True` iff any vector in the array float_compares to 0s of the same dim
Parameters
----------
vector_array
a |VectorArray| implementation
rtol
relative tolerance for float_cmp
atol
absolute tolerance for float_cmp
"""
for i in range(len(vector_array)):
sup = vector_array[i].sup_norm()
if float_cmp(sup, 0.0, rtol, atol):
return True
return False
\ No newline at end of file
......@@ -2,3 +2,6 @@
# Copyright 2013-2020 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
""" pymor.core.tools collects modules used throughout pyMOR
that generally do not depend on any of pyMOR's abstraction objects.
"""
\ No newline at end of file
......@@ -68,27 +68,6 @@ def bounded(lower, upper, x, rtol=None, atol=None):
return (lower < x < upper) or float_cmp(x, lower, rtol, atol) or float_cmp(x, upper, rtol, atol)
def contains_zero_vector(vector_array, rtol=None, atol=None):
"""returns `True` iff any vector in the array float_compares to 0s of the same dim
Parameters
----------
vector_array
a |VectorArray| implementation
rtol
relative tolerance for float_cmp
atol
absolute tolerance for float_cmp
"""
zero = np.zeros(vector_array.dim)
for i in range(len(vector_array)):
vec = vector_array[i].to_numpy()
if float_cmp_all(vec, zero, rtol, atol):
return True
return False
@defaults('rtol', 'atol')
def compare_with_tolerance(x, y, comparison_op, rtol=1e-14, atol=1e-14):
""" 'One-sided' Comparison x and y component-wise with given comparison op.
......
......@@ -9,7 +9,7 @@ from hypothesis import given, settings, assume, reproduce_failure, example
from pymor.algorithms.basic import almost_equal
from pymor.algorithms.gram_schmidt import gram_schmidt, gram_schmidt_biorth
from pymor.core.logger import getLogger, scoped_logger
from pymor.tools.floatcmp import contains_zero_vector
from pymor.algorithms.basic import contains_zero_vector
from pymor.vectorarrays.numpy import NumpyVectorArray, NumpyVectorSpace
from pymortests.base import runmodule
from pymortests.fixtures.operator import operator_with_arrays_and_products
......
......@@ -10,7 +10,7 @@ from hypothesis.strategies import sampled_from
from pymor.algorithms.basic import almost_equal
from pymor.algorithms.gram_schmidt import gram_schmidt
from pymor.algorithms.pod import pod
from pymor.tools.floatcmp import contains_zero_vector
from pymor.algorithms.basic import contains_zero_vector
from pymortests.fixtures.operator import operator_with_arrays_and_products
from pymortests.strategies import vector_arrays
......
......@@ -9,7 +9,7 @@ from hypothesis.strategies import sampled_from
from pymor.algorithms.basic import almost_equal
from pymor.algorithms.svd_va import method_of_snapshots, qr_svd
from pymor.tools.floatcmp import contains_zero_vector
from pymor.algorithms.basic import contains_zero_vector
from pymortests.base import runmodule
from pymortests.fixtures.operator import operator_with_arrays_and_products
from pymortests.strategies import vector_arrays
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment