Matrix scale() function will not run
Hello Blaze team,
I would like to use the built-in scale() function to perform elementwise matrix-matrix or vector-vector multiplication, but when I try to run:
blaze::StaticMatrix<dfloat, 2, 2> M1();
M1=1;
blaze::StaticMatrix<dfloat, 2, 2> M2(M1);
M2.scale(M1);
I get the following error:
[path2blaze]/blaze/include/blaze/math/dense/StaticMatrix.h:1960:21
error: invalid operands of types ‘double’ and ‘blaze::StaticMatrix<double, 2ul, 2ul>(’
to binary ‘operator’
v_[iNN+j] = scalar;
~~~^~~~~
[path2blaze]/blaze/include/blaze/math/dense/StaticMatrix.h:1960:21
error: in evaluation of ‘operator=(double, class blaze::StaticMatrix<double, 2ul, 2ul>())’
The same thing occurs when I attempt to use dynamic or sparse matrices, or even dynamic vectors. I can get around this with custom functions, but it would be extremely useful to simply be able to call this builtin function.
Best, Ben Beach
Comments (2)
-
reporter -
- changed status to wontfix
Hi Benjamin!
We have to apologize for the apparently misleading or incomplete documentation of the
scale()
function.scale()
does not perform a componentwise vector-vector or matrix-matrix multiplication, but applies the given scalar element to all elements of the vector or matrix:DynamicMatrix<int> A; A *= 5; // Scaling matrix A by 5; only works for fundamental data types and complex numbers A.scale( 5 ); // Same effect as the previous function call; works for all possible data types
In contrast to the multiplication assignment operator, which only works for fundamental data types and
std::complex
, thescale()
function works for all possible data types. This might for instance be necessary for block vectors and matrices.The componentwise multiplication for vectors is available via
operator*()
:DynamicVector<int> a, b, c; c = a * b; // Element-wise multiplication
The componentwise matrix multiplication (i.e. the Hadamard product or Schur product) is one of the big new features of Blaze 3.2 and will be available shortly (see issue #60).
Again, we are sorry for the confusing and will try to update the documentation of the
scale()
function accordingly.Best regards,
Klaus!
- Log in to comment
Update: When I said run, I really meant compile; the errors are compiler errors.