66 Copyright (c) 2011 Scientific Computing and Imaging Institute,
77 University of Utah.
88
9-
9+
1010 Permission is hereby granted, free of charge, to any person obtaining a
1111 copy of this software and associated documentation files (the "Software"),
1212 to deal in the Software without restriction, including without limitation
@@ -64,47 +64,47 @@ bool CalcTMPAlgo::calc_single_TMP(
6464 amplitude: Amplitude
6565 Output: Dense Matrix (1xsize of matrix) containing the transmembrane potential
6666 */
67-
67+
6868 size_type nrows = TMP_values.nrows ();
6969 size_type ncols = TMP_values.ncols ();
70-
70+
7171 if (nrows != 1 ){
72- error (" CalcTMPAlgo: TMP_values size incorrect" );
72+ error (" CalcTMPAlgo: TMP_values size incorrect: require rows == 1 " );
7373 return false ;
7474 }
75-
75+
7676 if (ncols <= 0 ){
77- error (" CalcTMPAlgo: TMP_values size incorrect" );
77+ error (" CalcTMPAlgo: TMP_values size incorrect: need non-empty matrix " );
7878 return false ;
7979 }
80-
80+
8181 double tdep = -dep;
8282 double trep = -rep;
83- double maxAmpl = 1e-6 ;
84-
83+ const double maxAmpl = 1e-6 ;
84+
8585 for (index_type t = 0 ; t < ncols; ++t)
8686 {
8787 double vali = 1.0 / (1.0 + exp (-depslope * tdep)) *
8888 (1.0 / (1.0 + exp (platslope * trep))) *
8989 (1.0 / (1.0 + exp (repslope * trep)));
90- TMP_values. put (0 ,t,vali) ;
90+ TMP_values (0 ,t) = vali ;
9191 if (vali > maxAmpl)
9292 {
9393 maxAmpl = vali;
9494 }
95-
95+
9696 tdep += 1.0 ;
9797 trep += 1.0 ;
9898 }
9999 double ampl = (amplitude - rest) / maxAmpl;
100100 for (index_type t = 0 ; t < ncols; ++t)
101101 {
102- TMP_values. put (0 ,t, TMP_values. get (0 ,t)* ampl + rest) ;
102+ TMP_values (0 ,t) = TMP_values (0 ,t) * ampl + rest;
103103 }
104-
104+
105105 return true ;
106106}
107-
107+
108108bool CalcTMPAlgo::calc_all_TMPs (
109109 const DenseMatrix& amplitudes,
110110 const DenseMatrix& deps,
@@ -126,13 +126,13 @@ bool CalcTMPAlgo::calc_all_TMPs(
126126 error (" CalcTMPAlgo: All inputs must be of size 1 x nodes" );
127127 return false ;
128128 }
129-
129+
130130 size_type nnodes = amplitudes.nrows ();
131131 if (nnodes <= 0 ){
132132 error (" CalcTMPAlgo: Size of inputs must be > 0" );
133133 return false ;
134134 }
135-
135+
136136 if (deps.nrows () != nnodes ||
137137 depslopes.nrows () != nnodes ||
138138 platslopes.nrows () != nnodes ||
@@ -143,19 +143,19 @@ bool CalcTMPAlgo::calc_all_TMPs(
143143 error (" CalcTMPAlgo: All inputs sizes must match" );
144144 return false ;
145145 }
146-
146+
147147 if (TMP_values.nrows () != nnodes)
148148 {
149149 error (" CalcTMPAlgo: MP_values size does not match number of nodes" );
150150 return false ;
151151 }
152-
152+
153153 if (TMP_values.ncols () <= 0 )
154154 {
155155 error (" CalcTMPAlgo: Number of columns in TMP_values must be greater than 0 for output" );
156156 return false ;
157157 }
158-
158+
159159 DenseMatrix mat (1 , TMP_values.ncols ());
160160 for (index_type node = 0 ; node < nnodes; ++node)
161161 {
@@ -175,10 +175,10 @@ bool CalcTMPAlgo::calc_all_TMPs(
175175 TMP_values.put (node, t, mat.get (0 , t));
176176 }
177177 }
178-
178+
179179 return true ;
180180}
181-
181+
182182bool CalcTMPAlgo::calc_TMPs (MatrixHandle amplitudes,
183183 MatrixHandle deps,
184184 MatrixHandle depslopes,
@@ -187,7 +187,7 @@ bool CalcTMPAlgo::calc_TMPs(MatrixHandle amplitudes,
187187 MatrixHandle repslopes,
188188 MatrixHandle rests,
189189 unsigned int nsamples,
190- MatrixHandle & output)
190+ DenseMatrixHandle & output)
191191{
192192 if (matrix_is::sparse (amplitudes) ||
193193 matrix_is::sparse (deps) ||
@@ -200,21 +200,21 @@ bool CalcTMPAlgo::calc_TMPs(MatrixHandle amplitudes,
200200 error (" CalcTMPAlgo: Sparse matrices not supported." );
201201 return false ;
202202 }
203-
204- output = new DenseMatrix (amplitudes->nrows (), nsamples);
205-
206- if (! calc_all_TMPs (*( amplitudes-> dense ()),
207- *(deps-> dense ()),
208- *(depslopes-> dense ()) ,
209- *(platslopes-> dense ()),
210- *(reps ->dense ()),
211- *(repslopes ->dense ()),
212- *(rests ->dense ()),
213- *(output ->dense ())))
214- {
215- return false ;
216- }
217- return true ;
203+
204+ output. reset ( new DenseMatrix (amplitudes->nrows (), nsamples) );
205+
206+ DenseMatrixHandle ampDense ( matrix_cast::as_dense ( amplitudes));
207+
208+ return calc_all_TMPs (*ampDense ,
209+
210+ *(deps ->dense ()),
211+ *(depslopes ->dense ()),
212+ *(platslopes ->dense ()),
213+ *(reps ->dense ()),
214+ *(repslopes-> dense ()),
215+ *(rests-> dense ()),
216+
217+ *output) ;
218218}
219219
220220
0 commit comments