00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "lapacke.h"
00035 #include "lapacke_utils.h"
00036
00037 lapack_int LAPACKE_sgelss_work( int matrix_order, lapack_int m, lapack_int n,
00038 lapack_int nrhs, float* a, lapack_int lda,
00039 float* b, lapack_int ldb, float* s, float rcond,
00040 lapack_int* rank, float* work,
00041 lapack_int lwork )
00042 {
00043 lapack_int info = 0;
00044 if( matrix_order == LAPACK_COL_MAJOR ) {
00045
00046 LAPACK_sgelss( &m, &n, &nrhs, a, &lda, b, &ldb, s, &rcond, rank, work,
00047 &lwork, &info );
00048 if( info < 0 ) {
00049 info = info - 1;
00050 }
00051 } else if( matrix_order == LAPACK_ROW_MAJOR ) {
00052 lapack_int lda_t = MAX(1,m);
00053 lapack_int ldb_t = MAX(1,MAX(m,n));
00054 float* a_t = NULL;
00055 float* b_t = NULL;
00056
00057 if( lda < n ) {
00058 info = -6;
00059 LAPACKE_xerbla( "LAPACKE_sgelss_work", info );
00060 return info;
00061 }
00062 if( ldb < nrhs ) {
00063 info = -8;
00064 LAPACKE_xerbla( "LAPACKE_sgelss_work", info );
00065 return info;
00066 }
00067
00068 if( lwork == -1 ) {
00069 LAPACK_sgelss( &m, &n, &nrhs, a, &lda_t, b, &ldb_t, s, &rcond, rank,
00070 work, &lwork, &info );
00071 return (info < 0) ? (info - 1) : info;
00072 }
00073
00074 a_t = (float*)LAPACKE_malloc( sizeof(float) * lda_t * MAX(1,n) );
00075 if( a_t == NULL ) {
00076 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00077 goto exit_level_0;
00078 }
00079 b_t = (float*)LAPACKE_malloc( sizeof(float) * ldb_t * MAX(1,nrhs) );
00080 if( b_t == NULL ) {
00081 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00082 goto exit_level_1;
00083 }
00084
00085 LAPACKE_sge_trans( matrix_order, m, n, a, lda, a_t, lda_t );
00086 LAPACKE_sge_trans( matrix_order, MAX(m,n), nrhs, b, ldb, b_t, ldb_t );
00087
00088 LAPACK_sgelss( &m, &n, &nrhs, a_t, &lda_t, b_t, &ldb_t, s, &rcond, rank,
00089 work, &lwork, &info );
00090 if( info < 0 ) {
00091 info = info - 1;
00092 }
00093
00094 LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, a_t, lda_t, a, lda );
00095 LAPACKE_sge_trans( LAPACK_COL_MAJOR, MAX(m,n), nrhs, b_t, ldb_t, b,
00096 ldb );
00097
00098 LAPACKE_free( b_t );
00099 exit_level_1:
00100 LAPACKE_free( a_t );
00101 exit_level_0:
00102 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
00103 LAPACKE_xerbla( "LAPACKE_sgelss_work", info );
00104 }
00105 } else {
00106 info = -1;
00107 LAPACKE_xerbla( "LAPACKE_sgelss_work", info );
00108 }
00109 return info;
00110 }