5

I already know how to multiply two matrices with alglib, using rmatrixgemm (see this question).

Is there a way to compute a linear combination of two matrices without using this function, setting B to the identity ? It wouldn't be very efficient.

Alglib provides tons of complex algorithms but I can't find such a basic function.

The manual is here.

Community
  • 1
  • 1
pintoch
  • 2,293
  • 1
  • 18
  • 26

3 Answers3

0

I think rmatrixgencopy is ALGLIB's way of providing matrix addition when you set the alpha and beta input parameters both to 1.

rmatrixgencopy (C++)

rmatrixgencopy (C#)

William
  • 1,993
  • 2
  • 23
  • 40
-1

you might be able just to use alglib.cmatrixgemm to do Addition.

This subroutine calculates C = alpha*op1(A)op2(B) +betaC where:

  • C is MxN general matrix
  • op1(A) is MxK matrix
  • op2(B) is KxN matrix
  • "op" may be identity transformation, transposition, conjugate transposition.

If you want to do C = A + C, you just need to set: B = Identity, alpha = 1, beta = 1, op = identity transformation.

Di Wang
  • 471
  • 1
  • 8
  • 22
  • Thanks! Is there a benefit over doing it with `rmatrixgemm` as mentioned in the question? – pintoch Aug 04 '21 at 15:02
  • Not much, you can not add matrix that is not square. Have you tried MathNet.Numerics? it looks much simpler, just do: Matrix A, Matrix B, then print A + B. – Di Wang Aug 11 '21 at 05:12
  • I haven't done a benchmark, but I think it's probably not a great idea (for readability or performance) to use the ALGLIB multiplication routines in a degenerate configuration to do what 3 LoCs (probably a bit more if you use SIMD) could do. – William Nov 04 '22 at 14:59
-3

Why don't you try using another library that was created for the purpose of matrix math such as MTL4?

http://www.simunova.com/en/node/24

Manual - http://www.simunova.com/node/148

J_Xlin
  • 73
  • 1
  • 10
  • Indeed it seems that alglib isn't suited to this use. – pintoch May 12 '13 at 08:25
  • This is useful info (pointing to similar libraries), but it should go in a comment under the question, not as a separate answer (because it doesn't actually answer the question). – William Nov 04 '22 at 14:56