How to use the pyodesys.native._base._NativeCodeBase function in pyodesys

To help you get started, we’ve selected a few pyodesys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bjodah / pyodesys / pyodesys / native / gsl.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)

import copy
import os
from ..util import import_
from ._base import _NativeCodeBase, _NativeSysBase, _compile_kwargs

_config, get_include = import_('pygslodeiv2', '_config', 'get_include')


class NativeGSLCode(_NativeCodeBase):
    """ Looks for the environment variable: ``PYODESYS_BLAS`` (``gslcblas``) """
    wrapper_name = '_gsl_wrapper'

    def __init__(self, *args, **kwargs):
        self.compile_kwargs = copy.deepcopy(_compile_kwargs)
        self.compile_kwargs['include_dirs'].append(get_include())
        self.compile_kwargs['libraries'].extend(_config.env['GSL_LIBS'].split(','))
        self.compile_kwargs['libraries'].extend(os.environ.get('PYODESYS_BLAS', _config.env['BLAS']).split(','))
        super(NativeGSLCode, self).__init__(*args, **kwargs)


class NativeGSLSys(_NativeSysBase):
    _NativeCode = NativeGSLCode
    _native_name = 'gsl'
github bjodah / pyodesys / pyodesys / native / odeint.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)

import copy

from ..util import import_
from ._base import _NativeCodeBase, _NativeSysBase, _compile_kwargs

pyodeint = import_('pyodeint')


class NativeOdeintCode(_NativeCodeBase):
    wrapper_name = '_odeint_wrapper'

    def __init__(self, *args, **kwargs):
        self.compile_kwargs = copy.deepcopy(_compile_kwargs)
        self.compile_kwargs['include_dirs'].append(pyodeint.get_include())
        self.compile_kwargs['libraries'].extend(['m'])
        super(NativeOdeintCode, self).__init__(*args, **kwargs)


class NativeOdeintSys(_NativeSysBase):
    _NativeCode = NativeOdeintCode
    _native_name = 'odeint'
github bjodah / pyodesys / pyodesys / native / cvode.py View on Github external
import copy
import os
import sys

from ..util import import_
from ._base import _NativeCodeBase, _NativeSysBase, _compile_kwargs

get_include, config, _libs = import_("pycvodes", "get_include", "config", "_libs")

if sys.version_info < (3, 6, 0):
    class ModuleNotFoundError(ImportError):
        pass


class NativeCvodeCode(_NativeCodeBase):
    wrapper_name = '_cvode_wrapper'

    try:
        _realtype = config['REAL_TYPE']
        _indextype = config['INDEX_TYPE']
    except ModuleNotFoundError:
        _realtype = '#error "realtype_failed-to-import-pycvodes-or-too-old-version"'
        _indextype = '#error "indextype_failed-to-import-pycvodes-or-too-old-version"'

    namespace = {
        'p_includes': ['"odesys_anyode_iterative.hpp"'],
        'p_support_recoverable_error': True,
        'p_jacobian_set_to_zero_by_solver': True,
        'p_baseclass': 'OdeSysIterativeBase',
        'p_realtype': _realtype,
        'p_indextype': _indextype
github bjodah / pyodesys / pyodesys / native / _base.py View on Github external
self.odesys = odesys
        for _src, _dest in prebuild.items():
            if not os.path.exists(_dest):
                tmpdir = tempfile.mkdtemp()
                try:
                    compile_sources([_src], cwd=tmpdir, metadir=cachedir,
                                    logger=logger, **self.compile_kwargs)
                    shutil.copy(os.path.join(tmpdir, os.path.basename(_src)[:-4] + '.o'),
                                _dest)
                finally:
                    if not kwargs.get('save_temp', False):
                        shutil.rmtree(tmpdir)
                if not os.path.exists(_dest):
                    raise OSError("Failed to place prebuilt file at: %s" % _dest)
        super(_NativeCodeBase, self).__init__(*args, logger=logger, **kwargs)