Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ build-dir = "build/{wheel_tag}"
CMAKE_BUILD_TYPE = "Release"

[tool.pytest.ini_options]
testpaths = ["tests/python"]
testpaths = ["python/tests"]
python_files = ["test_*.py"]
python_functions = ["test_*"]

Expand Down
57 changes: 0 additions & 57 deletions python/CMakeLists.txt

This file was deleted.

31 changes: 31 additions & 0 deletions python/atoms/asinh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef ATOM_ASINH_H
#define ATOM_ASINH_H

#include "common.h"
#include "elementwise_univariate.h"

static PyObject *py_make_asinh(PyObject *self, PyObject *args)
{
PyObject *child_capsule;
if (!PyArg_ParseTuple(args, "O", &child_capsule))
{
return NULL;
}
expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
if (!child)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

expr *node = new_asinh(child);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create asinh node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_ASINH_H */
31 changes: 31 additions & 0 deletions python/atoms/atanh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef ATOM_ATANH_H
#define ATOM_ATANH_H

#include "common.h"
#include "elementwise_univariate.h"

static PyObject *py_make_atanh(PyObject *self, PyObject *args)
{
PyObject *child_capsule;
if (!PyArg_ParseTuple(args, "O", &child_capsule))
{
return NULL;
}
expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
if (!child)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

expr *node = new_atanh(child);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create atanh node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_ATANH_H */
31 changes: 31 additions & 0 deletions python/atoms/cos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef ATOM_COS_H
#define ATOM_COS_H

#include "common.h"
#include "elementwise_univariate.h"

static PyObject *py_make_cos(PyObject *self, PyObject *args)
{
PyObject *child_capsule;
if (!PyArg_ParseTuple(args, "O", &child_capsule))
{
return NULL;
}
expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
if (!child)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

expr *node = new_cos(child);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create cos node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_COS_H */
31 changes: 31 additions & 0 deletions python/atoms/entr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef ATOM_ENTR_H
#define ATOM_ENTR_H

#include "common.h"
#include "elementwise_univariate.h"

static PyObject *py_make_entr(PyObject *self, PyObject *args)
{
PyObject *child_capsule;
if (!PyArg_ParseTuple(args, "O", &child_capsule))
{
return NULL;
}
expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
if (!child)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

expr *node = new_entr(child);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create entr node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_ENTR_H */
63 changes: 63 additions & 0 deletions python/atoms/left_matmul.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef ATOM_LEFT_MATMUL_H
#define ATOM_LEFT_MATMUL_H

#include "common.h"
#include "bivariate.h"

/* Left matrix multiplication: A @ f(x) where A is a constant matrix */
static PyObject *py_make_left_matmul(PyObject *self, PyObject *args)
{
PyObject *child_capsule;
PyObject *data_obj, *indices_obj, *indptr_obj;
int m, n;
if (!PyArg_ParseTuple(args, "OOOOii", &child_capsule, &data_obj, &indices_obj,
&indptr_obj, &m, &n))
{
return NULL;
}

expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
if (!child)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

PyArrayObject *data_array =
(PyArrayObject *) PyArray_FROM_OTF(data_obj, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
PyArrayObject *indices_array = (PyArrayObject *) PyArray_FROM_OTF(
indices_obj, NPY_INT32, NPY_ARRAY_IN_ARRAY);
PyArrayObject *indptr_array = (PyArrayObject *) PyArray_FROM_OTF(
indptr_obj, NPY_INT32, NPY_ARRAY_IN_ARRAY);

if (!data_array || !indices_array || !indptr_array)
{
Py_XDECREF(data_array);
Py_XDECREF(indices_array);
Py_XDECREF(indptr_array);
return NULL;
}

int nnz = (int) PyArray_SIZE(data_array);
CSR_Matrix *A = new_csr_matrix(m, n, nnz);
memcpy(A->x, PyArray_DATA(data_array), nnz * sizeof(double));
memcpy(A->i, PyArray_DATA(indices_array), nnz * sizeof(int));
memcpy(A->p, PyArray_DATA(indptr_array), (m + 1) * sizeof(int));

Py_DECREF(data_array);
Py_DECREF(indices_array);
Py_DECREF(indptr_array);

expr *node = new_left_matmul(child, A);
free_csr_matrix(A);

if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create left_matmul node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_LEFT_MATMUL_H */
31 changes: 31 additions & 0 deletions python/atoms/logistic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef ATOM_LOGISTIC_H
#define ATOM_LOGISTIC_H

#include "common.h"
#include "elementwise_univariate.h"

static PyObject *py_make_logistic(PyObject *self, PyObject *args)
{
PyObject *child_capsule;
if (!PyArg_ParseTuple(args, "O", &child_capsule))
{
return NULL;
}
expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
if (!child)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

expr *node = new_logistic(child);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create logistic node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_LOGISTIC_H */
32 changes: 32 additions & 0 deletions python/atoms/multiply.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef ATOM_MULTIPLY_H
#define ATOM_MULTIPLY_H

#include "common.h"
#include "bivariate.h"

static PyObject *py_make_multiply(PyObject *self, PyObject *args)
{
PyObject *left_capsule, *right_capsule;
if (!PyArg_ParseTuple(args, "OO", &left_capsule, &right_capsule))
{
return NULL;
}
expr *left = (expr *) PyCapsule_GetPointer(left_capsule, EXPR_CAPSULE_NAME);
expr *right = (expr *) PyCapsule_GetPointer(right_capsule, EXPR_CAPSULE_NAME);
if (!left || !right)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

expr *node = new_elementwise_mult(left, right);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create multiply node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_MULTIPLY_H */
32 changes: 32 additions & 0 deletions python/atoms/power.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef ATOM_POWER_H
#define ATOM_POWER_H

#include "common.h"
#include "elementwise_univariate.h"

static PyObject *py_make_power(PyObject *self, PyObject *args)
{
PyObject *child_capsule;
double p;
if (!PyArg_ParseTuple(args, "Od", &child_capsule, &p))
{
return NULL;
}
expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
if (!child)
{
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
return NULL;
}

expr *node = new_power(child, p);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create power node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_POWER_H */
Loading
Loading