@@ -71,8 +71,6 @@ static void jacobian_init(expr *node)
7171
7272 /* we never have to store more than the child's nnz */
7373 node -> jacobian = new_csr_matrix (node -> d1 , node -> n_vars , x -> jacobian -> nnz );
74- snode -> int_double_pairs = new_int_double_pair_array (x -> jacobian -> nnz );
75-
7674 node -> iwork = malloc (MAX (node -> jacobian -> n , x -> jacobian -> nnz ) * sizeof (int ));
7775 snode -> idx_map = malloc (x -> jacobian -> nnz * sizeof (int ));
7876
@@ -96,15 +94,14 @@ static void jacobian_init(expr *node)
9694static void eval_jacobian (expr * node )
9795{
9896 expr * x = node -> left ;
99- sum_expr * snode = (sum_expr * ) node ;
100- int axis = snode -> axis ;
10197
10298 /* evaluate child's jacobian */
10399 x -> eval_jacobian (x );
104100
105101 /* we have precomputed an idx map between the nonzeros of A and the result in C,
106102 so we just accumulate accordingly */
107- idx_map_accumulator (x -> jacobian , snode -> idx_map , node -> jacobian -> x );
103+ idx_map_accumulator (x -> jacobian , ((sum_expr * ) node )-> idx_map ,
104+ node -> jacobian -> x );
108105}
109106
110107static void wsum_hess_init (expr * node )
@@ -116,6 +113,10 @@ static void wsum_hess_init(expr *node)
116113 /* we never have to store more than the child's nnz */
117114 node -> wsum_hess = new_csr_matrix (node -> n_vars , node -> n_vars , x -> wsum_hess -> nnz );
118115 node -> dwork = malloc (x -> size * sizeof (double ));
116+
117+ /* copy sparsity pattern */
118+ memcpy (node -> wsum_hess -> p , x -> wsum_hess -> p , (x -> n_vars + 1 ) * sizeof (int ));
119+ memcpy (node -> wsum_hess -> i , x -> wsum_hess -> i , x -> wsum_hess -> nnz * sizeof (int ));
119120}
120121
121122static void eval_wsum_hess (expr * node , const double * w )
@@ -139,8 +140,8 @@ static void eval_wsum_hess(expr *node, const double *w)
139140
140141 x -> eval_wsum_hess (x , node -> dwork );
141142
142- /* todo : is this copy necessary or can we just change pointers? */
143- copy_csr_matrix ( x -> wsum_hess , node -> wsum_hess );
143+ /* copy values (TODO : is this necessary or can we just change pointers?) */
144+ memcpy ( node -> wsum_hess -> x , x -> wsum_hess -> x , x -> wsum_hess -> nnz * sizeof ( double ) );
144145}
145146
146147static bool is_affine (const expr * node )
@@ -151,7 +152,7 @@ static bool is_affine(const expr *node)
151152static void free_type_data (expr * node )
152153{
153154 sum_expr * snode = (sum_expr * ) node ;
154- free_int_double_pair_array (snode -> int_double_pairs );
155+ free (snode -> idx_map );
155156}
156157
157158expr * new_sum (expr * child , int axis )
@@ -188,7 +189,6 @@ expr *new_sum(expr *child, int axis)
188189
189190 /* Set type-specific fields */
190191 snode -> axis = axis ;
191- snode -> int_double_pairs = NULL ;
192192
193193 return node ;
194194}
0 commit comments