Lines Matching refs:ctx

17 static PetscErrorCode DestroyCtx(AppCtx *ctx)  in DestroyCtx()  argument
20 PetscCall(MatDestroy(&(*ctx)->X)); in DestroyCtx()
21 PetscCall(VecDestroy(&(*ctx)->y)); in DestroyCtx()
22 PetscCall(VecDestroy(&(*ctx)->y_predicted)); in DestroyCtx()
23 PetscCall(PetscFree(*ctx)); in DestroyCtx()
27 static PetscErrorCode TestRegressorViews(PetscRegressor regressor, AppCtx ctx) in TestRegressorViews() argument
33 if (ctx->flg_view_sol) { in TestRegressorViews()
35 PetscCall(VecView(ctx->y, PETSC_VIEWER_STDOUT_WORLD)); in TestRegressorViews()
37 PetscCall(VecView(ctx->y_predicted, PETSC_VIEWER_STDOUT_WORLD)); in TestRegressorViews()
39 PetscCall(VecView(ctx->coefficients, PETSC_VIEWER_STDOUT_WORLD)); in TestRegressorViews()
42 if (ctx->flg_string) { in TestRegressorViews()
53 } else if (ctx->flg_ascii) PetscCall(PetscRegressorView(regressor, PETSC_VIEWER_STDOUT_WORLD)); in TestRegressorViews()
61 static PetscErrorCode TestPrefixRegressor(PetscRegressor regressor, AppCtx ctx) in TestPrefixRegressor() argument
64 if (ctx->test_prefix) { in TestPrefixRegressor()
71 static PetscErrorCode CreateData(AppCtx ctx) in CreateData() argument
79 PetscCall(VecCreate(PETSC_COMM_WORLD, &ctx->y)); in CreateData()
80 PetscCall(VecSetSizes(ctx->y, PETSC_DECIDE, ctx->N)); in CreateData()
81 PetscCall(VecSetFromOptions(ctx->y)); in CreateData()
82 PetscCall(VecDuplicate(ctx->y, &ctx->y_predicted)); in CreateData()
83 PetscCall(MatCreate(PETSC_COMM_WORLD, &ctx->X)); in CreateData()
84 PetscCall(MatSetSizes(ctx->X, PETSC_DECIDE, PETSC_DECIDE, ctx->N, ctx->N)); in CreateData()
85 PetscCall(MatSetFromOptions(ctx->X)); in CreateData()
86 PetscCall(MatSetUp(ctx->X)); in CreateData()
89 for (i = 0; i < ctx->N; i++) { in CreateData()
90 PetscCall(VecSetValue(ctx->y, i, (PetscScalar)i, INSERT_VALUES)); in CreateData()
91 PetscCall(MatSetValue(ctx->X, i, i, 1.0, INSERT_VALUES)); in CreateData()
105 PetscCall(VecAssemblyBegin(ctx->y)); in CreateData()
106 PetscCall(VecAssemblyEnd(ctx->y)); in CreateData()
107 PetscCall(MatAssemblyBegin(ctx->X, MAT_FINAL_ASSEMBLY)); in CreateData()
108 PetscCall(MatAssemblyEnd(ctx->X, MAT_FINAL_ASSEMBLY)); in CreateData()
110 PetscCall(VecMean(ctx->y, &mean)); in CreateData()
111 PetscCall(VecShift(ctx->y, -1.0 * mean)); in CreateData()
115 static PetscErrorCode ConfigureContext(AppCtx ctx) in ConfigureContext() argument
118 ctx->flg_string = PETSC_FALSE; in ConfigureContext()
119 ctx->flg_ascii = PETSC_FALSE; in ConfigureContext()
120 ctx->flg_view_sol = PETSC_FALSE; in ConfigureContext()
121 ctx->test_prefix = PETSC_FALSE; in ConfigureContext()
122 ctx->N = 10; in ConfigureContext()
124 …PetscCall(PetscOptionsInt("-N", "Dimension of the N x N data matrix", "ex3.c", ctx->N, &ctx->N, NU… in ConfigureContext()
125 PetscCall(PetscOptionsGetBool(NULL, NULL, "-test_string_viewer", &ctx->flg_string, NULL)); in ConfigureContext()
126 PetscCall(PetscOptionsGetBool(NULL, NULL, "-test_ascii_viewer", &ctx->flg_ascii, NULL)); in ConfigureContext()
127 PetscCall(PetscOptionsGetBool(NULL, NULL, "-view_sols", &ctx->flg_view_sol, NULL)); in ConfigureContext()
128 PetscCall(PetscOptionsGetBool(NULL, NULL, "-test_prefix", &ctx->test_prefix, NULL)); in ConfigureContext()
135 AppCtx ctx; in main() local
143 PetscCall(PetscNew(&ctx)); in main()
144 PetscCall(ConfigureContext(ctx)); in main()
145 PetscCall(CreateData(ctx)); in main()
153 PetscCall(TestPrefixRegressor(regressor, ctx)); in main()
157 PetscCall(PetscRegressorFit(regressor, ctx->X, ctx->y)); in main()
159 PetscCall(PetscRegressorPredict(regressor, ctx->X, ctx->y_predicted)); in main()
162 PetscCall(PetscRegressorLinearGetCoefficients(regressor, &ctx->coefficients)); in main()
165 PetscCall(TestRegressorViews(regressor, ctx)); in main()
167 PetscCall(DestroyCtx(&ctx)); in main()