How to use the cppimport.imp function in cppimport

To help you get started, we’ve selected a few cppimport 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 molpopgen / fwdpy11 / tests / test_fitness_callback_polymorphism.py View on Github external
import cppimport
cppimport.force_rebuild()
cppimport.set_quiet(False)
snowdrift = cppimport.imp("snowdrift")
test_polymorphism = cppimport.imp("test_polymorphism")
import unittest
import fwdpy11.fitness as fp11w
import re


class testFitnessPolymorphism(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.w = [
            fp11w.SlocusAdditive(),
            fp11w.SlocusMult(),
            snowdrift.SlocusSnowdrift(0.2, -0.2, 1, -2)]
        self.v = test_polymorphism.test_callback_names(self.w)

    def testCallbackNameLen(self):
        self.assertEqual(len(self.v), 3)
github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
def test_package_mymodule():
    mymodule = cppimport.imp("apackage.mymodule")
    module_tester(mymodule)
github tbenthompson / tectosaur / bin / adjacent.py View on Github external
import multiprocessing
import matplotlib.pyplot as plt
import numpy as np

import tectosaur.quadrature as quad
import tectosaur.geometry as geometry
from tectosaur.interpolate import cheb, cheb_wts, to_interval, barycentric_evalnd
from tectosaur.limit import limit, richardson_limit

from coincident import build_tables

from gpu_integrator import new_integrate

import cppimport
adaptive_integrate = cppimport.imp('adaptive_integrate')

# H parameters
K = "H"
rho_order = 100
starting_eps = 0.0001
n_eps = 4
tol = 0.0001
n_pr = 8
n_theta = 8

# play parameters
K = "H"
rho_order = 40
theta_order = 28
starting_eps = 1e-4
n_eps = 2
github tbenthompson / cppimport / cppimport / cpprun.py View on Github external
filename = args.filename
    filedir = os.path.dirname(filename)
    filebasename = os.path.basename(filename)
    module_name, file_extension = os.path.splitext(filebasename)

    if args.add_main_caller:
        cpprun_dir = '.cpprunfiles'
        if not os.path.exists(cpprun_dir):
            os.makedirs(cpprun_dir)
        src = os.path.join(cpprun_dir, filebasename)
        open(src, 'w').write(open(filename, 'r').read() + footer)
        sys.path.append(cpprun_dir)
    else:
        sys.path.append(filedir)

    module = cppimport.imp(module_name)

    if args.verbose:
        print("Launching!")
    module.main()
github tbenthompson / tectosaur / playground / specqr / adjacent.py View on Github external
import matplotlib.pyplot as plt
import numpy as np
import cppimport
import tectosaur.quadrature as quad
from tectosaur.geometry import tri_normal
import interpolate
adaptive_integrate = cppimport.imp('adaptive_integrate')

tri1 = [[0,0,0],[1,0,0],[0,1,0]]

n_theta = 13
theta = np.linspace(0, 2 * np.pi, n_theta)[1:-1]
y = np.cos(theta)
z = np.sin(theta)
rho = 0.5 * np.tan(np.deg2rad(20))

def remove_proj(V, b):
    return V - (V.dot(b) * b) / np.linalg.norm(b)

def vec_angle(v1, v2):
    return np.arccos(v1.dot(v2) / np.linalg.norm(v1) / np.linalg.norm(v2))

def get_offset(tri1, tri2):
github hrpan / tetris_mcts / agents / helper.py View on Github external
import cppimport

cppimport.imp('agents.cppmodule.agent')
cppimport.imp('agents.cppmodule.core')
github tbenthompson / tectosaur / tectosaur / fmm_wrapper.py View on Github external
import numpy as np

import tectosaur.util.gpu as gpu
from tectosaur.util.timer import Timer

import cppimport
fmm = cppimport.imp("tectosaur.fmm.fmm").fmm.fmm
for k in dir(fmm):
    locals()[k] = getattr(fmm, k)

float_type = np.float32
def gpu_p2p_eval(fmm_mat, input_vals):
    f = gpu.load_gpu('fmm/p2p_kernel.cl', tmpl_args = dict()).p2p_kernel

    t = Timer()
    #TODO: Benchmark and check if its worth exposing the
    # buffer interface for these arrays to avoid copying the data
    gpu_obs_pts = gpu.to_gpu(np.array(fmm_mat.obs_tree.pts), float_type)
    gpu_obs_normals = gpu.to_gpu(np.array(fmm_mat.obs_tree.normals), float_type)
    gpu_src_pts = gpu.to_gpu(np.array(fmm_mat.src_tree.pts), float_type)
    gpu_src_normals = gpu.to_gpu(np.array(fmm_mat.src_tree.normals), float_type)

    gpu_obs_n_start = gpu.to_gpu(np.array(fmm_mat.p2p.obs_n_start), np.int32)