@@ -23,45 +23,21 @@ static void free_type_data(expr *node)
2323 free_csc_matrix (lin_node -> A_csc );
2424}
2525
26- /* Helper function to initialize a linear operator expr */
27- void init_linear_op (expr * node , expr * child , int d1 , int d2 )
28- {
29- node -> d1 = d1 ;
30- node -> d2 = d2 ;
31- node -> size = d1 * d2 ;
32- node -> n_vars = child -> n_vars ;
33- node -> var_id = -1 ;
34- node -> refcount = 1 ;
35- node -> left = child ;
36- node -> right = NULL ;
37- node -> dwork = NULL ;
38- node -> iwork = NULL ;
39- node -> value = (double * ) calloc (node -> size , sizeof (double ));
40- node -> jacobian = NULL ;
41- node -> wsum_hess = NULL ;
42- node -> jacobian_init = NULL ;
43- node -> wsum_hess_init = NULL ;
44- node -> eval_jacobian = NULL ;
45- node -> eval_wsum_hess = NULL ;
46- node -> local_jacobian = NULL ;
47- node -> local_wsum_hess = NULL ;
48- node -> forward = forward ;
49- node -> is_affine = is_affine ;
50- node -> free_type_data = free_type_data ;
51-
52- expr_retain (child );
53- }
54-
5526expr * new_linear (expr * u , const CSR_Matrix * A )
5627{
5728 /* Allocate the type-specific struct */
58- linear_op_expr * lin_node = (linear_op_expr * ) malloc ( sizeof (linear_op_expr ));
29+ linear_op_expr * lin_node = (linear_op_expr * ) calloc ( 1 , sizeof (linear_op_expr ));
5930 if (!lin_node ) return NULL ;
6031
6132 expr * node = & lin_node -> base ;
6233
63- /* Initialize base linear operator fields */
64- init_linear_op (node , u , A -> m , 1 );
34+ /* Initialize base fields */
35+ init_expr (node , A -> m , 1 , u -> n_vars , forward , NULL , NULL , is_affine ,
36+ free_type_data );
37+
38+ /* Set left child */
39+ node -> left = u ;
40+ expr_retain (u );
6541
6642 /* Check if allocation succeeded */
6743 if (!node -> value )
0 commit comments