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

use to_lapack_int to check overflow and convert int64_t #67

Merged
merged 3 commits into from
Oct 26, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ add_library(
src/lagge.cc
src/laghe.cc
src/lagsy.cc
src/lamch.cc
src/langb.cc
src/lange.cc
src/langt.cc
Expand Down
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
Loading
Loading