@@ -145,35 +145,6 @@ static void free_type_data(expr *node)
145145 free_int_double_pair_array (snode -> int_double_pairs );
146146}
147147
148- /* Helper function to initialize a sum expr */
149- void init_sum (expr * node , expr * child , int d1 )
150- {
151- node -> d1 = d1 ;
152- node -> d2 = 1 ;
153- node -> size = d1 * 1 ;
154- node -> n_vars = child -> n_vars ;
155- node -> var_id = -1 ;
156- node -> refcount = 1 ;
157- node -> left = child ;
158- node -> right = NULL ;
159- node -> dwork = NULL ;
160- node -> iwork = NULL ;
161- node -> value = (double * ) calloc (node -> size , sizeof (double ));
162- node -> jacobian = NULL ;
163- node -> wsum_hess = NULL ;
164- node -> jacobian_init = jacobian_init ;
165- node -> wsum_hess_init = wsum_hess_init ;
166- node -> eval_jacobian = eval_jacobian ;
167- node -> eval_wsum_hess = eval_wsum_hess ;
168- node -> local_jacobian = NULL ;
169- node -> local_wsum_hess = NULL ;
170- node -> is_affine = is_affine ;
171- node -> forward = forward ;
172- node -> free_type_data = free_type_data ;
173-
174- expr_retain (child );
175- }
176-
177148expr * new_sum (expr * child , int axis )
178149{
179150 int d1 = 0 ;
@@ -195,20 +166,16 @@ expr *new_sum(expr *child, int axis)
195166 }
196167
197168 /* Allocate the type-specific struct */
198- sum_expr * snode = (sum_expr * ) malloc (sizeof (sum_expr ));
199- if (!snode ) return NULL ;
200-
169+ sum_expr * snode = (sum_expr * ) calloc (1 , sizeof (sum_expr ));
201170 expr * node = & snode -> base ;
171+ init_expr (node , d1 , 1 , child -> n_vars , forward , jacobian_init , eval_jacobian ,
172+ is_affine , free_type_data );
173+ node -> left = child ;
174+ expr_retain (child );
202175
203- /* Initialize base sum fields */
204- init_sum (node , child , d1 );
205-
206- /* Check if allocation succeeded */
207- if (!node -> value )
208- {
209- free (snode );
210- return NULL ;
211- }
176+ /* hessian function pointers */
177+ node -> wsum_hess_init = wsum_hess_init ;
178+ node -> eval_wsum_hess = eval_wsum_hess ;
212179
213180 /* Set type-specific fields */
214181 snode -> axis = axis ;
0 commit comments