@@ -977,12 +977,15 @@ PoissonLogLikelihoodWithLinearModelForMeanAndProjData<
977
977
this ->get_num_subsets ());
978
978
979
979
info (" Forward projecting input image." , 2 );
980
+ volatile bool any_negatives = false ;
980
981
#ifdef STIR_OPENMP
981
982
# pragma omp parallel for schedule(dynamic)
982
983
#endif
983
984
// note: older versions of openmp need an int as loop
984
985
for (int i = 0 ; i < static_cast <int >(vg_idx_to_process.size ()); ++i)
985
986
{
987
+ if (any_negatives)
988
+ continue ; // early exit as we'll throw error outside of the parallel for
986
989
const auto viewgram_idx = vg_idx_to_process[i];
987
990
{
988
991
#ifdef STIR_OPENMP
@@ -1011,6 +1014,11 @@ PoissonLogLikelihoodWithLinearModelForMeanAndProjData<
1011
1014
{
1012
1015
tmp_viewgrams = this ->get_proj_data ().get_empty_related_viewgrams (viewgram_idx, symmetries_sptr);
1013
1016
this ->get_projector_pair ().get_forward_projector_sptr ()->forward_project (tmp_viewgrams);
1017
+ if (tmp_viewgrams.find_min () < 0 )
1018
+ {
1019
+ any_negatives = true ;
1020
+ continue ; // throw error outside of parallel for
1021
+ }
1014
1022
}
1015
1023
1016
1024
// now divide by the data term
@@ -1024,6 +1032,11 @@ PoissonLogLikelihoodWithLinearModelForMeanAndProjData<
1024
1032
1025
1033
} // end of loop over view/segments
1026
1034
1035
+ if (any_negatives)
1036
+ error (" PoissonLL add_multiplication_with_approximate_sub_Hessian: forward projection of input contains negatives. The "
1037
+ " result would be incorrect, so we abort.\n "
1038
+ " See https://github.com/UCL/STIR/issues/1461" );
1039
+
1027
1040
shared_ptr<TargetT> tmp (output.get_empty_copy ());
1028
1041
this ->get_projector_pair ().get_back_projector_sptr ()->get_output (*tmp);
1029
1042
// output += tmp;
@@ -1098,11 +1111,15 @@ PoissonLogLikelihoodWithLinearModelForMeanAndProjData<TargetT>::actual_accumulat
1098
1111
1099
1112
// Forward project input image
1100
1113
info (" Forward projecting input image." , 2 );
1114
+ volatile bool any_negatives = false ;
1101
1115
#ifdef STIR_OPENMP
1102
1116
# pragma omp parallel for schedule(dynamic)
1103
1117
#endif
1104
1118
for (int i = 0 ; i < static_cast <int >(vg_idx_to_process.size ()); ++i)
1105
1119
{ // Loop over each of the viewgrams in input_viewgrams_vec, forward projecting input into them
1120
+ if (any_negatives)
1121
+ continue ; // early exit as we'll throw error outside of the parallel for
1122
+
1106
1123
const auto viewgram_idx = vg_idx_to_process[i];
1107
1124
{
1108
1125
#ifdef STIR_OPENMP
@@ -1118,7 +1135,16 @@ PoissonLogLikelihoodWithLinearModelForMeanAndProjData<TargetT>::actual_accumulat
1118
1135
}
1119
1136
input_viewgrams_vec[i] = this ->get_proj_data ().get_empty_related_viewgrams (viewgram_idx, symmetries_sptr);
1120
1137
this ->get_projector_pair ().get_forward_projector_sptr ()->forward_project (input_viewgrams_vec[i]);
1138
+ if (input_viewgrams_vec[i].find_min () < 0 )
1139
+ {
1140
+ any_negatives = true ;
1141
+ continue ; // throw error outside of parallel for
1142
+ }
1121
1143
}
1144
+ if (any_negatives)
1145
+ error (" PoissonLL accumulate_sub_Hessian_times_input: forward projection of input contains negatives. The "
1146
+ " result would be incorrect, so we abort.\n "
1147
+ " See https://github.com/UCL/STIR/issues/1461" );
1122
1148
1123
1149
info (" Forward projecting current image estimate and back projecting to output." , 2 );
1124
1150
this ->get_projector_pair ().get_forward_projector_sptr ()->set_input (current_image_estimate);
0 commit comments