Skip to content

Commit 4a25e71

Browse files
dance858claude
andauthored
Bindings for Gaussian CDF atom (#6)
* bindings * bump version to 0.1.5 and update SparseDiffEngine submodule Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4383ba5 commit 4a25e71

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
44

55
[project]
66
name = "sparsediffpy"
7-
version = "0.1.4"
7+
version = "0.1.5"
88
description = "Python bindings for SparseDiffEngine automatic differentiation"
99
requires-python = ">=3.11"
1010
dependencies = ["numpy >= 2.0.0"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef ATOM_NORMAL_CDF_H
2+
#define ATOM_NORMAL_CDF_H
3+
4+
#include "common.h"
5+
6+
static PyObject *py_make_normal_cdf(PyObject *self, PyObject *args)
7+
{
8+
PyObject *child_capsule;
9+
if (!PyArg_ParseTuple(args, "O", &child_capsule))
10+
{
11+
return NULL;
12+
}
13+
expr *child = (expr *) PyCapsule_GetPointer(child_capsule, EXPR_CAPSULE_NAME);
14+
if (!child)
15+
{
16+
PyErr_SetString(PyExc_ValueError, "invalid child capsule");
17+
return NULL;
18+
}
19+
20+
expr *node = new_normal_cdf(child);
21+
if (!node)
22+
{
23+
PyErr_SetString(PyExc_RuntimeError, "failed to create normal_cdf node");
24+
return NULL;
25+
}
26+
expr_retain(node); /* Capsule owns a reference */
27+
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
28+
}
29+
30+
#endif /* ATOM_NORMAL_CDF_H */

sparsediffpy/_bindings/bindings.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "atoms/matmul.h"
2626
#include "atoms/multiply.h"
2727
#include "atoms/neg.h"
28+
#include "atoms/normal_cdf.h"
2829
#include "atoms/power.h"
2930
#include "atoms/prod.h"
3031
#include "atoms/prod_axis_one.h"
@@ -83,6 +84,7 @@ static PyMethodDef DNLPMethods[] = {
8384
"e2, ...], n_vars))"},
8485
{"make_sum", py_make_sum, METH_VARARGS, "Create sum node"},
8586
{"make_neg", py_make_neg, METH_VARARGS, "Create neg node"},
87+
{"make_normal_cdf", py_make_normal_cdf, METH_VARARGS, "Create normal_cdf node"},
8688
{"make_promote", py_make_promote, METH_VARARGS, "Create promote node"},
8789
{"make_multiply", py_make_multiply, METH_VARARGS,
8890
"Create elementwise multiply node"},

0 commit comments

Comments
 (0)