Python numpy.seterr() Examples
The following are 30
code examples of numpy.seterr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_core.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def setUp(self): # Base data definition. x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.]) y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.]) a10 = 10. m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1] xm = masked_array(x, mask=m1) ym = masked_array(y, mask=m2) z = np.array([-.5, 0., .5, .8]) zm = masked_array(z, mask=[0, 1, 0, 0]) xf = np.where(m1, 1e+20, x) xm.set_fill_value(1e+20) self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf) self.err_status = np.geterr() np.seterr(divide='ignore', invalid='ignore')
Example #2
Source File: test_core.py From lambda-packs with MIT License | 6 votes |
def setUp(self): # Base data definition. x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.]) y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.]) a10 = 10. m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1] xm = masked_array(x, mask=m1) ym = masked_array(y, mask=m2) z = np.array([-.5, 0., .5, .8]) zm = masked_array(z, mask=[0, 1, 0, 0]) xf = np.where(m1, 1e+20, x) xm.set_fill_value(1e+20) self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf) self.err_status = np.geterr() np.seterr(divide='ignore', invalid='ignore')
Example #3
Source File: _distn_infrastructure.py From lambda-packs with MIT License | 6 votes |
def _entropy(self, *args): def integ(x): val = self._pdf(x, *args) return entr(val) # upper limit is often inf, so suppress warnings when integrating olderr = np.seterr(over='ignore') h = integrate.quad(integ, self.a, self.b)[0] np.seterr(**olderr) if not np.isnan(h): return h else: # try with different limits if integration problems low, upp = self.ppf([1e-10, 1. - 1e-10], *args) if np.isinf(self.b): upper = upp else: upper = self.b if np.isinf(self.a): lower = low else: lower = self.a return integrate.quad(integ, lower, upper)[0]
Example #4
Source File: test_core.py From vnpy_crypto with MIT License | 6 votes |
def setup(self): # Base data definition. x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.]) y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.]) a10 = 10. m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1] xm = masked_array(x, mask=m1) ym = masked_array(y, mask=m2) z = np.array([-.5, 0., .5, .8]) zm = masked_array(z, mask=[0, 1, 0, 0]) xf = np.where(m1, 1e+20, x) xm.set_fill_value(1e+20) self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf) self.err_status = np.geterr() np.seterr(divide='ignore', invalid='ignore')
Example #5
Source File: test_core.py From recruit with Apache License 2.0 | 6 votes |
def setup(self): # Base data definition. x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.]) y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.]) a10 = 10. m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1] xm = masked_array(x, mask=m1) ym = masked_array(y, mask=m2) z = np.array([-.5, 0., .5, .8]) zm = masked_array(z, mask=[0, 1, 0, 0]) xf = np.where(m1, 1e+20, x) xm.set_fill_value(1e+20) self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf) self.err_status = np.geterr() np.seterr(divide='ignore', invalid='ignore')
Example #6
Source File: evaluation.py From few with GNU General Public License v3.0 | 6 votes |
def evaluate(self,n, features, stack_float, stack_bool,labels=None): """evaluate node in program""" np.seterr(all='ignore') if len(stack_float) >= n.arity['f'] and len(stack_bool) >= n.arity['b']: if n.out_type == 'f': stack_float.append( self.safe(self.eval_dict[n.name](n,features,stack_float, stack_bool,labels))) if (np.isnan(stack_float[-1]).any() or np.isinf(stack_float[-1]).any()): print("problem operator:",n) else: stack_bool.append(self.safe(self.eval_dict[n.name](n,features, stack_float, stack_bool, labels))) if np.isnan(stack_bool[-1]).any() or np.isinf(stack_bool[-1]).any(): print("problem operator:",n)
Example #7
Source File: test_core.py From Computable with MIT License | 6 votes |
def setUp (self): "Base data definition." x = np.array([1., 1., 1., -2., pi / 2.0, 4., 5., -10., 10., 1., 2., 3.]) y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.]) a10 = 10. m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1] xm = masked_array(x, mask=m1) ym = masked_array(y, mask=m2) z = np.array([-.5, 0., .5, .8]) zm = masked_array(z, mask=[0, 1, 0, 0]) xf = np.where(m1, 1e+20, x) xm.set_fill_value(1e+20) self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf) self.err_status = np.geterr() np.seterr(divide='ignore', invalid='ignore')
Example #8
Source File: basic_stats_generator_test.py From data-validation with Apache License 2.0 | 6 votes |
def test_basic_stats_generator_no_runtime_warnings_close_to_max_int(self): # input has batches with values that are slightly smaller than the maximum # integer value. less_than_max_int_value = np.iinfo(np.int64).max - 1 batches = ([ pa.RecordBatch.from_arrays([pa.array([[less_than_max_int_value]])], ['a']) ] * 2) generator = basic_stats_generator.BasicStatsGenerator() old_nperr = np.geterr() np.seterr(over='raise') accumulators = [ generator.add_input(generator.create_accumulator(), batch) for batch in batches ] generator.merge_accumulators(accumulators) np.seterr(**old_nperr)
Example #9
Source File: decorators.py From ngraph-python with Apache License 2.0 | 6 votes |
def with_error_settings(**new_settings): """ TODO. Arguments: **new_settings: TODO Returns: """ @decorator.decorator def dec(f, *args, **kwargs): old_settings = np.geterr() np.seterr(**new_settings) ret = f(*args, **kwargs) np.seterr(**old_settings) return ret return dec
Example #10
Source File: test_multilabel_average_precision_metric.py From comb_dist_direct_relex with Apache License 2.0 | 6 votes |
def test_get_metrics(cls): np.seterr(divide='ignore', invalid='ignore') bins = 1000 diff = 0.01 metric = MultilabelAveragePrecision(bins=bins) size = [1000, 100] pred = Tensor(np.random.uniform(0, 1, size)) gold = Tensor(np.random.randint(0, 2, size)) metric.__call__(pred, gold) fast_ap = metric.get_metric() # calls the fast get_metric ap = metric.get_metric(reset=True) # calls the accurate get_metric assert (abs(ap - fast_ap)) < diff metric.__call__(pred, gold) metric.__call__(pred, gold) metric.__call__(pred, gold) fast_ap = metric.get_metric() ap = metric.get_metric(reset=True) assert (abs(ap - fast_ap)) < diff
Example #11
Source File: test_numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.olderr)
Example #12
Source File: test_umath.py From vnpy_crypto with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.olderr)
Example #13
Source File: test_umath.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def setUp(self): self.olderr = np.seterr(invalid='ignore')
Example #14
Source File: test_umath.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.olderr)
Example #15
Source File: rng_mrg.py From D-VAE with MIT License | 5 votes |
def perform(self, node, inp, out): rstate, size = inp o_rstate, o_sample = out n_elements = 1 for s in size: n_elements *= s if n_elements > M1: # The limit is on the C and GPU code. This perform don't # have this limit. But to have all of them behave the # same (and have DebugMode don't use too much memory for # some rng_mrg tests) I also add this limit here. raise ValueError("rng_mrg does not support more then (2**31 -1) samples") rstate = numpy.asarray(rstate) # bring state from GPU if necessary if not self.inplace: rstate = rstate.copy() n_streams, _ = rstate.shape rval = numpy.zeros(n_elements, dtype=self.output_type.dtype) err_orig = numpy.seterr(over='ignore') try: for i in xrange(n_elements): sample = mrg_next_value(rstate[i % n_streams], rstate[i % n_streams]) rval[i] = sample finally: numpy.seterr(**err_orig) # send to GPU if necessary o_rstate[0] = node.outputs[0].type.filter(rstate) o_sample[0] = node.outputs[1].type.filter(rval.reshape(size))
Example #16
Source File: fel.py From ocelot with GNU General Public License v3.0 | 5 votes |
def beta_opt(self, method='mxie', apply=False, **kwargs): if method == 'mxie': beta_orig_x, beta_orig_y = self.betax, self.betay beta_orig = np.mean([beta_orig_x, beta_orig_y]) fel_copy = deepcopy(self) def f(x, method=method): fel_copy.betax = fel_copy.betay = x fel_copy.eval(method=method) return fel_copy.lg3 err_dict = np.geterr() np.seterr(all='ignore') beta_opt = fmin(f, beta_orig, disp=0, **kwargs) np.seterr(**err_dict) elif method == 'ssy_opt': beta_opt = self.beta_opt_calc else: _logger.error('method should be in ["mxie", "ssy_opt"]') raise ValueError('method should be in ["mxie", "ssy_opt"]') if apply: self.betax = beta_opt self.betay = beta_opt self.eval(method) else: return beta_opt[0]
Example #17
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def setup(self): self.olderr = np.seterr(invalid='ignore')
Example #18
Source File: test_umath_complex.py From vnpy_crypto with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.olderr)
Example #19
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_set(self): with np.errstate(): err = np.seterr() old = np.seterr(divide='print') assert_(err == old) new = np.seterr() assert_(new['divide'] == 'print') np.seterr(over='raise') assert_(np.geterr()['over'] == 'raise') assert_(new['divide'] == 'print') np.seterr(**old) assert_(np.geterr() == old)
Example #20
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_divide_err(self): with np.errstate(divide='raise'): try: np.array([1.]) / np.array([0.]) except FloatingPointError: pass else: self.fail() np.seterr(divide='ignore') np.array([1.]) / np.array([0.])
Example #21
Source File: test_numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_divide_err(self): with np.errstate(divide='raise'): try: np.array([1.]) / np.array([0.]) except FloatingPointError: pass else: self.fail() np.seterr(divide='ignore') np.array([1.]) / np.array([0.])
Example #22
Source File: test_numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_set(self): with np.errstate(): err = np.seterr() old = np.seterr(divide='print') self.assertTrue(err == old) new = np.seterr() self.assertTrue(new['divide'] == 'print') np.seterr(over='raise') self.assertTrue(np.geterr()['over'] == 'raise') self.assertTrue(new['divide'] == 'print') np.seterr(**old) self.assertTrue(np.geterr() == old)
Example #23
Source File: test_umath_complex.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.olderr)
Example #24
Source File: test_old_ma.py From Computable with MIT License | 5 votes |
def test_testUfuncRegression(self): f_invalid_ignore = ['sqrt', 'arctanh', 'arcsin', 'arccos', 'arccosh', 'arctanh', 'log', 'log10', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod'] for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate', 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh', 'absolute', 'fabs', 'negative', # 'nonzero', 'around', 'floor', 'ceil', # 'sometrue', 'alltrue', 'logical_not', 'add', 'subtract', 'multiply', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod', 'hypot', 'arctan2', 'equal', 'not_equal', 'less_equal', 'greater_equal', 'less', 'greater', 'logical_and', 'logical_or', 'logical_xor', ]: try: uf = getattr(umath, f) except AttributeError: uf = getattr(fromnumeric, f) mf = getattr(np.ma, f) args = self.d[:uf.nin] with np.errstate(): if f in f_invalid_ignore: np.seterr(invalid='ignore') if f in ['arctanh', 'log', 'log10']: np.seterr(divide='ignore') ur = uf(*args) mr = mf(*args) self.assertTrue(eq(ur.filled(0), mr.filled(0), f)) self.assertTrue(eqmask(ur.mask, mr.mask))
Example #25
Source File: test_umath_complex.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def setUp(self): self.olderr = np.seterr(invalid='ignore')
Example #26
Source File: test_core.py From Computable with MIT License | 5 votes |
def test_fix_invalid(self): "Checks fix_invalid." with np.errstate(): np.seterr(invalid='ignore') data = masked_array([np.nan, 0., 1.], mask=[0, 0, 1]) data_fixed = fix_invalid(data) assert_equal(data_fixed._data, [data.fill_value, 0., 1.]) assert_equal(data_fixed._mask, [1., 0., 1.])
Example #27
Source File: test_umath_complex.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.olderr)
Example #28
Source File: test_core.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.err_status)
Example #29
Source File: test_core.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def setUp(self): # Base data definition. self.d = (array([1.0, 0, -1, pi / 2] * 2, mask=[0, 1] + [0] * 6), array([1.0, 0, -1, pi / 2] * 2, mask=[1, 0] + [0] * 6),) self.err_status = np.geterr() np.seterr(divide='ignore', invalid='ignore')
Example #30
Source File: test_core.py From Computable with MIT License | 5 votes |
def tearDown(self): np.seterr(**self.err_status)