Skip to content

Commit

Permalink
Use simpler naming for logging singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed May 14, 2024
1 parent 029d5a9 commit b0952d3
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 40 deletions.
5 changes: 2 additions & 3 deletions include/tapkee/embed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TapkeeOutput embed(RandomAccessIterator begin, RandomAccessIterator end, KernelC
parameters.check();
parameters.merge(tapkee_internal::defaults);
parameters.visit([] (const stichwort::Parameter& p) {
tapkee::LoggingSingleton::instance().message_debug(fmt::format("Parameter {} = [{}]", p.name(), p.repr()));
tapkee::Logging::instance().message_debug(fmt::format("Parameter {} = [{}]", p.name(), p.repr()));
});

DimensionReductionMethod selected_method = parameters[method];
Expand All @@ -114,8 +114,7 @@ TapkeeOutput embed(RandomAccessIterator begin, RandomAccessIterator end, KernelC

tapkee_internal::Context context(progress_function_ptr, cancel_function_ptr);

LoggingSingleton::instance().message_info(
fmt::format("Using the {} method.", get_method_name(selected_method)));
Logging::instance().message_info(fmt::format("Using the {} method.", get_method_name(selected_method)));

output = tapkee_internal::initialize(begin, end, kernel_callback, distance_callback, features_callback,
parameters, context)
Expand Down
7 changes: 3 additions & 4 deletions include/tapkee/external/barnes_hut_sne/tsne.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class TSNE
// Determine whether we are using an exact algorithm
bool exact = (theta == .0) ? true : false;
if (exact)
tapkee::LoggingSingleton::instance().message_info("Using exact t-SNE algorithm");
tapkee::Logging::instance().message_info("Using exact t-SNE algorithm");
else
tapkee::LoggingSingleton::instance().message_info("Using Barnes-Hut-SNE algorithm");
tapkee::Logging::instance().message_info("Using Barnes-Hut-SNE algorithm");

// Set learning parameters
int max_iter = 1000, stop_lying_iter = 250, mom_switch_iter = 250;
Expand Down Expand Up @@ -188,8 +188,7 @@ class TSNE
C = evaluateError(P.data(), Y, N);
else
C = evaluateError(row_P, col_P, val_P, Y, N, theta); // doing approximate computation here!
tapkee::LoggingSingleton::instance().message_info(
fmt::format("Iteration {}: error is {}", iter, C));
tapkee::Logging::instance().message_info(fmt::format("Iteration {}: error is {}", iter, C));
}
}
// Clean up memory
Expand Down
8 changes: 4 additions & 4 deletions include/tapkee/neighbors/neighbors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ Neighbors find_neighbors(NeighborsMethod method, const RandomAccessIterator& beg
{
if (k > static_cast<IndexType>(end - begin - 1))
{
LoggingSingleton::instance().message_warning("Number of neighbors is greater than number of objects to embed. "
Logging::instance().message_warning("Number of neighbors is greater than number of objects to embed. "
"Using greatest possible number of neighbors.");
k = static_cast<IndexType>(end - begin - 1);
}
LoggingSingleton::instance().message_info("Using the " + get_neighbors_method_name(method) +
Logging::instance().message_info("Using the " + get_neighbors_method_name(method) +
" neighbors computation method.");

Neighbors neighbors;
Expand All @@ -199,15 +199,15 @@ Neighbors find_neighbors(NeighborsMethod method, const RandomAccessIterator& beg
"is not connected. Recomputing with a "
"larger number of neighbors {}.",
k, 2 * k);
LoggingSingleton::instance().message_warning(message);
Logging::instance().message_warning(message);
neighbors = find_neighbors(method, begin, end, callback, 2 * k, check_connectivity);
}
else
{
const std::string message = fmt::format("The neighborhood graph with {} neighbors "
"is connected.",
k);
LoggingSingleton::instance().message_info(message);
Logging::instance().message_info(message);
}
return neighbors;
}
Expand Down
5 changes: 2 additions & 3 deletions include/tapkee/routines/eigendecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ EigendecompositionResult eigendecomposition_impl_arpack(const MatrixType& wm, In
if (arpack.info() == Eigen::Success)
{
std::string message = fmt::format("Took {} iterations.", arpack.getNbrIterations());
LoggingSingleton::instance().message_info(message);
Logging::instance().message_info(message);
DenseMatrix selected_eigenvectors = arpack.eigenvectors().rightCols(target_dimension);
return EigendecompositionResult(selected_eigenvectors, arpack.eigenvalues().tail(target_dimension));
}
Expand Down Expand Up @@ -329,8 +329,7 @@ EigendecompositionResult eigendecomposition(const EigenMethod& method, const Com
const EigendecompositionStrategy& eigen_strategy, const MatrixType& m,
IndexType target_dimension)
{
LoggingSingleton::instance().message_info(
fmt::format("Using the {} eigendecomposition method.", get_eigen_method_name(method)));
Logging::instance().message_info(fmt::format("Using the {} eigendecomposition method.", get_eigen_method_name(method)));
#ifdef TAPKEE_WITH_ARPACK
if (method.is(Arpack))
return eigendecomposition_impl<MatrixType>().arpack(m, strategy, eigen_strategy, target_dimension);
Expand Down
5 changes: 2 additions & 3 deletions include/tapkee/routines/generalized_eigendecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ EigendecompositionResult generalized_eigendecomposition_impl_arpack(const LMatri
if (arpack.info() == Eigen::Success)
{
std::string message = fmt::format("Took {} iterations.", arpack.getNbrIterations());
LoggingSingleton::instance().message_info(message);
Logging::instance().message_info(message);
DenseMatrix selected_eigenvectors = (arpack.eigenvectors()).rightCols(target_dimension);
return EigendecompositionResult(selected_eigenvectors, arpack.eigenvalues().tail(target_dimension));
}
Expand Down Expand Up @@ -169,8 +169,7 @@ EigendecompositionResult generalized_eigendecomposition(const EigenMethod& metho
const LMatrixType& lhs, const RMatrixType& rhs,
IndexType target_dimension)
{
LoggingSingleton::instance().message_info(
fmt::format("Using the {} eigendecomposition method.", get_eigen_method_name(method)));
Logging::instance().message_info(fmt::format("Using the {} eigendecomposition method.", get_eigen_method_name(method)));
#ifdef TAPKEE_WITH_ARPACK
if (method.is(Arpack))
return generalized_eigendecomposition_impl<LMatrixType, RMatrixType>().arpack(lhs, rhs, strategy,
Expand Down
14 changes: 7 additions & 7 deletions include/tapkee/utils/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ class DefaultLoggerImplementation : public LoggerImplementation
//! Main logging singleton used by the library. Can use provided
//! @ref LoggerImplementation if necessary. By default uses
//! @ref DefaultLoggerImplementation.
class LoggingSingleton
class Logging
{
private:
LoggingSingleton()
Logging()
: impl(new DefaultLoggerImplementation), LEVEL_ENABLED_FIELD_INITIALIZER(info, false),
LEVEL_ENABLED_FIELD_INITIALIZER(warning, true), LEVEL_ENABLED_FIELD_INITIALIZER(debug, false),
LEVEL_ENABLED_FIELD_INITIALIZER(error, true), LEVEL_ENABLED_FIELD_INITIALIZER(benchmark, false){};
~LoggingSingleton()
~Logging()
{
delete impl;
}
LoggingSingleton(const LoggingSingleton& ls);
void operator=(const LoggingSingleton& ls);
Logging(const Logging& ls) = delete;
void operator=(const Logging& ls) = delete;

LoggerImplementation* impl;

Expand All @@ -106,9 +106,9 @@ class LoggingSingleton

public:
//! @return instance of the singleton
static LoggingSingleton& instance()
static Logging& instance()
{
static LoggingSingleton s;
static Logging s;
return s;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tapkee/utils/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct timed_context
{
std::string message =
fmt::format("{} took {} seconds.", operation_name, double(CLOCK_GET - start_clock) / CLOCK_DIVISOR);
LoggingSingleton::instance().message_benchmark(message);
Logging::instance().message_benchmark(message);
}
};
} // namespace tapkee_internal
Expand Down
30 changes: 15 additions & 15 deletions src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,18 @@ int run(int argc, const char **argv)
}
if (opt.count(VERBOSE_KEYWORD))
{
tapkee::LoggingSingleton::instance().enable_info();
tapkee::Logging::instance().enable_info();
}
if (opt.count(DEBUG_KEYWORD))
{
tapkee::LoggingSingleton::instance().enable_debug();
tapkee::LoggingSingleton::instance().message_info("Debug messages enabled");
tapkee::Logging::instance().enable_debug();
tapkee::Logging::instance().message_info("Debug messages enabled");
}

if (opt.count(BENCHMARK_KEYWORD))
{
tapkee::LoggingSingleton::instance().enable_benchmark();
tapkee::LoggingSingleton::instance().message_info("Benchmarking enabled");
tapkee::Logging::instance().enable_benchmark();
tapkee::Logging::instance().message_info("Benchmarking enabled");
}

tapkee::DimensionReductionMethod tapkee_method = tapkee::PassThru;
Expand All @@ -302,7 +302,7 @@ int run(int argc, const char **argv)
}
catch (const std::exception &)
{
tapkee::LoggingSingleton::instance().message_error(string("Unknown method ") + method);
tapkee::Logging::instance().message_error(string("Unknown method ") + method);
return 1;
}
}
Expand All @@ -316,7 +316,7 @@ int run(int argc, const char **argv)
}
catch (const std::exception &)
{
tapkee::LoggingSingleton::instance().message_error(string("Unknown neighbors method ") + method);
tapkee::Logging::instance().message_error(string("Unknown neighbors method ") + method);
return 1;
}
}
Expand All @@ -329,7 +329,7 @@ int run(int argc, const char **argv)
}
catch (const std::exception &)
{
tapkee::LoggingSingleton::instance().message_error(string("Unknown eigendecomposition method ") + method);
tapkee::Logging::instance().message_error(string("Unknown eigendecomposition method ") + method);
return 1;
}
}
Expand All @@ -342,15 +342,15 @@ int run(int argc, const char **argv)
}
catch (const std::exception &)
{
tapkee::LoggingSingleton::instance().message_error(string("Unknown computation strategy ") + method);
tapkee::Logging::instance().message_error(string("Unknown computation strategy ") + method);
return 1;
}
}

int target_dim = opt[TARGET_DIMENSION_KEYWORD].as<int>();
if (target_dim < 0)
{
tapkee::LoggingSingleton::instance().message_error(
tapkee::Logging::instance().message_error(
"Negative target dimensionality is not possible in current circumstances. "
"Please visit other universe");
return 1;
Expand All @@ -359,20 +359,20 @@ int run(int argc, const char **argv)
int k = opt[NUM_NEIGHBORS_KEYWORD].as<int>();
if (k < 3)
{
tapkee::LoggingSingleton::instance().message_error(
tapkee::Logging::instance().message_error(
"The provided number of neighbors is too small, consider at least 3.");
return 1;
}
double width = opt[GAUSSIAN_WIDTH_KEYWORD].as<double>();
if (width < 0.0)
{
tapkee::LoggingSingleton::instance().message_error("Width of the gaussian kernel is negative.");
tapkee::Logging::instance().message_error("Width of the gaussian kernel is negative.");
return 1;
}
int timesteps = opt[TIMESTEPS_KEYWORD].as<int>();
if (timesteps < 0)
{
tapkee::LoggingSingleton::instance().message_error("Number of timesteps is negative.");
tapkee::Logging::instance().message_error("Number of timesteps is negative.");
return 1;
}
double eigenshift = opt[EIGENSHIFT_KEYWORD].as<double>();
Expand Down Expand Up @@ -414,7 +414,7 @@ int run(int argc, const char **argv)

std::stringstream ss;
ss << "Data contains " << input_data.cols() << " feature vectors with dimension of " << input_data.rows();
tapkee::LoggingSingleton::instance().message_info(ss.str());
tapkee::Logging::instance().message_info(ss.str());

tapkee::TapkeeOutput output;

Expand Down Expand Up @@ -481,7 +481,7 @@ int run(int argc, const char **argv)
dynamic_cast<tapkee::MatrixProjectionImplementation *>(output.projection.implementation.get());
if (!matrix_projection)
{
tapkee::LoggingSingleton::instance().message_error("Projection function unavailable");
tapkee::Logging::instance().message_error("Projection function unavailable");
return 1;
}
write_matrix(&matrix_projection->proj_mat, ofs_matrix, delimiter[0]);
Expand Down

0 comments on commit b0952d3

Please sign in to comment.