From eab9a77c17802381663df489aa2ba258941ba621 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 21 Dec 2024 22:42:50 +0100 Subject: [PATCH] Rename the local utility function to my_?copy to avoid symbol clash with the BLAS function --- utest/test_extensions/common.c | 518 +++---- utest/test_extensions/common.h | 152 +- utest/test_extensions/test_cimatcopy.c | 1644 ++++++++++----------- utest/test_extensions/test_comatcopy.c | 1400 +++++++++--------- utest/test_extensions/test_dimatcopy.c | 1838 ++++++++++++------------ utest/test_extensions/test_domatcopy.c | 1288 ++++++++--------- utest/test_extensions/test_simatcopy.c | 1838 ++++++++++++------------ utest/test_extensions/test_somatcopy.c | 1288 ++++++++--------- utest/test_extensions/test_zimatcopy.c | 1644 ++++++++++----------- utest/test_extensions/test_zomatcopy.c | 1434 +++++++++--------- 10 files changed, 6522 insertions(+), 6522 deletions(-) diff --git a/utest/test_extensions/common.c b/utest/test_extensions/common.c index 808aa5455..60c944d31 100644 --- a/utest/test_extensions/common.c +++ b/utest/test_extensions/common.c @@ -1,259 +1,259 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "common.h" - -/** - * Generate random array - */ -void srand_generate(float *alpha, blasint n) -{ - blasint i; - for (i = 0; i < n; i++) - alpha[i] = (float)rand() / (float)RAND_MAX; -} - -void drand_generate(double *alpha, blasint n) -{ - blasint i; - for (i = 0; i < n; i++) - alpha[i] = (double)rand() / (double)RAND_MAX; -} - -/** - * Find difference between two rectangle matrix - * return norm of differences - */ -float smatrix_difference(float *a, float *b, blasint cols, blasint rows, blasint ld) -{ - blasint i = 0; - blasint j = 0; - blasint inc = 1; - float norm = 0.0f; - - float *a_ptr = a; - float *b_ptr = b; - - for(i = 0; i < rows; i++) - { - for (j = 0; j < cols; j++) { - a_ptr[j] -= b_ptr[j]; - } - norm += BLASFUNC(snrm2)(&cols, a_ptr, &inc); - - a_ptr += ld; - b_ptr += ld; - } - return norm/(float)(rows); -} - -double dmatrix_difference(double *a, double *b, blasint cols, blasint rows, blasint ld) -{ - blasint i = 0; - blasint j = 0; - blasint inc = 1; - double norm = 0.0; - - double *a_ptr = a; - double *b_ptr = b; - - for(i = 0; i < rows; i++) - { - for (j = 0; j < cols; j++) { - a_ptr[j] -= b_ptr[j]; - } - norm += BLASFUNC(dnrm2)(&cols, a_ptr, &inc); - - a_ptr += ld; - b_ptr += ld; - } - return norm/(double)(rows); -} - -/** - * Complex conjugate operation for vector - * - * param n specifies number of elements in vector x - * param inc_x specifies increment of vector x - * param x_ptr specifies buffer holding vector x - */ -void cconjugate_vector(blasint n, blasint inc_x, float *x_ptr) -{ - blasint i; - inc_x *= 2; - - for (i = 0; i < n; i++) - { - x_ptr[1] *= (-1.0f); - x_ptr += inc_x; - } -} - -void zconjugate_vector(blasint n, blasint inc_x, double *x_ptr) -{ - blasint i; - inc_x *= 2; - - for (i = 0; i < n; i++) - { - x_ptr[1] *= (-1.0); - x_ptr += inc_x; - } -} - -/** - * Transpose matrix - * - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param alpha specifies scaling factor for matrix A - * param a_src - buffer holding input matrix A - * param lda_src - leading dimension of the matrix A - * param a_dst - buffer holding output matrix A - * param lda_dst - leading dimension of output matrix A - */ -void stranspose(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst) -{ - blasint i, j; - for (i = 0; i != cols; i++) - { - for (j = 0; j != rows; j++) - a_dst[i*lda_dst+j] = alpha*a_src[j*lda_src+i]; - } -} - -void dtranspose(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst) -{ - blasint i, j; - for (i = 0; i != cols; i++) - { - for (j = 0; j != rows; j++) - a_dst[i*lda_dst+j] = alpha*a_src[j*lda_src+i]; - } -} - -void ctranspose(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst, int conj) -{ - blasint i, j; - lda_dst *= 2; - lda_src *= 2; - for (i = 0; i != cols*2; i+=2) - { - for (j = 0; j != rows*2; j+=2){ - a_dst[(i/2)*lda_dst+j] = alpha[0] * a_src[(j/2)*lda_src+i] + conj * alpha[1] * a_src[(j/2)*lda_src+i+1]; - a_dst[(i/2)*lda_dst+j+1] = (-1.0f) * conj * alpha[0] * a_src[(j/2)*lda_src+i+1] + alpha[1] * a_src[(j/2)*lda_src+i]; - } - } -} - -void ztranspose(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst, int conj) -{ - blasint i, j; - lda_dst *= 2; - lda_src *= 2; - for (i = 0; i != cols*2; i+=2) - { - for (j = 0; j != rows*2; j+=2){ - a_dst[(i/2)*lda_dst+j] = alpha[0] * a_src[(j/2)*lda_src+i] + conj * alpha[1] * a_src[(j/2)*lda_src+i+1]; - a_dst[(i/2)*lda_dst+j+1] = (-1.0) * conj * alpha[0] * a_src[(j/2)*lda_src+i+1] + alpha[1] * a_src[(j/2)*lda_src+i]; - } - } -} - -/** - * Copy matrix from source A to destination A - * - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param alpha specifies scaling factor for matrix A - * param a_src - buffer holding input matrix A - * param lda_src - leading dimension of the matrix A - * param a_dst - buffer holding output matrix A - * param lda_dst - leading dimension of output matrix A - * param conj specifies conjugation - */ -void scopy(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst) -{ - blasint i, j; - for (i = 0; i != rows; i++) - { - for (j = 0; j != cols; j++) - a_dst[i*lda_dst+j] = alpha*a_src[i*lda_src+j]; - } -} - -void dcopy(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst) -{ - blasint i, j; - for (i = 0; i != rows; i++) - { - for (j = 0; j != cols; j++) - a_dst[i*lda_dst+j] = alpha*a_src[i*lda_src+j]; - } -} - -void ccopy(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst, int conj) -{ - blasint i, j; - lda_dst *= 2; - lda_src *= 2; - for (i = 0; i != rows; i++) - { - for (j = 0; j != cols*2; j+=2){ - a_dst[i*lda_dst+j] = alpha[0] * a_src[i*lda_src+j] + conj * alpha[1] * a_src[i*lda_src+j+1]; - a_dst[i*lda_dst+j+1] = (-1.0f) * conj *alpha[0] * a_src[i*lda_src+j+1] + alpha[1] * a_src[i*lda_src+j]; - } - } -} - -void zcopy(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst, int conj) -{ - blasint i, j; - lda_dst *= 2; - lda_src *= 2; - for (i = 0; i != rows; i++) - { - for (j = 0; j != cols*2; j+=2){ - a_dst[i*lda_dst+j] = alpha[0] * a_src[i*lda_src+j] + conj * alpha[1] * a_src[i*lda_src+j+1]; - a_dst[i*lda_dst+j+1] = (-1.0) * conj *alpha[0] * a_src[i*lda_src+j+1] + alpha[1] * a_src[i*lda_src+j]; - } - } -} +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "common.h" + +/** + * Generate random array + */ +void srand_generate(float *alpha, blasint n) +{ + blasint i; + for (i = 0; i < n; i++) + alpha[i] = (float)rand() / (float)RAND_MAX; +} + +void drand_generate(double *alpha, blasint n) +{ + blasint i; + for (i = 0; i < n; i++) + alpha[i] = (double)rand() / (double)RAND_MAX; +} + +/** + * Find difference between two rectangle matrix + * return norm of differences + */ +float smatrix_difference(float *a, float *b, blasint cols, blasint rows, blasint ld) +{ + blasint i = 0; + blasint j = 0; + blasint inc = 1; + float norm = 0.0f; + + float *a_ptr = a; + float *b_ptr = b; + + for(i = 0; i < rows; i++) + { + for (j = 0; j < cols; j++) { + a_ptr[j] -= b_ptr[j]; + } + norm += BLASFUNC(snrm2)(&cols, a_ptr, &inc); + + a_ptr += ld; + b_ptr += ld; + } + return norm/(float)(rows); +} + +double dmatrix_difference(double *a, double *b, blasint cols, blasint rows, blasint ld) +{ + blasint i = 0; + blasint j = 0; + blasint inc = 1; + double norm = 0.0; + + double *a_ptr = a; + double *b_ptr = b; + + for(i = 0; i < rows; i++) + { + for (j = 0; j < cols; j++) { + a_ptr[j] -= b_ptr[j]; + } + norm += BLASFUNC(dnrm2)(&cols, a_ptr, &inc); + + a_ptr += ld; + b_ptr += ld; + } + return norm/(double)(rows); +} + +/** + * Complex conjugate operation for vector + * + * param n specifies number of elements in vector x + * param inc_x specifies increment of vector x + * param x_ptr specifies buffer holding vector x + */ +void cconjugate_vector(blasint n, blasint inc_x, float *x_ptr) +{ + blasint i; + inc_x *= 2; + + for (i = 0; i < n; i++) + { + x_ptr[1] *= (-1.0f); + x_ptr += inc_x; + } +} + +void zconjugate_vector(blasint n, blasint inc_x, double *x_ptr) +{ + blasint i; + inc_x *= 2; + + for (i = 0; i < n; i++) + { + x_ptr[1] *= (-1.0); + x_ptr += inc_x; + } +} + +/** + * Transpose matrix + * + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param alpha specifies scaling factor for matrix A + * param a_src - buffer holding input matrix A + * param lda_src - leading dimension of the matrix A + * param a_dst - buffer holding output matrix A + * param lda_dst - leading dimension of output matrix A + */ +void stranspose(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst) +{ + blasint i, j; + for (i = 0; i != cols; i++) + { + for (j = 0; j != rows; j++) + a_dst[i*lda_dst+j] = alpha*a_src[j*lda_src+i]; + } +} + +void dtranspose(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst) +{ + blasint i, j; + for (i = 0; i != cols; i++) + { + for (j = 0; j != rows; j++) + a_dst[i*lda_dst+j] = alpha*a_src[j*lda_src+i]; + } +} + +void ctranspose(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst, int conj) +{ + blasint i, j; + lda_dst *= 2; + lda_src *= 2; + for (i = 0; i != cols*2; i+=2) + { + for (j = 0; j != rows*2; j+=2){ + a_dst[(i/2)*lda_dst+j] = alpha[0] * a_src[(j/2)*lda_src+i] + conj * alpha[1] * a_src[(j/2)*lda_src+i+1]; + a_dst[(i/2)*lda_dst+j+1] = (-1.0f) * conj * alpha[0] * a_src[(j/2)*lda_src+i+1] + alpha[1] * a_src[(j/2)*lda_src+i]; + } + } +} + +void ztranspose(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst, int conj) +{ + blasint i, j; + lda_dst *= 2; + lda_src *= 2; + for (i = 0; i != cols*2; i+=2) + { + for (j = 0; j != rows*2; j+=2){ + a_dst[(i/2)*lda_dst+j] = alpha[0] * a_src[(j/2)*lda_src+i] + conj * alpha[1] * a_src[(j/2)*lda_src+i+1]; + a_dst[(i/2)*lda_dst+j+1] = (-1.0) * conj * alpha[0] * a_src[(j/2)*lda_src+i+1] + alpha[1] * a_src[(j/2)*lda_src+i]; + } + } +} + +/** + * Copy matrix from source A to destination A + * + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param alpha specifies scaling factor for matrix A + * param a_src - buffer holding input matrix A + * param lda_src - leading dimension of the matrix A + * param a_dst - buffer holding output matrix A + * param lda_dst - leading dimension of output matrix A + * param conj specifies conjugation + */ +void my_scopy(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst) +{ + blasint i, j; + for (i = 0; i != rows; i++) + { + for (j = 0; j != cols; j++) + a_dst[i*lda_dst+j] = alpha*a_src[i*lda_src+j]; + } +} + +void my_dcopy(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst) +{ + blasint i, j; + for (i = 0; i != rows; i++) + { + for (j = 0; j != cols; j++) + a_dst[i*lda_dst+j] = alpha*a_src[i*lda_src+j]; + } +} + +void my_ccopy(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst, int conj) +{ + blasint i, j; + lda_dst *= 2; + lda_src *= 2; + for (i = 0; i != rows; i++) + { + for (j = 0; j != cols*2; j+=2){ + a_dst[i*lda_dst+j] = alpha[0] * a_src[i*lda_src+j] + conj * alpha[1] * a_src[i*lda_src+j+1]; + a_dst[i*lda_dst+j+1] = (-1.0f) * conj *alpha[0] * a_src[i*lda_src+j+1] + alpha[1] * a_src[i*lda_src+j]; + } + } +} + +void my_zcopy(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst, int conj) +{ + blasint i, j; + lda_dst *= 2; + lda_src *= 2; + for (i = 0; i != rows; i++) + { + for (j = 0; j != cols*2; j+=2){ + a_dst[i*lda_dst+j] = alpha[0] * a_src[i*lda_src+j] + conj * alpha[1] * a_src[i*lda_src+j+1]; + a_dst[i*lda_dst+j+1] = (-1.0) * conj *alpha[0] * a_src[i*lda_src+j+1] + alpha[1] * a_src[i*lda_src+j]; + } + } +} diff --git a/utest/test_extensions/common.h b/utest/test_extensions/common.h index 62b84325c..bd3919de5 100644 --- a/utest/test_extensions/common.h +++ b/utest/test_extensions/common.h @@ -1,76 +1,76 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#ifndef _TEST_EXTENSION_COMMON_H_ -#define _TEST_EXTENSION_COMMON_H_ - -#include -#include - -#define TRUE 1 -#define FALSE 0 -#define INVALID -1 -#define SINGLE_TOL 1e-02f -#define DOUBLE_TOL 1e-10 - -extern int check_error(void); -extern void set_xerbla(char* current_rout, int expected_info); -extern int BLASFUNC(xerbla)(char *name, blasint *info, blasint length); - -extern void srand_generate(float *alpha, blasint n); -extern void drand_generate(double *alpha, blasint n); - -extern float smatrix_difference(float *a, float *b, blasint cols, blasint rows, blasint ld); -extern double dmatrix_difference(double *a, double *b, blasint cols, blasint rows, blasint ld); - -extern void cconjugate_vector(blasint n, blasint inc_x, float *x_ptr); -extern void zconjugate_vector(blasint n, blasint inc_x, double *x_ptr); - -extern void stranspose(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst); -extern void dtranspose(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst); -extern void ctranspose(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst, int conj); -extern void ztranspose(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst, int conj); - -extern void scopy(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst); -extern void dcopy(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst); -extern void ccopy(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, - float *a_dst, blasint lda_dst, int conj); -extern void zcopy(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, - double *a_dst, blasint lda_dst, int conj); -#endif \ No newline at end of file +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#ifndef _TEST_EXTENSION_COMMON_H_ +#define _TEST_EXTENSION_COMMON_H_ + +#include +#include + +#define TRUE 1 +#define FALSE 0 +#define INVALID -1 +#define SINGLE_TOL 1e-02f +#define DOUBLE_TOL 1e-10 + +extern int check_error(void); +extern void set_xerbla(char* current_rout, int expected_info); +extern int BLASFUNC(xerbla)(char *name, blasint *info, blasint length); + +extern void srand_generate(float *alpha, blasint n); +extern void drand_generate(double *alpha, blasint n); + +extern float smatrix_difference(float *a, float *b, blasint cols, blasint rows, blasint ld); +extern double dmatrix_difference(double *a, double *b, blasint cols, blasint rows, blasint ld); + +extern void cconjugate_vector(blasint n, blasint inc_x, float *x_ptr); +extern void zconjugate_vector(blasint n, blasint inc_x, double *x_ptr); + +extern void stranspose(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst); +extern void dtranspose(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst); +extern void ctranspose(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst, int conj); +extern void ztranspose(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst, int conj); + +extern void my_scopy(blasint rows, blasint cols, float alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst); +extern void my_dcopy(blasint rows, blasint cols, double alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst); +extern void my_ccopy(blasint rows, blasint cols, float *alpha, float *a_src, int lda_src, + float *a_dst, blasint lda_dst, int conj); +extern void my_zcopy(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src, + double *a_dst, blasint lda_dst, int conj); +#endif diff --git a/utest/test_extensions/test_cimatcopy.c b/utest/test_extensions/test_cimatcopy.c index 0c96a3b17..5fb6c5e39 100644 --- a/utest/test_extensions/test_cimatcopy.c +++ b/utest/test_extensions/test_cimatcopy.c @@ -1,822 +1,822 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_CIMATCOPY { - float a_test[DATASIZE * DATASIZE * 2]; - float a_verify[DATASIZE * DATASIZE * 2]; -}; - -#ifdef BUILD_COMPLEX -static struct DATA_CIMATCOPY data_cimatcopy; - -/** - * Comapare results computed by cimatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param alpha specifies scaling factor for matrix A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * return norm of difference between openblas and reference func - */ -static float check_cimatcopy(char api, char order, char trans, blasint rows, blasint cols, float *alpha, - blasint lda_src, blasint lda_dst) -{ - blasint m, n; - blasint rows_out, cols_out; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - int conj = -1; - - if (order == 'C') { - n = rows; m = cols; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - rows_out = n; cols_out = m*2; - if (trans == 'C') - conj = 1; - } - else { - rows_out = m; cols_out = n*2; - if (trans == 'R') - conj = 1; - } - - srand_generate(data_cimatcopy.a_test, lda_src*m*2); - - if (trans == 'T' || trans == 'C') { - ctranspose(m, n, alpha, data_cimatcopy.a_test, lda_src, data_cimatcopy.a_verify, lda_dst, conj); - } - else { - ccopy(m, n, alpha, data_cimatcopy.a_test, lda_src, data_cimatcopy.a_verify, lda_dst, conj); - } - - if (api == 'F') { - BLASFUNC(cimatcopy)(&order, &trans, &rows, &cols, alpha, data_cimatcopy.a_test, - &lda_src, &lda_dst); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_cimatcopy(corder, ctrans, rows, cols, alpha, data_cimatcopy.a_test, - lda_src, lda_dst); - } -#endif - - // Find the differences between output matrix computed by cimatcopy and reference func - return smatrix_difference(data_cimatcopy.a_test, data_cimatcopy.a_verify, cols_out, rows_out, 2*lda_dst); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda_src, blasint lda_dst, int expected_info) -{ - float alpha[] = {1.0f, 1.0f}; - - set_xerbla("CIMATCOPY", expected_info); - - BLASFUNC(cimatcopy)(&order, &trans, &rows, &cols, alpha, data_cimatcopy.a_test, - &lda_src, &lda_dst); - - return check_error(); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha_r = -3.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha[] = {-3.0f, 1.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'R'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, colmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'C'; - float alpha[] = {2.0f, 1.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, colmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 50; - char order = 'C'; - char trans = 'N'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific tests - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, colmajor_conjtrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'C'; - float alpha[] = {1.0f, 1.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, colmajor_conj_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 50; - char order = 'C'; - char trans = 'R'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha_r = 2.0, alpha_i = 3.0 - */ -CTEST(cimatcopy, rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha[] = {2.0f, 3.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific tests - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'R'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific tests - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'C'; - float alpha[] = {2.0f, 1.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 50; - char order = 'R'; - char trans = 'N'; - float alpha[] = {2.0f, 1.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, rowmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(cimatcopy, rowmajor_conj_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 50; - char order = 'R'; - char trans = 'R'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, rowmajor_conjtrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'C'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha_r = 3.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, c_api_colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - float alpha[] = {3.0f, 2.0f}; - - float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha_r = 3.0, alpha_i = 1.5 - */ -CTEST(cimatcopy, c_api_colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha[] = {3.0f, 1.5f}; - - float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha_r = 3.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, c_api_rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - float alpha[] = {3.0f, 1.0f}; - - float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, c_api_colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'R'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, c_api_colmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'C'; - float alpha[] = {2.0f, 1.0f}; - - float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha_r = 1.0, alpha_i = 1.0 - */ -CTEST(cimatcopy, c_api_rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha[] = {1.0f, 1.0f}; - - float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(cimatcopy, c_api_rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'R'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test cimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(cimatcopy, c_api_rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'C'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} -#endif - -/** - * Test error function for an invalid param order. - * Must be column (C) or row major (R). - */ -CTEST(cimatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param trans. - * Must be trans (T/C) or no-trans (N/R). - */ -CTEST(cimatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using row major layout, - * lda_src must be at least n. - */ -CTEST(cimatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using column major layout, - * lda_src must be at least m. - */ -CTEST(cimatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is no transposition, lda_dst must be at least n. - */ -CTEST(cimatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is transposition, lda_dst must be at least m. - */ -CTEST(cimatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is no transposition, lda_dst must be at least m. - */ -CTEST(cimatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is transposition, lda_dst must be at least n. - */ -CTEST(cimatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_CIMATCOPY { + float a_test[DATASIZE * DATASIZE * 2]; + float a_verify[DATASIZE * DATASIZE * 2]; +}; + +#ifdef BUILD_COMPLEX +static struct DATA_CIMATCOPY data_cimatcopy; + +/** + * Comapare results computed by cimatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param alpha specifies scaling factor for matrix A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * return norm of difference between openblas and reference func + */ +static float check_cimatcopy(char api, char order, char trans, blasint rows, blasint cols, float *alpha, + blasint lda_src, blasint lda_dst) +{ + blasint m, n; + blasint rows_out, cols_out; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + int conj = -1; + + if (order == 'C') { + n = rows; m = cols; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + rows_out = n; cols_out = m*2; + if (trans == 'C') + conj = 1; + } + else { + rows_out = m; cols_out = n*2; + if (trans == 'R') + conj = 1; + } + + srand_generate(data_cimatcopy.a_test, lda_src*m*2); + + if (trans == 'T' || trans == 'C') { + ctranspose(m, n, alpha, data_cimatcopy.a_test, lda_src, data_cimatcopy.a_verify, lda_dst, conj); + } + else { + my_ccopy(m, n, alpha, data_cimatcopy.a_test, lda_src, data_cimatcopy.a_verify, lda_dst, conj); + } + + if (api == 'F') { + BLASFUNC(cimatcopy)(&order, &trans, &rows, &cols, alpha, data_cimatcopy.a_test, + &lda_src, &lda_dst); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_cimatcopy(corder, ctrans, rows, cols, alpha, data_cimatcopy.a_test, + lda_src, lda_dst); + } +#endif + + // Find the differences between output matrix computed by cimatcopy and reference func + return smatrix_difference(data_cimatcopy.a_test, data_cimatcopy.a_verify, cols_out, rows_out, 2*lda_dst); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda_src, blasint lda_dst, int expected_info) +{ + float alpha[] = {1.0f, 1.0f}; + + set_xerbla("CIMATCOPY", expected_info); + + BLASFUNC(cimatcopy)(&order, &trans, &rows, &cols, alpha, data_cimatcopy.a_test, + &lda_src, &lda_dst); + + return check_error(); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha_r = -3.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha[] = {-3.0f, 1.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'R'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, colmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'C'; + float alpha[] = {2.0f, 1.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, colmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 50; + char order = 'C'; + char trans = 'N'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific tests + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, colmajor_conjtrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'C'; + float alpha[] = {1.0f, 1.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, colmajor_conj_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 50; + char order = 'C'; + char trans = 'R'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha_r = 2.0, alpha_i = 3.0 + */ +CTEST(cimatcopy, rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha[] = {2.0f, 3.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific tests + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'R'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific tests + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'C'; + float alpha[] = {2.0f, 1.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 50; + char order = 'R'; + char trans = 'N'; + float alpha[] = {2.0f, 1.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, rowmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(cimatcopy, rowmajor_conj_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 50; + char order = 'R'; + char trans = 'R'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, rowmajor_conjtrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'C'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha_r = 3.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, c_api_colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + float alpha[] = {3.0f, 2.0f}; + + float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha_r = 3.0, alpha_i = 1.5 + */ +CTEST(cimatcopy, c_api_colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha[] = {3.0f, 1.5f}; + + float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha_r = 3.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, c_api_rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + float alpha[] = {3.0f, 1.0f}; + + float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, c_api_colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'R'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, c_api_colmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'C'; + float alpha[] = {2.0f, 1.0f}; + + float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha_r = 1.0, alpha_i = 1.0 + */ +CTEST(cimatcopy, c_api_rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha[] = {1.0f, 1.0f}; + + float norm = check_cimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(cimatcopy, c_api_rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'R'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test cimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(cimatcopy, c_api_rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'C'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_cimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} +#endif + +/** + * Test error function for an invalid param order. + * Must be column (C) or row major (R). + */ +CTEST(cimatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param trans. + * Must be trans (T/C) or no-trans (N/R). + */ +CTEST(cimatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using row major layout, + * lda_src must be at least n. + */ +CTEST(cimatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using column major layout, + * lda_src must be at least m. + */ +CTEST(cimatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is no transposition, lda_dst must be at least n. + */ +CTEST(cimatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is transposition, lda_dst must be at least m. + */ +CTEST(cimatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is no transposition, lda_dst must be at least m. + */ +CTEST(cimatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is transposition, lda_dst must be at least n. + */ +CTEST(cimatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif diff --git a/utest/test_extensions/test_comatcopy.c b/utest/test_extensions/test_comatcopy.c index b493c93a6..612cfc49e 100644 --- a/utest/test_extensions/test_comatcopy.c +++ b/utest/test_extensions/test_comatcopy.c @@ -1,700 +1,700 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_COMATCOPY { - float a_test[DATASIZE * DATASIZE * 2]; - float b_test[DATASIZE * DATASIZE * 2]; - float b_verify[DATASIZE * DATASIZE * 2]; -}; - -#ifdef BUILD_COMPLEX -static struct DATA_COMATCOPY data_comatcopy; - -/** - * Comapare results computed by comatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param alpha - scaling factor for matrix B - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * return norm of difference between openblas and reference func - */ -static float check_comatcopy(char api, char order, char trans, blasint rows, blasint cols, float* alpha, - blasint lda, blasint ldb) -{ - blasint b_rows, b_cols; - blasint m, n; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - int conj = -1; - - if (order == 'C') { - m = cols; n = rows; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - b_rows = n; b_cols = m*2; - if (trans == 'C') - conj = 1; - } - else { - b_rows = m; b_cols = n*2; - if (trans == 'R') - conj = 1; - } - - srand_generate(data_comatcopy.a_test, lda*m*2); - - if (trans == 'T' || trans == 'C') { - ctranspose(m, n, alpha, data_comatcopy.a_test, lda, data_comatcopy.b_verify, ldb, conj); - } - else { - ccopy(m, n, alpha, data_comatcopy.a_test, lda, data_comatcopy.b_verify, ldb, conj); - } - - if (api == 'F') { - BLASFUNC(comatcopy)(&order, &trans, &rows, &cols, alpha, data_comatcopy.a_test, - &lda, data_comatcopy.b_test, &ldb); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_comatcopy(corder, ctrans, rows, cols, alpha, data_comatcopy.a_test, - lda, data_comatcopy.b_test, ldb); - } -#endif - - return smatrix_difference(data_comatcopy.b_test, data_comatcopy.b_verify, b_cols, b_rows, ldb*2); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda, blasint ldb, int expected_info) -{ - float alpha[] = {1.0f, 1.0f}; - - set_xerbla("COMATCOPY", expected_info); - - BLASFUNC(comatcopy)(&order, &trans, &rows, &cols, alpha, data_comatcopy.a_test, - &lda, data_comatcopy.b_test, &ldb); - - return check_error(); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * alpha_r = -1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - float alpha[] = {-1.0f, 2.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'R'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(comatcopy, colmajor_conjtrnas_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'C'; - float alpha[] = {2.0f, 1.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(comatcopy, rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 50; - char order = 'R'; - char trans = 'N'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(comatcopy, rowmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(comatcopy, rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'R'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'C'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, c_api_colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * alpha_r = -1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, c_api_colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - float alpha[] = {-1.0f, 2.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, c_api_colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'R'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(comatcopy, c_api_colmajor_conjtrnas_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'C'; - float alpha[] = {2.0f, 1.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(comatcopy, c_api_rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 50; - char order = 'R'; - char trans = 'N'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(comatcopy, c_api_rowmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(comatcopy, c_api_rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'R'; - float alpha[] = {1.5f, -1.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test comatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(comatcopy, c_api_rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'C'; - float alpha[] = {1.0f, 2.0f}; - - float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} -#endif - -/** - * Test error function for an invalid param order. - * Must be column (C) or row major (R). - */ -CTEST(comatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param trans. - * Must be trans (T/C) or no-trans (N/R). - */ -CTEST(comatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda. - * If matrices are stored using row major layout, - * lda must be at least n. - */ -CTEST(comatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda. - * If matrices are stored using column major layout, - * lda must be at least m. - */ -CTEST(comatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is no transposition, ldb must be at least n. - */ -CTEST(comatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is transposition, ldb must be at least m. - */ -CTEST(comatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is no transposition, ldb must be at least n. - */ -CTEST(comatcopy, xerbla_rowmajor_conj_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'R'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is transposition, ldb must be at least m. - */ -CTEST(comatcopy, xerbla_rowmajor_transconj_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'C'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is no transposition, ldb must be at least m. - */ -CTEST(comatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is transposition, ldb must be at least n. - */ -CTEST(comatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is no transposition, ldb must be at least m. - */ -CTEST(comatcopy, xerbla_colmajor_conj_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'R'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is transposition, ldb must be at least n. - */ -CTEST(comatcopy, xerbla_colmajor_transconj_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'C'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_COMATCOPY { + float a_test[DATASIZE * DATASIZE * 2]; + float b_test[DATASIZE * DATASIZE * 2]; + float b_verify[DATASIZE * DATASIZE * 2]; +}; + +#ifdef BUILD_COMPLEX +static struct DATA_COMATCOPY data_comatcopy; + +/** + * Comapare results computed by comatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param alpha - scaling factor for matrix B + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * return norm of difference between openblas and reference func + */ +static float check_comatcopy(char api, char order, char trans, blasint rows, blasint cols, float* alpha, + blasint lda, blasint ldb) +{ + blasint b_rows, b_cols; + blasint m, n; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + int conj = -1; + + if (order == 'C') { + m = cols; n = rows; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + b_rows = n; b_cols = m*2; + if (trans == 'C') + conj = 1; + } + else { + b_rows = m; b_cols = n*2; + if (trans == 'R') + conj = 1; + } + + srand_generate(data_comatcopy.a_test, lda*m*2); + + if (trans == 'T' || trans == 'C') { + ctranspose(m, n, alpha, data_comatcopy.a_test, lda, data_comatcopy.b_verify, ldb, conj); + } + else { + my_ccopy(m, n, alpha, data_comatcopy.a_test, lda, data_comatcopy.b_verify, ldb, conj); + } + + if (api == 'F') { + BLASFUNC(comatcopy)(&order, &trans, &rows, &cols, alpha, data_comatcopy.a_test, + &lda, data_comatcopy.b_test, &ldb); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_comatcopy(corder, ctrans, rows, cols, alpha, data_comatcopy.a_test, + lda, data_comatcopy.b_test, ldb); + } +#endif + + return smatrix_difference(data_comatcopy.b_test, data_comatcopy.b_verify, b_cols, b_rows, ldb*2); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda, blasint ldb, int expected_info) +{ + float alpha[] = {1.0f, 1.0f}; + + set_xerbla("COMATCOPY", expected_info); + + BLASFUNC(comatcopy)(&order, &trans, &rows, &cols, alpha, data_comatcopy.a_test, + &lda, data_comatcopy.b_test, &ldb); + + return check_error(); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * alpha_r = -1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + float alpha[] = {-1.0f, 2.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'R'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(comatcopy, colmajor_conjtrnas_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'C'; + float alpha[] = {2.0f, 1.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(comatcopy, rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 50; + char order = 'R'; + char trans = 'N'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(comatcopy, rowmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(comatcopy, rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'R'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'C'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_comatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, c_api_colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * alpha_r = -1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, c_api_colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + float alpha[] = {-1.0f, 2.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, c_api_colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'R'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(comatcopy, c_api_colmajor_conjtrnas_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'C'; + float alpha[] = {2.0f, 1.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(comatcopy, c_api_rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 50; + char order = 'R'; + char trans = 'N'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(comatcopy, c_api_rowmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(comatcopy, c_api_rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'R'; + float alpha[] = {1.5f, -1.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test comatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(comatcopy, c_api_rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'C'; + float alpha[] = {1.0f, 2.0f}; + + float norm = check_comatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} +#endif + +/** + * Test error function for an invalid param order. + * Must be column (C) or row major (R). + */ +CTEST(comatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param trans. + * Must be trans (T/C) or no-trans (N/R). + */ +CTEST(comatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda. + * If matrices are stored using row major layout, + * lda must be at least n. + */ +CTEST(comatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda. + * If matrices are stored using column major layout, + * lda must be at least m. + */ +CTEST(comatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is no transposition, ldb must be at least n. + */ +CTEST(comatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is transposition, ldb must be at least m. + */ +CTEST(comatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is no transposition, ldb must be at least n. + */ +CTEST(comatcopy, xerbla_rowmajor_conj_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'R'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is transposition, ldb must be at least m. + */ +CTEST(comatcopy, xerbla_rowmajor_transconj_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'C'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is no transposition, ldb must be at least m. + */ +CTEST(comatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is transposition, ldb must be at least n. + */ +CTEST(comatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is no transposition, ldb must be at least m. + */ +CTEST(comatcopy, xerbla_colmajor_conj_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'R'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is transposition, ldb must be at least n. + */ +CTEST(comatcopy, xerbla_colmajor_transconj_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'C'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif diff --git a/utest/test_extensions/test_dimatcopy.c b/utest/test_extensions/test_dimatcopy.c index eebb7669e..20c6b761d 100644 --- a/utest/test_extensions/test_dimatcopy.c +++ b/utest/test_extensions/test_dimatcopy.c @@ -1,919 +1,919 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_DIMATCOPY { - double a_test[DATASIZE* DATASIZE]; - double a_verify[DATASIZE* DATASIZE]; -}; - -#ifdef BUILD_DOUBLE -static struct DATA_DIMATCOPY data_dimatcopy; - -/** - * Comapare results computed by dimatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param alpha specifies scaling factor for matrix A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * return norm of difference between openblas and reference func - */ -static double check_dimatcopy(char api, char order, char trans, blasint rows, blasint cols, double alpha, - blasint lda_src, blasint lda_dst) -{ - blasint m, n; - blasint rows_out, cols_out; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - - if (order == 'C') { - n = rows; m = cols; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - rows_out = n; cols_out = m; - } - else { - rows_out = m; cols_out = n; - } - - drand_generate(data_dimatcopy.a_test, lda_src*m); - - if (trans == 'T' || trans == 'C') { - dtranspose(m, n, alpha, data_dimatcopy.a_test, lda_src, data_dimatcopy.a_verify, lda_dst); - } - else { - dcopy(m, n, alpha, data_dimatcopy.a_test, lda_src, data_dimatcopy.a_verify, lda_dst); - } - - if (api == 'F') { - BLASFUNC(dimatcopy)(&order, &trans, &rows, &cols, &alpha, data_dimatcopy.a_test, - &lda_src, &lda_dst); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_dimatcopy(corder, ctrans, rows, cols, alpha, data_dimatcopy.a_test, - lda_src, lda_dst); - } -#endif - - // Find the differences between output matrix computed by dimatcopy and reference func - return dmatrix_difference(data_dimatcopy.a_test, data_dimatcopy.a_verify, cols_out, rows_out, lda_dst); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda_src, blasint lda_dst, int expected_info) -{ - double alpha = 1.0; - - set_xerbla("DIMATCOPY", expected_info); - - BLASFUNC(dimatcopy)(&order, &trans, &rows, &cols, &alpha, data_dimatcopy.a_test, - &lda_src, &lda_dst); - - return check_error(); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, colmajor_trans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, colmajor_notrans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, colmajor_trans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, colmajor_notrans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, colmajor_trans_col_50_row_100_alpha_one) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, colmajor_notrans_col_50_row_100_alpha_one) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, colmajor_trans_col_50_row_100_alpha_zero) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, colmajor_notrans_col_50_row_100_alpha_zero) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, rowmajor_trans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, rowmajor_notrans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, rowmajor_trans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, rowmajor_notrans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, rowmajor_trans_col_100_row_50_alpha_one) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 1.0 - */ -CTEST(dimatcopy, rowmajor_notrans_col_100_row_50_alpha_one) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, rowmajor_trans_col_100_row_50_alpha_zero) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(dimatcopy, rowmajor_notrans_col_100_row_50_alpha_zero) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 0.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, rowmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, rowmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, c_api_colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - double alpha = 2.0; - - double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, c_api_colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, c_api_rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - double alpha = 2.0; - - double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test dimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 2.0 - */ -CTEST(dimatcopy, c_api_rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} -#endif - -/** - * Test error function for an invalid param order. - * Must be column (C) or row major (R). - */ -CTEST(dimatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param trans. - * Must be trans (T/C) or no-trans (N/R). - */ -CTEST(dimatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using row major layout, - * lda_src must be at least n. - */ -CTEST(dimatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using column major layout, - * lda_src must be at least m. - */ -CTEST(dimatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is no transposition, lda_dst must be at least n. - */ -CTEST(dimatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is transposition, lda_dst must be at least m. - */ -CTEST(dimatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is no transposition, lda_dst must be at least m. - */ -CTEST(dimatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is transposition, lda_dst must be at least n. - */ -CTEST(dimatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_DIMATCOPY { + double a_test[DATASIZE* DATASIZE]; + double a_verify[DATASIZE* DATASIZE]; +}; + +#ifdef BUILD_DOUBLE +static struct DATA_DIMATCOPY data_dimatcopy; + +/** + * Comapare results computed by dimatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param alpha specifies scaling factor for matrix A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * return norm of difference between openblas and reference func + */ +static double check_dimatcopy(char api, char order, char trans, blasint rows, blasint cols, double alpha, + blasint lda_src, blasint lda_dst) +{ + blasint m, n; + blasint rows_out, cols_out; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + + if (order == 'C') { + n = rows; m = cols; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + rows_out = n; cols_out = m; + } + else { + rows_out = m; cols_out = n; + } + + drand_generate(data_dimatcopy.a_test, lda_src*m); + + if (trans == 'T' || trans == 'C') { + dtranspose(m, n, alpha, data_dimatcopy.a_test, lda_src, data_dimatcopy.a_verify, lda_dst); + } + else { + my_dcopy(m, n, alpha, data_dimatcopy.a_test, lda_src, data_dimatcopy.a_verify, lda_dst); + } + + if (api == 'F') { + BLASFUNC(dimatcopy)(&order, &trans, &rows, &cols, &alpha, data_dimatcopy.a_test, + &lda_src, &lda_dst); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_dimatcopy(corder, ctrans, rows, cols, alpha, data_dimatcopy.a_test, + lda_src, lda_dst); + } +#endif + + // Find the differences between output matrix computed by dimatcopy and reference func + return dmatrix_difference(data_dimatcopy.a_test, data_dimatcopy.a_verify, cols_out, rows_out, lda_dst); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda_src, blasint lda_dst, int expected_info) +{ + double alpha = 1.0; + + set_xerbla("DIMATCOPY", expected_info); + + BLASFUNC(dimatcopy)(&order, &trans, &rows, &cols, &alpha, data_dimatcopy.a_test, + &lda_src, &lda_dst); + + return check_error(); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, colmajor_trans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, colmajor_notrans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, colmajor_trans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, colmajor_notrans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, colmajor_trans_col_50_row_100_alpha_one) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, colmajor_notrans_col_50_row_100_alpha_one) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, colmajor_trans_col_50_row_100_alpha_zero) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, colmajor_notrans_col_50_row_100_alpha_zero) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, rowmajor_trans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, rowmajor_notrans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, rowmajor_trans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, rowmajor_notrans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, rowmajor_trans_col_100_row_50_alpha_one) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 1.0 + */ +CTEST(dimatcopy, rowmajor_notrans_col_100_row_50_alpha_one) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, rowmajor_trans_col_100_row_50_alpha_zero) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(dimatcopy, rowmajor_notrans_col_100_row_50_alpha_zero) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 0.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, rowmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, rowmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_dimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, c_api_colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + double alpha = 2.0; + + double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, c_api_colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, c_api_rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + double alpha = 2.0; + + double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test dimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 2.0 + */ +CTEST(dimatcopy, c_api_rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_dimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} +#endif + +/** + * Test error function for an invalid param order. + * Must be column (C) or row major (R). + */ +CTEST(dimatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param trans. + * Must be trans (T/C) or no-trans (N/R). + */ +CTEST(dimatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using row major layout, + * lda_src must be at least n. + */ +CTEST(dimatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using column major layout, + * lda_src must be at least m. + */ +CTEST(dimatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is no transposition, lda_dst must be at least n. + */ +CTEST(dimatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is transposition, lda_dst must be at least m. + */ +CTEST(dimatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is no transposition, lda_dst must be at least m. + */ +CTEST(dimatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is transposition, lda_dst must be at least n. + */ +CTEST(dimatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif diff --git a/utest/test_extensions/test_domatcopy.c b/utest/test_extensions/test_domatcopy.c index e892271d2..077393a78 100644 --- a/utest/test_extensions/test_domatcopy.c +++ b/utest/test_extensions/test_domatcopy.c @@ -1,644 +1,644 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_DOMATCOPY { - double a_test[DATASIZE * DATASIZE]; - double b_test[DATASIZE * DATASIZE]; - double b_verify[DATASIZE * DATASIZE]; -}; - -#ifdef BUILD_DOUBLE -static struct DATA_DOMATCOPY data_domatcopy; - -/** - * Comapare results computed by domatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param alpha - scaling factor for matrix B - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * return norm of difference between openblas and reference func - */ -static double check_domatcopy(char api, char order, char trans, blasint rows, blasint cols, double alpha, - blasint lda, blasint ldb) -{ - blasint b_rows, b_cols; - blasint m, n; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - - if (order == 'C') { - m = cols; n = rows; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - b_rows = n; b_cols = m; - } - else { - b_rows = m; b_cols = n; - } - - drand_generate(data_domatcopy.a_test, lda*m); - - if (trans == 'T' || trans == 'C') { - dtranspose(m, n, alpha, data_domatcopy.a_test, lda, data_domatcopy.b_verify, ldb); - } - else { - dcopy(m, n, alpha, data_domatcopy.a_test, lda, data_domatcopy.b_verify, ldb); - } - - if (api == 'F') { - BLASFUNC(domatcopy)(&order, &trans, &rows, &cols, &alpha, data_domatcopy.a_test, - &lda, data_domatcopy.b_test, &ldb); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_domatcopy(corder, ctrans, rows, cols, alpha, data_domatcopy.a_test, - lda, data_domatcopy.b_test, ldb); - } -#endif - - return dmatrix_difference(data_domatcopy.b_test, data_domatcopy.b_verify, b_cols, b_rows, ldb); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda, blasint ldb, int expected_info) -{ - double alpha = 1.0; - - set_xerbla("DOMATCOPY", expected_info); - - BLASFUNC(domatcopy)(&order, &trans, &rows, &cols, &alpha, data_domatcopy.a_test, - &lda, data_domatcopy.b_test, &ldb); - - return check_error(); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'T'; - double alpha = 1.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(domatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - double alpha = 2.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific tests - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(domatcopy, colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(domatcopy, colmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 100; - char order = 'C'; - char trans = 'T'; - double alpha = 0.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(domatcopy, colmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 50; - char order = 'C'; - char trans = 'N'; - double alpha = 0.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'T'; - double alpha = 1.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(domatcopy, rowmajor_conjtrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - double alpha = 2.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(domatcopy, rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 50; - char order = 'R'; - char trans = 'N'; - double alpha = 2.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Matrix dimensions leave residues from 4 and 2 (specialize - * for rt case) - * alpha = 1.5 - */ -CTEST(domatcopy, rowmajor_trans_col_27_row_27) -{ - blasint m = 27, n = 27; - blasint lda = 27, ldb = 27; - char order = 'R'; - char trans = 'T'; - double alpha = 1.5; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(domatcopy, rowmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 0.0; - - double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, c_api_colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'T'; - double alpha = 1.0; - - double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, c_api_colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, c_api_rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'T'; - double alpha = 1.0; - - double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test domatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(domatcopy, c_api_rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'N'; - double alpha = 1.0; - - double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} -#endif - -/** - * Test error function for an invalid param order. - * Must be column (C) or row major (R). - */ -CTEST(domatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param trans. - * Must be trans (T/C) or no-trans (N/R). - */ -CTEST(domatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda. - * If matrices are stored using row major layout, - * lda must be at least n. - */ -CTEST(domatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda. - * If matrices are stored using column major layout, - * lda must be at least m. - */ -CTEST(domatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is no transposition, ldb must be at least n. - */ -CTEST(domatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is transposition, ldb must be at least m. - */ -CTEST(domatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is no transposition, ldb must be at least m. - */ -CTEST(domatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is transposition, ldb must be at least n. - */ -CTEST(domatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_DOMATCOPY { + double a_test[DATASIZE * DATASIZE]; + double b_test[DATASIZE * DATASIZE]; + double b_verify[DATASIZE * DATASIZE]; +}; + +#ifdef BUILD_DOUBLE +static struct DATA_DOMATCOPY data_domatcopy; + +/** + * Comapare results computed by domatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param alpha - scaling factor for matrix B + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * return norm of difference between openblas and reference func + */ +static double check_domatcopy(char api, char order, char trans, blasint rows, blasint cols, double alpha, + blasint lda, blasint ldb) +{ + blasint b_rows, b_cols; + blasint m, n; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + + if (order == 'C') { + m = cols; n = rows; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + b_rows = n; b_cols = m; + } + else { + b_rows = m; b_cols = n; + } + + drand_generate(data_domatcopy.a_test, lda*m); + + if (trans == 'T' || trans == 'C') { + dtranspose(m, n, alpha, data_domatcopy.a_test, lda, data_domatcopy.b_verify, ldb); + } + else { + my_dcopy(m, n, alpha, data_domatcopy.a_test, lda, data_domatcopy.b_verify, ldb); + } + + if (api == 'F') { + BLASFUNC(domatcopy)(&order, &trans, &rows, &cols, &alpha, data_domatcopy.a_test, + &lda, data_domatcopy.b_test, &ldb); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_domatcopy(corder, ctrans, rows, cols, alpha, data_domatcopy.a_test, + lda, data_domatcopy.b_test, ldb); + } +#endif + + return dmatrix_difference(data_domatcopy.b_test, data_domatcopy.b_verify, b_cols, b_rows, ldb); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda, blasint ldb, int expected_info) +{ + double alpha = 1.0; + + set_xerbla("DOMATCOPY", expected_info); + + BLASFUNC(domatcopy)(&order, &trans, &rows, &cols, &alpha, data_domatcopy.a_test, + &lda, data_domatcopy.b_test, &ldb); + + return check_error(); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'T'; + double alpha = 1.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(domatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + double alpha = 2.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific tests + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(domatcopy, colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(domatcopy, colmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 100; + char order = 'C'; + char trans = 'T'; + double alpha = 0.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(domatcopy, colmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 50; + char order = 'C'; + char trans = 'N'; + double alpha = 0.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'T'; + double alpha = 1.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(domatcopy, rowmajor_conjtrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + double alpha = 2.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(domatcopy, rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 50; + char order = 'R'; + char trans = 'N'; + double alpha = 2.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Matrix dimensions leave residues from 4 and 2 (specialize + * for rt case) + * alpha = 1.5 + */ +CTEST(domatcopy, rowmajor_trans_col_27_row_27) +{ + blasint m = 27, n = 27; + blasint lda = 27, ldb = 27; + char order = 'R'; + char trans = 'T'; + double alpha = 1.5; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(domatcopy, rowmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 0.0; + + double norm = check_domatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, c_api_colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'T'; + double alpha = 1.0; + + double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, c_api_colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, c_api_rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'T'; + double alpha = 1.0; + + double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test domatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(domatcopy, c_api_rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'N'; + double alpha = 1.0; + + double norm = check_domatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} +#endif + +/** + * Test error function for an invalid param order. + * Must be column (C) or row major (R). + */ +CTEST(domatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param trans. + * Must be trans (T/C) or no-trans (N/R). + */ +CTEST(domatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda. + * If matrices are stored using row major layout, + * lda must be at least n. + */ +CTEST(domatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda. + * If matrices are stored using column major layout, + * lda must be at least m. + */ +CTEST(domatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is no transposition, ldb must be at least n. + */ +CTEST(domatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is transposition, ldb must be at least m. + */ +CTEST(domatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is no transposition, ldb must be at least m. + */ +CTEST(domatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is transposition, ldb must be at least n. + */ +CTEST(domatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif diff --git a/utest/test_extensions/test_simatcopy.c b/utest/test_extensions/test_simatcopy.c index c00ea0c8f..31d02b05f 100644 --- a/utest/test_extensions/test_simatcopy.c +++ b/utest/test_extensions/test_simatcopy.c @@ -1,919 +1,919 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_SIMATCOPY { - float a_test[DATASIZE* DATASIZE]; - float a_verify[DATASIZE* DATASIZE]; -}; - -#ifdef BUILD_SINGLE -static struct DATA_SIMATCOPY data_simatcopy; - -/** - * Comapare results computed by simatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param alpha specifies scaling factor for matrix A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * return norm of difference between openblas and reference func - */ -static float check_simatcopy(char api, char order, char trans, blasint rows, blasint cols, float alpha, - blasint lda_src, blasint lda_dst) -{ - blasint m, n; - blasint rows_out, cols_out; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - - if (order == 'C') { - n = rows; m = cols; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - rows_out = n; cols_out = m; - } - else { - rows_out = m; cols_out = n; - } - - srand_generate(data_simatcopy.a_test, lda_src*m); - - if (trans == 'T' || trans == 'C') { - stranspose(m, n, alpha, data_simatcopy.a_test, lda_src, data_simatcopy.a_verify, lda_dst); - } - else { - scopy(m, n, alpha, data_simatcopy.a_test, lda_src, data_simatcopy.a_verify, lda_dst); - } - - if (api == 'F') { - BLASFUNC(simatcopy)(&order, &trans, &rows, &cols, &alpha, data_simatcopy.a_test, - &lda_src, &lda_dst); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_simatcopy(corder, ctrans, rows, cols, alpha, data_simatcopy.a_test, - lda_src, lda_dst); - } -#endif - - // Find the differences between output matrix computed by simatcopy and reference func - return smatrix_difference(data_simatcopy.a_test, data_simatcopy.a_verify, cols_out, rows_out, lda_dst); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda_src, blasint lda_dst, int expected_info) -{ - float alpha = 1.0f; - - set_xerbla("SIMATCOPY", expected_info); - - BLASFUNC(simatcopy)(&order, &trans, &rows, &cols, &alpha, data_simatcopy.a_test, - &lda_src, &lda_dst); - - return check_error(); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 1.0f - */ -CTEST(simatcopy, colmajor_trans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 1.0f - */ -CTEST(simatcopy, colmajor_notrans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 0.0f - */ -CTEST(simatcopy, colmajor_trans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 0.0f - */ -CTEST(simatcopy, colmajor_notrans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 1.0f - */ -CTEST(simatcopy, colmajor_trans_col_50_row_100_alpha_one) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 1.0f - */ -CTEST(simatcopy, colmajor_notrans_col_50_row_100_alpha_one) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 0.0f - */ -CTEST(simatcopy, colmajor_trans_col_50_row_100_alpha_zero) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 0.0f - */ -CTEST(simatcopy, colmajor_notrans_col_50_row_100_alpha_zero) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 2.0f - */ -CTEST(simatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 2.0f - */ -CTEST(simatcopy, colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 1.0f - */ -CTEST(simatcopy, rowmajor_trans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 1.0f - */ -CTEST(simatcopy, rowmajor_notrans_col_100_row_100_alpha_one) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 0.0f - */ -CTEST(simatcopy, rowmajor_trans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 0.0f - */ -CTEST(simatcopy, rowmajor_notrans_col_100_row_100_alpha_zero) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific tests - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 1.0f - */ -CTEST(simatcopy, rowmajor_trans_col_100_row_50_alpha_one) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 1.0f - */ -CTEST(simatcopy, rowmajor_notrans_col_100_row_50_alpha_one) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 0.0f - */ -CTEST(simatcopy, rowmajor_trans_col_100_row_50_alpha_zero) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 0.0f - */ -CTEST(simatcopy, rowmajor_notrans_col_100_row_50_alpha_zero) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 0.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 2.0f - */ -CTEST(simatcopy, rowmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 2.0f - */ -CTEST(simatcopy, rowmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, c_api_colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - float alpha = 2.0f; - - float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, c_api_colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, c_api_rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - float alpha = 2.0f; - - float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test simatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 2.0f - */ -CTEST(simatcopy, c_api_rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} -#endif - -/** - * Test error function for an invalid param order. - * Must be column (C) or row major (R). - */ -CTEST(simatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param trans. - * Must be trans (T/C) or no-trans (N/R). - */ -CTEST(simatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using row major layout, - * lda_src must be at least n. - */ -CTEST(simatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using column major layout, - * lda_src must be at least m. - */ -CTEST(simatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is no transposition, lda_dst must be at least n. - */ -CTEST(simatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is transposition, lda_dst must be at least m. - */ -CTEST(simatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is no transposition, lda_dst must be at least m. - */ -CTEST(simatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is transposition, lda_dst must be at least n. - */ -CTEST(simatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 8; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_SIMATCOPY { + float a_test[DATASIZE* DATASIZE]; + float a_verify[DATASIZE* DATASIZE]; +}; + +#ifdef BUILD_SINGLE +static struct DATA_SIMATCOPY data_simatcopy; + +/** + * Comapare results computed by simatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param alpha specifies scaling factor for matrix A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * return norm of difference between openblas and reference func + */ +static float check_simatcopy(char api, char order, char trans, blasint rows, blasint cols, float alpha, + blasint lda_src, blasint lda_dst) +{ + blasint m, n; + blasint rows_out, cols_out; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + + if (order == 'C') { + n = rows; m = cols; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + rows_out = n; cols_out = m; + } + else { + rows_out = m; cols_out = n; + } + + srand_generate(data_simatcopy.a_test, lda_src*m); + + if (trans == 'T' || trans == 'C') { + stranspose(m, n, alpha, data_simatcopy.a_test, lda_src, data_simatcopy.a_verify, lda_dst); + } + else { + my_scopy(m, n, alpha, data_simatcopy.a_test, lda_src, data_simatcopy.a_verify, lda_dst); + } + + if (api == 'F') { + BLASFUNC(simatcopy)(&order, &trans, &rows, &cols, &alpha, data_simatcopy.a_test, + &lda_src, &lda_dst); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_simatcopy(corder, ctrans, rows, cols, alpha, data_simatcopy.a_test, + lda_src, lda_dst); + } +#endif + + // Find the differences between output matrix computed by simatcopy and reference func + return smatrix_difference(data_simatcopy.a_test, data_simatcopy.a_verify, cols_out, rows_out, lda_dst); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda_src, blasint lda_dst, int expected_info) +{ + float alpha = 1.0f; + + set_xerbla("SIMATCOPY", expected_info); + + BLASFUNC(simatcopy)(&order, &trans, &rows, &cols, &alpha, data_simatcopy.a_test, + &lda_src, &lda_dst); + + return check_error(); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 1.0f + */ +CTEST(simatcopy, colmajor_trans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 1.0f + */ +CTEST(simatcopy, colmajor_notrans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 0.0f + */ +CTEST(simatcopy, colmajor_trans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 0.0f + */ +CTEST(simatcopy, colmajor_notrans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 1.0f + */ +CTEST(simatcopy, colmajor_trans_col_50_row_100_alpha_one) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 1.0f + */ +CTEST(simatcopy, colmajor_notrans_col_50_row_100_alpha_one) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 0.0f + */ +CTEST(simatcopy, colmajor_trans_col_50_row_100_alpha_zero) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 0.0f + */ +CTEST(simatcopy, colmajor_notrans_col_50_row_100_alpha_zero) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 2.0f + */ +CTEST(simatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 2.0f + */ +CTEST(simatcopy, colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 1.0f + */ +CTEST(simatcopy, rowmajor_trans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 1.0f + */ +CTEST(simatcopy, rowmajor_notrans_col_100_row_100_alpha_one) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 0.0f + */ +CTEST(simatcopy, rowmajor_trans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 0.0f + */ +CTEST(simatcopy, rowmajor_notrans_col_100_row_100_alpha_zero) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific tests + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 1.0f + */ +CTEST(simatcopy, rowmajor_trans_col_100_row_50_alpha_one) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 1.0f + */ +CTEST(simatcopy, rowmajor_notrans_col_100_row_50_alpha_one) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 0.0f + */ +CTEST(simatcopy, rowmajor_trans_col_100_row_50_alpha_zero) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 0.0f + */ +CTEST(simatcopy, rowmajor_notrans_col_100_row_50_alpha_zero) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 0.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 2.0f + */ +CTEST(simatcopy, rowmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 2.0f + */ +CTEST(simatcopy, rowmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_simatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, c_api_colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + float alpha = 2.0f; + + float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, c_api_colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, c_api_rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + float alpha = 2.0f; + + float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test simatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 2.0f + */ +CTEST(simatcopy, c_api_rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_simatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} +#endif + +/** + * Test error function for an invalid param order. + * Must be column (C) or row major (R). + */ +CTEST(simatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param trans. + * Must be trans (T/C) or no-trans (N/R). + */ +CTEST(simatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using row major layout, + * lda_src must be at least n. + */ +CTEST(simatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using column major layout, + * lda_src must be at least m. + */ +CTEST(simatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is no transposition, lda_dst must be at least n. + */ +CTEST(simatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is transposition, lda_dst must be at least m. + */ +CTEST(simatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is no transposition, lda_dst must be at least m. + */ +CTEST(simatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is transposition, lda_dst must be at least n. + */ +CTEST(simatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 8; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif diff --git a/utest/test_extensions/test_somatcopy.c b/utest/test_extensions/test_somatcopy.c index 62a6056d9..29ca3efd8 100644 --- a/utest/test_extensions/test_somatcopy.c +++ b/utest/test_extensions/test_somatcopy.c @@ -1,644 +1,644 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_SOMATCOPY { - float a_test[DATASIZE * DATASIZE]; - float b_test[DATASIZE * DATASIZE]; - float b_verify[DATASIZE * DATASIZE]; -}; - -#ifdef BUILD_SINGLE -static struct DATA_SOMATCOPY data_somatcopy; - -/** - * Comapare results computed by somatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param alpha - scaling factor for matrix B - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * return norm of difference between openblas and reference func - */ -static float check_somatcopy(char api, char order, char trans, blasint rows, blasint cols, float alpha, - blasint lda, blasint ldb) -{ - blasint b_rows, b_cols; - blasint m, n; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - - if (order == 'C') { - m = cols; n = rows; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - b_rows = n; b_cols = m; - } - else { - b_rows = m; b_cols = n; - } - - srand_generate(data_somatcopy.a_test, lda*m); - - if (trans == 'T' || trans == 'C') { - stranspose(m, n, alpha, data_somatcopy.a_test, lda, data_somatcopy.b_verify, ldb); - } - else { - scopy(m, n, alpha, data_somatcopy.a_test, lda, data_somatcopy.b_verify, ldb); - } - - if (api == 'F') { - BLASFUNC(somatcopy)(&order, &trans, &rows, &cols, &alpha, data_somatcopy.a_test, - &lda, data_somatcopy.b_test, &ldb); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_somatcopy(corder, ctrans, rows, cols, alpha, data_somatcopy.a_test, - lda, data_somatcopy.b_test, ldb); - } -#endif - - return smatrix_difference(data_somatcopy.b_test, data_somatcopy.b_verify, b_cols, b_rows, ldb); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda, blasint ldb, int expected_info) -{ - float alpha = 1.0; - - set_xerbla("SOMATCOPY", expected_info); - - BLASFUNC(somatcopy)(&order, &trans, &rows, &cols, &alpha, data_somatcopy.a_test, - &lda, data_somatcopy.b_test, &ldb); - - return check_error(); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'T'; - float alpha = 1.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(somatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - float alpha = 2.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(somatcopy, colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(somatcopy, colmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 100; - char order = 'C'; - char trans = 'T'; - float alpha = 0.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(somatcopy, colmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 50; - char order = 'C'; - char trans = 'N'; - float alpha = 0.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'T'; - float alpha = 1.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(somatcopy, rowmajor_conjtrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'C'; // same as trans for real matrix - float alpha = 2.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 2.0 - */ -CTEST(somatcopy, rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 50; - char order = 'R'; - char trans = 'N'; - float alpha = 2.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Matrix dimensions leave residues from 4 and 2 (specialize - * for rt case) - * alpha = 1.5 - */ -CTEST(somatcopy, rowmajor_trans_col_27_row_27) -{ - blasint m = 27, n = 27; - blasint lda = 27, ldb = 27; - char order = 'R'; - char trans = 'T'; - float alpha = 1.5f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * Fortran API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha = 0.0 - */ -CTEST(somatcopy, rowmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 0.0f; - - float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, c_api_colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'T'; - float alpha = 1.0f; - - float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, c_api_colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, c_api_rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'T'; - float alpha = 1.0f; - - float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} - -/** - * C API specific test - * Test somatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha = 1.0 - */ -CTEST(somatcopy, c_api_rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'N'; - float alpha = 1.0f; - - float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); -} -#endif - -/** - * Test error function for an invalid param order. - * Must be column (C) or row major (R). - */ -CTEST(somatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param trans. - * Must be trans (T/C) or no-trans (N/R). - */ -CTEST(somatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda. - * If matrices are stored using row major layout, - * lda must be at least n. - */ -CTEST(somatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda. - * If matrices are stored using column major layout, - * lda must be at least m. - */ -CTEST(somatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is no transposition, ldb must be at least n. - */ -CTEST(somatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using row major layout and - * there is transposition, ldb must be at least m. - */ -CTEST(somatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is no transposition, ldb must be at least m. - */ -CTEST(somatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param ldb. - * If matrices are stored using column major layout and - * there is transposition, ldb must be at least n. - */ -CTEST(somatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_SOMATCOPY { + float a_test[DATASIZE * DATASIZE]; + float b_test[DATASIZE * DATASIZE]; + float b_verify[DATASIZE * DATASIZE]; +}; + +#ifdef BUILD_SINGLE +static struct DATA_SOMATCOPY data_somatcopy; + +/** + * Comapare results computed by somatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param alpha - scaling factor for matrix B + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * return norm of difference between openblas and reference func + */ +static float check_somatcopy(char api, char order, char trans, blasint rows, blasint cols, float alpha, + blasint lda, blasint ldb) +{ + blasint b_rows, b_cols; + blasint m, n; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + + if (order == 'C') { + m = cols; n = rows; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + b_rows = n; b_cols = m; + } + else { + b_rows = m; b_cols = n; + } + + srand_generate(data_somatcopy.a_test, lda*m); + + if (trans == 'T' || trans == 'C') { + stranspose(m, n, alpha, data_somatcopy.a_test, lda, data_somatcopy.b_verify, ldb); + } + else { + my_scopy(m, n, alpha, data_somatcopy.a_test, lda, data_somatcopy.b_verify, ldb); + } + + if (api == 'F') { + BLASFUNC(somatcopy)(&order, &trans, &rows, &cols, &alpha, data_somatcopy.a_test, + &lda, data_somatcopy.b_test, &ldb); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_somatcopy(corder, ctrans, rows, cols, alpha, data_somatcopy.a_test, + lda, data_somatcopy.b_test, ldb); + } +#endif + + return smatrix_difference(data_somatcopy.b_test, data_somatcopy.b_verify, b_cols, b_rows, ldb); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda, blasint ldb, int expected_info) +{ + float alpha = 1.0; + + set_xerbla("SOMATCOPY", expected_info); + + BLASFUNC(somatcopy)(&order, &trans, &rows, &cols, &alpha, data_somatcopy.a_test, + &lda, data_somatcopy.b_test, &ldb); + + return check_error(); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'T'; + float alpha = 1.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(somatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + float alpha = 2.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(somatcopy, colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(somatcopy, colmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 100; + char order = 'C'; + char trans = 'T'; + float alpha = 0.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(somatcopy, colmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 50; + char order = 'C'; + char trans = 'N'; + float alpha = 0.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'T'; + float alpha = 1.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(somatcopy, rowmajor_conjtrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'C'; // same as trans for real matrix + float alpha = 2.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 2.0 + */ +CTEST(somatcopy, rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 50; + char order = 'R'; + char trans = 'N'; + float alpha = 2.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Matrix dimensions leave residues from 4 and 2 (specialize + * for rt case) + * alpha = 1.5 + */ +CTEST(somatcopy, rowmajor_trans_col_27_row_27) +{ + blasint m = 27, n = 27; + blasint lda = 27, ldb = 27; + char order = 'R'; + char trans = 'T'; + float alpha = 1.5f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * Fortran API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha = 0.0 + */ +CTEST(somatcopy, rowmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 0.0f; + + float norm = check_somatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, c_api_colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'T'; + float alpha = 1.0f; + + float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, c_api_colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, c_api_rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'T'; + float alpha = 1.0f; + + float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} + +/** + * C API specific test + * Test somatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha = 1.0 + */ +CTEST(somatcopy, c_api_rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'N'; + float alpha = 1.0f; + + float norm = check_somatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS); +} +#endif + +/** + * Test error function for an invalid param order. + * Must be column (C) or row major (R). + */ +CTEST(somatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param trans. + * Must be trans (T/C) or no-trans (N/R). + */ +CTEST(somatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda. + * If matrices are stored using row major layout, + * lda must be at least n. + */ +CTEST(somatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda. + * If matrices are stored using column major layout, + * lda must be at least m. + */ +CTEST(somatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is no transposition, ldb must be at least n. + */ +CTEST(somatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using row major layout and + * there is transposition, ldb must be at least m. + */ +CTEST(somatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is no transposition, ldb must be at least m. + */ +CTEST(somatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param ldb. + * If matrices are stored using column major layout and + * there is transposition, ldb must be at least n. + */ +CTEST(somatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif diff --git a/utest/test_extensions/test_zimatcopy.c b/utest/test_extensions/test_zimatcopy.c index 86bc4670f..644b9ce8c 100644 --- a/utest/test_extensions/test_zimatcopy.c +++ b/utest/test_extensions/test_zimatcopy.c @@ -1,822 +1,822 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_ZIMATCOPY { - double a_test[DATASIZE * DATASIZE * 2]; - double a_verify[DATASIZE * DATASIZE * 2]; -}; - -#ifdef BUILD_COMPLEX16 -static struct DATA_ZIMATCOPY data_zimatcopy; - -/** - * Comapare results computed by zimatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param alpha specifies scaling factor for matrix A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * return norm of difference between openblas and reference func - */ -static double check_zimatcopy(char api, char order, char trans, blasint rows, blasint cols, double *alpha, - blasint lda_src, blasint lda_dst) -{ - blasint m, n; - blasint rows_out, cols_out; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - int conj = -1; - - if (order == 'C') { - n = rows; m = cols; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - rows_out = n; cols_out = m*2; - if (trans == 'C') - conj = 1; - } - else { - rows_out = m; cols_out = n*2; - if (trans == 'R') - conj = 1; - } - - drand_generate(data_zimatcopy.a_test, lda_src*m*2); - - if (trans == 'T' || trans == 'C') { - ztranspose(m, n, alpha, data_zimatcopy.a_test, lda_src, data_zimatcopy.a_verify, lda_dst, conj); - } - else { - zcopy(m, n, alpha, data_zimatcopy.a_test, lda_src, data_zimatcopy.a_verify, lda_dst, conj); - } - - if (api == 'F') { - BLASFUNC(zimatcopy)(&order, &trans, &rows, &cols, alpha, data_zimatcopy.a_test, - &lda_src, &lda_dst); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_zimatcopy(corder, ctrans, rows, cols, alpha, data_zimatcopy.a_test, - lda_src, lda_dst); - } -#endif - - // Find the differences between output matrix computed by zimatcopy and reference func - return dmatrix_difference(data_zimatcopy.a_test, data_zimatcopy.a_verify, cols_out, rows_out, lda_dst*2); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows specifies number of rows of A - * param cols specifies number of columns of A - * param lda_src - leading dimension of the matrix A - * param lda_dst - leading dimension of output matrix A - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda_src, blasint lda_dst, int expected_info) -{ - double alpha[] = {1.0, 1.0}; - - set_xerbla("ZIMATCOPY", expected_info); - - BLASFUNC(zimatcopy)(&order, &trans, &rows, &cols, alpha, data_zimatcopy.a_test, - &lda_src, &lda_dst); - - return check_error(); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha_r = -3.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha[] = {-3.0, 1.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'R'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, colmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'C'; - double alpha[] = {2.0, 1.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, colmajor_notrans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 50; - char order = 'C'; - char trans = 'N'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, colmajor_conjtrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'C'; - double alpha[] = {1.0, 1.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, colmajor_conj_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 50; - char order = 'C'; - char trans = 'R'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha_r = 2.0, alpha_i = 3.0 - */ -CTEST(zimatcopy, rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha[] = {2.0, 3.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'R'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'C'; - double alpha[] = {2.0, 1.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Rectangular matrix - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 50; - char order = 'R'; - char trans = 'N'; - double alpha[] = {2.0, 1.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Rectangular matrix - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, rowmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zimatcopy, rowmajor_conj_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 50; - char order = 'R'; - char trans = 'R'; - double alpha[] = {1.5, -1.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, rowmajor_conjtrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'C'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition - * Square matrix - * alpha_r = 3.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, c_api_colmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - double alpha[] = {3.0, 2.0}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy only - * Square matrix - * alpha_r = 3.0, alpha_i = 1.5 - */ -CTEST(zimatcopy, c_api_colmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'N'; - double alpha[] = {3.0, 1.5}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition - * Square matrix - * alpha_r = 3.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, c_api_rowmajor_trans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - double alpha[] = {3.0, 1.0}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, c_api_colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'R'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, c_api_colmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'C'; - double alpha[] = {2.0, 1.0}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy only - * Square matrix - * alpha_r = 1.0, alpha_i = 1.0 - */ -CTEST(zimatcopy, c_api_rowmajor_notrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'N'; - double alpha[] = {1.0, 1.0}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zimatcopy, c_api_rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'R'; - double alpha[] = {1.5, -1.0}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zimatcopy by comparing it against reference - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zimatcopy, c_api_rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'R'; - char trans = 'C'; - double alpha[] = {1.0, 2.0}; - - double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} -#endif - -/** - * Test error function for an invalid param order. - * Must be column (C) or row major (R). - */ -CTEST(zimatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param trans. - * Must be trans (T/C) or no-trans (N/R). - */ -CTEST(zimatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda_src = 100, lda_dst = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using row major layout, - * lda_src must be at least n. - */ -CTEST(zimatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda_src = 50, lda_dst = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_src. - * If matrices are stored using column major layout, - * lda_src must be at least m. - */ -CTEST(zimatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda_src = 50, lda_dst = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is no transposition, lda_dst must be at least n. - */ -CTEST(zimatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using row major layout and - * there is transposition, lda_dst must be at least m. - */ -CTEST(zimatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is no transposition, lda_dst must be at least m. - */ -CTEST(zimatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** - * Test error function for an invalid param lda_dst. - * If matrices are stored using column major layout and - * there is transposition, lda_dst must be at least n. - */ -CTEST(zimatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda_src = 100, lda_dst = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_ZIMATCOPY { + double a_test[DATASIZE * DATASIZE * 2]; + double a_verify[DATASIZE * DATASIZE * 2]; +}; + +#ifdef BUILD_COMPLEX16 +static struct DATA_ZIMATCOPY data_zimatcopy; + +/** + * Comapare results computed by zimatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param alpha specifies scaling factor for matrix A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * return norm of difference between openblas and reference func + */ +static double check_zimatcopy(char api, char order, char trans, blasint rows, blasint cols, double *alpha, + blasint lda_src, blasint lda_dst) +{ + blasint m, n; + blasint rows_out, cols_out; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + int conj = -1; + + if (order == 'C') { + n = rows; m = cols; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + rows_out = n; cols_out = m*2; + if (trans == 'C') + conj = 1; + } + else { + rows_out = m; cols_out = n*2; + if (trans == 'R') + conj = 1; + } + + drand_generate(data_zimatcopy.a_test, lda_src*m*2); + + if (trans == 'T' || trans == 'C') { + ztranspose(m, n, alpha, data_zimatcopy.a_test, lda_src, data_zimatcopy.a_verify, lda_dst, conj); + } + else { + my_zcopy(m, n, alpha, data_zimatcopy.a_test, lda_src, data_zimatcopy.a_verify, lda_dst, conj); + } + + if (api == 'F') { + BLASFUNC(zimatcopy)(&order, &trans, &rows, &cols, alpha, data_zimatcopy.a_test, + &lda_src, &lda_dst); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_zimatcopy(corder, ctrans, rows, cols, alpha, data_zimatcopy.a_test, + lda_src, lda_dst); + } +#endif + + // Find the differences between output matrix computed by zimatcopy and reference func + return dmatrix_difference(data_zimatcopy.a_test, data_zimatcopy.a_verify, cols_out, rows_out, lda_dst*2); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows specifies number of rows of A + * param cols specifies number of columns of A + * param lda_src - leading dimension of the matrix A + * param lda_dst - leading dimension of output matrix A + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda_src, blasint lda_dst, int expected_info) +{ + double alpha[] = {1.0, 1.0}; + + set_xerbla("ZIMATCOPY", expected_info); + + BLASFUNC(zimatcopy)(&order, &trans, &rows, &cols, alpha, data_zimatcopy.a_test, + &lda_src, &lda_dst); + + return check_error(); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha_r = -3.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha[] = {-3.0, 1.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'R'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, colmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'C'; + double alpha[] = {2.0, 1.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, colmajor_notrans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 50; + char order = 'C'; + char trans = 'N'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, colmajor_conjtrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'C'; + double alpha[] = {1.0, 1.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, colmajor_conj_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 50; + char order = 'C'; + char trans = 'R'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha_r = 2.0, alpha_i = 3.0 + */ +CTEST(zimatcopy, rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha[] = {2.0, 3.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'R'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'C'; + double alpha[] = {2.0, 1.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Rectangular matrix + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 50; + char order = 'R'; + char trans = 'N'; + double alpha[] = {2.0, 1.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Rectangular matrix + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, rowmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zimatcopy, rowmajor_conj_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 50; + char order = 'R'; + char trans = 'R'; + double alpha[] = {1.5, -1.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, rowmajor_conjtrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'C'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('F', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition + * Square matrix + * alpha_r = 3.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, c_api_colmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + double alpha[] = {3.0, 2.0}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy only + * Square matrix + * alpha_r = 3.0, alpha_i = 1.5 + */ +CTEST(zimatcopy, c_api_colmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'N'; + double alpha[] = {3.0, 1.5}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition + * Square matrix + * alpha_r = 3.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, c_api_rowmajor_trans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + double alpha[] = {3.0, 1.0}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, c_api_colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'R'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, c_api_colmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'C'; + double alpha[] = {2.0, 1.0}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy only + * Square matrix + * alpha_r = 1.0, alpha_i = 1.0 + */ +CTEST(zimatcopy, c_api_rowmajor_notrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'N'; + double alpha[] = {1.0, 1.0}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zimatcopy, c_api_rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'R'; + double alpha[] = {1.5, -1.0}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zimatcopy by comparing it against reference + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zimatcopy, c_api_rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'R'; + char trans = 'C'; + double alpha[] = {1.0, 2.0}; + + double norm = check_zimatcopy('C', order, trans, m, n, alpha, lda_src, lda_dst); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} +#endif + +/** + * Test error function for an invalid param order. + * Must be column (C) or row major (R). + */ +CTEST(zimatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param trans. + * Must be trans (T/C) or no-trans (N/R). + */ +CTEST(zimatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda_src = 100, lda_dst = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using row major layout, + * lda_src must be at least n. + */ +CTEST(zimatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda_src = 50, lda_dst = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_src. + * If matrices are stored using column major layout, + * lda_src must be at least m. + */ +CTEST(zimatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda_src = 50, lda_dst = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is no transposition, lda_dst must be at least n. + */ +CTEST(zimatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using row major layout and + * there is transposition, lda_dst must be at least m. + */ +CTEST(zimatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is no transposition, lda_dst must be at least m. + */ +CTEST(zimatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** + * Test error function for an invalid param lda_dst. + * If matrices are stored using column major layout and + * there is transposition, lda_dst must be at least n. + */ +CTEST(zimatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda_src = 100, lda_dst = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif diff --git a/utest/test_extensions/test_zomatcopy.c b/utest/test_extensions/test_zomatcopy.c index 208cfd981..8b2c2b89f 100644 --- a/utest/test_extensions/test_zomatcopy.c +++ b/utest/test_extensions/test_zomatcopy.c @@ -1,717 +1,717 @@ -/***************************************************************************** -Copyright (c) 2023, The OpenBLAS Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. Neither the name of the OpenBLAS project nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -**********************************************************************************/ - -#include "utest/openblas_utest.h" -#include "common.h" - -#define DATASIZE 100 - -struct DATA_ZOMATCOPY { - double a_test[DATASIZE * DATASIZE * 2]; - double b_test[DATASIZE * DATASIZE * 2]; - double b_verify[DATASIZE * DATASIZE * 2]; -}; - -#ifdef BUILD_COMPLEX16 -static struct DATA_ZOMATCOPY data_zomatcopy; - -/** - * Comapare results computed by zomatcopy and reference func - * - * param api specifies tested api (C or Fortran) - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param alpha - scaling factor for matrix B - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * return norm of difference between openblas and reference func - */ -static double check_zomatcopy(char api, char order, char trans, blasint rows, blasint cols, double* alpha, - blasint lda, blasint ldb) -{ - blasint b_rows, b_cols; - blasint m, n; - enum CBLAS_ORDER corder; - enum CBLAS_TRANSPOSE ctrans; - int conj = -1; - - if (order == 'C') { - m = cols; n = rows; - } - else { - m = rows; n = cols; - } - - if(trans == 'T' || trans == 'C') { - b_rows = n; b_cols = m*2; - if (trans == 'C') - conj = 1; - } - else { - b_rows = m; b_cols = n*2; - if (trans == 'R') - conj = 1; - } - - drand_generate(data_zomatcopy.a_test, lda*m*2); - - if (trans == 'T' || trans == 'C') { - ztranspose(m, n, alpha, data_zomatcopy.a_test, lda, data_zomatcopy.b_verify, ldb, conj); - } - else { - zcopy(m, n, alpha, data_zomatcopy.a_test, lda, data_zomatcopy.b_verify, ldb, conj); - } - - if (api == 'F') { - BLASFUNC(zomatcopy)(&order, &trans, &rows, &cols, alpha, data_zomatcopy.a_test, - &lda, data_zomatcopy.b_test, &ldb); - } -#ifndef NO_CBLAS - else { - if (order == 'C') corder = CblasColMajor; - if (order == 'R') corder = CblasRowMajor; - if (trans == 'T') ctrans = CblasTrans; - if (trans == 'N') ctrans = CblasNoTrans; - if (trans == 'C') ctrans = CblasConjTrans; - if (trans == 'R') ctrans = CblasConjNoTrans; - cblas_zomatcopy(corder, ctrans, rows, cols, alpha, data_zomatcopy.a_test, - lda, data_zomatcopy.b_test, ldb); - } -#endif - - return dmatrix_difference(data_zomatcopy.b_test, data_zomatcopy.b_verify, b_cols, b_rows, ldb*2); -} - -/** - * Check if error function was called with expected function name - * and param info - * - * param order specifies row or column major order - * param trans specifies op(A), the transposition operation - * applied to the matrix A - * param rows - number of rows of A - * param cols - number of columns of A - * param lda - leading dimension of the matrix A - * param ldb - leading dimension of the matrix B - * param expected_info - expected invalid parameter number - * return TRUE if everything is ok, otherwise FALSE - */ -static int check_badargs(char order, char trans, blasint rows, blasint cols, - blasint lda, blasint ldb, int expected_info) -{ - double alpha[] = {1.0, 1.0}; - - set_xerbla("ZOMATCOPY", expected_info); - - BLASFUNC(zomatcopy)(&order, &trans, &rows, &cols, alpha, data_zomatcopy.a_test, - &lda, data_zomatcopy.b_test, &ldb); - - return check_error(); -} - -/** - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - double alpha[] = {1.0, 2.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * alpha_r = -1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - double alpha[] = {-1.0, 2.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'R'; - double alpha[] = {1.0, 2.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(zomatcopy, colmajor_conjtrnas_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'C'; - double alpha[] = {2.0, 1.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zomatcopy, rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 50; - char order = 'R'; - char trans = 'N'; - double alpha[] = {1.5, -1.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zomatcopy, rowmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - double alpha[] = {1.5, -1.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zomatcopy, rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'R'; - double alpha[] = {1.5, -1.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * Fortran API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'C'; - double alpha[] = {1.0, 2.0}; - double norm; - - norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -#ifndef NO_CBLAS -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy only - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, c_api_colmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'N'; - double alpha[] = {1.0, 2.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition - * alpha_r = -1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, c_api_colmajor_trans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - double alpha[] = {-1.0, 2.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Copy and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, c_api_colmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'R'; - double alpha[] = {1.0, 2.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Column Major - * Transposition and conjugate - * alpha_r = 2.0, alpha_i = 1.0 - */ -CTEST(zomatcopy, c_api_colmajor_conjtrnas_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'C'; - double alpha[] = {2.0, 1.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy only - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zomatcopy, c_api_rowmajor_notrans_col_50_row_100) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 50; - char order = 'R'; - char trans = 'N'; - double alpha[] = {1.5, -1.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zomatcopy, c_api_rowmajor_trans_col_100_row_50) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - double alpha[] = {1.5, -1.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Copy and conjugate - * alpha_r = 1.5, alpha_i = -1.0 - */ -CTEST(zomatcopy, c_api_rowmajor_conj_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'R'; - double alpha[] = {1.5, -1.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} - -/** - * C API specific test - * Test zomatcopy by comparing it against refernce - * with the following options: - * - * Row Major - * Transposition and conjugate - * alpha_r = 1.0, alpha_i = 2.0 - */ -CTEST(zomatcopy, c_api_rowmajor_conjtrans_col_100_row_100) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'R'; - char trans = 'C'; - double alpha[] = {1.0, 2.0}; - double norm; - - norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); - - ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); -} -#endif - -/** -* Test error function for an invalid param order. -* Must be column (C) or row major (R). -*/ -CTEST(zomatcopy, xerbla_invalid_order) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'O'; - char trans = 'T'; - int expected_info = 1; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param trans. -* Must be trans (T/C) or no-trans (N/R). -*/ -CTEST(zomatcopy, xerbla_invalid_trans) -{ - blasint m = 100, n = 100; - blasint lda = 100, ldb = 100; - char order = 'C'; - char trans = 'O'; - int expected_info = 2; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param lda. -* If matrices are stored using row major layout, -* lda must be at least n. -*/ -CTEST(zomatcopy, xerbla_rowmajor_invalid_lda) -{ - blasint m = 50, n = 100; - blasint lda = 50, ldb = 100; - char order = 'R'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param lda. -* If matrices are stored using column major layout, -* lda must be at least m. -*/ -CTEST(zomatcopy, xerbla_colmajor_invalid_lda) -{ - blasint m = 100, n = 50; - blasint lda = 50, ldb = 100; - char order = 'C'; - char trans = 'T'; - int expected_info = 7; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using row major layout and -* there is no transposition, ldb must be at least n. -*/ -CTEST(zomatcopy, xerbla_rowmajor_notrans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using row major layout and -* there is transposition, ldb must be at least m. -*/ -CTEST(zomatcopy, xerbla_rowmajor_trans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using row major layout and -* there is no transposition, ldb must be at least n. -*/ -CTEST(zomatcopy, xerbla_rowmajor_conj_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'R'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using row major layout and -* there is transposition, ldb must be at least m. -*/ -CTEST(zomatcopy, xerbla_rowmajor_transconj_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'R'; - char trans = 'C'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using column major layout and -* there is no transposition, ldb must be at least m. -*/ -CTEST(zomatcopy, xerbla_colmajor_notrans_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'N'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using column major layout and -* there is transposition, ldb must be at least n. -*/ -CTEST(zomatcopy, xerbla_colmajor_trans_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'T'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using column major layout and -* there is no transposition, ldb must be at least m. -*/ -CTEST(zomatcopy, xerbla_colmajor_conj_invalid_ldb) -{ - blasint m = 100, n = 50; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'R'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} - -/** -* Test error function for an invalid param ldb. -* If matrices are stored using column major layout and -* there is transposition, ldb must be at least n. -*/ -CTEST(zomatcopy, xerbla_colmajor_transconj_invalid_ldb) -{ - blasint m = 50, n = 100; - blasint lda = 100, ldb = 50; - char order = 'C'; - char trans = 'C'; - int expected_info = 9; - - int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); - ASSERT_EQUAL(TRUE, passed); -} -#endif +/***************************************************************************** +Copyright (c) 2023, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "utest/openblas_utest.h" +#include "common.h" + +#define DATASIZE 100 + +struct DATA_ZOMATCOPY { + double a_test[DATASIZE * DATASIZE * 2]; + double b_test[DATASIZE * DATASIZE * 2]; + double b_verify[DATASIZE * DATASIZE * 2]; +}; + +#ifdef BUILD_COMPLEX16 +static struct DATA_ZOMATCOPY data_zomatcopy; + +/** + * Comapare results computed by zomatcopy and reference func + * + * param api specifies tested api (C or Fortran) + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param alpha - scaling factor for matrix B + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * return norm of difference between openblas and reference func + */ +static double check_zomatcopy(char api, char order, char trans, blasint rows, blasint cols, double* alpha, + blasint lda, blasint ldb) +{ + blasint b_rows, b_cols; + blasint m, n; + enum CBLAS_ORDER corder; + enum CBLAS_TRANSPOSE ctrans; + int conj = -1; + + if (order == 'C') { + m = cols; n = rows; + } + else { + m = rows; n = cols; + } + + if(trans == 'T' || trans == 'C') { + b_rows = n; b_cols = m*2; + if (trans == 'C') + conj = 1; + } + else { + b_rows = m; b_cols = n*2; + if (trans == 'R') + conj = 1; + } + + drand_generate(data_zomatcopy.a_test, lda*m*2); + + if (trans == 'T' || trans == 'C') { + ztranspose(m, n, alpha, data_zomatcopy.a_test, lda, data_zomatcopy.b_verify, ldb, conj); + } + else { + my_zcopy(m, n, alpha, data_zomatcopy.a_test, lda, data_zomatcopy.b_verify, ldb, conj); + } + + if (api == 'F') { + BLASFUNC(zomatcopy)(&order, &trans, &rows, &cols, alpha, data_zomatcopy.a_test, + &lda, data_zomatcopy.b_test, &ldb); + } +#ifndef NO_CBLAS + else { + if (order == 'C') corder = CblasColMajor; + if (order == 'R') corder = CblasRowMajor; + if (trans == 'T') ctrans = CblasTrans; + if (trans == 'N') ctrans = CblasNoTrans; + if (trans == 'C') ctrans = CblasConjTrans; + if (trans == 'R') ctrans = CblasConjNoTrans; + cblas_zomatcopy(corder, ctrans, rows, cols, alpha, data_zomatcopy.a_test, + lda, data_zomatcopy.b_test, ldb); + } +#endif + + return dmatrix_difference(data_zomatcopy.b_test, data_zomatcopy.b_verify, b_cols, b_rows, ldb*2); +} + +/** + * Check if error function was called with expected function name + * and param info + * + * param order specifies row or column major order + * param trans specifies op(A), the transposition operation + * applied to the matrix A + * param rows - number of rows of A + * param cols - number of columns of A + * param lda - leading dimension of the matrix A + * param ldb - leading dimension of the matrix B + * param expected_info - expected invalid parameter number + * return TRUE if everything is ok, otherwise FALSE + */ +static int check_badargs(char order, char trans, blasint rows, blasint cols, + blasint lda, blasint ldb, int expected_info) +{ + double alpha[] = {1.0, 1.0}; + + set_xerbla("ZOMATCOPY", expected_info); + + BLASFUNC(zomatcopy)(&order, &trans, &rows, &cols, alpha, data_zomatcopy.a_test, + &lda, data_zomatcopy.b_test, &ldb); + + return check_error(); +} + +/** + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + double alpha[] = {1.0, 2.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * alpha_r = -1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + double alpha[] = {-1.0, 2.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'R'; + double alpha[] = {1.0, 2.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(zomatcopy, colmajor_conjtrnas_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'C'; + double alpha[] = {2.0, 1.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zomatcopy, rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 50; + char order = 'R'; + char trans = 'N'; + double alpha[] = {1.5, -1.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zomatcopy, rowmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + double alpha[] = {1.5, -1.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zomatcopy, rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'R'; + double alpha[] = {1.5, -1.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * Fortran API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'C'; + double alpha[] = {1.0, 2.0}; + double norm; + + norm = check_zomatcopy('F', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +#ifndef NO_CBLAS +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy only + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, c_api_colmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'N'; + double alpha[] = {1.0, 2.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition + * alpha_r = -1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, c_api_colmajor_trans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + double alpha[] = {-1.0, 2.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Copy and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, c_api_colmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'R'; + double alpha[] = {1.0, 2.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Column Major + * Transposition and conjugate + * alpha_r = 2.0, alpha_i = 1.0 + */ +CTEST(zomatcopy, c_api_colmajor_conjtrnas_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'C'; + double alpha[] = {2.0, 1.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy only + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zomatcopy, c_api_rowmajor_notrans_col_50_row_100) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 50; + char order = 'R'; + char trans = 'N'; + double alpha[] = {1.5, -1.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zomatcopy, c_api_rowmajor_trans_col_100_row_50) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + double alpha[] = {1.5, -1.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Copy and conjugate + * alpha_r = 1.5, alpha_i = -1.0 + */ +CTEST(zomatcopy, c_api_rowmajor_conj_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'R'; + double alpha[] = {1.5, -1.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} + +/** + * C API specific test + * Test zomatcopy by comparing it against refernce + * with the following options: + * + * Row Major + * Transposition and conjugate + * alpha_r = 1.0, alpha_i = 2.0 + */ +CTEST(zomatcopy, c_api_rowmajor_conjtrans_col_100_row_100) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'R'; + char trans = 'C'; + double alpha[] = {1.0, 2.0}; + double norm; + + norm = check_zomatcopy('C', order, trans, m, n, alpha, lda, ldb); + + ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS); +} +#endif + +/** +* Test error function for an invalid param order. +* Must be column (C) or row major (R). +*/ +CTEST(zomatcopy, xerbla_invalid_order) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'O'; + char trans = 'T'; + int expected_info = 1; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param trans. +* Must be trans (T/C) or no-trans (N/R). +*/ +CTEST(zomatcopy, xerbla_invalid_trans) +{ + blasint m = 100, n = 100; + blasint lda = 100, ldb = 100; + char order = 'C'; + char trans = 'O'; + int expected_info = 2; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param lda. +* If matrices are stored using row major layout, +* lda must be at least n. +*/ +CTEST(zomatcopy, xerbla_rowmajor_invalid_lda) +{ + blasint m = 50, n = 100; + blasint lda = 50, ldb = 100; + char order = 'R'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param lda. +* If matrices are stored using column major layout, +* lda must be at least m. +*/ +CTEST(zomatcopy, xerbla_colmajor_invalid_lda) +{ + blasint m = 100, n = 50; + blasint lda = 50, ldb = 100; + char order = 'C'; + char trans = 'T'; + int expected_info = 7; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using row major layout and +* there is no transposition, ldb must be at least n. +*/ +CTEST(zomatcopy, xerbla_rowmajor_notrans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using row major layout and +* there is transposition, ldb must be at least m. +*/ +CTEST(zomatcopy, xerbla_rowmajor_trans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using row major layout and +* there is no transposition, ldb must be at least n. +*/ +CTEST(zomatcopy, xerbla_rowmajor_conj_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'R'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using row major layout and +* there is transposition, ldb must be at least m. +*/ +CTEST(zomatcopy, xerbla_rowmajor_transconj_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'R'; + char trans = 'C'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using column major layout and +* there is no transposition, ldb must be at least m. +*/ +CTEST(zomatcopy, xerbla_colmajor_notrans_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'N'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using column major layout and +* there is transposition, ldb must be at least n. +*/ +CTEST(zomatcopy, xerbla_colmajor_trans_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'T'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using column major layout and +* there is no transposition, ldb must be at least m. +*/ +CTEST(zomatcopy, xerbla_colmajor_conj_invalid_ldb) +{ + blasint m = 100, n = 50; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'R'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} + +/** +* Test error function for an invalid param ldb. +* If matrices are stored using column major layout and +* there is transposition, ldb must be at least n. +*/ +CTEST(zomatcopy, xerbla_colmajor_transconj_invalid_ldb) +{ + blasint m = 50, n = 100; + blasint lda = 100, ldb = 50; + char order = 'C'; + char trans = 'C'; + int expected_info = 9; + + int passed = check_badargs(order, trans, m, n, lda, ldb, expected_info); + ASSERT_EQUAL(TRUE, passed); +} +#endif