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 TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
4. in the refactor, add consts
10. For performance reasons, is it useful to have a dense matmul with A and B as dense matrices?
11. right matmul, add broadcasting logic as in left matmul
11. right matmul, add broadcasting logic as in left matmul. Is this necessary?

Going through all atoms to see that sparsity pattern is computed in initialization of jacobian:
2. trace - not ok
Expand Down
3 changes: 3 additions & 0 deletions include/other.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ expr *new_quad_form(expr *child, CSR_Matrix *Q);
/* product of all entries, without axis argument */
expr *new_prod(expr *child);

/* product of entries along axis=0 (columnwise products) */
expr *new_prod_axis_zero(expr *child);

#endif /* OTHER_H */
9 changes: 9 additions & 0 deletions include/subexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ typedef struct prod_expr
double prod_nonzero; /* product of non-zero elements */
} prod_expr;

/* Product of entries along axis=0 (columnwise products) */
typedef struct prod_axis_zero_expr
{
expr base;
int *num_of_zeros; /* num of zeros for each column */
int *zero_index; /* stores idx of zero element per column */
double *prod_nonzero; /* product of non-zero elements per column */
} prod_axis_zero_expr;

/* Horizontal stack (concatenate) */
typedef struct hstack_expr
{
Expand Down
33 changes: 33 additions & 0 deletions python/atoms/prod_axis_zero.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef ATOM_PROD_AXIS_ZERO_H
#define ATOM_PROD_AXIS_ZERO_H

#include "common.h"
#include "other.h"

static PyObject *py_make_prod_axis_zero(PyObject *self, PyObject *args)
{
(void) self;
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_prod_axis_zero(child);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create prod_axis_zero node");
return NULL;
}
expr_retain(node); /* Capsule owns a reference */
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}

#endif /* ATOM_PROD_AXIS_ZERO_H */
3 changes: 3 additions & 0 deletions python/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "atoms/neg.h"
#include "atoms/power.h"
#include "atoms/prod.h"
#include "atoms/prod_axis_zero.h"
#include "atoms/promote.h"
#include "atoms/quad_form.h"
#include "atoms/quad_over_lin.h"
Expand Down Expand Up @@ -77,6 +78,8 @@ static PyMethodDef DNLPMethods[] = {
"Create constant vector multiplication node (a ∘ f(x))"},
{"make_power", py_make_power, METH_VARARGS, "Create power node"},
{"make_prod", py_make_prod, METH_VARARGS, "Create prod node"},
{"make_prod_axis_zero", py_make_prod_axis_zero, METH_VARARGS,
"Create prod_axis_zero node"},
{"make_sin", py_make_sin, METH_VARARGS, "Create sin node"},
{"make_cos", py_make_cos, METH_VARARGS, "Create cos node"},
{"make_tan", py_make_tan, METH_VARARGS, "Create tan node"},
Expand Down
Loading
Loading