Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLAS/LAPACK code assumes all StridedMatrices are column-major #6356

Closed
stevengj opened this issue Apr 1, 2014 · 12 comments
Closed

BLAS/LAPACK code assumes all StridedMatrices are column-major #6356

stevengj opened this issue Apr 1, 2014 · 12 comments
Labels
domain:linear algebra Linear algebra good first issue Indicates a good issue for first-time contributors to Julia kind:bug Indicates an unexpected problem or unintended behavior

Comments

@stevengj
Copy link
Member

stevengj commented Apr 1, 2014

As I understand it, one of the purposes of the DenseMatrix type from #987, as discussed in #6212, is to include things like row-major NumPy arrays. However, it looks like most of the BLAS/LAPACK code assumes, without checking, that StridedMatrix arguments are column-major (or subsets of column-major matrices), i.e. they assume that stride(A,1) == 1.

Probably these routines should have stride(A,1) != 1 && ...generic fallback... for now. Ideally, they could do

if stride(A,1) != 1
   if stride(A,2) == 1
       ...handle row-major case by treating A as if it were transposed....
   else
       ...generic fallback
   end
end

cc: @andreasnoack, @lindahua

@lindahua
Copy link
Contributor

lindahua commented Apr 1, 2014

I don't have problems with this. Looks like it is going to be a lot of work though.

@stevengj
Copy link
Member Author

stevengj commented Apr 2, 2014

I agree that it is a lot of work. Until it is done, however, it will be dangerous to define any new DenseMatrix subtypes, as a consequence of linear algebra dispatching to LAPACK for DenseMatrix{Float64} etc.

For 0.3, I see several options:

  • Leave things as-is, and hope that not too many people define such subtypes.
  • Leave things as-is, but change the manual to recommend (for now) that DenseMatrix subtypes have unit stride along the first dimension.
  • Leave things as-is, but don't document DenseMatrix at all; leave it as an undocumented internal type that is not ready for public consumption.
  • Change StridedMatrix to be Union(Matrix,SubArray{Matrix}), as before.
  • Try to fix this in time for 0.3, which may delay the release still further (unless someone is very quick with a patch).

@JeffBezanson, @jiahao?

@lindahua
Copy link
Contributor

lindahua commented Apr 2, 2014

A stopgap: inserting this to each function that wraps BLAS:

stride(A, 1) == 1 || error( ... )

@lindahua
Copy link
Contributor

lindahua commented Apr 2, 2014

The array view types in ArrayViews.jl, which are subtypes of DenseMatrix, now work well with BLAS & LAPACK. Changing StridedMatrix to Union(Matrix, SubArray{Matrix}) would cause problems.

@jiahao
Copy link
Member

jiahao commented Apr 3, 2014

I'm in favour of undocumented DenseMatrix for 0.3.

@andreasnoack
Copy link
Member

We should probably add chkstride1 to all BLAS and LAPACK methods.

cc: @jakebolewski

@kshyatt
Copy link
Contributor

kshyatt commented Jan 25, 2017

Since we recently added Row* etc I'm pinging @andyferris on this - can we close?

@tkelman
Copy link
Contributor

tkelman commented Jan 26, 2017

that only handled vectors, not strided matrices or blas and lapack interfaces, so no

@tkelman
Copy link
Contributor

tkelman commented Jan 26, 2017

though strided matrix is a union recently, and I think many of the calls do have chkstride1 now, so it may have been fixed just not by the rowvector work.

@ViralBShah
Copy link
Member

Closing this since it is unlikely to do much about row-major arrays - and a package would be a better place for such things.

@stevengj
Copy link
Member Author

Note that this issue is not about supporting row-major arrays, it is about making sure that we call chkstride1 or similar in any LAPACK call that accepts a StridedArray but requires column-major (i.e. all LAPACK calls).

@ViralBShah ViralBShah reopened this May 26, 2020
@ViralBShah ViralBShah added the good first issue Indicates a good issue for first-time contributors to Julia label May 26, 2020
@ViralBShah
Copy link
Member

I believe we do chkstride1 widely throughout blas.jl and lapack.jl. Perhaps we need a specific issue for places we don't do it. Let's reopen if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:linear algebra Linear algebra good first issue Indicates a good issue for first-time contributors to Julia kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

7 participants