Exemple #1
0
def cython_cdf(q, k, v):
    # atol = 10**-(dps)
    usr_data = np.array([q, k, v], float).ctypes.data_as(ctypes.c_void_p)
    llc = LowLevelCallable.from_cython(srd, "genstudentized_range_cdf",
                                       usr_data)
    ranges = [(-np.inf, np.inf), (0, np.inf)]
    opts = dict(epsabs=10e-14)
    res = integrate.nquad(llc, ranges=ranges, opts=opts)[0]
    return res
import numpy as np
from numpy.testing import assert_allclose

from scipy import ndimage
from scipy.ndimage import _ctest
from scipy.ndimage import _ctest_oldapi
from scipy.ndimage import _cytest
from scipy._lib._ccallback import LowLevelCallable

FILTER1D_FUNCTIONS = [
    lambda filter_size: _ctest.filter1d(filter_size),
    lambda filter_size: _ctest_oldapi.filter1d(filter_size),
    lambda filter_size: _cytest.filter1d(filter_size, with_signature=False),
    lambda filter_size: LowLevelCallable(
        _cytest.filter1d(filter_size, with_signature=True)),
    lambda filter_size: LowLevelCallable.from_cython(
        _cytest, "_filter1d", _cytest.filter1d_capsule(filter_size)),
]

FILTER2D_FUNCTIONS = [
    lambda weights: _ctest.filter2d(weights),
    lambda weights: _ctest_oldapi.filter2d(weights),
    lambda weights: _cytest.filter2d(weights, with_signature=False),
    lambda weights: LowLevelCallable(
        _cytest.filter2d(weights, with_signature=True)),
    lambda weights: LowLevelCallable.from_cython(
        _cytest, "_filter2d", _cytest.filter2d_capsule(weights)),
]

TRANSFORM_FUNCTIONS = [
    lambda shift: _ctest.transform(shift),
    lambda shift: _ctest_oldapi.transform(shift),
Exemple #3
0
import numpy as np
from numpy.testing import assert_allclose

from scipy import ndimage
from scipy.ndimage import _ctest
from scipy.ndimage import _ctest_oldapi
from scipy.ndimage import _cytest
from scipy._lib._ccallback import LowLevelCallable

FILTER1D_FUNCTIONS = [
    lambda filter_size: _ctest.filter1d(filter_size),
    lambda filter_size: _ctest_oldapi.filter1d(filter_size),
    lambda filter_size: _cytest.filter1d(filter_size, with_signature=False),
    lambda filter_size: LowLevelCallable(_cytest.filter1d(filter_size, with_signature=True)),
    lambda filter_size: LowLevelCallable.from_cython(_cytest, "_filter1d",
                                                     _cytest.filter1d_capsule(filter_size)),
]

FILTER2D_FUNCTIONS = [
    lambda weights: _ctest.filter2d(weights),
    lambda weights: _ctest_oldapi.filter2d(weights),
    lambda weights: _cytest.filter2d(weights, with_signature=False),
    lambda weights: LowLevelCallable(_cytest.filter2d(weights, with_signature=True)),
    lambda weights: LowLevelCallable.from_cython(_cytest, "_filter2d", _cytest.filter2d_capsule(weights)),
]

TRANSFORM_FUNCTIONS = [
    lambda shift: _ctest.transform(shift),
    lambda shift: _ctest_oldapi.transform(shift),
    lambda shift: _cytest.transform(shift, with_signature=False),
    lambda shift: LowLevelCallable(_cytest.transform(shift, with_signature=True)),
CALLERS = {
    'simple': _test_ccallback.test_call_simple,
    'nodata': _test_ccallback.test_call_nodata,
    'nonlocal': _test_ccallback.test_call_nonlocal,
    'cython': _test_ccallback_cython.test_call_cython,
}

# These functions have signatures known to the callers
FUNCS = {
    'python':
    lambda: callback_python,
    'capsule':
    lambda: _test_ccallback.test_get_plus1_capsule(),
    'cython':
    lambda: LowLevelCallable.from_cython(_test_ccallback_cython, "plus1_cython"
                                         ),
    'ctypes':
    lambda: _test_ccallback_cython.plus1_ctypes,
    'cffi':
    lambda: _get_cffi_func(_test_ccallback_cython.plus1_ctypes,
                           'double (*)(double, int *, void *)'),
    'capsule_b':
    lambda: _test_ccallback.test_get_plus1b_capsule(),
    'cython_b':
    lambda: LowLevelCallable.from_cython(_test_ccallback_cython,
                                         "plus1b_cython"),
    'ctypes_b':
    lambda: _test_ccallback_cython.plus1b_ctypes,
    'cffi_b':
    lambda: _get_cffi_func(_test_ccallback_cython.plus1b_ctypes,
                           'double (*)(double, double, int *, void *)'),
Exemple #5
0
    ffi = cffi.FFI()
    return ffi.new('double *', 2.0)


CALLERS = {
    'simple': _test_ccallback.test_call_simple,
    'nodata': _test_ccallback.test_call_nodata,
    'nonlocal': _test_ccallback.test_call_nonlocal,
    'cython': _test_ccallback_cython.test_call_cython,
}

# These functions have signatures known to the callers
FUNCS = {
    'python': lambda: callback_python,
    'capsule': lambda: _test_ccallback.test_get_plus1_capsule(),
    'cython': lambda: LowLevelCallable.from_cython(_test_ccallback_cython, "plus1_cython"),
    'ctypes': lambda: _test_ccallback_cython.plus1_ctypes,
    'cffi': lambda: _get_cffi_func(_test_ccallback_cython.plus1_ctypes,
                                   'double (*)(double, int *, void *)'),
    'capsule_b': lambda: _test_ccallback.test_get_plus1b_capsule(),
    'cython_b': lambda: LowLevelCallable.from_cython(_test_ccallback_cython, "plus1b_cython"),
    'ctypes_b': lambda: _test_ccallback_cython.plus1b_ctypes,
    'cffi_b': lambda: _get_cffi_func(_test_ccallback_cython.plus1b_ctypes,
                                     'double (*)(double, double, int *, void *)'),
}

# These functions have signatures the callers don't know
BAD_FUNCS = {
    'capsule_bc': lambda: _test_ccallback.test_get_plus1bc_capsule(),
    'cython_bc': lambda: LowLevelCallable.from_cython(_test_ccallback_cython, "plus1bc_cython"),
    'ctypes_bc': lambda: _test_ccallback_cython.plus1bc_ctypes,
Exemple #6
0
# -*- coding: utf-8 -*-
"""
Created on Mon May  3 18:18:10 2021

@author: swallan
"""

import srd
import ctypes
from scipy._lib._ccallback import LowLevelCallable
import numpy as np
import scipy.integrate as integrate

usr_data = np.array([4.577, 10, 10], float).ctypes.data_as(ctypes.c_void_p)
# usr_data = np.array([3.77, 3, 12], float).ctypes.data_as(ctypes.c_void_p)
llc = LowLevelCallable.from_cython(srd, "genstudentized_range_cdf", usr_data)


#%%
def cython_cdf(dps):
    atol = 10**-(dps)

    ranges = [(-np.inf, np.inf), (0, np.inf)]
    opts = dict(epsabs=atol)
    res = integrate.nquad(llc, ranges=ranges, opts=opts)[0]
    print(atol)
    print(res)
    return res
    # return integrate.dblquad(llc, -np.inf, np.inf, gfun=0, hfun=np.inf,
    #                                 epsabs=atol)