Skip to content

Commit bf85b00

Browse files
committed
clean up
1 parent 9af0607 commit bf85b00

27 files changed

Lines changed: 63 additions & 159 deletions

include/expr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ typedef struct expr
6161

6262
void init_expr(expr *node, int d1, int d2, int n_vars, forward_fn forward,
6363
jacobian_init_fn jacobian_init, eval_jacobian_fn eval_jacobian,
64-
is_affine_fn is_affine, free_type_data_fn free_type_data);
64+
is_affine_fn is_affine, wsum_hess_init_fn wsum_hess_init,
65+
wsum_hess_fn eval_wsum_hess, free_type_data_fn free_type_data);
6566

66-
expr *new_expr(int d1, int d2, int n_vars);
6767
void free_expr(expr *node);
6868

6969
/* Reference counting helpers */

src/affine/add.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "affine.h"
22
#include <assert.h>
33
#include <stdio.h>
4+
#include <stdlib.h>
45

56
static void forward(expr *node, const double *u)
67
{
@@ -75,17 +76,13 @@ static bool is_affine(const expr *node)
7576
expr *new_add(expr *left, expr *right)
7677
{
7778
assert(left->d1 == right->d1 && left->d2 == right->d2);
78-
expr *node = new_expr(left->d1, left->d2, left->n_vars);
79+
expr *node = (expr *) calloc(1, sizeof(expr));
80+
init_expr(node, left->d1, left->d2, left->n_vars, forward, jacobian_init,
81+
eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, NULL);
7982
node->left = left;
8083
node->right = right;
8184
expr_retain(left);
8285
expr_retain(right);
83-
node->forward = forward;
84-
node->is_affine = is_affine;
85-
node->jacobian_init = jacobian_init;
86-
node->eval_jacobian = eval_jacobian;
87-
node->wsum_hess_init = wsum_hess_init;
88-
node->eval_wsum_hess = eval_wsum_hess;
8986

9087
// just for debugging, should be removed
9188
strcpy(node->name, "add");

src/affine/broadcast.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,9 @@ expr *new_broadcast(expr *child, int d1, int d2)
264264
// initialize the rest of the expression
265265
// --------------------------------------------------------------------------
266266
init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian,
267-
is_affine, NULL);
267+
is_affine, wsum_hess_init, eval_wsum_hess, NULL);
268268
node->left = child;
269269
expr_retain(child);
270-
node->wsum_hess_init = wsum_hess_init;
271-
node->eval_wsum_hess = eval_wsum_hess;
272270
bcast->type = type;
273271

274272
return node;

src/affine/constant.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "affine.h"
2+
#include <stdlib.h>
23
#include <string.h>
34

45
static void forward(expr *node, const double *u)
@@ -42,14 +43,10 @@ static bool is_affine(const expr *node)
4243

4344
expr *new_constant(int d1, int d2, int n_vars, const double *values)
4445
{
45-
expr *node = new_expr(d1, d2, n_vars);
46+
expr *node = (expr *) calloc(1, sizeof(expr));
47+
init_expr(node, d1, d2, n_vars, forward, jacobian_init, eval_jacobian, is_affine,
48+
wsum_hess_init, eval_wsum_hess, NULL);
4649
memcpy(node->value, values, node->size * sizeof(double));
47-
node->forward = forward;
48-
node->is_affine = is_affine;
49-
node->jacobian_init = jacobian_init;
50-
node->eval_jacobian = eval_jacobian;
51-
node->wsum_hess_init = wsum_hess_init;
52-
node->eval_wsum_hess = eval_wsum_hess;
5350

5451
return node;
5552
}

src/affine/hstack.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,11 @@ expr *new_hstack(expr **args, int n_args, int n_vars)
154154
hstack_expr *hnode = (hstack_expr *) calloc(1, sizeof(hstack_expr));
155155
expr *node = &hnode->base;
156156
init_expr(node, args[0]->d1, d2, n_vars, forward, jacobian_init, eval_jacobian,
157-
is_affine, free_type_data);
157+
is_affine, wsum_hess_init, wsum_hess_eval, free_type_data);
158158

159159
/* Set type-specific fields */
160160
hnode->args = args;
161161
hnode->n_args = n_args;
162-
node->wsum_hess_init = wsum_hess_init;
163-
node->eval_wsum_hess = wsum_hess_eval;
164162

165163
for (int i = 0; i < n_args; i++)
166164
{

src/affine/index.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,11 @@ expr *new_index(expr *child, int d1, int d2, const int *indices, int n_idxs)
152152
expr *node = &idx->base;
153153

154154
init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian,
155-
is_affine, free_type_data);
155+
is_affine, wsum_hess_init, eval_wsum_hess, free_type_data);
156156

157157
node->left = child;
158158
expr_retain(child);
159159

160-
node->wsum_hess_init = wsum_hess_init;
161-
node->eval_wsum_hess = eval_wsum_hess;
162-
163160
/* copy indices */
164161
idx->indices = (int *) malloc(n_idxs * sizeof(int));
165162
memcpy(idx->indices, indices, n_idxs * sizeof(int));

src/affine/linear_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ expr *new_linear(expr *u, const CSR_Matrix *A)
4646
linear_op_expr *lin_node = (linear_op_expr *) calloc(1, sizeof(linear_op_expr));
4747
expr *node = &lin_node->base;
4848
init_expr(node, A->m, 1, u->n_vars, forward, jacobian_init, NULL, is_affine,
49-
free_type_data);
49+
NULL, NULL, free_type_data);
5050
node->left = u;
5151
expr_retain(u);
5252

src/affine/neg.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "affine.h"
22
#include <stdio.h>
3+
#include <stdlib.h>
34
#include <string.h>
45

56
static void forward(expr *node, const double *u)
@@ -77,15 +78,11 @@ static bool is_affine(const expr *node)
7778

7879
expr *new_neg(expr *child)
7980
{
80-
expr *node = new_expr(child->d1, child->d2, child->n_vars);
81+
expr *node = (expr *) calloc(1, sizeof(expr));
82+
init_expr(node, child->d1, child->d2, child->n_vars, forward, jacobian_init,
83+
eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, NULL);
8184
node->left = child;
8285
expr_retain(child);
83-
node->forward = forward;
84-
node->is_affine = is_affine;
85-
node->jacobian_init = jacobian_init;
86-
node->eval_jacobian = eval_jacobian;
87-
node->wsum_hess_init = wsum_hess_init;
88-
node->eval_wsum_hess = eval_wsum_hess;
8986

9087
return node;
9188
}

src/affine/promote.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,9 @@ static bool is_affine(const expr *node)
9494
expr *new_promote(expr *child, int d1, int d2)
9595
{
9696
assert(child->size == 1);
97-
expr *node = new_expr(d1, d2, child->n_vars);
98-
node->forward = forward;
99-
node->jacobian_init = jacobian_init;
100-
node->eval_jacobian = eval_jacobian;
101-
node->is_affine = is_affine;
102-
node->wsum_hess_init = wsum_hess_init;
103-
node->eval_wsum_hess = eval_wsum_hess;
104-
97+
expr *node = (expr *) calloc(1, sizeof(expr));
98+
init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian,
99+
is_affine, wsum_hess_init, eval_wsum_hess, NULL);
105100
node->left = child;
106101
expr_retain(child);
107102

src/affine/reshape.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "affine.h"
22
#include <assert.h>
33
#include <stdio.h>
4+
#include <stdlib.h>
45
#include <string.h>
56

67
/* Reshape changes the shape of an expression without permuting data.
@@ -55,15 +56,11 @@ static bool is_affine(const expr *node)
5556
expr *new_reshape(expr *child, int d1, int d2)
5657
{
5758
assert(d1 * d2 == child->size);
58-
expr *node = new_expr(d1, d2, child->n_vars);
59+
expr *node = (expr *) calloc(1, sizeof(expr));
60+
init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian,
61+
is_affine, wsum_hess_init, eval_wsum_hess, NULL);
5962
node->left = child;
6063
expr_retain(child);
61-
node->forward = forward;
62-
node->is_affine = is_affine;
63-
node->jacobian_init = jacobian_init;
64-
node->eval_jacobian = eval_jacobian;
65-
node->wsum_hess_init = wsum_hess_init;
66-
node->eval_wsum_hess = eval_wsum_hess;
6764

6865
return node;
6966
}

0 commit comments

Comments
 (0)