def test_reduceat():
    """Test bug in reduceat when structured arrays are not copied."""
    db = np.dtype([('name', 'S11'), ('time', np.int64), ('value', np.float32)])
    a = np.empty([100], dtype=db)
    a['name'] = 'Simple'
    a['time'] = 10
    a['value'] = 100
    indx = [0, 7, 15, 25]

    h2 = []
    val1 = indx[0]
    for val2 in indx[1:]:
        h2.append(np.add.reduce(a['value'][val1:val2]))
        val1 = val2
    h2.append(np.add.reduce(a['value'][val1:]))
    h2 = np.array(h2)

    # test buffered -- this should work
    h1 = np.add.reduceat(a['value'], indx)
    assert_array_almost_equal(h1, h2)

    # This is when the error occurs.
    # test no buffer
    res = np.setbufsize(32)
    h1 = np.add.reduceat(a['value'], indx)
    np.setbufsize(np.UFUNC_BUFSIZE_DEFAULT)
    assert_array_almost_equal(h1, h2)
Esempio n. 2
0
def test_reduceat():
    """Test bug in reduceat when structured arrays are not copied."""
    db = np.dtype([("name", "S11"), ("time", np.int64), ("value", np.float32)])
    a = np.empty([100], dtype=db)
    a["name"] = "Simple"
    a["time"] = 10
    a["value"] = 100
    indx = [0, 7, 15, 25]

    h2 = []
    val1 = indx[0]
    for val2 in indx[1:]:
        h2.append(np.add.reduce(a["value"][val1:val2]))
        val1 = val2
    h2.append(np.add.reduce(a["value"][val1:]))
    h2 = np.array(h2)

    # test buffered -- this should work
    h1 = np.add.reduceat(a["value"], indx)
    assert_array_almost_equal(h1, h2)

    # This is when the error occurs.
    # test no buffer
    res = np.setbufsize(32)
    h1 = np.add.reduceat(a["value"], indx)
    np.setbufsize(np.UFUNC_BUFSIZE_DEFAULT)
    assert_array_almost_equal(h1, h2)
Esempio n. 3
0
def test_reduceat():
    """Test bug in reduceat with structured arrays copied for speed."""
    db = np.dtype([("name", "S11"), ("time", np.int64), ("value", np.float32)])
    a = np.empty([100], dtype=db)
    a["name"] = "Simple"
    a["time"] = 10
    a["value"] = 100
    indx = [0, 7, 15, 25]

    h2 = []
    val1 = indx[0]
    for val2 in indx[1:]:
        h2.append(np.add.reduce(a["value"][val1:val2]))
        val1 = val2
    h2.append(np.add.reduce(a["value"][val1:]))
    h2 = np.array(h2)

    # test buffered
    res = np.setbufsize(32)
    h1 = np.add.reduceat(a["value"], indx)
    assert_array_almost_equal(h1, h2)

    # test nobuffer
    np.setbufsize(res)
    h1 = np.add.reduceat(a["value"], indx)
    assert_array_almost_equal(h1, h2)
Esempio n. 4
0
def test_reduceat():
    """Test bug in reduceat with structured arrays copied for speed."""
    db = np.dtype([('name', 'S11'), ('time', np.int64), ('value', np.float32)])
    a = np.empty([100], dtype=db)
    a['name'] = 'Simple'
    a['time'] = 10
    a['value'] = 100
    indx = [0, 7, 15, 25]

    h2 = []
    val1 = indx[0]
    for val2 in indx[1:]:
        h2.append(np.add.reduce(a['value'][val1:val2]))
        val1 = val2
    h2.append(np.add.reduce(a['value'][val1:]))
    h2 = np.array(h2)

    # test buffered
    res = np.setbufsize(32)
    h1 = np.add.reduceat(a['value'], indx)
    assert_array_almost_equal(h1, h2)

    # test nobuffer
    np.setbufsize(res)
    h1 = np.add.reduceat(a['value'], indx)
    assert_array_almost_equal(h1, h2)
Esempio n. 5
0
 def test_reduce_big_object_array(self, level=rlevel):
     """Ticket #713"""
     oldsize = np.setbufsize(10 * 16)
     a = np.array([None] * 161, object)
     assert not np.any(a)
     np.setbufsize(oldsize)
Esempio n. 6
0
 def test_reduce_big_object_array(self, level=rlevel):
     """Ticket #713"""
     oldsize = np.setbufsize(10*16)
     a = np.array([None]*161, object)
     assert not np.any(a)
     np.setbufsize(oldsize)
import numpy as np

np.geterrobj()  # first get the defaults


def err_handler(err_type, flag):
    print
    "Floating point error (%s), with flag %s" % (err_type, flag)


old_bufsize = np.setbufsize(20000)
old_err = np.seterr(divide='raise')
old_handler = np.seterrcall(err_handler)
np.geterrobj()
old_err = np.seterr(all='ignore')
np.base_repr(np.geterrobj()[1], 8)
old_err = np.seterr(divide='warn', over='log', under='call')
np.base_repr(np.geterrobj()[1], 8)
Esempio n. 8
0
    def write(self, a: str) -> int: ...


_err_default = np.geterr()
_bufsize_default = np.getbufsize()
_errcall_default = np.geterrcall()

try:
    np.seterr(all=None)
    np.seterr(divide="ignore")
    np.seterr(over="warn")
    np.seterr(under="call")
    np.seterr(invalid="raise")
    np.geterr()

    np.setbufsize(4096)
    np.getbufsize()

    np.seterrcall(func1)
    np.seterrcall(func2)
    np.seterrcall(func3)
    np.seterrcall(Write1())
    np.seterrcall(Write2())
    np.seterrcall(Write3())
    np.geterrcall()

    with np.errstate(call=func1, all="call"):
        pass
    with np.errstate(call=Write1(), divide="log", over="log"):
        pass
Esempio n. 9
0
from matplotlib.animation import FuncAnimation
from skimage import morphology
import argparse
import bootstrapped.bootstrap as bs
import bootstrapped.stats_functions as bs_stats
import csv
import matplotlib.cm as cm
import numpy as np
import os
import tifffile

# custom libraries
import scope_utils3 as su
import muscle_fish as mf

np.setbufsize(1E7)

#--  FUNCTION DECLARATIONS  ---------------------------------------------------#


def update_z(frame):
    '''Frame updater for FuncAnimation.
    '''
    im_xy.set_data(imgs_rna[chan][:, :, frame])
    colors = []
    for spot in spots_masked:
        alpha = su.gauss_1d(frame, 1., spot[2], spot[3])
        colors.append([1., 0., 0., alpha])
    spots_xy.set_facecolor(colors)
    return im_xy, spots_xy  # this return structure is a requirement for the FuncAnimation() callable
Esempio n. 10
0
        ...


reveal_type(
    np.seterr(all=None))  # E: TypedDict('numpy.core._ufunc_config._ErrDict'
reveal_type(np.seterr(
    divide="ignore"))  # E: TypedDict('numpy.core._ufunc_config._ErrDict'
reveal_type(
    np.seterr(over="warn"))  # E: TypedDict('numpy.core._ufunc_config._ErrDict'
reveal_type(np.seterr(
    under="call"))  # E: TypedDict('numpy.core._ufunc_config._ErrDict'
reveal_type(np.seterr(
    invalid="raise"))  # E: TypedDict('numpy.core._ufunc_config._ErrDict'
reveal_type(np.geterr())  # E: TypedDict('numpy.core._ufunc_config._ErrDict'

reveal_type(np.setbufsize(4096))  # E: int
reveal_type(np.getbufsize())  # E: int

reveal_type(
    np.seterrcall(func)
)  # E: Union[None, def (builtins.str, builtins.int) -> Any, numpy.core._ufunc_config._SupportsWrite]
reveal_type(
    np.seterrcall(Write())
)  # E: Union[None, def (builtins.str, builtins.int) -> Any, numpy.core._ufunc_config._SupportsWrite]
reveal_type(
    np.geterrcall()
)  # E: Union[None, def (builtins.str, builtins.int) -> Any, numpy.core._ufunc_config._SupportsWrite]

reveal_type(np.errstate(
    call=func,
    all="call"))  # E: numpy.errstate[def (a: builtins.str, b: builtins.int)]
import numpy

numpy.setbufsize(1)