Skip to content

Commit bd5e60c

Browse files
committed
Had to add some further testing for non-converging kernels
1 parent 9fc1582 commit bd5e60c

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

src/numerics/APRDenoise.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,18 +1085,30 @@ class APRDenoise {
10851085

10861086
bool valid_check = true;
10871087

1088-
float c_sum = 0;
1088+
double coeff_sum = 0;
10891089

10901090
for (size_t l1 = 0; l1 < stencil.linear_coeffs.size(); ++l1) {
10911091
if(std::isnan(stencil.linear_coeffs[l1])){
10921092
valid_check = false;
10931093
}
1094-
c_sum += stencil.linear_coeffs[l1];
1094+
coeff_sum += stencil.linear_coeffs[l1];
10951095
}
10961096

1097+
1098+
10971099
// Does it sum close to 1? very liberal to detect agian non-convergence.
1098-
float error_threshold = 0.2;
1099-
if(std::abs(c_sum - 1.0f) > error_threshold){
1100+
float error_threshold = 0.1;
1101+
double val = coeff_sum - 1.0;
1102+
1103+
if(std::abs(val) > error_threshold){
1104+
valid_check = false;
1105+
}
1106+
1107+
std::cout << "kernel sum: " << coeff_sum << std::endl;
1108+
1109+
bool diverged_val = std::isnan(coeff_sum);
1110+
1111+
if(diverged_val){
11001112
valid_check = false;
11011113
}
11021114

test/DenoiseTest.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void init_stencil(TestData& testData){
6464
stencil.linear_coeffs.resize(num_pts);
6565

6666
//make the pts just be the index of the array for easy checking;
67-
for(int i = 0; i < stencil.linear_coeffs.size();i++) {
67+
for(size_t i = 0; i < stencil.linear_coeffs.size();i++) {
6868
stencil.linear_coeffs[i] = i;
6969
}
7070

@@ -178,7 +178,7 @@ bool test_io(TestData &testData){
178178
auto &stencil_input = inputStencils.stencils[level];
179179
auto &stencil_read = readStencils.stencils[level];
180180

181-
for (int i = 0; i < stencil_input.linear_coeffs.size(); i++) {
181+
for (size_t i = 0; i < stencil_input.linear_coeffs.size(); i++) {
182182

183183
if (stencil_read.linear_coeffs[i] != stencil_input.linear_coeffs[i]) {
184184
success = false;
@@ -222,7 +222,7 @@ bool test_apply(TestData &testData){
222222

223223
auto& stencil = testData.aprStencils.stencils[number_stencils];
224224

225-
for (int i = 0; i < stencil.linear_coeffs.size(); ++i) {
225+
for (size_t i = 0; i < stencil.linear_coeffs.size(); ++i) {
226226
stencil_total += stencil.linear_coeffs[i];
227227
}
228228

@@ -267,7 +267,7 @@ bool test_apply_center(TestData &testData){
267267
ParticleData<float> particlesOutput;
268268
particlesOutput.init(testData.apr);
269269

270-
for (int j = 0; j < indexParticles.size(); ++j) {
270+
for (size_t j = 0; j < indexParticles.size(); ++j) {
271271
indexParticles[j] = j;
272272
}
273273

@@ -322,14 +322,33 @@ bool test_train(TestData& testData){
322322

323323
ParticleData<float> particlesOutput;
324324

325+
325326
aprDenoise.train_denoise(testData.apr,testData.parts,testData.aprStencils);
326327

327328
aprDenoise.apply_denoise(testData.apr,testData.parts,particlesOutput,testData.aprStencils);
328329

330+
float s_threshold = 0.1;
331+
332+
//output and check stencils
333+
for (size_t i = 0; i < testData.aprStencils.stencils.size(); ++i) {
334+
335+
auto stencil = testData.aprStencils.stencils[i];
336+
float sum = 0;
337+
for (size_t j = 0; j < stencil.linear_coeffs.size(); ++j) {
338+
sum+= stencil.linear_coeffs[j];
339+
}
340+
if(stencil.linear_coeffs.size() > 0) {
341+
if (std::abs(sum - 1.0f) > s_threshold) {
342+
success = false;
343+
}
344+
}
345+
346+
}
347+
329348

330349
float threshold = 0.2; //arbitrary testing threshold, is the value somewhere close?
331350

332-
for (int i = 0; i < testData.parts.size(); ++i) {
351+
for (size_t i = 0; i < testData.parts.size(); ++i) {
333352

334353
float diff = std::abs((testData.parts[i] - particlesOutput[i]));
335354

test/ExamplesTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ void CreateGTSmall1DTest::SetUp(){
140140

141141
void CreateSmallSphereTest::SetUp(){
142142

143-
144143
std::string file_name = get_source_directory_apr() + "files/Apr/sphere_120/sphere.apr";
145144
test_data.apr_filename = file_name;
146145

0 commit comments

Comments
 (0)