Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove namespaces #3269

Merged
merged 61 commits into from
Sep 21, 2022
Merged

Remove namespaces #3269

merged 61 commits into from
Sep 21, 2022

Conversation

rcurtin
Copy link
Member

@rcurtin rcurtin commented Sep 9, 2022

This PR implements the result of the discussion in #3261:

  • All namespaces under mlpack:: are now removed, except mlpack::data and mlpack::util. mlpack::data remains because it is very specific to utilities for loading/saving data, and mlpack::util is utility stuff that shouldn't ever really be touched by users anyway, so it makes sense to keep it separate. mlpack::bindings is also left as-is, because users shouldn't ever be using things in that namespace.

  • All using namespace ... declarations in test files and examples are updated accordingly; only using namespace mlpack should be needed.

  • The namespace_compat.hpp file is added, which reintroduces reverse-compatibility namespaces like this:

namespace mlpack {
namespace math { using namespace mlpack; }
}

That can help make transitions for users to mlpack 4 a little less painful.

  • A few classes needed to be renamed here and there to avoid collisions.

@shrit
Copy link
Member

shrit commented Sep 9, 2022

Okay, finished 10 percent of this PR and still a lot of things to do, I will continue later this weekend

@rcurtin
Copy link
Member Author

rcurtin commented Sep 9, 2022

Okay, finished 10 percent of this PR and still a lot of things to do, I will continue later this weekend

Thanks! I know it is very tedious ...

I tried to fix the static code analysis warnings, but I think that they are false positives.

Copy link
Member

@shrit shrit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of comments, and some of them are relevant.
Everything looks good to me.

@@ -51,7 +50,7 @@ TEST_CASE("AMFMaxIterationTerminationTest", "[TerminationPolicyTest]")
// Custom tighter tolerance.
MaxIterationTermination mit(10); // Only 10 iterations.
AMF<MaxIterationTermination,
RandomInitialization,
RandomAMFInitialization,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well noticed

src/mlpack/tests/random_test.cpp Outdated Show resolved Hide resolved
@@ -24,31 +24,30 @@ inline void MockCategoricalData(arma::mat& d,
// We'll build a spiral dataset plus two noisy categorical features. We need
// to build the distributions for the categorical features (they'll be
// discrete distributions).
mlpack::distribution::DiscreteDistribution c1[5];
mlpack::DiscreteDistribution c1[5];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you keeping the mlpack namespace here? why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MockCategoricalData() function isn't in any namespace, so I fully qualify mlpack:: here. 👍

src/mlpack/tests/math_test.cpp Outdated Show resolved Hide resolved
@@ -16,9 +16,6 @@
#include "test_catch_tools.hpp"

using namespace mlpack;
using namespace mlpack::math;
using namespace mlpack::kpca;
using namespace mlpack::kernel;
using namespace std;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using namespace std;

Comment on lines +7 to +11
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny how many files did not have the license in them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I used to have a script I ran to check that every file had a license, but it has been many years since I ran it...

Comment on lines 292 to 296
if (modeStr == "dual-tree")
kde->Mode() = KDEMode::DUAL_TREE_MODE;
kde->Mode() = KDEMode::KDE_DUAL_TREE_MODE;
else if (modeStr == "single-tree")
kde->Mode() = KDEMode::SINGLE_TREE_MODE;
kde->Mode() = KDEMode::KDE_SINGLE_TREE_MODE;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the KDE necessary here in the KDE_DUAL_TREE_MODE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah---the DUAL_TREE_MODE name is already taken by the NSMode enum (which is used for various neighbor searching classes). This might not be the best possible solution, but I think it'll work for now.

src/mlpack/methods/ann/init_rules/glorot_init.hpp Outdated Show resolved Hide resolved
Comment on lines +12 to +41
#ifndef MLPACK_CORE_TREE_BUILD_TREE_HPP
#define MLPACK_CORE_TREE_BUILD_TREE_HPP

#include <mlpack/prereqs.hpp>

namespace mlpack {

//! Construct tree that rearranges the dataset.
template<typename TreeType, typename MatType>
TreeType* BuildTree(
MatType&& dataset,
std::vector<size_t>& oldFromNew,
const typename std::enable_if<
TreeTraits<TreeType>::RearrangesDataset>::type* = 0)
{
return new TreeType(std::forward<MatType>(dataset), oldFromNew);
}

//! Construct tree that doesn't rearrange the dataset.
template<typename TreeType, typename MatType>
TreeType* BuildTree(
MatType&& dataset,
const std::vector<size_t>& /* oldFromNew */,
const typename std::enable_if<
!TreeTraits<TreeType>::RearrangesDataset>::type* = 0)
{
return new TreeType(std::forward<MatType>(dataset));
}

} // namespace mlpack
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, I see where this has been moved

rcurtin and others added 4 commits September 13, 2022 22:23
Co-authored-by: Omar Shrit <omar@shrit.me>
Co-authored-by: Omar Shrit <omar@shrit.me>
Co-authored-by: Omar Shrit <omar@shrit.me>
Copy link
Member

@shrit shrit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@mlpack-bot mlpack-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second approval provided automatically after 24 hours. 👍

@conradsnicta
Copy link
Contributor

@rcurtin Seems that #3270 also has many commits that remove namespaces. This raises the risk of possible clashes. Or is #3270 meant as a followup to this PR ?

@rcurtin
Copy link
Member Author

rcurtin commented Sep 19, 2022

@rcurtin Seems that #3270 also has many commits that remove namespaces. This raises the risk of possible clashes. Or is #3270 meant as a followup to this PR ?

My error---that's meant to be merged after this one. I updated the description there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants