Skip to main content

Easily build C code into dll and call it from python script

Project description

C2DLL

Easily build C code into dll and call it from python script

Here is the example of usage:

from c2dll import dllfunc, as_ptr
import numpy as np

def fwd(eps, n, x=[0.1711, 0.1117]):
    d = dllfunc('''
        #define PI2 6.283185307179586
        #include <math.h>

        double mod1(double x) {double x_mod_1 = fmod(x, 1); x_mod_1 = (x_mod_1 < 0) ? x_mod_1 + 1 : x_mod_1; return x_mod_1;}
                
        DLL_API void fwd(double* params, double* x, int n, double* out) {
            double eps_square = params[0]*params[0]; 
            for (int i=0; i<n; i++) { 
                double x_ = atan2((1 - eps_square) * sin(PI2 * x[0]), (1 + eps_square) * cos(PI2 * x[0]) + 2*params[0]) / PI2;
                x[0] = 2 * x_ + x[1];
                x[1] = x_ + x[1];
                x[0] = atan2((1 - eps_square) * sin(PI2 * x[0]), (1 + eps_square) * cos(PI2 * x[0]) + 2*params[0]) / PI2;
                x[0] = mod1(x[0]);
                x[1] = mod1(x[1]);
                out[2*i] = x[0];
                out[2*i+1] = x[1];
            }
        }''')
    n = int(n)
    points = np.zeros(shape=(2*n))
    d.fwd(as_ptr([eps,]), as_ptr(x), n, as_ptr(points))
    return points.reshape((n, 2))

GitHub: https://github.com/chiga17/c2dll

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c2dll-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

c2dll-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file c2dll-0.1.0.tar.gz.

File metadata

  • Download URL: c2dll-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.0

File hashes

Hashes for c2dll-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4c31f487e47a975afc70c2b09858113543ababe1f6f3568d1847e41025e5f086
MD5 83b86875d0388d85dd4d0277bbb7eea5
BLAKE2b-256 e7dccf7c6f7eb8fa6fe42b12f9796445bedf4c87c65ea0e2c539834bf2e66668

See more details on using hashes here.

File details

Details for the file c2dll-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: c2dll-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.0

File hashes

Hashes for c2dll-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a76dbbe9de46eb98cee6d98bd9fd3a6437c44a6fc79b2355d662ac018e08fc7b
MD5 5f63da69e3d847e0db4881232a178c5d
BLAKE2b-256 04a01db1bc7f1b7b2fd1c201c9c5fdc415f946154422dc876204e6ef2b9c2570

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page