Skip to content

Commit 63ee672

Browse files
authored
[ML] Avoid multi-line macros (#1763)
1 parent d4c8a60 commit 63ee672

18 files changed

+72
-69
lines changed

include/api/CDataFrameAnalysisConfigReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class API_EXPORT CDataFrameAnalysisConfigReader {
7575
T as() const {
7676
if (m_Value == nullptr) {
7777
HANDLE_FATAL(<< "Input error: expected value for '" << m_Name
78-
<< "'. Please report this problem.")
78+
<< "'. Please report this problem.");
7979
}
8080
return this->fallback(T{});
8181
}
@@ -84,7 +84,7 @@ class API_EXPORT CDataFrameAnalysisConfigReader {
8484
const std::string& value) const {
8585
if (m_Value == nullptr) {
8686
HANDLE_FATAL(<< "Input error: expected value for '" << m_Name
87-
<< "'. Please report this problem.")
87+
<< "'. Please report this problem.");
8888
}
8989
return this->fallback(name, value, std::make_pair("", 0.0));
9090
}

include/core/LogMacros.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
#undef LOG_WARN
7878
#endif
7979
#define LOG_WARN(message) \
80-
{ \
80+
do { \
8181
std::size_t countOfWarnMessages; \
8282
bool skipWarnMessage; \
8383
std::tie(countOfWarnMessages, skipWarnMessage) = \
@@ -90,12 +90,12 @@
9090
? " | repeated [" + std::to_string(countOfWarnMessages) + "]" \
9191
: ""); \
9292
} \
93-
}
93+
} while (0)
9494
#ifdef LOG_ERROR
9595
#undef LOG_ERROR
9696
#endif
9797
#define LOG_ERROR(message) \
98-
{ \
98+
do { \
9999
std::size_t countOfErrorMessages; \
100100
bool skipErrorMessage; \
101101
std::tie(countOfErrorMessages, skipErrorMessage) = \
@@ -108,7 +108,7 @@
108108
? " | repeated [" + std::to_string(countOfErrorMessages) + "]" \
109109
: ""); \
110110
} \
111-
}
111+
} while (0)
112112
#ifdef LOG_FATAL
113113
#undef LOG_FATAL
114114
#endif
@@ -120,11 +120,11 @@
120120
#undef HANDLE_FATAL
121121
#endif
122122
#define HANDLE_FATAL(message) \
123-
{ \
123+
do { \
124124
std::ostringstream ss; \
125125
ss message; \
126126
ml::core::CLogger::instance().handleFatal(ss.str()); \
127-
}
127+
} while (0)
128128

129129
#ifdef LOG_ABORT
130130
#undef LOG_ABORT

lib/api/CBoostedTreeInferenceModelBuilder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void CBoostedTreeInferenceModelBuilder::addNode(std::size_t splitFeature,
100100
// use dynamic cast to prevent using wrong type of trained models
101101
auto tree = dynamic_cast<CTree*>(ensemble->trainedModels().back().get());
102102
if (tree == nullptr) {
103-
HANDLE_FATAL(<< "Internal error. Tree points to a nullptr.")
103+
HANDLE_FATAL(<< "Internal error. Tree points to a nullptr.");
104104
}
105105
tree->treeStructure().emplace_back(tree->size(), splitValue, assignMissingToLeft,
106106
nodeValue.to<TDoubleVec>(), splitFeature,

lib/api/CDataFrameAnalysisConfigReader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CDataFrameAnalysisConfigReader::read(const rapidjson::Value& json) const {
7777
}
7878
if (found == false) {
7979
HANDLE_FATAL(<< "Input error: unexpected parameter '"
80-
<< i->name.GetString() << "'. Please report this problem.")
80+
<< i->name.GetString() << "'. Please report this problem.");
8181
}
8282
}
8383

lib/api/CDataFrameAnalysisInstrumentation.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void CDataFrameAnalysisInstrumentation::updateMemoryUsage(std::int64_t delta) {
119119
<< memoryReestimateBytes << ".");
120120
HANDLE_FATAL(<< "Input error: memory limit [" << bytesToString(m_MemoryLimit)
121121
<< "] has been exceeded. Please force stop the job, increase to new estimated limit ["
122-
<< bytesToString(memoryReestimateBytes) << "] and restart.")
122+
<< bytesToString(memoryReestimateBytes) << "] and restart.");
123123
}
124124
} else {
125125
// Something has gone wrong with memory estimation. Trap this case

lib/api/CDataFrameAnalysisSpecification.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ CDataFrameAnalysisSpecification::CDataFrameAnalysisSpecification(
118118
rapidjson::Document specification;
119119
if (specification.Parse(jsonSpecification) == false) {
120120
HANDLE_FATAL(<< "Input error: failed to parse analysis specification '"
121-
<< jsonSpecification << "'. Please report this problem.")
121+
<< jsonSpecification << "'. Please report this problem.");
122122
} else {
123123

124124
auto parameters = CONFIG_READER.read(specification);
125125

126126
for (auto name : {ROWS, COLS, MEMORY_LIMIT, THREADS}) {
127127
if (parameters[name].as<std::size_t>() == 0) {
128-
HANDLE_FATAL(<< "Input error: '" << name << "' must be non-zero")
128+
HANDLE_FATAL(<< "Input error: '" << name << "' must be non-zero");
129129
}
130130
}
131131
m_NumberRows = parameters[ROWS].as<std::size_t>();
@@ -144,11 +144,11 @@ CDataFrameAnalysisSpecification::CDataFrameAnalysisSpecification(
144144
if (m_MissingFieldValue != core::CDataFrame::DEFAULT_MISSING_STRING &&
145145
core::CStringUtils::stringToTypeSilent(m_MissingFieldValue, missing)) {
146146
HANDLE_FATAL(<< "Input error: you can't use a number (" << missing
147-
<< ") to denote a missing field value.")
147+
<< ") to denote a missing field value.");
148148
}
149149
if (m_DiskUsageAllowed && m_TemporaryDirectory.empty()) {
150150
HANDLE_FATAL(<< "Input error: temporary directory path should be explicitly set if disk"
151-
" usage is allowed! Please report this problem.")
151+
" usage is allowed! Please report this problem.");
152152
}
153153

154154
auto jsonAnalysis = parameters[ANALYSIS].jsonObject();
@@ -218,20 +218,20 @@ bool CDataFrameAnalysisSpecification::validate(const core::CDataFrame& frame) co
218218
if (frame.numberRows() > this->numberRows()) {
219219
HANDLE_FATAL(<< "Input error: expected no more than '" << this->numberRows()
220220
<< "' rows but got '" << frame.numberRows() << "' rows"
221-
<< ". Please report this problem.")
221+
<< ". Please report this problem.");
222222
return false;
223223
}
224224
// As with rows, we only care if the analysis might use more memory than was
225225
// budgeted for.
226226
if (frame.numberColumns() > this->numberColumns()) {
227227
HANDLE_FATAL(<< "Input error: expected '" << this->numberColumns()
228228
<< "' columns but got '" << frame.numberRows() << "' columns"
229-
<< ". Please report this problem.")
229+
<< ". Please report this problem.");
230230
return false;
231231
}
232232

233233
if (frame.numberRows() == 0) {
234-
HANDLE_FATAL(<< "Input error: no data sent.")
234+
HANDLE_FATAL(<< "Input error: no data sent.");
235235
return false;
236236
}
237237

@@ -245,7 +245,7 @@ CDataFrameAnalysisRunner* CDataFrameAnalysisSpecification::runner() {
245245
void CDataFrameAnalysisSpecification::estimateMemoryUsage(CMemoryUsageEstimationResultJsonWriter& writer) const {
246246
if (m_Runner == nullptr) {
247247
HANDLE_FATAL(<< "Internal error: no runner available so can't estimate memory."
248-
<< " Please report this problem.")
248+
<< " Please report this problem.");
249249
return;
250250
}
251251
m_Runner->estimateMemoryUsage(writer);
@@ -270,7 +270,7 @@ void CDataFrameAnalysisSpecification::initializeRunner(const rapidjson::Value& j
270270
}
271271

272272
HANDLE_FATAL(<< "Input error: unexpected analysis name '" << m_AnalysisName
273-
<< "'. Please report this problem.")
273+
<< "'. Please report this problem.");
274274
}
275275

276276
CDataFrameAnalysisSpecification::TDataAdderUPtr

lib/api/CDataFrameAnalysisSpecificationJsonWriter.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void CDataFrameAnalysisSpecificationJsonWriter::write(const std::string& jobId,
3333
analysisParametersDoc.Parse(analysisParameters);
3434
if (analysisParametersDoc.GetParseError()) {
3535
HANDLE_FATAL(<< "Input error: analysis parameters " << analysisParameters
36-
<< " cannot be parsed as json. Please report this problem.")
36+
<< " cannot be parsed as json. Please report this problem.");
3737
}
3838
}
3939
write(jobId, rows, cols, memoryLimit, numberThreads, temporaryDirectory,
@@ -105,7 +105,7 @@ void CDataFrameAnalysisSpecificationJsonWriter::write(const std::string& jobId,
105105
writer.write(analysisParametersDocument);
106106
} else {
107107
HANDLE_FATAL(<< "Input error: analysis parameters suppose to "
108-
<< "contain an object as root node.")
108+
<< "contain an object as root node.");
109109
}
110110
}
111111

lib/api/CDataFrameAnalyzer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ bool CDataFrameAnalyzer::handleControlMessage(const TStrVec& fieldValues) {
239239
}
240240
if (unrecognised || fieldValues[m_ControlFieldIndex].size() > 1) {
241241
HANDLE_FATAL(<< "Input error: invalid control message value '"
242-
<< fieldValues[m_ControlFieldIndex] << "'. Please report this problem.")
242+
<< fieldValues[m_ControlFieldIndex] << "'. Please report this problem.");
243243
return false;
244244
}
245245
return true;

lib/api/CDataFrameOutliersRunner.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void CDataFrameOutliersRunner::writeOneRow(const core::CDataFrame& frame,
114114

115115
bool CDataFrameOutliersRunner::validate(const core::CDataFrame& frame) const {
116116
if (frame.numberColumns() < 1) {
117-
HANDLE_FATAL(<< "Input error: analysis needs at least one feature")
117+
HANDLE_FATAL(<< "Input error: analysis needs at least one feature");
118118
return false;
119119
}
120120
return true;

lib/api/CDataFrameTrainBoostedTreeClassifierRunner.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,24 @@ CDataFrameTrainBoostedTreeClassifierRunner::CDataFrameTrainBoostedTreeClassifier
102102
const TStrVec& categoricalFieldNames{spec.categoricalFieldNames()};
103103
if (std::find(categoricalFieldNames.begin(), categoricalFieldNames.end(),
104104
this->dependentVariableFieldName()) == categoricalFieldNames.end()) {
105-
HANDLE_FATAL(<< "Input error: trying to perform classification with numeric target.")
105+
HANDLE_FATAL(<< "Input error: trying to perform classification with numeric target.");
106106
}
107107
if (PREDICTION_FIELD_NAME_BLACKLIST.count(this->predictionFieldName()) > 0) {
108108
HANDLE_FATAL(<< "Input error: " << PREDICTION_FIELD_NAME << " must not be equal to any of "
109-
<< core::CContainerPrinter::print(PREDICTION_FIELD_NAME_BLACKLIST) << ".")
109+
<< core::CContainerPrinter::print(PREDICTION_FIELD_NAME_BLACKLIST)
110+
<< ".");
110111
}
111112
if (classificationWeights.size() > 0 &&
112113
classAssignmentObjective != maths::CBoostedTree::E_Custom) {
113114
HANDLE_FATAL(<< "Input error: expected "
114115
<< CLASS_ASSIGNMENT_OBJECTIVE_VALUES[maths::CDataFramePredictiveModel::E_Custom]
115116
<< " for " << CLASS_ASSIGNMENT_OBJECTIVE << " if supplying "
116117
<< CLASSIFICATION_WEIGHTS << " but got '"
117-
<< CLASS_ASSIGNMENT_OBJECTIVE_VALUES[classAssignmentObjective] << "'.")
118+
<< CLASS_ASSIGNMENT_OBJECTIVE_VALUES[classAssignmentObjective] << "'.");
118119
}
119120
if (classificationWeights.size() > 0 && classificationWeights.size() != numberClasses) {
120121
HANDLE_FATAL(<< "Input error: expected " << numberClasses << " " << CLASSIFICATION_WEIGHTS
121-
<< " but got " << classificationWeights.size() << ".")
122+
<< " but got " << classificationWeights.size() << ".");
122123
}
123124
}
124125

@@ -299,13 +300,13 @@ void CDataFrameTrainBoostedTreeClassifierRunner::validate(const core::CDataFrame
299300
<< "two classes. Trying to predict '"
300301
<< frame.columnNames()[dependentVariableColumn] << "' which has '"
301302
<< categoryCount << "' categories in the training data. "
302-
<< "The number of rows read is '" << frame.numberRows() << "'.")
303+
<< "The number of rows read is '" << frame.numberRows() << "'.");
303304
} else if (categoryCount > MAX_NUMBER_CLASSES) {
304305
HANDLE_FATAL(<< "Input error: the maximum number of classes supported is "
305306
<< MAX_NUMBER_CLASSES << ". Trying to predict '"
306307
<< frame.columnNames()[dependentVariableColumn] << "' which has '"
307308
<< categoryCount << "' categories in the training data. "
308-
<< "The number of rows read is '" << frame.numberRows() << "'.")
309+
<< "The number of rows read is '" << frame.numberRows() << "'.");
309310
}
310311
}
311312

@@ -353,7 +354,7 @@ const std::string& CDataFrameTrainBoostedTreeClassifierRunnerFactory::name() con
353354
CDataFrameTrainBoostedTreeClassifierRunnerFactory::TRunnerUPtr
354355
CDataFrameTrainBoostedTreeClassifierRunnerFactory::makeImpl(const CDataFrameAnalysisSpecification&) const {
355356
HANDLE_FATAL(<< "Input error: classification has a non-optional parameter '"
356-
<< CDataFrameTrainBoostedTreeRunner::DEPENDENT_VARIABLE_NAME << "'.")
357+
<< CDataFrameTrainBoostedTreeRunner::DEPENDENT_VARIABLE_NAME << "'.");
357358
return nullptr;
358359
}
359360

lib/api/CDataFrameTrainBoostedTreeRegressionRunner.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ CDataFrameTrainBoostedTreeRegressionRunner::CDataFrameTrainBoostedTreeRegression
8686
const TStrVec& categoricalFieldNames{spec.categoricalFieldNames()};
8787
if (std::find(categoricalFieldNames.begin(), categoricalFieldNames.end(),
8888
this->dependentVariableFieldName()) != categoricalFieldNames.end()) {
89-
HANDLE_FATAL(<< "Input error: trying to perform regression with categorical target.")
89+
HANDLE_FATAL(<< "Input error: trying to perform regression with categorical target.");
9090
}
9191
if (PREDICTION_FIELD_NAME_BLACKLIST.count(this->predictionFieldName()) > 0) {
9292
HANDLE_FATAL(<< "Input error: " << PREDICTION_FIELD_NAME << " must not be equal to any of "
93-
<< core::CContainerPrinter::print(PREDICTION_FIELD_NAME_BLACKLIST) << ".")
93+
<< core::CContainerPrinter::print(PREDICTION_FIELD_NAME_BLACKLIST)
94+
<< ".");
9495
}
9596
}
9697

@@ -180,7 +181,7 @@ const std::string& CDataFrameTrainBoostedTreeRegressionRunnerFactory::name() con
180181
CDataFrameTrainBoostedTreeRegressionRunnerFactory::TRunnerUPtr
181182
CDataFrameTrainBoostedTreeRegressionRunnerFactory::makeImpl(const CDataFrameAnalysisSpecification&) const {
182183
HANDLE_FATAL(<< "Input error: regression has a non-optional parameter '"
183-
<< CDataFrameTrainBoostedTreeRunner::DEPENDENT_VARIABLE_NAME << "'.")
184+
<< CDataFrameTrainBoostedTreeRunner::DEPENDENT_VARIABLE_NAME << "'.");
184185
return nullptr;
185186
}
186187

0 commit comments

Comments
 (0)