annotate toolboxes/FullBNT-1.0.7/KPMtools/colmult.c @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 #include <stdio.h>
Daniel@0 2 #include "mex.h"
Daniel@0 3
Daniel@0 4 /*
Daniel@0 5 out = colop(M, v)
Daniel@0 6
Daniel@0 7 Apply binary operator to a vector v and to each column of M in turn
Daniel@0 8 to produce a matrix the same size as M.
Daniel@0 9
Daniel@0 10 This is equivalent to
Daniel@0 11
Daniel@0 12 out = zeros(size(M));
Daniel@0 13 for col=1:size(M,2)
Daniel@0 14 out(:,col) = op(M(:,col), v);
Daniel@0 15 end
Daniel@0 16
Daniel@0 17 The code needs to be modified for each different operator 'op'.
Daniel@0 18 eg op = '.*'
Daniel@0 19
Daniel@0 20 In vectorized form:
Daniel@0 21
Daniel@0 22 out = M .* repmat(v(:), 1, size(M,2))
Daniel@0 23
Daniel@0 24 (This function was formerly called repmat_and_mult.c)
Daniel@0 25
Daniel@0 26 */
Daniel@0 27
Daniel@0 28 /* M(i,j) = M(i + nrows*j) since Matlab uses Fortran layout. */
Daniel@0 29
Daniel@0 30
Daniel@0 31 #define INMAT(i,j) M[(i)+nrows*(j)]
Daniel@0 32 #define OUTMAT(i,j) out[(i)+nrows*(j)]
Daniel@0 33
Daniel@0 34 void mexFunction(
Daniel@0 35 int nlhs, mxArray *plhs[],
Daniel@0 36 int nrhs, const mxArray *prhs[]
Daniel@0 37 )
Daniel@0 38 {
Daniel@0 39 double *out, *M, *v;
Daniel@0 40 int nrows, ncols, r, c;
Daniel@0 41
Daniel@0 42 /* read the input args */
Daniel@0 43 M = mxGetPr(prhs[0]);
Daniel@0 44 nrows = mxGetM(prhs[0]);
Daniel@0 45 ncols = mxGetN(prhs[0]);
Daniel@0 46
Daniel@0 47 v = mxGetPr(prhs[1]);
Daniel@0 48
Daniel@0 49 plhs[0] = mxCreateDoubleMatrix(nrows, ncols, mxREAL);
Daniel@0 50 out = mxGetPr(plhs[0]);
Daniel@0 51
Daniel@0 52 for (c=0; c < ncols; c++) {
Daniel@0 53 for (r=0; r < nrows; r++) {
Daniel@0 54 OUTMAT(r,c) = INMAT(r,c) * v[r];
Daniel@0 55 /* printf("r=%d, c=%d, M=%f, v=%f\n", r, c, INMAT(r,c), v[r]); */
Daniel@0 56 }
Daniel@0 57 }
Daniel@0 58
Daniel@0 59 }
Daniel@0 60
Daniel@0 61
Daniel@0 62