void THBlas_swap(long size, real *x, long xStride, real *y, long yStride) { if(size == 1) { xStride = 1; yStride = 1; } #if USE_CBLAS if( (size < INT_MAX) && (xStride < INT_MAX) && (yStride < INT_MAX) ) { #ifdef USE_DOUBLE cblas_dswap(size, x, xStride, y, yStride); #else cblas_sswap(size, x, xStride, y, yStride); #endif return; } #endif { long i; for(i = 0; i < size; i++) { real z = x[i*xStride]; x[i*xStride] = y[i*yStride]; y[i*yStride] = z; } } }
void THBlas_(swap)(long n, real *x, long incx, real *y, long incy) { if(n == 1) { incx = 1; incy = 1; } #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (n <= INT_MAX) && (incx <= INT_MAX) && (incy <= INT_MAX) ) { int i_n = (int)n; int i_incx = (int)incx; int i_incy = (int)incy; #if defined(TH_REAL_IS_DOUBLE) cblas_dswap(i_n, x, i_incx, y, i_incy); #else cblas_sswap(i_n, x, i_incx, y, i_incy); #endif return; } #endif { long i; for(i = 0; i < n; i++) { real z = x[i*incx]; x[i*incx] = y[i*incy]; y[i*incy] = z; } } }
JNIEXPORT void JNICALL Java_uncomplicate_neanderthal_CBLAS_sswap (JNIEnv *env, jclass clazz, jint N, jobject X, jint offsetX, jint incX, jobject Y, jint offsetY, jint incY) { float *cX = (float *) (*env)->GetDirectBufferAddress(env, X); float *cY = (float *) (*env)->GetDirectBufferAddress(env, Y); cblas_sswap(N, cX + offsetX, incX, cY + offsetY, incY); };
void bli_sswap( int n, float* x, int incx, float* y, int incy ) { #ifdef BLIS_ENABLE_CBLAS_INTERFACES cblas_sswap( n, x, incx, y, incy ); #else F77_sswap( &n, x, &incx, y, &incy ); #endif }
void test_swap (void) { const double flteps = 1e-4, dbleps = 1e-6; { int N = 1; float X[] = { 0.539f }; int incX = 1; float Y[] = { -0.262f }; int incY = -1; float expected1[] = { -0.262f }; float expected2[] = { 0.539f }; cblas_sswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[i], expected1[i], flteps, "sswap(case 88)"); } }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[i], expected2[i], flteps, "sswap(case 89)"); } }; }; { int N = 1; double X[] = { 0.906 }; int incX = 1; double Y[] = { 0.373 }; int incY = -1; double expected1[] = { 0.373 }; double expected2[] = { 0.906 }; cblas_dswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[i], expected1[i], dbleps, "dswap(case 90)"); } }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[i], expected2[i], dbleps, "dswap(case 91)"); } }; }; { int N = 1; float X[] = { -0.316f, -0.529f }; int incX = 1; float Y[] = { -0.313f, 0.363f }; int incY = -1; float expected1[] = { -0.313f, 0.363f }; float expected2[] = { -0.316f, -0.529f }; cblas_cswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[2*i], expected1[2*i], flteps, "cswap(case 92) real"); gsl_test_rel(X[2*i+1], expected1[2*i+1], flteps, "cswap(case 92) imag"); }; }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[2*i], expected2[2*i], flteps, "cswap(case 93) real"); gsl_test_rel(Y[2*i+1], expected2[2*i+1], flteps, "cswap(case 93) imag"); }; }; }; { int N = 1; double X[] = { 0.512, -0.89 }; int incX = 1; double Y[] = { -0.225, -0.511 }; int incY = -1; double expected1[] = { -0.225, -0.511 }; double expected2[] = { 0.512, -0.89 }; cblas_zswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[2*i], expected1[2*i], dbleps, "zswap(case 94) real"); gsl_test_rel(X[2*i+1], expected1[2*i+1], dbleps, "zswap(case 94) imag"); }; }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[2*i], expected2[2*i], dbleps, "zswap(case 95) real"); gsl_test_rel(Y[2*i+1], expected2[2*i+1], dbleps, "zswap(case 95) imag"); }; }; }; { int N = 1; float X[] = { 0.336f }; int incX = -1; float Y[] = { -0.431f }; int incY = 1; float expected1[] = { -0.431f }; float expected2[] = { 0.336f }; cblas_sswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[i], expected1[i], flteps, "sswap(case 96)"); } }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[i], expected2[i], flteps, "sswap(case 97)"); } }; }; { int N = 1; double X[] = { 0.764 }; int incX = -1; double Y[] = { -0.293 }; int incY = 1; double expected1[] = { -0.293 }; double expected2[] = { 0.764 }; cblas_dswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[i], expected1[i], dbleps, "dswap(case 98)"); } }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[i], expected2[i], dbleps, "dswap(case 99)"); } }; }; { int N = 1; float X[] = { -0.239f, 0.361f }; int incX = -1; float Y[] = { 0.149f, 0.347f }; int incY = 1; float expected1[] = { 0.149f, 0.347f }; float expected2[] = { -0.239f, 0.361f }; cblas_cswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[2*i], expected1[2*i], flteps, "cswap(case 100) real"); gsl_test_rel(X[2*i+1], expected1[2*i+1], flteps, "cswap(case 100) imag"); }; }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[2*i], expected2[2*i], flteps, "cswap(case 101) real"); gsl_test_rel(Y[2*i+1], expected2[2*i+1], flteps, "cswap(case 101) imag"); }; }; }; { int N = 1; double X[] = { -0.171, -0.936 }; int incX = -1; double Y[] = { 0.495, -0.835 }; int incY = 1; double expected1[] = { 0.495, -0.835 }; double expected2[] = { -0.171, -0.936 }; cblas_zswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[2*i], expected1[2*i], dbleps, "zswap(case 102) real"); gsl_test_rel(X[2*i+1], expected1[2*i+1], dbleps, "zswap(case 102) imag"); }; }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[2*i], expected2[2*i], dbleps, "zswap(case 103) real"); gsl_test_rel(Y[2*i+1], expected2[2*i+1], dbleps, "zswap(case 103) imag"); }; }; }; { int N = 1; float X[] = { -0.405f }; int incX = -1; float Y[] = { -0.213f }; int incY = -1; float expected1[] = { -0.213f }; float expected2[] = { -0.405f }; cblas_sswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[i], expected1[i], flteps, "sswap(case 104)"); } }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[i], expected2[i], flteps, "sswap(case 105)"); } }; }; { int N = 1; double X[] = { -0.761 }; int incX = -1; double Y[] = { -0.585 }; int incY = -1; double expected1[] = { -0.585 }; double expected2[] = { -0.761 }; cblas_dswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[i], expected1[i], dbleps, "dswap(case 106)"); } }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[i], expected2[i], dbleps, "dswap(case 107)"); } }; }; { int N = 1; float X[] = { 0.853f, 0.146f }; int incX = -1; float Y[] = { 0.009f, -0.178f }; int incY = -1; float expected1[] = { 0.009f, -0.178f }; float expected2[] = { 0.853f, 0.146f }; cblas_cswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[2*i], expected1[2*i], flteps, "cswap(case 108) real"); gsl_test_rel(X[2*i+1], expected1[2*i+1], flteps, "cswap(case 108) imag"); }; }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[2*i], expected2[2*i], flteps, "cswap(case 109) real"); gsl_test_rel(Y[2*i+1], expected2[2*i+1], flteps, "cswap(case 109) imag"); }; }; }; { int N = 1; double X[] = { -0.228, 0.386 }; int incX = -1; double Y[] = { 0.988, -0.084 }; int incY = -1; double expected1[] = { 0.988, -0.084 }; double expected2[] = { -0.228, 0.386 }; cblas_zswap(N, X, incX, Y, incY); { int i; for (i = 0; i < 1; i++) { gsl_test_rel(X[2*i], expected1[2*i], dbleps, "zswap(case 110) real"); gsl_test_rel(X[2*i+1], expected1[2*i+1], dbleps, "zswap(case 110) imag"); }; }; { int i; for (i = 0; i < 1; i++) { gsl_test_rel(Y[2*i], expected2[2*i], dbleps, "zswap(case 111) real"); gsl_test_rel(Y[2*i+1], expected2[2*i+1], dbleps, "zswap(case 111) imag"); }; }; }; }
void sswap_(int *n, float *X, int *incx, float *Y, int *incy) { Blasx_Debug_Output("Calling sswap_\n "); cblas_sswap(*n,X,*incx,Y,*incy); }
// // Overloaded function for dispatching to // * CBLAS backend, and // * float value-type. // inline void swap( const int n, float* x, const int incx, float* y, const int incy ) { cblas_sswap( n, x, incx, y, incy ); }
int CORE_ststrf(int M, int N, int IB, int NB, float *U, int LDU, float *A, int LDA, float *L, int LDL, int *IPIV, float *WORK, int LDWORK, int *INFO) { static float zzero = 0.0; static float mzone =-1.0; float alpha; int i, j, ii, sb; int im, ip; /* Check input arguments */ *INFO = 0; if (M < 0) { coreblas_error(1, "Illegal value of M"); return -1; } if (N < 0) { coreblas_error(2, "Illegal value of N"); return -2; } if (IB < 0) { coreblas_error(3, "Illegal value of IB"); return -3; } if ((LDU < max(1,NB)) && (NB > 0)) { coreblas_error(6, "Illegal value of LDU"); return -6; } if ((LDA < max(1,M)) && (M > 0)) { coreblas_error(8, "Illegal value of LDA"); return -8; } if ((LDL < max(1,IB)) && (IB > 0)) { coreblas_error(10, "Illegal value of LDL"); return -10; } /* Quick return */ if ((M == 0) || (N == 0) || (IB == 0)) return PLASMA_SUCCESS; /* Set L to 0 */ memset(L, 0, LDL*N*sizeof(float)); ip = 0; for (ii = 0; ii < N; ii += IB) { sb = min(N-ii, IB); for (i = 0; i < sb; i++) { im = cblas_isamax(M, &A[LDA*(ii+i)], 1); IPIV[ip] = ii+i+1; if (fabsf(A[LDA*(ii+i)+im]) > fabsf(U[LDU*(ii+i)+ii+i])) { /* * Swap behind. */ cblas_sswap(i, &L[LDL*ii+i], LDL, &WORK[im], LDWORK ); /* * Swap ahead. */ cblas_sswap(sb-i, &U[LDU*(ii+i)+ii+i], LDU, &A[LDA*(ii+i)+im], LDA ); /* * Set IPIV. */ IPIV[ip] = NB + im + 1; for (j = 0; j < i; j++) { A[LDA*(ii+j)+im] = zzero; } } if ((*INFO == 0) && (fabsf(A[LDA*(ii+i)+im]) == zzero) && (fabsf(U[LDU*(ii+i)+ii+i]) == zzero)) { *INFO = ii+i+1; } alpha = ((float)1. / U[LDU*(ii+i)+ii+i]); cblas_sscal(M, (alpha), &A[LDA*(ii+i)], 1); cblas_scopy(M, &A[LDA*(ii+i)], 1, &WORK[LDWORK*i], 1); cblas_sger( CblasColMajor, M, sb-i-1, (mzone), &A[LDA*(ii+i)], 1, &U[LDU*(ii+i+1)+ii+i], LDU, &A[LDA*(ii+i+1)], LDA ); ip = ip+1; } /* * Apply the subpanel to the rest of the panel. */ if(ii+i < N) { for(j = ii; j < ii+sb; j++) { if (IPIV[j] <= NB) { IPIV[j] = IPIV[j] - ii; } } CORE_sssssm( NB, N-(ii+sb), M, N-(ii+sb), sb, sb, &U[LDU*(ii+sb)+ii], LDU, &A[LDA*(ii+sb)], LDA, &L[LDL*ii], LDL, WORK, LDWORK, &IPIV[ii]); for(j = ii; j < ii+sb; j++) { if (IPIV[j] <= NB) { IPIV[j] = IPIV[j] + ii; } } } } return PLASMA_SUCCESS; }
void STARPU_SSWAP(const int n, float *x, const int incx, float *y, const int incy) { cblas_sswap(n, x, incx, y, incy); }