Skip to content

Commit 43f51b8

Browse files
committed
started refactoring polymorphism
1 parent 105d2ee commit 43f51b8

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/elementwise_univariate/common.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,26 @@ bool is_affine_elementwise(expr *node)
9696
}
9797

9898
/* Helper function to initialize an already-allocated expr for elementwise operations
99+
* This is called when a power_expr or other type-specific struct is allocated
100+
* and we need to initialize the base expr fields
99101
*/
100102
void init_elementwise(expr *node, expr *child)
101103
{
104+
/* Initialize dimensions from child */
102105
node->d1 = child->d1;
103106
node->d2 = child->d2;
104107
node->size = child->d1 * child->d2;
105108
node->n_vars = child->n_vars;
106109
node->var_id = -1;
107110
node->refcount = 1;
111+
112+
/* Allocate the value array */
113+
node->value = (double *) calloc(node->size, sizeof(double));
114+
108115
node->left = child;
109116
node->right = NULL;
110117
node->dwork = NULL;
111118
node->iwork = NULL;
112-
node->value = (double *) calloc(node->size, sizeof(double));
113119
node->jacobian = NULL;
114120
node->wsum_hess = NULL;
115121
node->CSR_work = NULL;
@@ -128,7 +134,7 @@ void init_elementwise(expr *node, expr *child)
128134

129135
expr *new_elementwise(expr *child)
130136
{
131-
expr *node = new_expr(child->d1, child->d2, child->n_vars);
137+
expr *node = (expr *) malloc(sizeof(expr));
132138
if (!node) return NULL;
133139

134140
init_elementwise(node, child);

0 commit comments

Comments
 (0)