Skip to content

Commit

Permalink
use to_lapack_int to check overflow and convert int64_t
Browse files Browse the repository at this point in the history
  • Loading branch information
mgates3 committed Oct 25, 2024
1 parent 822498d commit 9a72397
Show file tree
Hide file tree
Showing 384 changed files with 5,123 additions and 12,780 deletions.
97 changes: 29 additions & 68 deletions src/bbcsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.

#include "lapack.hh"
#include "lapack_internal.hh"
#include "lapack/fortran.h"
#include "NoConstructAllocator.hh"

Expand Down Expand Up @@ -36,28 +37,18 @@ int64_t bbcsd(
float* B22D,
float* B22E )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(m) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(p) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(q) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu1) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu2) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv1t) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv2t) > std::numeric_limits<lapack_int>::max() );
}
char jobu1_ = to_char_csd( jobu1 );
char jobu2_ = to_char_csd( jobu2 );
char jobv1t_ = to_char_csd( jobv1t );
char jobv2t_ = to_char_csd( jobv2t );
char trans_ = to_char( trans );
lapack_int m_ = (lapack_int) m;
lapack_int p_ = (lapack_int) p;
lapack_int q_ = (lapack_int) q;
lapack_int ldu1_ = (lapack_int) ldu1;
lapack_int ldu2_ = (lapack_int) ldu2;
lapack_int ldv1t_ = (lapack_int) ldv1t;
lapack_int ldv2t_ = (lapack_int) ldv2t;
lapack_int m_ = to_lapack_int( m );
lapack_int p_ = to_lapack_int( p );
lapack_int q_ = to_lapack_int( q );
lapack_int ldu1_ = to_lapack_int( ldu1 );
lapack_int ldu2_ = to_lapack_int( ldu2 );
lapack_int ldv1t_ = to_lapack_int( ldv1t );
lapack_int ldv2t_ = to_lapack_int( ldv2t );
lapack_int info_ = 0;

// query for workspace size
Expand Down Expand Up @@ -132,28 +123,18 @@ int64_t bbcsd(
double* B22D,
double* B22E )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(m) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(p) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(q) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu1) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu2) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv1t) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv2t) > std::numeric_limits<lapack_int>::max() );
}
char jobu1_ = to_char_csd( jobu1 );
char jobu2_ = to_char_csd( jobu2 );
char jobv1t_ = to_char_csd( jobv1t );
char jobv2t_ = to_char_csd( jobv2t );
char trans_ = to_char( trans );
lapack_int m_ = (lapack_int) m;
lapack_int p_ = (lapack_int) p;
lapack_int q_ = (lapack_int) q;
lapack_int ldu1_ = (lapack_int) ldu1;
lapack_int ldu2_ = (lapack_int) ldu2;
lapack_int ldv1t_ = (lapack_int) ldv1t;
lapack_int ldv2t_ = (lapack_int) ldv2t;
lapack_int m_ = to_lapack_int( m );
lapack_int p_ = to_lapack_int( p );
lapack_int q_ = to_lapack_int( q );
lapack_int ldu1_ = to_lapack_int( ldu1 );
lapack_int ldu2_ = to_lapack_int( ldu2 );
lapack_int ldv1t_ = to_lapack_int( ldv1t );
lapack_int ldv2t_ = to_lapack_int( ldv2t );
lapack_int info_ = 0;

// query for workspace size
Expand Down Expand Up @@ -228,28 +209,18 @@ int64_t bbcsd(
float* B22D,
float* B22E )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(m) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(p) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(q) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu1) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu2) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv1t) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv2t) > std::numeric_limits<lapack_int>::max() );
}
char jobu1_ = to_char_csd( jobu1 );
char jobu2_ = to_char_csd( jobu2 );
char jobv1t_ = to_char_csd( jobv1t );
char jobv2t_ = to_char_csd( jobv2t );
char trans_ = to_char( trans );
lapack_int m_ = (lapack_int) m;
lapack_int p_ = (lapack_int) p;
lapack_int q_ = (lapack_int) q;
lapack_int ldu1_ = (lapack_int) ldu1;
lapack_int ldu2_ = (lapack_int) ldu2;
lapack_int ldv1t_ = (lapack_int) ldv1t;
lapack_int ldv2t_ = (lapack_int) ldv2t;
lapack_int m_ = to_lapack_int( m );
lapack_int p_ = to_lapack_int( p );
lapack_int q_ = to_lapack_int( q );
lapack_int ldu1_ = to_lapack_int( ldu1 );
lapack_int ldu2_ = to_lapack_int( ldu2 );
lapack_int ldv1t_ = to_lapack_int( ldv1t );
lapack_int ldv2t_ = to_lapack_int( ldv2t );
lapack_int info_ = 0;

// query for workspace size
Expand Down Expand Up @@ -509,28 +480,18 @@ int64_t bbcsd(
double* B22D,
double* B22E )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(m) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(p) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(q) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu1) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu2) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv1t) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldv2t) > std::numeric_limits<lapack_int>::max() );
}
char jobu1_ = to_char_csd( jobu1 );
char jobu2_ = to_char_csd( jobu2 );
char jobv1t_ = to_char_csd( jobv1t );
char jobv2t_ = to_char_csd( jobv2t );
char trans_ = to_char( trans );
lapack_int m_ = (lapack_int) m;
lapack_int p_ = (lapack_int) p;
lapack_int q_ = (lapack_int) q;
lapack_int ldu1_ = (lapack_int) ldu1;
lapack_int ldu2_ = (lapack_int) ldu2;
lapack_int ldv1t_ = (lapack_int) ldv1t;
lapack_int ldv2t_ = (lapack_int) ldv2t;
lapack_int m_ = to_lapack_int( m );
lapack_int p_ = to_lapack_int( p );
lapack_int q_ = to_lapack_int( q );
lapack_int ldu1_ = to_lapack_int( ldu1 );
lapack_int ldu2_ = to_lapack_int( ldu2 );
lapack_int ldv1t_ = to_lapack_int( ldv1t );
lapack_int ldv2t_ = to_lapack_int( ldv2t );
lapack_int info_ = 0;

// query for workspace size
Expand Down
25 changes: 7 additions & 18 deletions src/bdsdc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.

#include "lapack.hh"
#include "lapack_internal.hh"
#include "lapack/fortran.h"
#include "NoConstructAllocator.hh"

Expand All @@ -26,17 +27,11 @@ int64_t bdsdc(
float* Q,
int64_t* IQ )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldvt) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
char compq_ = to_char_comp( compq );
lapack_int n_ = (lapack_int) n;
lapack_int ldu_ = (lapack_int) ldu;
lapack_int ldvt_ = (lapack_int) ldvt;
lapack_int n_ = to_lapack_int( n );
lapack_int ldu_ = to_lapack_int( ldu );
lapack_int ldvt_ = to_lapack_int( ldvt );
lapack_int info_ = 0;

// IQ disabled for now, due to complicated dimension
Expand Down Expand Up @@ -192,17 +187,11 @@ int64_t bdsdc(
double* Q,
int64_t* IQ )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldvt) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
char compq_ = to_char_comp( compq );
lapack_int n_ = (lapack_int) n;
lapack_int ldu_ = (lapack_int) ldu;
lapack_int ldvt_ = (lapack_int) ldvt;
lapack_int n_ = to_lapack_int( n );
lapack_int ldu_ = to_lapack_int( ldu );
lapack_int ldvt_ = to_lapack_int( ldvt );
lapack_int info_ = 0;

// IQ disabled for now, due to complicated dimension
Expand Down
97 changes: 29 additions & 68 deletions src/bdsqr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.

#include "lapack.hh"
#include "lapack_internal.hh"
#include "lapack/fortran.h"
#include "NoConstructAllocator.hh"

Expand All @@ -25,24 +26,14 @@ int64_t bdsqr(
float* U, int64_t ldu,
float* C, int64_t ldc )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(nru) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncc) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldc) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
lapack_int n_ = (lapack_int) n;
lapack_int ncvt_ = (lapack_int) ncvt;
lapack_int nru_ = (lapack_int) nru;
lapack_int ncc_ = (lapack_int) ncc;
lapack_int ldvt_ = (lapack_int) ldvt;
lapack_int ldu_ = (lapack_int) ldu;
lapack_int ldc_ = (lapack_int) ldc;
lapack_int n_ = to_lapack_int( n );
lapack_int ncvt_ = to_lapack_int( ncvt );
lapack_int nru_ = to_lapack_int( nru );
lapack_int ncc_ = to_lapack_int( ncc );
lapack_int ldvt_ = to_lapack_int( ldvt );
lapack_int ldu_ = to_lapack_int( ldu );
lapack_int ldc_ = to_lapack_int( ldc );
lapack_int info_ = 0;

// allocate workspace
Expand Down Expand Up @@ -73,24 +64,14 @@ int64_t bdsqr(
double* U, int64_t ldu,
double* C, int64_t ldc )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(nru) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncc) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldc) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
lapack_int n_ = (lapack_int) n;
lapack_int ncvt_ = (lapack_int) ncvt;
lapack_int nru_ = (lapack_int) nru;
lapack_int ncc_ = (lapack_int) ncc;
lapack_int ldvt_ = (lapack_int) ldvt;
lapack_int ldu_ = (lapack_int) ldu;
lapack_int ldc_ = (lapack_int) ldc;
lapack_int n_ = to_lapack_int( n );
lapack_int ncvt_ = to_lapack_int( ncvt );
lapack_int nru_ = to_lapack_int( nru );
lapack_int ncc_ = to_lapack_int( ncc );
lapack_int ldvt_ = to_lapack_int( ldvt );
lapack_int ldu_ = to_lapack_int( ldu );
lapack_int ldc_ = to_lapack_int( ldc );
lapack_int info_ = 0;

// allocate workspace
Expand Down Expand Up @@ -121,24 +102,14 @@ int64_t bdsqr(
std::complex<float>* U, int64_t ldu,
std::complex<float>* C, int64_t ldc )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(nru) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncc) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldc) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
lapack_int n_ = (lapack_int) n;
lapack_int ncvt_ = (lapack_int) ncvt;
lapack_int nru_ = (lapack_int) nru;
lapack_int ncc_ = (lapack_int) ncc;
lapack_int ldvt_ = (lapack_int) ldvt;
lapack_int ldu_ = (lapack_int) ldu;
lapack_int ldc_ = (lapack_int) ldc;
lapack_int n_ = to_lapack_int( n );
lapack_int ncvt_ = to_lapack_int( ncvt );
lapack_int nru_ = to_lapack_int( nru );
lapack_int ncc_ = to_lapack_int( ncc );
lapack_int ldvt_ = to_lapack_int( ldvt );
lapack_int ldu_ = to_lapack_int( ldu );
lapack_int ldc_ = to_lapack_int( ldc );
lapack_int info_ = 0;

// allocate workspace
Expand Down Expand Up @@ -268,24 +239,14 @@ int64_t bdsqr(
std::complex<double>* U, int64_t ldu,
std::complex<double>* C, int64_t ldc )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(nru) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ncc) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldvt) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldc) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
lapack_int n_ = (lapack_int) n;
lapack_int ncvt_ = (lapack_int) ncvt;
lapack_int nru_ = (lapack_int) nru;
lapack_int ncc_ = (lapack_int) ncc;
lapack_int ldvt_ = (lapack_int) ldvt;
lapack_int ldu_ = (lapack_int) ldu;
lapack_int ldc_ = (lapack_int) ldc;
lapack_int n_ = to_lapack_int( n );
lapack_int ncvt_ = to_lapack_int( ncvt );
lapack_int nru_ = to_lapack_int( nru );
lapack_int ncc_ = to_lapack_int( ncc );
lapack_int ldvt_ = to_lapack_int( ldvt );
lapack_int ldu_ = to_lapack_int( ldu );
lapack_int ldc_ = to_lapack_int( ldc );
lapack_int info_ = 0;

// allocate workspace
Expand Down
35 changes: 11 additions & 24 deletions src/bdsvdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.

#include "lapack.hh"
#include "lapack_internal.hh"
#include "lapack/fortran.h"
#include "NoConstructAllocator.hh"

Expand All @@ -27,21 +28,14 @@ int64_t bdsvdx(
float* S,
float* Z, int64_t ldz )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(il) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(iu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldz) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
char jobz_ = to_char( jobz );
char range_ = to_char( range );
lapack_int n_ = (lapack_int) n;
lapack_int il_ = (lapack_int) il;
lapack_int iu_ = (lapack_int) iu;
lapack_int nfound_ = (lapack_int) *nfound;
lapack_int ldz_ = (lapack_int) ldz;
lapack_int n_ = to_lapack_int( n );
lapack_int il_ = to_lapack_int( il );
lapack_int iu_ = to_lapack_int( iu );
lapack_int nfound_ = to_lapack_int( *nfound );
lapack_int ldz_ = to_lapack_int( ldz );
lapack_int info_ = 0;

// allocate workspace
Expand Down Expand Up @@ -202,21 +196,14 @@ int64_t bdsvdx(
double* S,
double* Z, int64_t ldz )
{
// check for overflow
if (sizeof(int64_t) > sizeof(lapack_int)) {
lapack_error_if( std::abs(n) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(il) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(iu) > std::numeric_limits<lapack_int>::max() );
lapack_error_if( std::abs(ldz) > std::numeric_limits<lapack_int>::max() );
}
char uplo_ = to_char( uplo );
char jobz_ = to_char( jobz );
char range_ = to_char( range );
lapack_int n_ = (lapack_int) n;
lapack_int il_ = (lapack_int) il;
lapack_int iu_ = (lapack_int) iu;
lapack_int nfound_ = (lapack_int) *nfound;
lapack_int ldz_ = (lapack_int) ldz;
lapack_int n_ = to_lapack_int( n );
lapack_int il_ = to_lapack_int( il );
lapack_int iu_ = to_lapack_int( iu );
lapack_int nfound_ = to_lapack_int( *nfound );
lapack_int ldz_ = to_lapack_int( ldz );
lapack_int info_ = 0;

// allocate workspace
Expand Down
Loading

0 comments on commit 9a72397

Please sign in to comment.