Skip to content
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

Update C tests and examples for 64-bit integer #254

Merged
merged 7 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/galahad_precision.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* http://galahad.rl.ac.uk/galahad-www/specs.html
*/

#include <stdint.h>

// include guard
#ifndef GALAHAD_PRECISION_H
#define GALAHAD_PRECISION_H
Expand All @@ -27,5 +29,11 @@ typedef float real_wp_; // working precision
typedef double real_wp_; // working precision
#endif

#ifdef INTEGER_64
typedef int64_t ipc_; // integer precision
#else
typedef int ipc_; // integer precision
#endif

// end include guard
#endif
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ if build_tests and build_ciface
endif

# Python tests
if build_tests and build_pythoniface and build_ciface and build_double and host_system != 'windows'
if build_tests and build_pythoniface and build_ciface and build_double and (not galahad_int64) and (host_system != 'windows')

foreach test: galahad_python_tests
package = test[0]
Expand Down
26 changes: 13 additions & 13 deletions src/arc/C/arcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ struct userdata_type {
};

// Function prototypes
int fun(int n, const real_wp_ x[], real_wp_ *f, const void *);
int grad(int n, const real_wp_ x[], real_wp_ g[], const void *);
int hess(int n, int ne, const real_wp_ x[], real_wp_ hval[], const void *);
ipc_ fun(ipc_ n, const real_wp_ x[], real_wp_ *f, const void *);
ipc_ grad(ipc_ n, const real_wp_ x[], real_wp_ g[], const void *);
ipc_ hess(ipc_ n, ipc_ ne, const real_wp_ x[], real_wp_ hval[], const void *);

int main(void) {

Expand All @@ -24,7 +24,7 @@ int main(void) {
struct arc_inform_type inform;

// Initialize ARC
int status;
ipc_ status;
arc_initialize( &data, &control, &status );

// Set user-defined control options
Expand All @@ -36,13 +36,13 @@ int main(void) {
userdata.p = 4.0;

// Set problem data
int n = 3; // dimension
int ne = 5; // Hesssian elements
ipc_ n = 3; // dimension
ipc_ ne = 5; // Hesssian elements
real_wp_ x[] = {1,1,1}; // start from one
real_wp_ infty = 1e20; // infinity
char H_type[] = "coordinate"; // specify co-ordinate storage
int H_row[] = {0, 2, 1, 2, 2}; // Hessian H
int H_col[] = {0, 0, 1, 1, 2}; // NB lower triangle
ipc_ H_row[] = {0, 2, 1, 2, 2}; // Hessian H
ipc_ H_col[] = {0, 0, 1, 1, 2}; // NB lower triangle

// Set storage
real_wp_ g[n]; // gradient
Expand All @@ -61,11 +61,11 @@ int main(void) {
printf("ARC successful solve\n");
printf("iter: %d \n", inform.iter);
printf("x: ");
for(int i = 0; i < n; i++) printf("%f ", x[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", x[i]);
printf("\n");
printf("objective: %f \n", inform.obj);
printf("gradient: ");
for(int i = 0; i < n; i++) printf("%f ", g[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", g[i]);
printf("\n");
printf("f_eval: %d \n", inform.f_eval);
printf("time: %f \n", inform.time.clock_total);
Expand All @@ -82,7 +82,7 @@ int main(void) {
}

// Objective function
int fun(int n, const real_wp_ x[], real_wp_ *f, const void *userdata){
ipc_ fun(ipc_ n, const real_wp_ x[], real_wp_ *f, const void *userdata){
struct userdata_type *myuserdata = (struct userdata_type *) userdata;
real_wp_ p = myuserdata->p;

Expand All @@ -91,7 +91,7 @@ int fun(int n, const real_wp_ x[], real_wp_ *f, const void *userdata){
}

// Gradient of the objective
int grad(int n, const real_wp_ x[], real_wp_ g[], const void *userdata){
ipc_ grad(ipc_ n, const real_wp_ x[], real_wp_ g[], const void *userdata){
struct userdata_type *myuserdata = (struct userdata_type *) userdata;
real_wp_ p = myuserdata->p;

Expand All @@ -102,7 +102,7 @@ int grad(int n, const real_wp_ x[], real_wp_ g[], const void *userdata){
}

// Hessian of the objective
int hess(int n, int ne, const real_wp_ x[], real_wp_ hval[],
ipc_ hess(ipc_ n, ipc_ ne, const real_wp_ x[], real_wp_ hval[],
const void *userdata){
hval[0] = 2.0 - cos(x[0]);
hval[1] = 2.0;
Expand Down
22 changes: 11 additions & 11 deletions src/arc/C/arcs2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ struct userdata_type {
};

// Function prototypes
int fun(int n, const real_wp_ x[], real_wp_ *f, const void *);
int grad(int n, const real_wp_ x[], real_wp_ g[], const void *);
int hessprod(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[],
ipc_ fun(ipc_ n, const real_wp_ x[], real_wp_ *f, const void *);
ipc_ grad(ipc_ n, const real_wp_ x[], real_wp_ g[], const void *);
ipc_ hessprod(ipc_ n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[],
bool got_h, const void *);

int main(void) {
Expand All @@ -25,7 +25,7 @@ int main(void) {
struct arc_inform_type inform;

// Initialize ARC
int status;
ipc_ status;
arc_initialize( &data, &control, &status );

// Set user-defined control options
Expand All @@ -37,8 +37,8 @@ int main(void) {
userdata.p = 4.0;

// Set problem data
int n = 3; // dimension
int ne = 5; // Hesssian elements
ipc_ n = 3; // dimension
ipc_ ne = 5; // Hesssian elements
real_wp_ x[] = {1.,1.,1.}; // start from one
real_wp_ infty = 1e20; // infinity
char H_type[] = "absent"; // specify Hessian-vector products
Expand All @@ -60,11 +60,11 @@ int main(void) {
printf("ARC successful solve\n");
printf("iter: %d \n", inform.iter);
printf("x: ");
for(int i = 0; i < n; i++) printf("%f ", x[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", x[i]);
printf("\n");
printf("objective: %f \n", inform.obj);
printf("gradient: ");
for(int i = 0; i < n; i++) printf("%f ", g[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", g[i]);
printf("\n");
printf("f_eval: %d \n", inform.f_eval);
printf("time: %f \n", inform.time.clock_total);
Expand All @@ -81,7 +81,7 @@ int main(void) {
}

// Objective function
int fun(int n, const real_wp_ x[], real_wp_ *f, const void *userdata){
ipc_ fun(ipc_ n, const real_wp_ x[], real_wp_ *f, const void *userdata){
struct userdata_type *myuserdata = (struct userdata_type *) userdata;
real_wp_ p = myuserdata->p;

Expand All @@ -90,7 +90,7 @@ int fun(int n, const real_wp_ x[], real_wp_ *f, const void *userdata){
}

// Gradient of the objective
int grad(int n, const real_wp_ x[], real_wp_ g[], const void *userdata){
ipc_ grad(ipc_ n, const real_wp_ x[], real_wp_ g[], const void *userdata){
struct userdata_type *myuserdata = (struct userdata_type *) userdata;
real_wp_ p = myuserdata->p;

Expand All @@ -101,7 +101,7 @@ int grad(int n, const real_wp_ x[], real_wp_ g[], const void *userdata){
}

// Hessian-vector product
int hessprod(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[],
ipc_ hessprod(ipc_ n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[],
bool got_h, const void *userdata){
u[0] = u[0] + 2.0 * ( v[0] + v[2] ) - cos( x[0] ) * v[0];
u[1] = u[1] + 2.0 * ( v[1] + v[2] );
Expand Down
16 changes: 8 additions & 8 deletions src/arc/C/arcs3.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ int main(void) {
struct arc_inform_type inform;

// Initialize ARC
int status;
ipc_ status;
arc_initialize( &data, &control, &status );

// Set user-defined control options
control.f_indexing = false; // C sparse matrix indexing (default)
//control.print_level = 1;

// Set problem data
int n = 3; // dimension
int ne = 5; // Hesssian elements
ipc_ n = 3; // dimension
ipc_ ne = 5; // Hesssian elements
real_wp_ x[] = {1.,1.,1.}; // start from one
real_wp_ infty = 1e20; // infinity
char H_type[] = "coordinate"; // specify co-ordinate storage
int H_row[] = {0, 2, 1, 2, 2}; // Hessian H
int H_col[] = {0, 0, 1, 1, 2}; // NB lower triangle
ipc_ H_row[] = {0, 2, 1, 2, 2}; // Hessian H
ipc_ H_col[] = {0, 0, 1, 1, 2}; // NB lower triangle

// Reverse-communication input/output
int eval_status;
ipc_ eval_status;
real_wp_ f;
real_wp_ g[n];
real_wp_ u[n], v[n];
Expand Down Expand Up @@ -82,11 +82,11 @@ int main(void) {
// Print solution details
printf("iter: %d \n", inform.iter);
printf("x: ");
for(int i = 0; i < n; i++) printf("%f ", x[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", x[i]);
printf("\n");
printf("objective: %f \n", inform.obj);
printf("gradient: ");
for(int i = 0; i < n; i++) printf("%f ", g[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", g[i]);
printf("\n");
printf("f_eval: %d \n", inform.f_eval);
printf("time: %f \n", inform.time.clock_total);
Expand Down
12 changes: 6 additions & 6 deletions src/arc/C/arcs4.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ int main(void) {
struct arc_inform_type inform;

// Initialize ARC
int status;
ipc_ status;
arc_initialize( &data, &control, &status );

// Set user-defined control options
control.f_indexing = false; // C sparse matrix indexing (default)
//control.print_level = 1;

// Set problem data
int n = 3; // dimension
int ne = 5; // Hesssian elements
ipc_ n = 3; // dimension
ipc_ ne = 5; // Hesssian elements
real_wp_ x[] = {1.,1.,1.}; // start from one
real_wp_ infty = 1e20; // infinity
char H_type[] = "absent"; // specify Hessian-vector products

// Reverse-communication input/output
int eval_status;
ipc_ eval_status;
real_wp_ f;
real_wp_ g[n];
real_wp_ u[n], v[n];
Expand Down Expand Up @@ -78,11 +78,11 @@ int main(void) {
// Print solution details
printf("iter: %d \n", inform.iter);
printf("x: ");
for(int i = 0; i < n; i++) printf("%f ", x[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", x[i]);
printf("\n");
printf("objective: %f \n", inform.obj);
printf("gradient: ");
for(int i = 0; i < n; i++) printf("%f ", g[i]);
for(ipc_ i = 0; i < n; i++) printf("%f ", g[i]);
printf("\n");
printf("f_eval: %d \n", inform.f_eval);
printf("time: %f \n", inform.time.clock_total);
Expand Down
Loading
Loading