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
23 changes: 22 additions & 1 deletion include/affine.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ expr *new_reshape(expr *child, int d1, int d2);
expr *new_broadcast(expr *child, int target_d1, int target_d2);
expr *new_diag_vec(expr *child);
expr *new_transpose(expr *child);
expr *new_diag_vec(expr *child);

/* Left matrix multiplication: A @ f(x) where A is a constant sparse
* matrix */
expr *new_left_matmul(expr *u, const CSR_Matrix *A);

/* Left matrix multiplication: A @ f(x) where A is a constant dense
* matrix (row-major, m x n). Uses CBLAS for efficient computation. */
expr *new_left_matmul_dense(expr *u, int m, int n, const double *data);

/* Right matrix multiplication: f(x) @ A where A is a constant
* matrix */
expr *new_right_matmul(expr *u, const CSR_Matrix *A);

expr *new_right_matmul_dense(expr *u, int m, int n, const double *data);

/* Constant scalar multiplication: a * f(x) where a is a constant
* double */
expr *new_const_scalar_mult(double a, expr *child);

/* Constant vector elementwise multiplication: a . f(x) where a is
* constant */
expr *new_const_vector_mult(const double *a, expr *child);

#endif /* AFFINE_H */
35 changes: 6 additions & 29 deletions include/bivariate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,11 @@
#ifndef BIVARIATE_H
#define BIVARIATE_H

#include "expr.h"

expr *new_elementwise_mult(expr *left, expr *right);
expr *new_rel_entr_vector_args(expr *left, expr *right);
expr *new_quad_over_lin(expr *left, expr *right);

expr *new_rel_entr_first_arg_scalar(expr *left, expr *right);
expr *new_rel_entr_second_arg_scalar(expr *left, expr *right);

/* Matrix multiplication: Z = X @ Y */
expr *new_matmul(expr *x, expr *y);

/* Left matrix multiplication: A @ f(x) where A is a constant sparse matrix */
expr *new_left_matmul(expr *u, const CSR_Matrix *A);

/* Left matrix multiplication: A @ f(x) where A is a constant dense matrix
* (row-major, m x n). Uses CBLAS for efficient computation. */
expr *new_left_matmul_dense(expr *u, int m, int n, const double *data);

/* Right matrix multiplication: f(x) @ A where A is a constant matrix */
expr *new_right_matmul(expr *u, const CSR_Matrix *A);

expr *new_right_matmul_dense(expr *u, int m, int n, const double *data);

/* Constant scalar multiplication: a * f(x) where a is a constant double */
expr *new_const_scalar_mult(double a, expr *child);

/* Constant vector elementwise multiplication: a ∘ f(x) where a is constant */
expr *new_const_vector_mult(const double *a, expr *child);
/* Compatibility header — includes all bivariate-related declarations.
* Prefer including the specific header directly:
* affine.h, bivariate_full_dom.h, bivariate_restricted_dom.h */
#include "affine.h"
#include "bivariate_full_dom.h"
#include "bivariate_restricted_dom.h"

#endif /* BIVARIATE_H */
11 changes: 11 additions & 0 deletions include/bivariate_full_dom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BIVARIATE_FULL_DOM_H
#define BIVARIATE_FULL_DOM_H

#include "expr.h"

expr *new_elementwise_mult(expr *left, expr *right);

/* Matrix multiplication: Z = X @ Y */
expr *new_matmul(expr *x, expr *y);

#endif /* BIVARIATE_FULL_DOM_H */
11 changes: 11 additions & 0 deletions include/bivariate_restricted_dom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BIVARIATE_RESTRICTED_DOM_H
#define BIVARIATE_RESTRICTED_DOM_H

#include "expr.h"

expr *new_quad_over_lin(expr *left, expr *right);
expr *new_rel_entr_vector_args(expr *left, expr *right);
expr *new_rel_entr_first_arg_scalar(expr *left, expr *right);
expr *new_rel_entr_second_arg_scalar(expr *left, expr *right);

#endif /* BIVARIATE_RESTRICTED_DOM_H */
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "affine.h"
#include "subexpr.h"
#include <assert.h>
#include <stdio.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "affine.h"
#include "subexpr.h"
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion src/affine/diag_vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void forward(expr *node, const double *u)
/* child's forward pass */
x->forward(x, u);

/* zero-initialize output */
/* zero-initialize output, TODO: do we need to do this? */
memset(node->value, 0, node->size * sizeof(double));

/* place input elements on the diagonal */
Expand Down
2 changes: 1 addition & 1 deletion src/bivariate/left_matmul.c → src/affine/left_matmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "affine.h"
#include "subexpr.h"
#include "utils/matrix.h"
#include <assert.h>
Expand Down
2 changes: 1 addition & 1 deletion src/bivariate/right_matmul.c → src/affine/right_matmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/
#include "affine.h"
#include "bivariate.h"

#include "utils/CSR_Matrix.h"
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion src/bivariate/matmul.c → src/bivariate_full_dom/matmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "bivariate_full_dom.h"
#include "subexpr.h"
#include "utils/mini_numpy.h"
#include <assert.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "bivariate_full_dom.h"
#include "subexpr.h"
#include "utils/CSR_sum.h"
#include <assert.h>
Expand Down Expand Up @@ -76,6 +76,7 @@ static void wsum_hess_init(expr *node)
/* both x and y are variables*/
if (x->var_id != NOT_A_VARIABLE)
{
assert(y->var_id != NOT_A_VARIABLE);
node->wsum_hess = new_csr_matrix(node->n_vars, node->n_vars, 2 * node->size);

int i, var1_id, var2_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "bivariate_restricted_dom.h"
#include "subexpr.h"
#include "utils/CSC_Matrix.h"
#include <assert.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "bivariate_restricted_dom.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "bivariate_restricted_dom.h"
#include <assert.h>
#include <math.h>
#include <stdlib.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bivariate.h"
#include "bivariate_restricted_dom.h"
#include <assert.h>
#include <math.h>
#include <stdlib.h>
Expand Down
126 changes: 63 additions & 63 deletions tests/all_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,46 @@
#include "forward_pass/affine/test_add.h"
#include "forward_pass/affine/test_broadcast.h"
#include "forward_pass/affine/test_hstack.h"
#include "forward_pass/affine/test_left_matmul_dense.h"
#include "forward_pass/affine/test_linear_op.h"
#include "forward_pass/affine/test_neg.h"
#include "forward_pass/affine/test_promote.h"
#include "forward_pass/affine/test_sum.h"
#include "forward_pass/affine/test_variable_constant.h"
#include "forward_pass/affine/test_vstack.h"
#include "forward_pass/bivariate_full_dom/test_matmul.h"
#include "forward_pass/composite/test_composite.h"
#include "forward_pass/elementwise/test_exp.h"
#include "forward_pass/elementwise/test_log.h"
#include "forward_pass/elementwise/test_normal_cdf.h"
#include "forward_pass/test_left_matmul_dense.h"
#include "forward_pass/test_matmul.h"
#include "forward_pass/test_prod_axis_one.h"
#include "forward_pass/test_prod_axis_zero.h"
#include "jacobian_tests/test_broadcast.h"
#include "jacobian_tests/test_chain_rule_jacobian.h"
#include "jacobian_tests/test_composite_exp.h"
#include "jacobian_tests/test_const_scalar_mult.h"
#include "jacobian_tests/test_const_vector_mult.h"
#include "jacobian_tests/test_elementwise_mult.h"
#include "jacobian_tests/test_hstack.h"
#include "jacobian_tests/test_index.h"
#include "jacobian_tests/test_left_matmul.h"
#include "jacobian_tests/test_log.h"
#include "jacobian_tests/test_matmul.h"
#include "jacobian_tests/test_neg.h"
#include "jacobian_tests/test_prod.h"
#include "jacobian_tests/test_prod_axis_one.h"
#include "jacobian_tests/test_prod_axis_zero.h"
#include "jacobian_tests/test_promote.h"
#include "jacobian_tests/test_quad_form.h"
#include "jacobian_tests/test_quad_over_lin.h"
#include "jacobian_tests/test_rel_entr.h"
#include "jacobian_tests/test_rel_entr_scalar_vector.h"
#include "jacobian_tests/test_rel_entr_vector_scalar.h"
#include "jacobian_tests/test_right_matmul.h"
#include "jacobian_tests/test_sum.h"
#include "jacobian_tests/test_trace.h"
#include "jacobian_tests/test_transpose.h"
#include "jacobian_tests/test_vstack.h"
#include "forward_pass/elementwise_full_dom/test_exp.h"
#include "forward_pass/elementwise_full_dom/test_normal_cdf.h"
#include "forward_pass/elementwise_restricted_dom/test_log.h"
#include "forward_pass/other/test_prod_axis_one.h"
#include "forward_pass/other/test_prod_axis_zero.h"
#include "jacobian_tests/affine/test_broadcast.h"
#include "jacobian_tests/affine/test_const_scalar_mult.h"
#include "jacobian_tests/affine/test_const_vector_mult.h"
#include "jacobian_tests/affine/test_hstack.h"
#include "jacobian_tests/affine/test_index.h"
#include "jacobian_tests/affine/test_left_matmul.h"
#include "jacobian_tests/affine/test_neg.h"
#include "jacobian_tests/affine/test_promote.h"
#include "jacobian_tests/affine/test_right_matmul.h"
#include "jacobian_tests/affine/test_sum.h"
#include "jacobian_tests/affine/test_trace.h"
#include "jacobian_tests/affine/test_transpose.h"
#include "jacobian_tests/affine/test_vstack.h"
#include "jacobian_tests/bivariate_full_dom/test_elementwise_mult.h"
#include "jacobian_tests/bivariate_full_dom/test_matmul.h"
#include "jacobian_tests/bivariate_restricted_dom/test_quad_over_lin.h"
#include "jacobian_tests/bivariate_restricted_dom/test_rel_entr.h"
#include "jacobian_tests/bivariate_restricted_dom/test_rel_entr_scalar_vector.h"
#include "jacobian_tests/bivariate_restricted_dom/test_rel_entr_vector_scalar.h"
#include "jacobian_tests/composite/test_chain_rule_jacobian.h"
#include "jacobian_tests/composite/test_composite_exp.h"
#include "jacobian_tests/elementwise_restricted_dom/test_log.h"
#include "jacobian_tests/other/test_prod.h"
#include "jacobian_tests/other/test_prod_axis_one.h"
#include "jacobian_tests/other/test_prod_axis_zero.h"
#include "jacobian_tests/other/test_quad_form.h"
#include "numerical_diff/test_numerical_diff.h"
#include "problem/test_problem.h"
#include "utils/test_cblas.h"
Expand All @@ -56,36 +56,36 @@
#include "utils/test_csr_matrix.h"
#include "utils/test_linalg_sparse_matmuls.h"
#include "utils/test_matrix.h"
#include "wsum_hess/elementwise/test_entr.h"
#include "wsum_hess/elementwise/test_exp.h"
#include "wsum_hess/elementwise/test_hyperbolic.h"
#include "wsum_hess/elementwise/test_log.h"
#include "wsum_hess/elementwise/test_logistic.h"
#include "wsum_hess/elementwise/test_power.h"
#include "wsum_hess/elementwise/test_trig.h"
#include "wsum_hess/elementwise/test_xexp.h"
#include "wsum_hess/test_broadcast.h"
#include "wsum_hess/test_chain_rule_wsum_hess.h"
#include "wsum_hess/test_const_scalar_mult.h"
#include "wsum_hess/test_const_vector_mult.h"
#include "wsum_hess/test_hstack.h"
#include "wsum_hess/test_index.h"
#include "wsum_hess/test_left_matmul.h"
#include "wsum_hess/test_matmul.h"
#include "wsum_hess/test_multiply.h"
#include "wsum_hess/test_prod.h"
#include "wsum_hess/test_prod_axis_one.h"
#include "wsum_hess/test_prod_axis_zero.h"
#include "wsum_hess/test_quad_form.h"
#include "wsum_hess/test_quad_over_lin.h"
#include "wsum_hess/test_rel_entr.h"
#include "wsum_hess/test_rel_entr_scalar_vector.h"
#include "wsum_hess/test_rel_entr_vector_scalar.h"
#include "wsum_hess/test_right_matmul.h"
#include "wsum_hess/test_sum.h"
#include "wsum_hess/test_trace.h"
#include "wsum_hess/test_transpose.h"
#include "wsum_hess/test_vstack.h"
#include "wsum_hess/affine/test_broadcast.h"
#include "wsum_hess/affine/test_const_scalar_mult.h"
#include "wsum_hess/affine/test_const_vector_mult.h"
#include "wsum_hess/affine/test_hstack.h"
#include "wsum_hess/affine/test_index.h"
#include "wsum_hess/affine/test_left_matmul.h"
#include "wsum_hess/affine/test_right_matmul.h"
#include "wsum_hess/affine/test_sum.h"
#include "wsum_hess/affine/test_trace.h"
#include "wsum_hess/affine/test_transpose.h"
#include "wsum_hess/affine/test_vstack.h"
#include "wsum_hess/bivariate_full_dom/test_matmul.h"
#include "wsum_hess/bivariate_full_dom/test_multiply.h"
#include "wsum_hess/bivariate_restricted_dom/test_quad_over_lin.h"
#include "wsum_hess/bivariate_restricted_dom/test_rel_entr.h"
#include "wsum_hess/bivariate_restricted_dom/test_rel_entr_scalar_vector.h"
#include "wsum_hess/bivariate_restricted_dom/test_rel_entr_vector_scalar.h"
#include "wsum_hess/composite/test_chain_rule_wsum_hess.h"
#include "wsum_hess/elementwise_full_dom/test_exp.h"
#include "wsum_hess/elementwise_full_dom/test_hyperbolic.h"
#include "wsum_hess/elementwise_full_dom/test_logistic.h"
#include "wsum_hess/elementwise_full_dom/test_power.h"
#include "wsum_hess/elementwise_full_dom/test_trig.h"
#include "wsum_hess/elementwise_full_dom/test_xexp.h"
#include "wsum_hess/elementwise_restricted_dom/test_entr.h"
#include "wsum_hess/elementwise_restricted_dom/test_log.h"
#include "wsum_hess/other/test_prod.h"
#include "wsum_hess/other/test_prod_axis_one.h"
#include "wsum_hess/other/test_prod_axis_zero.h"
#include "wsum_hess/other/test_quad_form.h"
#endif /* PROFILE_ONLY */

#ifdef PROFILE_ONLY
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>

#include "bivariate.h"
#include "affine.h"
#include "expr.h"
#include "minunit.h"
#include "test_helpers.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdio.h>
#include <stdlib.h>

#include "bivariate.h"
#include "bivariate_full_dom.h"
#include "expr.h"
#include "minunit.h"
#include "test_helpers.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>

#include "bivariate.h"
#include "affine.h"
#include "elementwise_full_dom.h"
#include "elementwise_restricted_dom.h"
#include "expr.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>

#include "bivariate.h"
#include "affine.h"
#include "elementwise_full_dom.h"
#include "elementwise_restricted_dom.h"
#include "expr.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <math.h>
#include <stdio.h>

#include "bivariate.h"
#include "affine.h"
#include "elementwise_full_dom.h"
#include "elementwise_restricted_dom.h"
#include "expr.h"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <stdio.h>

#include "affine.h"
#include "bivariate.h"
#include "elementwise_full_dom.h"
#include "elementwise_restricted_dom.h"
#include "expr.h"
Expand Down
Loading
Loading