00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "common.h"
00020 #include "ParallelMatrixWeight.h"
00021
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024
00025
00026
00027 ParallelMatrixWeight::ParallelMatrixWeight(mrs_string name) : MarSystem("ParallelMatrixWeight", name)
00028 {
00030
00031
00032
00033
00034
00035 addControls();
00036 }
00037
00038 ParallelMatrixWeight::ParallelMatrixWeight(const ParallelMatrixWeight& a) : MarSystem(a)
00039 {
00040
00043
00044 ctrl_weights_ = getctrl("mrs_realvec/weights");
00045 }
00046
00047
00048 ParallelMatrixWeight::~ParallelMatrixWeight()
00049 {
00050 }
00051
00052 MarSystem*
00053 ParallelMatrixWeight::clone() const
00054 {
00055
00056 return new ParallelMatrixWeight(*this);
00057 }
00058
00059 void
00060 ParallelMatrixWeight::addControls()
00061 {
00062 mrs_realvec tmp(1);
00063 tmp(0) = 1;
00064
00065 addctrl("mrs_realvec/weights", tmp, ctrl_weights_);
00066 }
00067
00068 void
00069 ParallelMatrixWeight::myUpdate(MarControlPtr sender)
00070 {
00071 MRSDIAG("ParallelMatrixWeight.cpp - ParallelMatrixWeight:myUpdate");
00072
00074 MarSystem::myUpdate(sender);
00075 }
00076
00077 void
00078 ParallelMatrixWeight::myProcess(realvec& in, realvec& out)
00079 {
00080 mrs_realvec weights = ctrl_weights_->to<mrs_realvec> ();
00081 mrs_natural k,i,j,
00082 numRows = weights.getRows (),
00083 numCols = weights.getCols (),
00084 intRows,
00085 intCols;
00086
00087 if (numRows == 0)
00088 {
00089 out.setval(0);
00090 return;
00091 }
00092
00093 if (in.getRows () % numRows)
00094 {
00095 MRSWARN("ParallelMatrixWeight: dimension mismatch");
00096 MRSASSERT(false);
00097 out.setval(0);
00098 return;
00099 }
00100
00101 intRows = in.getRows () / numRows,
00102 intCols = in.getCols ();
00103
00104 out = in;
00105
00106 if (numCols == 1)
00107 {
00108 for (k = 0; k < numRows; k++)
00109 {
00110 mrs_real weight = weights(k);
00111 for (i = 0; i < intRows; i++)
00112 {
00113 for (j = 0; j < intCols; j++)
00114 {
00115 out(k*intRows+i,j) *= weight;
00116 }
00117 }
00118 }
00119 }
00120 else
00121 {
00122 if (in.getCols () % numCols || in.getRows () != numRows)
00123 {
00124 MRSWARN("ParallelMatrixWeight: dimension mismatch");
00125 MRSASSERT(false);
00126 out.setval(0);
00127 return;
00128 }
00129
00130 out *= weights;
00131 }
00132 #ifdef MARSYAS_MATLAB
00133 #ifdef MTLB_DBG_LOG
00134 MATLAB_PUT(in, "in");
00135 MATLAB_PUT(out, "out");
00136 MATLAB_PUT(weights, "weights");
00137 MATLAB_EVAL("figure(2);subplot(221),imagesc(in),colorbar;subplot(222),imagesc(out),colorbar;subplot(212),imagesc(weights),colorbar;");
00138 #endif
00139 #endif
00140 }