Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- How do we select the column of a matrix?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Fiori

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-28-2014
01:09 AM

74 Views

How do we select the column of a matrix?

Hello!

I am new to MKL and to C in general. Lets say that we have two matrices A, B of size (n,k). We would like for j =1 until k to subtrack the j column of A from B. In Matlab language the code is: for j=1:k, B(:,j)-A(:,j), end and in R language for(j=1 in k), { B[,j]-A[,j] }. I would like to ask if there is a routine to select the j column (or row) of a matrix? I searched but I had no luck.

Thank you very much.

1 Solution

Ying_H_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2014
08:36 PM

74 Views

Hi GF,

What is the reason of you change the matlab or R to C? and What is your problem size (matrix)?

You may have known, you can use R or matlab directly, and get MKL performance benifit at the same time, because MKL can be intergarted into R and Matlab, please see the article http://software.intel.com/en-us/articles/using-intel-mkl-with-r

So first, i may suggest you to use matlab or R directy.

Secondly, MKL mainly focus on the computation and the interfaces are mainly based on some kind of standard interface, like BLAS ( matrix, vector operation). So it is not flexiable like Matlab and R.

It hasn't single routines like data operations like extract columns from a Matrix. But these operations are embeded in the computation.

for example, If you have to convert the matlab code to C/MKL code. You may first convert them to C code, then call MKL function.

for example, X(:, t-j) - B(:, t-j) , as mecej4 mentioned to use daxpy.

double * Ypointer=&(X[0][t-j]);

double * Xpointer=&(B[0][t-j]);

IncX= number of columns of B

IncY = number of columns of A;

N= row of column of A;

cblas_daxpy ( N, -1.0, Xpointer, incX, Ypointer,incY);

Then same as for A(:, :, J) * Ypointer. If A can access by C pointer with regular pattern by (expressed by incX and lda)

Call cblas_dgemv (const CBLAS_ORDER order, const CBLAS_TRANSPOSE TransA, const MKL_INT

M, const MKL_INT N, const double alpha, const double *A, const MKL_INT lda, const

double *X, const MKL_INT incX, Ypointer, 1).

Last, if you are using Intel C Compiler, Array notication also is helpful to convert your matlab to C code.

Please See http://software.intel.com/en-us/articles/about-intel-cilk-plus-and-how-to-get-started.

You can write A[:] - refers the entire array in C code.

Best Regards,

Ying

Link Copied

3 Replies

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-28-2014
05:41 AM

74 Views

**?axpy** routines. For such a simple operation as subtraction, you may also consider using the features that the programming language itself provides, such as those provided by BOOST.

Fiori

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-28-2014
06:00 AM

74 Views

Thank you for your help. I am confused with this language. I have written a program in Matlab and I want to convert it to C language using the MKL.

The part of my code is the following

**for t=1:T**

c1=0; c2=0;

*for j=1:p*

*c1=c1+A(:,:,j) * ( X(:,t-j)-B(:,t-j));*

*end*

**end**

I haven't known to use the library well yet. Thanks again.

Ying_H_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2014
08:36 PM

75 Views

Hi GF,

What is the reason of you change the matlab or R to C? and What is your problem size (matrix)?

You may have known, you can use R or matlab directly, and get MKL performance benifit at the same time, because MKL can be intergarted into R and Matlab, please see the article http://software.intel.com/en-us/articles/using-intel-mkl-with-r

So first, i may suggest you to use matlab or R directy.

Secondly, MKL mainly focus on the computation and the interfaces are mainly based on some kind of standard interface, like BLAS ( matrix, vector operation). So it is not flexiable like Matlab and R.

It hasn't single routines like data operations like extract columns from a Matrix. But these operations are embeded in the computation.

for example, If you have to convert the matlab code to C/MKL code. You may first convert them to C code, then call MKL function.

for example, X(:, t-j) - B(:, t-j) , as mecej4 mentioned to use daxpy.

double * Ypointer=&(X[0][t-j]);

double * Xpointer=&(B[0][t-j]);

IncX= number of columns of B

IncY = number of columns of A;

N= row of column of A;

cblas_daxpy ( N, -1.0, Xpointer, incX, Ypointer,incY);

Then same as for A(:, :, J) * Ypointer. If A can access by C pointer with regular pattern by (expressed by incX and lda)

Call cblas_dgemv (const CBLAS_ORDER order, const CBLAS_TRANSPOSE TransA, const MKL_INT

M, const MKL_INT N, const double alpha, const double *A, const MKL_INT lda, const

double *X, const MKL_INT incX, Ypointer, 1).

Last, if you are using Intel C Compiler, Array notication also is helpful to convert your matlab to C code.

Please See http://software.intel.com/en-us/articles/about-intel-cilk-plus-and-how-to-get-started.

You can write A[:] - refers the entire array in C code.

Best Regards,

Ying

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.