Python numpy.seterrcall() Examples

The following are 30 code examples for showing how to use numpy.seterrcall(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: recruit   Author: Frank-qlu   File: numeric.py    License: Apache License 2.0 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 2
Project: recruit   Author: Frank-qlu   File: numeric.py    License: Apache License 2.0 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 3
Project: InSilicoSeq   Author: HadrienG   File: modeller.py    License: MIT License 5 votes vote down vote up
def raw_qualities_to_histogram(qualities):
    """Approximate the distribution of base quality at each position in a read
    using a pseudo 2d kernel density estimation

    Generate cumulative distribution functions

    Args:
        qualities (list): raw count of all phred scores

    Returns:
        list: list of cumulative distribution functions. One cdf per base. The
            list has the size of the read length
    """
    logger = logging.getLogger(__name__)

    # moved this in quality_bins_to_histogram to try parallelization
    # quals = util.split_list([i for i in zip(*qualities)], n_parts=cpus)
    cdfs_list = []
    for q in qualities:
        numpy_log_handler = np.seterrcall(util.nplog)
        with np.errstate(under='ignore', divide='call'):
            try:
                kde = stats.gaussian_kde(q, bw_method=0.2 / np.std(q, ddof=1))
            except np.linalg.linalg.LinAlgError as e:
                # if np.std of array is 0, we modify the array slightly to be
                # able to divide by ~ np.std
                # this will print a FloatingPointError in DEBUG mode
                # logger.debug('np.std of quality array is zero: %s' % e)
                q = list(q)
                q[-1] += 1
                kde = stats.gaussian_kde(q, bw_method=0.2 / np.std(q, ddof=1))
            kde = kde.evaluate(range(41))
        cdf = np.cumsum(kde)
        cdf = cdf / cdf[-1]
        cdfs_list.append(cdf)
    return cdfs_list 
Example 4
Project: lambda-packs   Author: ryfeus   File: numeric.py    License: MIT License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 5
Project: lambda-packs   Author: ryfeus   File: numeric.py    License: MIT License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 6
Project: vnpy_crypto   Author: birforce   File: numeric.py    License: MIT License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 7
Project: vnpy_crypto   Author: birforce   File: numeric.py    License: MIT License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 8
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: numeric.py    License: MIT License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 9
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: numeric.py    License: MIT License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 10
Project: pywonderland   Author: neozhaoliang   File: helpers.py    License: MIT License 5 votes vote down vote up
def get_mirrors(coxeter_diagram):
    """
    Given a Coxter diagram consists of integers/rationals that represent the angles between
    the mirrors (a rational p means the angle is π/p), return a square matrix whose
    rows are the normal vectors of the mirrors. This matrix is not unique, here we use a
    lower triangle one to simplify the computations.
    """
    # error handling function when the input coxeter matrix is invalid.
    def err_handler(err_type, flag):
        print("Invalid input Coxeter diagram. This diagram does not give a finite \
symmetry group of an uniform polytope. See \
https://en.wikipedia.org/wiki/Coxeter_group#Symmetry_groups_of_regular_polytopes \
for a complete list of valid Coxeter diagrams.")
        sys.exit(1)

    np.seterrcall(err_handler)
    np.seterr(all="call")

    coxeter_matrix = np.array(make_symmetry_matrix(coxeter_diagram)).astype(np.float)
    C = -np.cos(np.pi / coxeter_matrix)
    M = np.zeros_like(C)
    n = len(M)
    # the first normal vector is simply (1, 0, ...)
    M[0, 0] = 1
    # in the i-th row, the j-th entry can be computed via the (j, j) entry.
    for i in range(1, n):
        for j in range(i):
            M[i, j] = (C[i, j] - np.dot(M[j, :j], M[i, :j])) / M[j, j]
        # the (i, i) entry is used to normalize this vector
        M[i, i] = np.sqrt(1 - np.dot(M[i, :i], M[i, :i]))

    return M 
Example 11
Project: GraphicDesignPatternByPython   Author: Relph1119   File: numeric.py    License: MIT License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 12
Project: GraphicDesignPatternByPython   Author: Relph1119   File: numeric.py    License: MIT License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 13
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 14
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 15
Project: pySINDy   Author: luckystarufo   File: numeric.py    License: MIT License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 16
Project: pySINDy   Author: luckystarufo   File: numeric.py    License: MIT License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 17
Project: mxnet-lambda   Author: awslabs   File: numeric.py    License: Apache License 2.0 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 18
Project: mxnet-lambda   Author: awslabs   File: numeric.py    License: Apache License 2.0 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 19
Project: pyblp   Author: jeffgortmaker   File: basics.py    License: MIT License 5 votes vote down vote up
def __call__(self, decorated: Callable) -> Callable:
        """Decorate the function."""
        @functools.wraps(decorated)
        def wrapper(*args: Any, **kwargs: Any) -> Any:
            """Configure NumPy to detect numerical errors."""
            detector = NumericalErrorDetector(self.error)
            with np.errstate(divide='call', over='call', under='ignore', invalid='call'):
                np.seterrcall(detector)
                returned = decorated(*args, **kwargs)
            if detector.detected is not None:
                returned[-1].append(detector.detected)
            return returned

        return wrapper 
Example 20
Project: Splunking-Crime   Author: nccgroup   File: numeric.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 21
Project: Splunking-Crime   Author: nccgroup   File: numeric.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 22
Project: traversing_knowledge_graphs   Author: millerjohnp   File: util.py    License: MIT License 5 votes vote down vote up
def catch_nans():
    np.seterr(invalid='call')
    np.seterrcall(examine_nan) 
Example 23
Project: elasticintel   Author: securityclippy   File: numeric.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 24
Project: elasticintel   Author: securityclippy   File: numeric.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 25
Project: coffeegrindsize   Author: jgagneastro   File: numeric.py    License: MIT License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 26
Project: coffeegrindsize   Author: jgagneastro   File: numeric.py    License: MIT License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 27
Project: Carnets   Author: holzschu   File: numeric.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 28
Project: Carnets   Author: holzschu   File: numeric.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall) 
Example 29
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda   Author: PacktPublishing   File: numeric.py    License: MIT License 5 votes vote down vote up
def __enter__(self):
        self.oldstate = seterr(**self.kwargs)
        if self.call is not _Unspecified:
            self.oldcall = seterrcall(self.call) 
Example 30
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda   Author: PacktPublishing   File: numeric.py    License: MIT License 5 votes vote down vote up
def __exit__(self, *exc_info):
        seterr(**self.oldstate)
        if self.call is not _Unspecified:
            seterrcall(self.oldcall)