Skip to content

Commit 833a41a

Browse files
committed
minor
1 parent 85edc51 commit 833a41a

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
7. Must be able to compute jacobian and hessian of A @ phi(x), so linear operator needs other code! This requires new infrastructure, I think.
66
8. Shortcut hessians of affine stuff?
77

8-
Going through all atoms to see that sparsity pattern is computed in jacobian:
9-
1. sum - not ok
10-
2. trace - not ok
8+
Going through all atoms to see that sparsity pattern is computed in initialization of jacobian:
9+
2. trace - not ok
10+
11+
Going through all atoms to see that sparsity pattern is computed in initialization of hessian:
12+
1. add - not ok
13+
2. hstack - not ok
14+
3. trace - not ok

include/subexpr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef struct sum_expr
3737
{
3838
expr base;
3939
int axis;
40-
struct int_double_pair *int_double_pairs; /* for sorting jacobian entries */
4140
int *idx_map; /* maps child nnz to summed-row positions */
4241
} sum_expr;
4342

src/affine/sum.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
9694
static 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

110107
static 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

121122
static 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

146147
static bool is_affine(const expr *node)
@@ -151,7 +152,7 @@ static bool is_affine(const expr *node)
151152
static 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

157158
expr *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

Comments
 (0)