how to compute matrix's power or square

642 views
Skip to first unread message

杨鑫

unread,
Oct 29, 2014, 3:10:29 PM10/29/14
to openbla...@googlegroups.com
Dear all, 

I'm a newbie to OpenBlas. Now, I encountered a  problem in computing such a simple equation: T = Center.^2;    Center is a m*n matrix.
I found ways in many references, but I still don't know how to implement it with OpenBlas. 
Could anybody tell me how to solve this problem?

Thanks,
Xin



Chelaru Viorel

unread,
Nov 3, 2014, 12:50:52 PM11/3/14
to openbla...@googlegroups.com
I have the same problem.

Zhang Xianyi

unread,
Nov 4, 2014, 3:57:13 AM11/4/14
to 杨鑫, Chelaru Viorel, openbla...@googlegroups.com
Hi Xin, Chelaru,

What's the meaning of T=Center^2? Do you mean T=Center * Center'(the transpose)?

If the matrix is col major (Fortran by default), the codes lists as following. 

double * center=(double *)malloc( m*n*sizeof(double));
double * t=(double*)malloc(m*m*sizeof(double));
int lda=m;    //CblasColMajor
int ldc=m;    //CblasColMajor
double alpha=1.0;
double beta=0.0;

cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, m, m, n, alpha, center, lda, center, lda, beta, t, ldc);


--
You received this message because you are subscribed to the Google Groups "OpenBLAS-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openblas-user...@googlegroups.com.
To post to this group, send email to openbla...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chelaru Viorel

unread,
Nov 4, 2014, 5:44:56 AM11/4/14
to openbla...@googlegroups.com, yangx...@gmail.com, chelaru...@gmail.com
Hi Zhang,
by .^ I think he meant element wise square function, matlab style; if it's not, Xin, please correct me.
so with openBLAS I can't apply sigmoid, pow, sqrt, ...etc.... function to each element of a vector or a matrix.

Viorel

杨鑫

unread,
Nov 4, 2014, 10:01:55 AM11/4/14
to openbla...@googlegroups.com
Dear Chelaru and Xianyi, 

Sorry for my omission. What I mean with this problem is in the same way Chelaru mentioned, that is
if T = [1 2 3; 2 2 2], then T.^2 = [1 4 9; 4 4 4].
Xianyi, I referred to your instructions and links in the email and I found that there were no proper functions in cblas, MKL and sparseBlas to calculate the pow, sqrt of a matrix. I'm really curious about the implemention of these special functions which are adopted by companies.
Finally, I only have to write a 'for' loop to calculate the .^2 with the 'powf' function provided by C++.

在 2014年10月29日星期三UTC-4下午3时10分29秒,杨鑫写道:

Zhang Xianyi

unread,
Nov 4, 2014, 10:44:56 AM11/4/14
to 杨鑫, openbla...@googlegroups.com

Hi Viorel, Xin,

I afraid BLAS doesn't support these functions. I suggest you can try Intel MKL Vector Math Library to calculate mul, power, sqrt on vectors.

For example, you can use vdMul as following.

vdMul(m*n, T, T, T);


B.T.W, for the multiplication case, I think the compiler can auto-vectorize your for loop. 

Chelaru Viorel

unread,
Nov 4, 2014, 12:46:46 PM11/4/14
to openbla...@googlegroups.com, yangx...@gmail.com
I know about Intel MKL, but openBLAS is free and with very good performance.
There is by any change a plan to introduce these basic element-wise functions in openBLAS ?
I don't know assembler, but since it's about only 1 vector it should be simpler to implement than a matrix multiplication... but I'm just guessing.

Viorel

Zhang Xianyi

unread,
Nov 5, 2014, 12:22:33 AM11/5/14
to Chelaru Viorel, openbla...@googlegroups.com, 杨鑫
Hi Viorel,

I think it's possible to implement similar VML functions in OpenBLAS.
However, it may be unoptimized at first.

Xianyi

Chelaru Viorel

unread,
Nov 5, 2014, 7:18:48 AM11/5/14
to openbla...@googlegroups.com, chelaru...@gmail.com, yangx...@gmail.com
Hi Xianyi,
you said unoptimized, but will run multi-core, right ?
for me it's ok to run at least multi core; optimized for some arhitecture... I can wait.

So you will implement some element-wise functions? in some near future ?
I personally need sigmoid, tanh, log, exp, pow for matrices and vectors.

Viorel
Reply all
Reply to author
Forward
0 new messages