Skip to content

Commit

Permalink
Merge pull request #2946 from rcurtin/static-code-analysis-fix
Browse files Browse the repository at this point in the history
Try to fix the static code analysis issue
  • Loading branch information
jeffin143 committed May 21, 2021
2 parents a112e1b + b5c2961 commit bcaa1b7
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/mlpack/methods/ann/layer/recurrent_attention_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace ann /** Artificial Neural Network. */ {

template<typename InputDataType, typename OutputDataType>
RecurrentAttention<InputDataType, OutputDataType>::RecurrentAttention() :
outSize(0),
rho(0),
forwardStep(0),
backwardStep(0),
deterministic(false),
outSize(0)
deterministic(false)
{
// Nothing to do.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace mlpack::ann;
* url = {http://arxiv.org/abs/1707.06887}
* }
* @endcode
*
*
* @tparam OutputLayerType The output layer type of the network.
* @tparam InitType The initialization type used for the network.
* @tparam NetworkType The type of network used for simple dqn.
Expand All @@ -53,7 +53,8 @@ class CategoricalDQN
/**
* Default constructor.
*/
CategoricalDQN() : network(), isNoisy(false), atomSize(0), vMin(0.0), vMax(0.0)
CategoricalDQN() :
network(), atomSize(0), vMin(0.0), vMax(0.0), isNoisy(false)
{ /* Nothing to do here. */ }

/**
Expand Down Expand Up @@ -101,7 +102,8 @@ class CategoricalDQN
}

/**
* Construct an instance of CategoricalDQN class from a pre-constructed network.
* Construct an instance of CategoricalDQN class from a pre-constructed
* network.
*
* @param network The network to be used by CategoricalDQN class.
* @param config Hyper-parameters for categorical dqn.
Expand Down
4 changes: 2 additions & 2 deletions src/mlpack/tests/decision_tree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,12 @@ TEST_CASE("RandomBinaryNumericSplitNoGainTest", "[DecisionTreeTest]")
for (int i = 0; i < 5; ++i)
{
// Call BestBinaryNumericSplit to do the splitting.
double gain = BestBinaryNumericSplit<GiniGain>::SplitIfBetter<false>(
(void) BestBinaryNumericSplit<GiniGain>::SplitIfBetter<false>(
bestGain, values, labels, 2, weights, 3, 1e-7, classProbabilities,
aux);

// Call RandomBinaryNumericSplit to do the splitting.
gain = RandomBinaryNumericSplit<GiniGain>::SplitIfBetter<false>(
(void) RandomBinaryNumericSplit<GiniGain>::SplitIfBetter<false>(
bestGain, values, labels, 2, weights, 3, 1e-7, classProbabilities1,
aux1);

Expand Down
1 change: 0 additions & 1 deletion src/mlpack/tests/lsh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,6 @@ TEST_CASE("SparseLSHTest", "[LSHTest]")
// Make sure that sparse LSH distances aren't garbage.
for (size_t i = 0; i < sparseNeighbors.n_elem; ++i)
{
REQUIRE(sparseNeighbors[i] >= 0);
REQUIRE(sparseNeighbors[i] < rdata.n_cols);
REQUIRE(sparseDistances[i] >= 0.0);
REQUIRE(!std::isinf(sparseDistances[i]));
Expand Down
10 changes: 5 additions & 5 deletions src/mlpack/tests/main_tests/hoeffding_tree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingMinSamplesTest",

// Check that small min_samples creates larger model.
REQUIRE((IO::GetParam<HoeffdingTreeModel*>("output_model"))->NumNodes() <
nodes);
(size_t) nodes);
}

/**
Expand Down Expand Up @@ -466,7 +466,7 @@ TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingMaxSamplesTest",
mlpackMain();

// Check that large max_samples creates smaller model.
REQUIRE(nodes <
REQUIRE((size_t) nodes <
(IO::GetParam<HoeffdingTreeModel*>("output_model"))->NumNodes());
}

Expand Down Expand Up @@ -533,7 +533,7 @@ TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingConfidenceTest",

mlpackMain();
// Check that higher confidence creates smaller tree.
REQUIRE(nodes <
REQUIRE((size_t) nodes <
(IO::GetParam<HoeffdingTreeModel*>("output_model"))->NumNodes());
}

Expand Down Expand Up @@ -601,7 +601,7 @@ TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingPassesTest",
mlpackMain();

// Check that model with larger number of passes has greater number of nodes.
REQUIRE(nodes <
REQUIRE((size_t) nodes <
(IO::GetParam<HoeffdingTreeModel*>("output_model"))->NumNodes());
}

Expand Down Expand Up @@ -715,7 +715,7 @@ TEST_CASE_METHOD(HoeffdingTreeTestFixture,

// Check that both models have different number of nodes.
CHECK((IO::GetParam<HoeffdingTreeModel*>("output_model"))->NumNodes() !=
nodes);
(size_t) nodes);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mlpack/tests/main_tests/kmeans_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ TEST_CASE_METHOD(KmTestFixture, "KmClusteringSizeCheck",
REQUIRE(IO::GetParam<arma::mat>("output").n_rows == row+1);
REQUIRE(IO::GetParam<arma::mat>("output").n_cols == col);
REQUIRE(IO::GetParam<arma::mat>("centroid").n_rows == row);
REQUIRE(IO::GetParam<arma::mat>("centroid").n_cols == c);
REQUIRE(IO::GetParam<arma::mat>("centroid").n_cols == (arma::uword) c);
}

/**
Expand All @@ -179,7 +179,7 @@ TEST_CASE_METHOD(KmTestFixture, "KmClusteringSizeCheckLabelOnly",
REQUIRE(IO::GetParam<arma::mat>("output").n_rows == 1);
REQUIRE(IO::GetParam<arma::mat>("output").n_cols == col);
REQUIRE(IO::GetParam<arma::mat>("centroid").n_rows == row);
REQUIRE(IO::GetParam<arma::mat>("centroid").n_cols == c);
REQUIRE(IO::GetParam<arma::mat>("centroid").n_cols == (arma::uword) c);
}


Expand Down
8 changes: 4 additions & 4 deletions src/mlpack/tests/main_tests/local_coordinate_coding_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ TEST_CASE_METHOD(LCCTestFixture, "LCCDimensionsTest",
mlpackMain();

// Check that the output has correct dimensions.
REQUIRE(IO::GetParam<arma::mat>("codes").n_rows == atoms);
REQUIRE(IO::GetParam<arma::mat>("codes").n_cols == cols);
REQUIRE(IO::GetParam<arma::mat>("dictionary").n_rows == rows);
REQUIRE(IO::GetParam<arma::mat>("dictionary").n_cols == atoms);
REQUIRE(IO::GetParam<arma::mat>("codes").n_rows == (arma::uword) atoms);
REQUIRE(IO::GetParam<arma::mat>("codes").n_cols == (arma::uword) cols);
REQUIRE(IO::GetParam<arma::mat>("dictionary").n_rows == (arma::uword) rows);
REQUIRE(IO::GetParam<arma::mat>("dictionary").n_cols == (arma::uword) atoms);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/mlpack/tests/main_tests/mean_shift_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ TEST_CASE_METHOD(
mlpackMain();

// Now check that the output has 1 extra row for labels.
REQUIRE(IO::GetParam<arma::mat>("output").n_rows == numRows + 1);
REQUIRE(IO::GetParam<arma::mat>("output").n_rows ==
(arma::uword) (numRows + 1));
// Check number of output points are the same.
REQUIRE(IO::GetParam<arma::mat>("output").n_cols == numCols);
REQUIRE(IO::GetParam<arma::mat>("output").n_cols == (arma::uword) numCols);
}

/**
Expand Down
20 changes: 12 additions & 8 deletions src/mlpack/tests/main_tests/preprocess_split_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ TEST_CASE_METHOD(
mlpackMain();

// Now check that the output has desired dimensions.
REQUIRE(IO::GetParam<arma::mat>("training").n_cols == inputSize);
REQUIRE(IO::GetParam<arma::mat>("training").n_cols ==
(arma::uword) inputSize);
REQUIRE(IO::GetParam<arma::mat>("test").n_cols == 0);

REQUIRE(IO::GetParam<arma::Mat<size_t>>("training_labels").n_cols ==
labelSize);
(arma::uword) labelSize);
REQUIRE(IO::GetParam<arma::Mat<size_t>>("test_labels").n_cols == 0);
}

Expand Down Expand Up @@ -205,10 +206,11 @@ TEST_CASE_METHOD(

// Now check that the output has desired dimensions.
REQUIRE(IO::GetParam<arma::mat>("training").n_cols == 0);
REQUIRE(IO::GetParam<arma::mat>("test").n_cols == inputSize);
REQUIRE(IO::GetParam<arma::mat>("test").n_cols == (arma::uword) inputSize);

REQUIRE(IO::GetParam<arma::Mat<size_t>>("training_labels").n_cols == 0);
REQUIRE(IO::GetParam<arma::Mat<size_t>>("test_labels").n_cols == labelSize);
REQUIRE(IO::GetParam<arma::Mat<size_t>>("test_labels").n_cols ==
(arma::uword) labelSize);
}

/**
Expand Down Expand Up @@ -275,11 +277,12 @@ TEST_CASE_METHOD(
mlpackMain();

// Now check that the output has desired dimensions.
REQUIRE(IO::GetParam<arma::mat>("training").n_cols == inputSize);
REQUIRE(IO::GetParam<arma::mat>("training").n_cols ==
(arma::uword) inputSize);
REQUIRE(IO::GetParam<arma::mat>("test").n_cols == 0);

REQUIRE(IO::GetParam<arma::Mat<size_t>>("training_labels").n_cols ==
labelSize);
(arma::uword) labelSize);
REQUIRE(IO::GetParam<arma::Mat<size_t>>("test_labels").n_cols == 0);
}

Expand Down Expand Up @@ -314,10 +317,11 @@ TEST_CASE_METHOD(

// Now check that the output has desired dimensions.
REQUIRE(IO::GetParam<arma::mat>("training").n_cols == 0);
REQUIRE(IO::GetParam<arma::mat>("test").n_cols == inputSize);
REQUIRE(IO::GetParam<arma::mat>("test").n_cols == (arma::uword) inputSize);

REQUIRE(IO::GetParam<arma::Mat<size_t>>("training_labels").n_cols == 0);
REQUIRE(IO::GetParam<arma::Mat<size_t>>("test_labels").n_cols == labelSize);
REQUIRE(IO::GetParam<arma::Mat<size_t>>("test_labels").n_cols ==
(arma::uword) labelSize);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/mlpack/tests/random_forest_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ TEST_CASE("WarmStartTreesTest", "[RandomForestTest]")
// Train a random forest.
RandomForest<> rf(trainingData, di, trainingLabels, 5, 25 /* 25 trees */, 1,
1e-7, 0, MultipleRandomDimensionSelect(4));

REQUIRE(rf.NumTrees() == 25);

rf.Train(trainingData, di, trainingLabels, 5, 20 /* 20 trees */, 1, 1e-7, 0,
Expand All @@ -538,7 +538,7 @@ TEST_CASE("WarmStartTreesPredictionsQualityTest", "[RandomForestTest]")
// Train a random forest.
RandomForest<> rf(trainingData, di, trainingLabels, 5, 3 /* 3 trees */, 1,
1e-7, 0, MultipleRandomDimensionSelect(4));

// Get performance statistics on train data.
arma::Row<size_t> oldPredictions;
rf.Classify(trainingData, oldPredictions);
Expand All @@ -556,7 +556,7 @@ TEST_CASE("WarmStartTreesPredictionsQualityTest", "[RandomForestTest]")
// Calculate the number of correct points.
size_t newCorrect = arma::accu(newPredictions == trainingLabels);

REQUIRE(newCorrect - oldCorrect >= 0);
REQUIRE(newCorrect >= oldCorrect);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/mlpack/tests/rectangle_tree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ TEST_CASE("TreeBalance", "[RectangleTreeTraitsTest]")
TreeType tree(dataset, 20, 6, 5, 2, 0);

REQUIRE(GetMinLevel(tree) == GetMaxLevel(tree));
REQUIRE(tree.TreeDepth() == GetMinLevel(tree));
REQUIRE((int) tree.TreeDepth() == GetMinLevel(tree));
}

// A test to see if point deletion is working correctly. We build a tree, then
Expand Down Expand Up @@ -982,7 +982,7 @@ TEST_CASE("RPlusTreeOverlapTest", "[RectangleTreeTraitsTest]")

// Ensure that all leaf nodes are at the same level.
REQUIRE(GetMinLevel(rPlusTree) == GetMaxLevel(rPlusTree));
REQUIRE(rPlusTree.TreeDepth() == GetMinLevel(rPlusTree));
REQUIRE((int) rPlusTree.TreeDepth() == GetMinLevel(rPlusTree));
}


Expand Down Expand Up @@ -1099,7 +1099,7 @@ TEST_CASE("RPlusPlusTreeBoundTest", "[RectangleTreeTraitsTest]")
REQUIRE(b == false);

REQUIRE(GetMinLevel(rPlusPlusTree) == GetMaxLevel(rPlusPlusTree));
REQUIRE(rPlusPlusTree.TreeDepth() == GetMinLevel(rPlusPlusTree));
REQUIRE((int) rPlusPlusTree.TreeDepth() == GetMinLevel(rPlusPlusTree));

// Check the MinimalSplitsNumberSweep.
typedef RectangleTree<EuclideanDistance,
Expand All @@ -1113,7 +1113,7 @@ TEST_CASE("RPlusPlusTreeBoundTest", "[RectangleTreeTraitsTest]")
CheckRPlusPlusTreeBound(rPlusPlusTree2);

REQUIRE(GetMinLevel(rPlusPlusTree2) == GetMaxLevel(rPlusPlusTree2));
REQUIRE(rPlusPlusTree2.TreeDepth() == GetMinLevel(rPlusPlusTree2));
REQUIRE((int) rPlusPlusTree2.TreeDepth() == GetMinLevel(rPlusPlusTree2));
}

TEST_CASE("RPlusPlusTreeTraverserTest", "[RectangleTreeTraitsTest]")
Expand Down

0 comments on commit bcaa1b7

Please sign in to comment.