Added GTestSuite helper functions

- Functions to convert to cblas enums from char.
- Functions to print matrix and vector elements.
- Functions to set matrix and vector elements with
  the given value.

AMD-Internal: [CPUPL-2732]
Change-Id: I1046b9578c8456e89eddba4a4e8577016b9361ca
This commit is contained in:
jagar
2023-04-11 16:30:37 +05:30
committed by Eleni Vlachopoulou
parent 6b8f4744a4
commit f164c7fe70
60 changed files with 450 additions and 751 deletions

View File

@@ -51,7 +51,7 @@ template<typename T>
void getfp(int from, int to, T* alpha)
{
using real_T = typename testinghelpers::type_info<T>::real_type;
std::mt19937 generator(94);
std::mt19937 generator(94);
std::uniform_real_distribution<real_T> distr(from, to);
if constexpr (testinghelpers::type_info<T>::is_real)
*alpha = distr(generator);
@@ -71,7 +71,7 @@ void getfp(int from, int to, gtint_t n, gtint_t incx, T* x)
{
using real_T = typename testinghelpers::type_info<T>::real_type;
T* chi;
std::mt19937 generator(94);
std::mt19937 generator(94);
std::uniform_real_distribution<real_T> distr(from, to);
for ( gtint_t i = 0; i < n; ++i )
{
@@ -116,7 +116,7 @@ template<typename T>
void getfp(int from, int to, char storage, gtint_t m, gtint_t n, T* a, char transa, gtint_t lda )
{
using real_T = typename testinghelpers::type_info<T>::real_type;
std::mt19937 generator(1994);
std::mt19937 generator(1994);
std::uniform_real_distribution<real_T> distr(from, to);
if( chktrans( transa )) {
@@ -164,7 +164,7 @@ template<typename T>
void getint(int from, int to, T* alpha)
{
using real_T = typename testinghelpers::type_info<T>::real_type;
std::mt19937 generator(94);
std::mt19937 generator(94);
std::uniform_int_distribution<int> distr(from, to);
if constexpr (testinghelpers::type_info<T>::is_real)
*alpha = real_T(distr(generator));
@@ -183,7 +183,7 @@ void getint(int from, int to, gtint_t n, gtint_t incx, T* x)
{
using real_T = typename testinghelpers::type_info<T>::real_type;
T* chi;
std::mt19937 generator(94);
std::mt19937 generator(94);
std::uniform_int_distribution<int> distr(from, to);
for ( gtint_t i = 0; i < n; ++i )
{
@@ -238,7 +238,7 @@ template<typename T>
void getint(int from, int to, char storage, gtint_t m, gtint_t n, T* a, char transa, gtint_t lda )
{
using real_T = typename testinghelpers::type_info<T>::real_type;
std::mt19937 generator(1994);
std::mt19937 generator(1994);
std::uniform_int_distribution<int> distr(from, to);
if( chktrans( transa )) {
@@ -355,7 +355,6 @@ void randomgenerators(int from, int to, char storage, char uplo, gtint_t k,
}
}
} //end of namespace datagenerators
template<typename T>
@@ -363,7 +362,7 @@ std::vector<T> get_random_matrix(int from, int to, char storage, char trans, gti
gtint_t lda, char datatype)
{
std::vector<T> a(matsize(storage, trans, m, n, lda));
datagenerators::randomgenerators<T>( from, to, storage, m, n, a.data(), trans, lda, datatype );
testinghelpers::datagenerators::randomgenerators<T>( from, to, storage, m, n, a.data(), trans, lda, datatype );
return a;
}
template<typename T>
@@ -384,6 +383,65 @@ std::vector<T> get_random_vector(int from, int to, gtint_t n, gtint_t incx, char
return x;
}
template<typename T>
void set_vector( gtint_t n, gtint_t incx, T* x, T value )
{
T* chi;
for ( gtint_t i = 0; i < n; ++i )
{
chi = x + i*std::abs(incx);
*chi = value ;
}
}
template<typename T>
void set_matrix( char storage, gtint_t m, gtint_t n, T* a, char transa, gtint_t lda, T value )
{
if( chktrans( transa )) {
swap_dims( &m, &n );
}
if((storage == 'c') || (storage == 'C'))
{
for( gtint_t i = 0 ; i < m ; i++ )
{
for( gtint_t j = 0 ; j < n ; j++ )
{
a[i+j*lda] = value ;
}
}
}
else if( (storage == 'r') || (storage == 'R') )
{
for( gtint_t j = 0 ; j < n ; j++ )
{
for( gtint_t i = 0 ; i < m ; i++ )
{
a[j+i*lda] = value ;
}
}
}
}
template<typename T>
std::vector<T> get_vector( gtint_t n, gtint_t incx, T value )
{
// Create vector for the given sizes.
std::vector<T> x( testinghelpers::buff_dim(n, incx) );
testinghelpers::set_vector( n, incx, x.data(), value );
return x;
}
template<typename T>
std::vector<T> get_matrix( char storage, char trans, gtint_t m, gtint_t n, gtint_t lda, T value )
{
std::vector<T> a( matsize( storage, trans, m, n, lda ) );
testinghelpers::set_matrix<T>( storage, m, n, a.data(), trans, lda, value );
return a;
}
} //end of namespace testinghelpers
// Explicit template instantiations
@@ -425,4 +483,14 @@ template std::vector<dcomplex> testinghelpers::get_random_matrix(int, int, char,
template std::vector<float> testinghelpers::get_random_vector(int, int, gtint_t, gtint_t, char);
template std::vector<double> testinghelpers::get_random_vector(int, int, gtint_t, gtint_t, char);
template std::vector<scomplex> testinghelpers::get_random_vector(int, int, gtint_t, gtint_t, char);
template std::vector<dcomplex> testinghelpers::get_random_vector(int, int, gtint_t, gtint_t, char);
template std::vector<dcomplex> testinghelpers::get_random_vector(int, int, gtint_t, gtint_t, char);
template std::vector<float> testinghelpers::get_vector(int, gtint_t, float);
template std::vector<double> testinghelpers::get_vector(int, gtint_t, double);
template std::vector<scomplex> testinghelpers::get_vector(int, gtint_t, scomplex);
template std::vector<dcomplex> testinghelpers::get_vector(int, gtint_t, dcomplex);
template std::vector<float> testinghelpers::get_matrix( char, char, gtint_t, gtint_t, gtint_t, float );
template std::vector<double> testinghelpers::get_matrix( char, char, gtint_t, gtint_t, gtint_t, double );
template std::vector<scomplex> testinghelpers::get_matrix( char, char, gtint_t, gtint_t, gtint_t, scomplex );
template std::vector<dcomplex> testinghelpers::get_matrix( char, char, gtint_t, gtint_t, gtint_t, dcomplex );