-
Notifications
You must be signed in to change notification settings - Fork 1
Parameter support #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
2913dee
fea0708
36ec239
4f93f7c
cf695a2
bd4f3b0
27acb7d
00f7732
dc56c90
978f319
01c6f82
b8cf436
9c23b40
bf8a55c
9700344
939a910
71dddf1
36864d4
978aa03
b3e2304
0edf928
b985028
4e25da7
4b58b1c
1c3ebee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,11 +62,7 @@ static void free_type_data(expr *node) | |
| if (lin_node->b != NULL) | ||
| { | ||
| free(lin_node->b); | ||
| lin_node->b = NULL; | ||
| } | ||
|
|
||
| lin_node->A_csr = NULL; | ||
| lin_node->A_csc = NULL; | ||
|
Comment on lines
64
to
-69
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. claude noticed that these NULL assignments were not necessary. please confirm if that's accurate. |
||
| } | ||
|
|
||
| static void jacobian_init(expr *node) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,39 +15,48 @@ | |
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* Unified parameter/constant leaf node. | ||
| * | ||
| * When param_id == PARAM_FIXED, this is a constant whose values are set at | ||
| * creation and never change. When param_id >= 0, values are updated via | ||
| * problem_update_params. | ||
| * | ||
| * In both cases the derivative behavior is identical: zero Jacobian and | ||
| * Hessian with respect to variables (always affine). */ | ||
|
|
||
| #include "affine.h" | ||
| #include "subexpr.h" | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| static void forward(expr *node, const double *u) | ||
| { | ||
| /* Constants don't depend on u; values are already set */ | ||
| /* Values are set at creation (constants) or by problem_update_params */ | ||
| (void) node; | ||
| (void) u; | ||
| } | ||
|
|
||
| static void jacobian_init(expr *node) | ||
| { | ||
| /* Constant jacobian is all zeros: size x n_vars with 0 nonzeros. | ||
| * new_csr_matrix uses calloc for row pointers, so they're already 0. */ | ||
| /* Parameter/constant jacobian is all zeros: size x n_vars with 0 nonzeros */ | ||
| node->jacobian = new_csr_matrix(node->size, node->n_vars, 0); | ||
| } | ||
|
|
||
| static void eval_jacobian(expr *node) | ||
| { | ||
| /* Constant jacobian never changes - nothing to evaluate */ | ||
| /* Jacobian never changes */ | ||
| (void) node; | ||
| } | ||
|
|
||
| static void wsum_hess_init(expr *node) | ||
| { | ||
| /* Constant Hessian is all zeros: n_vars x n_vars with 0 nonzeros. */ | ||
| /* Hessian is all zeros */ | ||
| node->wsum_hess = new_csr_matrix(node->n_vars, node->n_vars, 0); | ||
| } | ||
|
|
||
| static void eval_wsum_hess(expr *node, const double *w) | ||
| { | ||
| /* Constant Hessian is always zero - nothing to compute */ | ||
| (void) node; | ||
| (void) w; | ||
| } | ||
|
|
@@ -58,12 +67,19 @@ static bool is_affine(const expr *node) | |
| return true; | ||
| } | ||
|
|
||
| expr *new_constant(int d1, int d2, int n_vars, const double *values) | ||
| expr *new_parameter(int d1, int d2, int param_id, int n_vars, const double *values) | ||
| { | ||
| expr *node = (expr *) calloc(1, sizeof(expr)); | ||
| init_expr(node, d1, d2, n_vars, forward, jacobian_init, eval_jacobian, is_affine, | ||
| wsum_hess_init, eval_wsum_hess, NULL); | ||
| memcpy(node->value, values, node->size * sizeof(double)); | ||
| parameter_expr *pnode = (parameter_expr *) calloc(1, sizeof(parameter_expr)); | ||
| init_expr(&pnode->base, d1, d2, n_vars, forward, jacobian_init, eval_jacobian, | ||
| is_affine, wsum_hess_init, eval_wsum_hess, NULL); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this correct declaration for a parameter expression? I am not sure about the first argument being |
||
| pnode->param_id = param_id; | ||
|
|
||
| /* If values provided (fixed constant), copy them now */ | ||
| if (values != NULL) | ||
| { | ||
| memcpy(pnode->base.value, values, pnode->base.size * sizeof(double)); | ||
| } | ||
| /* Otherwise values will be populated by problem_update_params */ | ||
|
|
||
| return node; | ||
| return &pnode->base; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.