56 #include "scip/pub_message.h" 57 #include "blockmemshell/memory.h" 58 #include "scip/type_retcode.h" 65 #ifdef LAPACK_LONGLONGINT 73 #define BMS_CALL(x) do \ 77 SCIPerrorMessage("No memory in function call\n"); \ 78 return SCIP_NOMEMORY; \ 84 #define SCIP_RealTOINT(x) ((LAPACKINTTYPE) (x + 0.5)) 95 char* JOBZ,
char* RANGE,
char* UPLO,
97 SCIP_Real* VL, SCIP_Real* VU,
99 SCIP_Real* ABSTOL,
LAPACKINTTYPE* M, SCIP_Real* W, SCIP_Real* Z,
116 void F77_FUNC(dgelsd, DGELSD)(
int* M,
int* N,
int* NRHS,
117 SCIP_Real* A,
int* LDA, SCIP_Real* b,
int* LDB, SCIP_Real* S, SCIP_Real* RCOND,
int* RANK,
118 SCIP_Real* WORK,
int* LWORK,
int* IWORK,
int* INFO );
134 SCIP_Bool geteigenvectors,
138 SCIP_Real* eigenvalue,
139 SCIP_Real* eigenvector
164 assert( bufmem != NULL );
167 assert( 0 < i && i <= n );
168 assert( eigenvalue != NULL );
169 assert( ( ! geteigenvectors) || eigenvector != NULL );
172 JOBZ = geteigenvectors ?
'V' :
'N';
183 #ifdef LAPACK_LONGLONGINT 192 F77_FUNC(dsyevr, DSYEVR)( &JOBZ, &RANGE, &UPLO,
196 &ABSTOL, &M, NULL, NULL,
198 &LWORK, &WISIZE, &LIWORK,
204 SCIPerrorMessage(
"There was an error when calling DSYEVR. INFO = %lld.\n", INFO);
212 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &WORK, (
int) LWORK) );
213 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &IWORK, (
int) LIWORK) );
214 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &WTMP, (
int) N) );
215 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &ISUPPZ, 2) );
221 F77_FUNC(dsyevr, DSYEVR)( &JOBZ, &RANGE, &UPLO,
225 &ABSTOL, &M, WTMP, eigenvector,
227 &LWORK, IWORK, &LIWORK,
232 SCIPerrorMessage(
"There was an error when calling DSYEVR. INFO = %d.\n", INFO);
237 *eigenvalue = WTMP[0];
240 BMSfreeBufferMemoryArray(bufmem, &ISUPPZ);
241 BMSfreeBufferMemoryArray(bufmem, &WTMP);
242 BMSfreeBufferMemoryArray(bufmem, &IWORK);
243 BMSfreeBufferMemoryArray(bufmem, &WORK);
254 SCIP_Real* eigenvalues,
255 SCIP_Real* eigenvectors
277 assert( bufmem != NULL );
280 assert( eigenvalues != NULL );
281 assert( eigenvectors != NULL );
293 #ifdef LAPACK_LONGLONGINT 302 F77_FUNC(dsyevr, DSYEVR)( &JOBZ, &RANGE, &UPLO,
306 &ABSTOL, &M, NULL, NULL,
308 &LWORK, &WISIZE, &LIWORK,
313 SCIPerrorMessage(
"There was an error when calling DSYEVR. INFO = %d.\n", INFO);
321 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &WORK, (
int) LWORK) );
322 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &IWORK, (
int) LIWORK) );
323 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &ISUPPZ, (
int) 2 * N) );
329 F77_FUNC(dsyevr, DSYEVR)( &JOBZ, &RANGE, &UPLO,
333 &ABSTOL, &M, eigenvalues, eigenvectors,
335 &LWORK, IWORK, &LIWORK,
340 SCIPerrorMessage(
"There was an error when calling DSYEVR. INFO = %d.\n", INFO);
345 BMSfreeBufferMemoryArray(bufmem, &ISUPPZ);
346 BMSfreeBufferMemoryArray(bufmem, &IWORK);
347 BMSfreeBufferMemoryArray(bufmem, &WORK);
386 F77_FUNC(dgemv, DGEMV)(&TRANS, &M, &N, &ALPHA, A, &LDA, X, &INCX, &BETA, Y, &INCY);
397 SCIP_Bool transposeA,
401 SCIP_Bool transposeB,
416 assert( (transposeA && transposeB && (nrowsA == ncolsB)) || (transposeA && !transposeB && (nrowsA == nrowsB))
417 || (!transposeA && transposeB && (ncolsA == ncolsB)) || (!transposeA && !transposeB && (ncolsA == nrowsB)) );
419 TRANSA = transposeA ?
'T' :
'N';
420 TRANSB = transposeB ?
'T' :
'N';
421 M = transposeA ? ncolsA : nrowsA;
422 N = transposeB ? nrowsB : ncolsB;
423 K = transposeA ? nrowsA : ncolsA;
425 LDA = transposeA ? K : M;
426 LDB = transposeB ? N : K;
430 F77_FUNC(dgemm, DGEMM)(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, matrixA, &LDA, matrixB, &LDB, &BETA, result, &LDC);
464 SCIP_Real residual = 0.0;
467 assert( bufmem != NULL );
481 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &S, MIN(m,n)) );
487 F77_FUNC(dgelsd, DGELSD)( &M, &N, &NRHS,
488 NULL, &LDA, NULL, &LDB, NULL,
489 &RCOND, &RANK, &WSIZE, &LWORK,
494 SCIPerrorMessage(
"There was an error when calling DGELSD. INFO = %d\n", INFO);
502 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &WORK, (
int) LWORK) );
503 BMS_CALL( BMSallocBufferMemoryArray(bufmem, &IWORK, (
int) LIWORK) );
506 F77_FUNC(dgelsd, DGELSD)( &M, &N, &NRHS,
507 A, &LDA, b, &LDB, S, &RCOND, &RANK,
508 WORK, &LWORK, IWORK, &INFO );
511 printf(
"LWORK = %d\n", LWORK);
512 printf(
"LIWORK = %d\n", LIWORK);
513 printf(
"A has size (%d,%d), is of rank %d\n", M, N, RANK);
514 printf(
"Minimum l2-norm solution of linear equation system:\n");
516 for (i = 0; i < n; ++i)
518 printf(
"(%d, %f) ", i, b[i]);
521 for (i = n; i < m; ++i)
523 residual += b[i] * b[i];
527 printf(
"Residual sum-of-squares for the solution is %f\n", residual);
532 SCIPerrorMessage(
"There was an error when calling DGELSD. INFO = %d\n", INFO);
537 for (i = 0; i < n; ++i)
541 BMSfreeBufferMemoryArray(bufmem, &IWORK);
542 BMSfreeBufferMemoryArray(bufmem, &WORK);
543 BMSfreeBufferMemoryArray(bufmem, &S);
#define SCIP_RealTOINT(x)
Macros for calling Fortran-functions.
SCIP_RETCODE SCIPlapackMatrixMatrixMult(int nrowsA, int ncolsA, SCIP_Real *matrixA, SCIP_Bool transposeA, int nrowsB, int ncolsB, SCIP_Real *matrixB, SCIP_Bool transposeB, SCIP_Real *result)
SCIP_RETCODE SCIPlapackMatrixVectorMult(int nrows, int ncols, SCIP_Real *matrix, SCIP_Real *vector, SCIP_Real *result)
SCIP_EXPORT SCIP_RETCODE SCIPlapackComputeIthEigenvalue(BMS_BUFMEM *bufmem, SCIP_Bool geteigenvectors, int n, SCIP_Real *A, int i, SCIP_Real *eigenvalue, SCIP_Real *eigenvector)
SCIP_RETCODE SCIPlapackLinearSolve(BMS_BUFMEM *bufmem, int m, int n, SCIP_Real *A, SCIP_Real *b, SCIP_Real *x)
interface methods for eigenvector computation and matrix multiplication using openblas ...
#define F77_FUNC(name, NAME)
SCIP_RETCODE SCIPlapackComputeEigenvectorDecomposition(BMS_BUFMEM *bufmem, int n, SCIP_Real *A, SCIP_Real *eigenvalues, SCIP_Real *eigenvectors)