# dgelss will output incorrect result when matrix = [100, 3]

## dgelss will output incorrect result when matrix = [100, 3]

Hi,

I am using dgelss to simulate same result as pinv() in Matlab. When I set matrix to be [10, 3], the result is correct. But when I change the matrix size to be [100, 3], then the outcome will become a matrix with most elements to be 0.

Any input will be welcome.

Thanks

Hai

7 posts / 0 nouveau(x)
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hai,

Do you have a test code that could show this problem?

Regards,

Chao

Did someone else have similar problem?

Citation :

Did someone else have similar problem?

Here is an example that shows GELSS working correctly for a 100 X 3 matrix. Therefore, the MKL implementation of GELSS works for some inputs. If you have an input for which it fails to give correct results, please publish the example.

``` program gelss_example

USE MKL95_LAPACK, ONLY: GELSS

!DEC\$ OBJCOMMENT lib:'mkl_lapack95'

implicit none

integer, parameter :: dp=kind(1d0)

integer, parameter :: M=100,N=3

integer :: i,j,k

real(dp) :: A(M,N),x(N),B(M),delta(M)

!

! create test problem

!

call RANDOM_NUMBER(A); call RANDOM_NUMBER(delta)

x(1)=2.718; x(2)=3.1425; x(3)=0.1729

A=(2*A-1)*10          ! random numbers between -10 and +10

B=MATMUL(A,x)+(2*delta-1)*0.01

!

call GELSS(A,B)

write(*,10)x,B(1:N)

10 format(' Original x used to create B: ',3F8.5,/, &

' GELSS results for x        : ',3F8.5)

end program gelss_example

```

Compiling and running on Windows using

` ifort /Qmkl xgelss.f90`

I get the output

``` Original x used to create B:  2.71800 3.14250 0.17290

GELSS results for x        :  2.71796 3.14250 0.17291 ```

I already sent my code to Chao Y who help me provided a temporary solution which can calculate dgelss correctly for a 100x3 matrix.

I am not sure how Fortran code works. But my code works fine for a matrix with size 10x3. But when I change the matrix size to 100x3 or larger, the results will be almost zeros.

Thanks, Hai for the code.  yes, we could verify this is a bug, and will fix it in the future release soon.  I am also checking if there is any workaound for this problem.

Regards,
Chao

Dear Hai,

The problem comes from your code. Your reproducer has internal error: lwork query was done for the parameters differs from those of the second call of functionality.

According to the MKL Reference Guide  the size of work array for dgelss depends on the first three input parameters. You call dgelss for determining the size of workspace for the set (m, n, n)

dgelss(&m, &n, &n ...

where m=100 and n=3. Meanwhile the second call is for another set of parameters (m, n, m)

dgelss(&m, &n, &m, ..

BUT the values  of these parameters must be identical for both calls.

All the best

Sergey