How to use the cppimport.cppimport 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 tbenthompson / tectosaur / tests / fmm / test_run_cpp_tests.py View on Github external
def test_run_cpp_tests():
    from cppimport import cppimport
    cppimport('test_main').run_tests()
github tbenthompson / tectosaur / tectosaur / viennacl / viennacl.py View on Github external
import numpy as np
import tectosaur.util.gpu as gpu

from cppimport import cppimport
wrapper = cppimport("tectosaur.viennacl.vienna_wrapper")

setup = wrapper.setup
check_platform = wrapper.check_platform

def prod(A, x, float_type):
    float_char = 'd' if float_type == np.float64 else 's'
    assert(x.shape[0] == A.shape[1])
    A_gpu = gpu.to_gpu(A, float_type)
    x_gpu = gpu.to_gpu(x, float_type)

    A_ip = A_gpu.data.int_ptr
    x_ip = x_gpu.data.int_ptr
    if len(x_gpu.shape) > 1:
        C_gpu = gpu.zeros_gpu((A.shape[0], x.shape[1]), float_type)
        C_ip = C_gpu.data.int_ptr
        fnc = getattr(wrapper, 'mat_mat_prod_' + float_char)
github tbenthompson / tectosaur / tectosaur / mesh / find_nearfield.py View on Github external
import numpy as np
import scipy.spatial
from tectosaur.util.timer import Timer

import tectosaur.util.profile

from cppimport import cppimport
fast_find_nearfield = cppimport('tectosaur.mesh.fast_find_nearfield')

def remove_adjacents(near_tris, edge_adj, vert_adj):
    for adj_list in [edge_adj, vert_adj]:
        for pair in adj_list:
            try:
                near_tris[pair[0]].remove(pair[1])
            except ValueError:
                pass
            try:
                near_tris[pair[1]].remove(pair[0])
            except ValueError:
                pass

@profile
def find_close_or_touching(pts, tris, threshold):
    tri_pts = pts[tris]
github tbenthompson / tectosaur / tectosaur / fmm / fmm_wrapper.py View on Github external
import os
import attr
import numpy as np

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

from tectosaur.kernels import kernels

import tectosaur.fmm
from tectosaur.fmm.c2e import c2e_solve, surrounding_surface

from cppimport import cppimport
fmm = cppimport("tectosaur.fmm.fmm")

logger = setup_logger(__name__)

# TODO: There's a ton of refactoring still to be done in here.

two = fmm.two
three = fmm.three
module = dict()
module[2] = two
module[3] = three

n_workers_per_block = 128
n_c2e_block_rows = 16

def get_gpu_module(surf, K, float_type):
    args = dict(
github tbenthompson / tectosaur / examples / interior_pt.py View on Github external
import numpy as np
from cppimport import cppimport
import matplotlib.pyplot as plt

n = 100
xs = np.linspace(0, 1, n)
X, Y = np.meshgrid(xs, xs)
X = X * 4 - 1.5
Y = Y * 4 - 2

out = np.empty((n,n))
for i in range(n):
    for j in range(n):
        adaptive_integrate = cppimport('adaptive_integrate')
        res = np.array(adaptive_integrate.integrate_interior(
            "T", [X[i,j],Y[i,j],0.2],[0,1,0],
            [[0,0,0],[1,0,0],[0,1,0]],
            1e-2, 1.0, 0.25
        )).reshape((3,3))
        out[i,j] = res.dot((1,0,0))[0]
# plt.imshow(np.log10(np.abs(out)), interpolation = 'none')
plt.imshow(out, interpolation = 'none')
plt.colorbar()
plt.show()
github tbenthompson / tectosaur / tectosaur / nearfield / standardize.py View on Github external
import numpy as np

# THE PLAN!
# Find longest edge
# relabel to put that longest edge as the 0-1 edge
# flip to put the 2 vertex closer to the 0 vertex than the 1 vertex
# translate 0 vertex to origin
# rotate 1 vertex to be at (A, 0, 0) and store rotation
# rotate 2 vertex to be at (B, C, 0) and store rotation
# scale triangle so that 1 vertex is at (1, 0, 0) and store scale factor
# check that triangle internal angles are greater than 20 degrees

from cppimport import cppimport
fast_lookup = cppimport("tectosaur.nearfield.fast_lookup")

class BadTriangleError(Exception):
    def __init__(self, code):
        super(BadTriangleError, self).__init__("Bad tri: %d" % code)
        self.code = code

def tolist_args(f):
    def wrapper(*args):
        new_args = []
        for a in args:
            new_args.append(a.tolist() if type(a) == np.ndarray else a)
        return f(*new_args)
    return wrapper

get_edge_lens = tolist_args(fast_lookup.get_edge_lens)
get_longest_edge = tolist_args(fast_lookup.get_longest_edge)