I find that boost::ublas doesn't support element-by-element operations and operations in sequence very well (but the efficiency is pretty high :)) I am trying to
D = A^2 .* B^3 .* C
where A, B, C are all square matrices of the same size, operator ".*" denotes the element-by-element operation and ^ is the power of the matrix. With boost:ublas, I wrote
for (int n=0; n<300; n++)
{
for (int k=0; k<300; k++)
{
D(n, k) = pow(abs(A(n, k)), 2)*pow(abs(B(n, k)), 3)*C(n, k);
}
}
In my program I have many sequent operations like those shown above, anyway I can get the same result but using one line of code instead of loop?
Also, I observe that it seems no valid to assign a constant to all elements of matrix or vector like
boost::numeric::ublas::vector v(100); v = 0.2;
Instead, I have to use a loop to do the assignment again, any better way to save some code? My algorithm is a really long and there are so many tedious operations like those stated above. I tried another numerical library Armadillo, which provides a good way to simply the operations but it currently doesn't suppose sparse matrices (which will spend about 10 times in running my code).