[mlpack-svn] r17068 - mlpack/trunk/src/mlpack/core/tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Aug 18 20:55:53 EDT 2014
Author: rcurtin
Date: Mon Aug 18 20:55:53 2014
New Revision: 17068
Log:
Inline HRectBound functions. Minor to negligible speedup, but certainly no
slowdown. (at least on gcc)
Modified:
mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp Mon Aug 18 20:55:53 2014
@@ -21,7 +21,7 @@
* Empty constructor.
*/
template<int Power, bool TakeRoot>
-HRectBound<Power, TakeRoot>::HRectBound() :
+inline HRectBound<Power, TakeRoot>::HRectBound() :
dim(0),
bounds(NULL),
minWidth(0)
@@ -32,7 +32,7 @@
* set.
*/
template<int Power, bool TakeRoot>
-HRectBound<Power, TakeRoot>::HRectBound(const size_t dimension) :
+inline HRectBound<Power, TakeRoot>::HRectBound(const size_t dimension) :
dim(dimension),
bounds(new math::Range[dim]),
minWidth(0)
@@ -42,7 +42,7 @@
* Copy constructor necessary to prevent memory leaks.
*/
template<int Power, bool TakeRoot>
-HRectBound<Power, TakeRoot>::HRectBound(const HRectBound& other) :
+inline HRectBound<Power, TakeRoot>::HRectBound(const HRectBound& other) :
dim(other.Dim()),
bounds(new math::Range[dim]),
minWidth(other.MinWidth())
@@ -56,7 +56,7 @@
* Same as the copy constructor.
*/
template<int Power, bool TakeRoot>
-HRectBound<Power, TakeRoot>& HRectBound<Power, TakeRoot>::operator=(
+inline HRectBound<Power, TakeRoot>& HRectBound<Power, TakeRoot>::operator=(
const HRectBound& other)
{
if (dim != other.Dim())
@@ -82,7 +82,7 @@
* Destructor: clean up memory.
*/
template<int Power, bool TakeRoot>
-HRectBound<Power, TakeRoot>::~HRectBound()
+inline HRectBound<Power, TakeRoot>::~HRectBound()
{
if (bounds)
delete[] bounds;
@@ -92,7 +92,7 @@
* Resets all dimensions to the empty set.
*/
template<int Power, bool TakeRoot>
-void HRectBound<Power, TakeRoot>::Clear()
+inline void HRectBound<Power, TakeRoot>::Clear()
{
for (size_t i = 0; i < dim; i++)
bounds[i] = math::Range();
@@ -105,7 +105,7 @@
* @param centroid Vector which the centroid will be written to.
*/
template<int Power, bool TakeRoot>
-void HRectBound<Power, TakeRoot>::Centroid(arma::vec& centroid) const
+inline void HRectBound<Power, TakeRoot>::Centroid(arma::vec& centroid) const
{
// Set size correctly if necessary.
if (!(centroid.n_elem == dim))
@@ -121,7 +121,7 @@
* @return Volume of the hyperrectangle.
*/
template<int Power, bool TakeRoot>
-double HRectBound<Power, TakeRoot>::Volume() const
+inline double HRectBound<Power, TakeRoot>::Volume() const
{
double volume = 1.0;
for (size_t i = 0; i < dim; ++i)
@@ -135,7 +135,7 @@
*/
template<int Power, bool TakeRoot>
template<typename VecType>
-double HRectBound<Power, TakeRoot>::MinDistance(
+inline double HRectBound<Power, TakeRoot>::MinDistance(
const VecType& point,
typename boost::enable_if<IsVector<VecType> >* /* junk */) const
{
@@ -204,7 +204,7 @@
*/
template<int Power, bool TakeRoot>
template<typename VecType>
-double HRectBound<Power, TakeRoot>::MaxDistance(
+inline double HRectBound<Power, TakeRoot>::MaxDistance(
const VecType& point,
typename boost::enable_if<IsVector<VecType> >* /* junk */) const
{
@@ -230,7 +230,8 @@
* Computes maximum distance.
*/
template<int Power, bool TakeRoot>
-double HRectBound<Power, TakeRoot>::MaxDistance(const HRectBound& other) const
+inline double HRectBound<Power, TakeRoot>::MaxDistance(const HRectBound& other)
+ const
{
double sum = 0;
@@ -255,8 +256,8 @@
* Calculates minimum and maximum bound-to-bound squared distance.
*/
template<int Power, bool TakeRoot>
-math::Range HRectBound<Power, TakeRoot>::RangeDistance(const HRectBound& other)
- const
+inline math::Range HRectBound<Power, TakeRoot>::RangeDistance(
+ const HRectBound& other) const
{
double loSum = 0;
double hiSum = 0;
@@ -296,7 +297,7 @@
*/
template<int Power, bool TakeRoot>
template<typename VecType>
-math::Range HRectBound<Power, TakeRoot>::RangeDistance(
+inline math::Range HRectBound<Power, TakeRoot>::RangeDistance(
const VecType& point,
typename boost::enable_if<IsVector<VecType> >* /* junk */) const
{
@@ -346,7 +347,7 @@
*/
template<int Power, bool TakeRoot>
template<typename MatType>
-HRectBound<Power, TakeRoot>& HRectBound<Power, TakeRoot>::operator|=(
+inline HRectBound<Power, TakeRoot>& HRectBound<Power, TakeRoot>::operator|=(
const MatType& data)
{
Log::Assert(data.n_rows == dim);
@@ -370,7 +371,7 @@
* Expands this region to encompass another bound.
*/
template<int Power, bool TakeRoot>
-HRectBound<Power, TakeRoot>& HRectBound<Power, TakeRoot>::operator|=(
+inline HRectBound<Power, TakeRoot>& HRectBound<Power, TakeRoot>::operator|=(
const HRectBound& other)
{
assert(other.dim == dim);
@@ -392,7 +393,7 @@
*/
template<int Power, bool TakeRoot>
template<typename VecType>
-bool HRectBound<Power, TakeRoot>::Contains(const VecType& point) const
+inline bool HRectBound<Power, TakeRoot>::Contains(const VecType& point) const
{
for (size_t i = 0; i < point.n_elem; i++)
{
@@ -407,7 +408,7 @@
* Returns the diameter of the hyperrectangle (that is, the longest diagonal).
*/
template<int Power, bool TakeRoot>
-double HRectBound<Power, TakeRoot>::Diameter() const
+inline double HRectBound<Power, TakeRoot>::Diameter() const
{
double d = 0;
for (size_t i = 0; i < dim; ++i)
More information about the mlpack-svn
mailing list