Demo entry 2353798

Multiplies spares matrices

   

Submitted by anonymous on Aug 13, 2015 at 22:34
Language: C. Code size: 972 Bytes.

#include <stdio.h>
#include "mex.h"
#include "matrix.h"



void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
    /*** Variables declaration ***/
    double *vector_OUT;
    double *vector_IN;
    double *data;
    mwSize nrc,nrr;
    mwIndex j=0,i;
    mwIndex *cidx;
    mwIndex *ridx;

    /*** Read vector_IN ***/
    vector_IN=mxGetPr(prhs[1]);

    /*** Read cidx, ridx and data ***/
    cidx=mxGetJc(prhs[0]);
    ridx=mxGetIr(prhs[0]);
    data=mxGetPr(prhs[0]); // ***

    /*** Get nr of columns ***/
    nrc=mxGetN(prhs[0]);
    nrr=mxGetM(prhs[0]);


    /*** Create an Output vector and its pointer ***/
    plhs[0] = mxCreateNumericMatrix(nrr,1, mxDOUBLE_CLASS, mxREAL);
    vector_OUT = (double *)mxGetData(plhs[0]); // ***

    for (j=0; j<nrc; j++)
    {
        for (i=cidx[j]; i<cidx[j+1]; i++)
        {
            vector_OUT[ridx[i]]+=vector_IN[j]*data[i];
        }
    }




}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).