[mlpack-git] master: Fixed an error in MidpointSplit that may lead to a segfault (a659b90)
gitdub at mlpack.org
gitdub at mlpack.org
Wed Jul 27 11:00:28 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/3a1bc90ea5f1ffa45d2de000efb4429c60468b21...ef51b032f275266f781d42b9bd0aa50aa26a3077
>---------------------------------------------------------------
commit a659b90e57931d0377167cb980602ed565b44536
Author: Mikhail Lozhnikov <lozhnikovma at gmail.com>
Date: Wed Jul 27 18:00:28 2016 +0300
Fixed an error in MidpointSplit that may lead to a segfault
>---------------------------------------------------------------
a659b90e57931d0377167cb980602ed565b44536
.../tree/binary_space_tree/midpoint_split_impl.hpp | 28 ++++++++++++++++------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/mlpack/core/tree/binary_space_tree/midpoint_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/midpoint_split_impl.hpp
index 70ec94d..1aa16b3 100644
--- a/src/mlpack/core/tree/binary_space_tree/midpoint_split_impl.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/midpoint_split_impl.hpp
@@ -24,6 +24,7 @@ bool MidpointSplit<BoundType, MatType>::SplitNode(const BoundType& bound,
{
size_t splitDimension = data.n_rows; // Indicate invalid.
double maxWidth = -1;
+ double splitVal = DBL_MAX;
// Find the split dimension. If the bound is tight, we only need to consult
// the bound's width.
@@ -37,6 +38,9 @@ bool MidpointSplit<BoundType, MatType>::SplitNode(const BoundType& bound,
{
maxWidth = width;
splitDimension = d;
+
+ // Split in the midpoint of that dimension.
+ splitVal = bound[d].Mid();
}
}
}
@@ -65,18 +69,20 @@ bool MidpointSplit<BoundType, MatType>::SplitNode(const BoundType& bound,
{
maxWidth = width;
splitDimension = d;
+
+ // Split in the midpoint of that dimension.
+ splitVal = ranges[d].Mid();
}
}
delete[] ranges;
}
+ assert(splitVal != DBL_MAX);
+
if (maxWidth == 0) // All these points are the same. We can't split.
return false;
- // Split in the midpoint of that dimension.
- double splitVal = bound[splitDimension].Mid();
-
// Perform the actual splitting. This will order the dataset such that points
// with value in dimension splitDimension less than or equal to splitVal are
// on the left of splitCol, and points with value in dimension splitDimension
@@ -96,6 +102,7 @@ bool MidpointSplit<BoundType, MatType>::SplitNode(const BoundType& bound,
{
size_t splitDimension = data.n_rows; // Indicate invalid.
double maxWidth = -1;
+ double splitVal = DBL_MAX;
// Find the split dimension. If the bound is tight, we only need to consult
// the bound's width.
@@ -109,6 +116,9 @@ bool MidpointSplit<BoundType, MatType>::SplitNode(const BoundType& bound,
{
maxWidth = width;
splitDimension = d;
+
+ // Split in the midpoint of that dimension.
+ splitVal = bound[d].Mid();
}
}
}
@@ -132,22 +142,26 @@ bool MidpointSplit<BoundType, MatType>::SplitNode(const BoundType& bound,
// Now, which is the widest?
for (size_t d = 0; d < data.n_rows; d++)
{
- const double width = bound[d].Width();
+ const double width = ranges[d].Width();
if (width > maxWidth)
{
maxWidth = width;
splitDimension = d;
+
+ // Split in the midpoint of that dimension.
+ splitVal = ranges[d].Mid();
}
}
+
+ delete[] ranges;
}
+ assert(splitVal != DBL_MAX);
+
if (maxWidth == 0) // All these points are the same. We can't split.
return false;
- // Split in the midpoint of that dimension.
- double splitVal = bound[splitDimension].Mid();
-
// Perform the actual splitting. This will order the dataset such that points
// with value in dimension splitDimension less than or equal to splitVal are
// on the left of splitCol, and points with value in dimension splitDimension
More information about the mlpack-git
mailing list