This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Basic matrix multiplication of double* objects.

Tags: None
(comma "," separated)
jamesjo
Registered Member
Posts
1
Karma
0
I have just started using Eigen (also new to C++, although know C fairly well) and to help learn, wanted to interface some functionality with Python using Cython. Am I right in thinking that this is the correct way to matrix multiply with double* objects? I.e. the `Map`, `.matrix()` and `.array()` are essentially free and this would have no overhead as if I had just passed these objects to a BLAS function?
Code: Select all
#include <iostream>
#include <Eigen/Dense>

using namespace std;
using namespace Eigen;

int matrix_mult_d_c(double *A, double *B, double *C,
        int m, int n, int k) {
    // Convert A, B and C to Eigen arrays.
    Map<ArrayXXd> A_arr(A, m, n);
    Map<ArrayXXd> B_arr(B, n, k);
    Map<ArrayXXd> C_arr(C, m, k);

    // Convert Eigen arrays to matrices.
    // Do the matrix multiply.
    C_arr = (A_arr.matrix() * B_arr.matrix()).array();

    return 0;
}


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]