#include "validate.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
static int predicate(double real, double imag, double beta, void *arg)
{
if (0.0 < real && beta != 0.0)
return 1;
return 0;
}
int main()
{
const int n = 3000;
srand((unsigned) time(NULL));
int ldA = ((n/8)+1)*8, ldC = ((n/8)+1)*8;
double *A = malloc(n*ldA*sizeof(double));
double *C = malloc(n*ldC*sizeof(double));
for (int j = 0; j < n; j++)
for (int i = 0; i < n; i++)
A[j*ldA+i] = C[j*ldC+i] = 2.0*rand()/RAND_MAX - 1.0;
int ldB = ((n/8)+1)*8, ldD = ((n/8)+1)*8;
double *B = malloc(n*ldB*sizeof(double));
double *D = malloc(n*ldD*sizeof(double));
for (int j = 0; j < n; j++)
for (int i = 0; i < n; i++)
B[j*ldB+i] = D[j*ldD+i] = 2.0*rand()/RAND_MAX - 1.0;
int ldQ = ((n/8)+1)*8;
double *Q = malloc(n*ldA*sizeof(double));
for (int j = 0; j < n; j++)
for (int i = 0; i < n; i++)
Q[j*ldQ+i] = i == j ? 1.0 : 0.0;
int ldZ = ((n/8)+1)*8;
double *Z = malloc(n*ldZ*sizeof(double));
for (int j = 0; j < n; j++)
for (int i = 0; i < n; i++)
Z[j*ldZ+i] = i == j ? 1.0 : 0.0;
double *real = malloc(n*sizeof(double));
double *imag = malloc(n*sizeof(double));
double *beta = malloc(n*sizeof(double));
int *select = malloc(n*sizeof(int));
printf("Hessenberg-triangular reduction...\n");
printf("Schur reduction...\n");
starneig_GEP_SM_Schur(n, A, ldA, B, ldB, Q, ldQ, Z, ldZ, real, imag, beta);
int num_selected;
n, A, ldA, B, ldB, &predicate, NULL, select, &num_selected);
printf("Selected %d eigenvalues out of %d.\n", num_selected, n);
printf("Reordering...\n");
n, select, A, ldA, B, ldB, Q, ldQ, Z, ldZ, real, imag, beta);
check_residual(n, ldQ, ldA, ldZ, ldC, Q, A, Z, C);
check_residual(n, ldQ, ldB, ldZ, ldD, Q, B, Z, D);
check_orthogonality(n, ldQ, Q);
check_orthogonality(n, ldZ, Z);
free(A);
free(C);
free(B);
free(D);
free(Q);
free(Z);
free(real);
free(imag);
free(beta);
free(select);
return 0;
}