about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/colmult.c
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/KPMtools/colmult.c
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

I am calling this BNW_1.02. It can be accessed at:
compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/KPMtools/colmult.c')
-rw-r--r--sourcecodes/bnt-master/KPMtools/colmult.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMtools/colmult.c b/sourcecodes/bnt-master/KPMtools/colmult.c
new file mode 100644
index 00000000..e9d5008c
--- /dev/null
+++ b/sourcecodes/bnt-master/KPMtools/colmult.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include "mex.h"
+
+/*
+out = colop(M, v)
+
+Apply binary operator to a vector v and to each column of M in turn
+to produce a matrix the same size as M.
+
+This is equivalent to
+
+out = zeros(size(M));
+for col=1:size(M,2)
+  out(:,col) = op(M(:,col), v);
+end
+
+The code needs to be modified for each different operator 'op'.
+eg op = '.*'
+
+In vectorized form:
+
+out = M .* repmat(v(:), 1, size(M,2))
+
+(This function was formerly called repmat_and_mult.c)
+
+*/
+
+/* M(i,j) = M(i + nrows*j) since Matlab uses Fortran layout. */
+
+ 
+#define INMAT(i,j) M[(i)+nrows*(j)]
+#define OUTMAT(i,j) out[(i)+nrows*(j)]
+
+void mexFunction(
+                 int nlhs,       mxArray *plhs[],
+                 int nrhs, const mxArray *prhs[]
+		 )
+{
+  double *out, *M, *v;
+  int nrows, ncols, r, c;
+  
+  /* read the input args */
+  M = mxGetPr(prhs[0]);
+  nrows = mxGetM(prhs[0]);
+  ncols = mxGetN(prhs[0]);
+
+  v = mxGetPr(prhs[1]);
+
+  plhs[0] = mxCreateDoubleMatrix(nrows, ncols, mxREAL);
+  out = mxGetPr(plhs[0]); 
+
+  for (c=0; c < ncols; c++) {
+    for (r=0; r < nrows; r++) {
+      OUTMAT(r,c) = INMAT(r,c) * v[r]; 
+      /* printf("r=%d, c=%d, M=%f, v=%f\n", r, c, INMAT(r,c), v[r]);  */
+    }
+  }
+
+}
+
+
+