matrixmemcpyblascblas

How can I copy a strided matrix in BLAS?


BLAS level 3 Matrix/Matrix routines take arguments lda, ldb etc. that allow one to pass 'strided' matrices, as far as I understand. For instance, if I have the following 2 x 2 column-major matrix:

|1 2|
|3 4|
|x x|

where x's are data I want ignored, I can represent this using arguments m = 2, n = 2, lda=3 (for column major matrices). My question is, can such matrices be copied using BLAS routines?

If the stride equals the matrix dimension (i.e. the matrix is not strided) it is trivial to use vector copy procedure e.g. dcopy(m*n,A,1,B,1) to do this. Is there a way to do this when the matrix elements are not contiguous i.e. lda/stride != m

One way I can think of doing this is repeatedly calling dcopy with increasing offsets, while keeping the incrx parameter equal to m. It doesn't seem efficient. Alternatively dgemm with B = I and C = 0.


Solution

  • Please have a look at this documentation:

    http://www.netlib.org/lapack/explore-3.1.1-html/slacpy.f.html

    SLACPY( UPLO, M, N, A, LDA, B, LDB )
    

    The above would do what you want for single precision real matrices from all or part of A into B for example. Its use is fairly strait-forward. Of course you'll find implementations for all flavours D,C,Z