Skip to content

Commit c8f1202

Browse files
committed
Algo changes part 1
1 parent f8d0e26 commit c8f1202

File tree

3 files changed

+44
-45
lines changed

3 files changed

+44
-45
lines changed

src/Modules/Legacy/Forward/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ SET(Modules_Legacy_Forward_HEADERS
3232
BuildBEMatrix.h
3333
BuildBEMatrixImpl.h
3434
CalcTMP.h
35-
#CalcTMPAlgo.h
35+
CalcTMPAlgo.h
3636
)
3737

3838
SET(Modules_Legacy_Forward_SRCS
3939
BuildBEMatrix.cc
4040
BuildBEMatrixImpl.cc
4141
CalcTMP.cc
42-
#CalcTMPAlgo.cc
42+
CalcTMPAlgo.cc
4343
)
4444

4545
SCIRUN_ADD_LIBRARY(Modules_Legacy_Forward

src/Modules/Legacy/Forward/CalcTMPAlgo.cc

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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+
108108
bool 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+
182182
bool 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

src/Modules/Legacy/Forward/CalcTMPAlgo.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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
@@ -49,9 +49,8 @@
4949
#include <map>
5050
#include <string>
5151

52-
//#define maxAmpl 1e-6
53-
5452
#include <Packages/BioPSE/Core/Algorithms/NumApproximation/share.h>
53+
5554
namespace BioPSE {
5655

5756
using namespace SCIRun;
@@ -62,7 +61,7 @@ class SCISHARE CalcTMPAlgo : public AlgoLibrary
6261
private:
6362

6463

65-
64+
6665
public:
6766

6867
// assumes TMP_values is sized to 1 x nsamples
@@ -74,7 +73,7 @@ class SCISHARE CalcTMPAlgo : public AlgoLibrary
7473
const double repslope,
7574
const double rest,
7675
DenseMatrix& TMP_values);
77-
76+
7877
// assumes TMP_values is already sized to nnodes x nsamples
7978
bool calc_all_TMPs(const DenseMatrix& amplitudes,
8079
const DenseMatrix& deps,
@@ -84,7 +83,7 @@ class SCISHARE CalcTMPAlgo : public AlgoLibrary
8483
const DenseMatrix& repslopes,
8584
const DenseMatrix& rests,
8685
DenseMatrix& TMP_values);
87-
86+
8887

8988
// normal entry case
9089
bool calc_TMPs(MatrixHandle amplitudes,

0 commit comments

Comments
 (0)