Skip to content
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class DAAL_EXPORT Result : public classifier::training::Result
* \param[in] id Identifier of the result
* \return Result that corresponds to the given identifier
*/
engines::EnginePtr get(ResultEngineId id) const;
engines::EngineIfacePtr get(ResultEngineId id) const;

protected:
using daal::algorithms::interface1::Result::check;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class DAAL_EXPORT Result : public algorithms::regression::training::Result
* \param[in] id Identifier of the result
* \return Result that corresponds to the given identifier
*/
engines::EnginePtr get(ResultEngineId id) const;
engines::EngineIfacePtr get(ResultEngineId id) const;

protected:
using daal::algorithms::interface1::Result::check;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "data_management/data/numeric_table.h"
#include "data_management/data/data_serialize.h"
#include "services/daal_defines.h"
#include "algorithms/engines/mt2203/mt2203.h"
#include "algorithms/engines/engine.h"

namespace daal
{
Expand Down Expand Up @@ -138,7 +138,7 @@ class DAAL_EXPORT Parameter
size_t minObservationsInLeafNode; /*!< Minimal number of observations in a leaf node.
Default is 1 for classification, 5 for regression. */
size_t seed; /*!< Seed for the random numbers generator used by the algorithms \DAAL_DEPRECATED_USE{ engine } */
engines::EnginePtr engine; /*!< Engine for the random numbers generator used by the algorithms */
engines::EngineIfacePtr engine; /*!< Engine for the random numbers generator used by the algorithms */
double impurityThreshold; /*!< Threshold value used as stopping criteria: if the impurity value in the node is smaller
than the threshold then the node is not split anymore.*/
VariableImportanceMode varImportance; /*!< Variable importance computation mode */
Expand Down
4 changes: 2 additions & 2 deletions cpp/daal/include/algorithms/em/em_gmm_init_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "data_management/data/homogen_numeric_table.h"
#include "services/daal_defines.h"
#include "algorithms/em/em_gmm_covariance_storage_id.h"
#include "algorithms/engines/mt19937/mt19937.h"
#include "algorithms/engines/engine.h"

namespace daal
{
Expand Down Expand Up @@ -131,7 +131,7 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
size_t seed; /*!< Seed for randomly generating data points to start the initialization of short EM */
double accuracyThreshold; /*!< Threshold for the termination of the algorithm */
em_gmm::CovarianceStorageId covarianceStorage; /*!< Type of covariance in the Gaussian mixture model. */
engines::EnginePtr engine; /*!< Engine to be used for randomly generating data points to start the initialization of short EM */
engines::EngineIfacePtr engine; /*!< Engine to be used for randomly generating data points to start the initialization of short EM */
};
/* [Parameter source code] */

Expand Down
88 changes: 34 additions & 54 deletions cpp/daal/include/algorithms/engines/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

/*
//++
// Implementation engine.
// Public interface for random number engines.
//--
*/

#ifndef __ENGINE_H__
#define __ENGINE_H__

#include "algorithms/engines/engine_types.h"
#include "services/daal_defines.h"
#include "services/daal_shared_ptr.h"

namespace daal
{
Expand All @@ -36,75 +37,54 @@ namespace engines
* @ingroup engines
* @{
*/
/**
* <a name="DAAL-ENUM-ALGORITHMS__ENGINES__ENGINETYPE"></a>
* \brief Available random number engine types
*/
enum EngineType
{
mt19937Engine = 0, /*!< Mersenne Twister engine (mt19937) */
mt2203Engine = 1, /*!< Mersenne Twister engine (mt2203) */
mcg59Engine = 2, /*!< Multiplicative congruential generator (mcg59) */
mrg32k3aEngine = 3, /*!< Combined multiple recursive generator (mrg32k3a) */
philox4x32x10Engine = 4 /*!< Philox 4x32-10 counter-based engine */
};

namespace interface1
{
/**
* <a name="DAAL-CLASS-ALGORITHMS__ENGINES__BATCHBASE"></a>
* \brief Class representing an engine
* <a name="DAAL-CLASS-ALGORITHMS__ENGINES__ENGINEIFACE"></a>
* \brief Minimal public interface for random number engines
*/
class BatchBase : public daal::algorithms::Analysis<batch>
class DAAL_EXPORT EngineIface
{
public:
typedef algorithms::engines::Input InputType;
typedef algorithms::engines::Result ResultType;

InputType input; /*!< Input of the engine */

BatchBase() {}
virtual ~BatchBase() {}

/**
* Saves current engine state to destination
* \param[in] dest Destination to save the state
*
* \return Status of computations
*/
services::Status saveState(byte * dest) const { return saveStateImpl(dest); }

/**
* Rewrites current state with source one
* \param[in] src Source state
*
* \return Status of computations
*/
services::Status loadState(const byte * src) { return loadStateImpl(src); }

/**
* Enables the usage of current engine in parallel regions of code with leapfrog method
* \param[in] threadIdx Index of the thread
* \param[in] nThreads Number of threads
*
* \return Status of computations
*/
services::Status leapfrog(size_t threadIdx, size_t nThreads) { return leapfrogImpl(threadIdx, nThreads); }

/**
* Enables the usage of current engine in parallel regions of code with skipAhead method
* \param[in] nSkip Number of elements that will be skipped
*
* \return Status of computations
*/
services::Status skipAhead(size_t nSkip) { return skipAheadImpl(nSkip); }
virtual ~EngineIface() {}

/**
* Returns a pointer to the newly allocated engine
* with a copy of input objects and parameters of this engine
* \return Pointer to the newly allocated engine
*/
services::SharedPtr<BatchBase> clone() const { return services::SharedPtr<BatchBase>(cloneImpl()); }
virtual services::SharedPtr<EngineIface> clone() const = 0;

protected:
virtual services::Status saveStateImpl(byte * /*dest*/) const { return services::Status(); }
virtual services::Status loadStateImpl(const byte * /*src*/) { return services::Status(); }
virtual services::Status leapfrogImpl(size_t /*threadNum*/, size_t /*nThreads*/) { return services::Status(services::ErrorMethodNotSupported); }
virtual services::Status skipAheadImpl(size_t /*nSkip*/) { return services::Status(); }
virtual BatchBase * cloneImpl() const = 0;
EngineIface() {}
};
typedef services::SharedPtr<BatchBase> EnginePtr;
typedef services::SharedPtr<EngineIface> EngineIfacePtr;

/**
* Creates a random number engine of specified type
* \param[in] type Type of the engine to create
* \param[in] seed Initial seed for the engine
* \return Pointer to the newly created engine
*/
DAAL_EXPORT EngineIfacePtr createEngine(EngineType type, size_t seed = 777);

} // namespace interface1
using interface1::BatchBase;
using interface1::EnginePtr;
using interface1::EngineIface;
using interface1::EngineIfacePtr;
using interface1::createEngine;
/** @} */
} // namespace engines
} // namespace algorithms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DAAL_EXPORT Parameter
Default is 0 (use all features) */
size_t minObservationsInLeafNode; /*!< Minimal number of observations in a leaf node. Default is 5. */
bool memorySavingMode; /*!< If true then use memory saving (but slower) mode. Default is false */
engines::EnginePtr engine; /*!< Engine for the random numbers generator used by the algorithms */
engines::EngineIfacePtr engine; /*!< Engine for the random numbers generator used by the algorithms */
size_t maxBins; /*!< Used with 'inexact' split finding method only.
Maximal number of discrete bins to bucket continuous features.
Default is 256. Increasing the number results in higher computation costs */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "algorithms/implicit_als/implicit_als_model.h"
#include "algorithms/implicit_als/implicit_als_training_types.h"
#include "data_management/data/csr_numeric_table.h"
#include "algorithms/engines/mt19937/mt19937.h"
#include "algorithms/engines/engine.h"

namespace daal
{
Expand Down Expand Up @@ -160,10 +160,10 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
*/
Parameter(size_t nFactors = 10, size_t fullNUsers = 0, size_t seed = 777777);

size_t nFactors; /*!< Total number of factors */
size_t fullNUsers; /*!< Full number of users */
size_t seed; /*!< Seed for generating random numbers in the initialization step \DAAL_DEPRECATED_USE{ engine } */
engines::EnginePtr engine; /*!< Engine for generating random numbers in the initialization step */
size_t nFactors; /*!< Total number of factors */
size_t fullNUsers; /*!< Full number of users */
size_t seed; /*!< Seed for generating random numbers in the initialization step \DAAL_DEPRECATED_USE{ engine } */
engines::EngineIfacePtr engine; /*!< Engine for generating random numbers in the initialization step */

services::Status check() const override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define __BF_KNN_CLASSIFICATION_MODEL_H__

#include "algorithms/classifier/classifier_model.h"
#include "algorithms/engines/mcg59/mcg59.h"
#include "algorithms/engines/engine.h"

namespace daal
{
Expand Down Expand Up @@ -102,7 +102,7 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::classifier::Parameter
dataUseInModel(dataUse),
resultsToCompute(resToCompute),
voteWeights(vote),
engine(engines::mcg59::Batch<>::create())
engine(engines::createEngine(engines::mcg59Engine))
{
this->resultsToEvaluate = resToEvaluate;
}
Expand Down Expand Up @@ -147,11 +147,11 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::classifier::Parameter
*/
services::Status check() const override;

size_t k; /*!< Number of neighbors */
DataUseInModel dataUseInModel; /*!< The option to enable/disable an usage of the input dataset in kNN model */
DAAL_UINT64 resultsToCompute; /*!< 64 bit integer flag that indicates the results to compute */
VoteWeights voteWeights; /*!< Weight function used in prediction */
engines::EnginePtr engine; /*!< Engine for random choosing elements from training dataset */
size_t k; /*!< Number of neighbors */
DataUseInModel dataUseInModel; /*!< The option to enable/disable an usage of the input dataset in kNN model */
DAAL_UINT64 resultsToCompute; /*!< 64 bit integer flag that indicates the results to compute */
VoteWeights voteWeights; /*!< Weight function used in prediction */
engines::EngineIfacePtr engine; /*!< Engine for random choosing elements from training dataset */
};
/* [Parameter source code] */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "data_management/data/aos_numeric_table.h"
#include "data_management/data/soa_numeric_table.h"
#include "data_management/data/homogen_numeric_table.h"
#include "algorithms/engines/mcg59/mcg59.h"
#include "algorithms/engines/engine.h"

namespace daal
{
Expand Down Expand Up @@ -107,7 +107,7 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::classifier::Parameter
k(nNeighbors),
seed(randomSeed),
dataUseInModel(dataUse),
engine(engines::mcg59::Batch<>::create()),
engine(engines::createEngine(engines::mcg59Engine)),
resultsToCompute(resToCompute),
voteWeights(vote)
{
Expand All @@ -119,12 +119,12 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::classifier::Parameter
*/
services::Status check() const override;

size_t k; /*!< Number of neighbors */
int seed; /*!< Seed for random choosing elements from training dataset \DAAL_DEPRECATED_USE{ engine } */
DataUseInModel dataUseInModel; /*!< The option to enable/disable an usage of the input dataset in kNN model */
engines::EnginePtr engine; /*!< Engine for random choosing elements from training dataset */
DAAL_UINT64 resultsToCompute; /*!< 64 bit integer flag that indicates the results to compute */
VoteWeights voteWeights; /*!< Weight function used in prediction */
size_t k; /*!< Number of neighbors */
int seed; /*!< Seed for random choosing elements from training dataset \DAAL_DEPRECATED_USE{ engine } */
DataUseInModel dataUseInModel; /*!< The option to enable/disable an usage of the input dataset in kNN model */
engines::EngineIfacePtr engine; /*!< Engine for random choosing elements from training dataset */
DAAL_UINT64 resultsToCompute; /*!< 64 bit integer flag that indicates the results to compute */
VoteWeights voteWeights; /*!< Weight function used in prediction */
};
/* [Parameter source code] */
} // namespace interface3
Expand Down
4 changes: 2 additions & 2 deletions cpp/daal/include/algorithms/kmeans/kmeans_init_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "data_management/data/homogen_numeric_table.h"
#include "data_management/data/data_collection.h"
#include "services/daal_defines.h"
#include "algorithms/engines/mt19937/mt19937.h"
#include "algorithms/engines/engine.h"

namespace daal
{
Expand Down Expand Up @@ -296,7 +296,7 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
L = nClusters* oversamplingFactor points are sampled in a round. */
size_t nRounds; /*!< Kmeans|| only. Number of rounds for k-means||. (oversamplingFactor*nRounds) > 1 is a requirement.*/

engines::EnginePtr engine; /*!< Engine to be used for generating random numbers for the initialization */
engines::EngineIfacePtr engine; /*!< Engine to be used for generating random numbers for the initialization */

services::Status check() const override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "data_management/data/homogen_numeric_table.h"
#include "services/daal_defines.h"
#include "algorithms/optimization_solver/iterative_solver/iterative_solver_types.h"
#include "algorithms/engines/mt19937/mt19937.h"
#include "algorithms/engines/engine.h"
#include "algorithms/optimization_solver/objective_function/logistic_loss_batch.h"

namespace daal
Expand Down Expand Up @@ -99,9 +99,9 @@ struct DAAL_EXPORT Parameter : public optimization_solver::iterative_solver::Par
*/
services::Status check() const override;

size_t seed; /*!< Seed for random generation of 32 bit integer indices of terms
size_t seed; /*!< Seed for random generation of 32 bit integer indices of terms
in the objective function. \DAAL_DEPRECATED_USE{ engine } */
engines::EnginePtr engine; /*!< Engine for random generation of 32 bit integer indices of terms
engines::EngineIfacePtr engine; /*!< Engine for random generation of 32 bit integer indices of terms
in the objective function. */
SelectionStrategy selection;
bool positive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "services/daal_defines.h"
#include "algorithms/optimization_solver/iterative_solver/iterative_solver_batch.h"
#include "algorithms/optimization_solver/objective_function/sum_of_functions_batch.h"
#include "algorithms/engines/mt19937/mt19937.h"
#include "algorithms/engines/engine.h"

namespace daal
{
Expand Down Expand Up @@ -114,12 +114,12 @@ struct DAAL_EXPORT Parameter : public optimization_solver::iterative_solver::Par

virtual ~Parameter() {}

size_t m; /*!< Memory parameter of LBFGS.
size_t m; /*!< Memory parameter of LBFGS.
The maximum number of correction pairs that define the approximation
of inverse Hessian matrix. */
size_t L; /*!< The number of iterations between the curvature estimates calculations */
size_t seed; /*!< Seed for random choosing terms from objective function. \DAAL_DEPRECATED_USE{ engine } */
engines::EnginePtr engine; /*!< Engine for random choosing terms from objective function. */
size_t L; /*!< The number of iterations between the curvature estimates calculations */
size_t seed; /*!< Seed for random choosing terms from objective function. \DAAL_DEPRECATED_USE{ engine } */
engines::EngineIfacePtr engine; /*!< Engine for random choosing terms from objective function. */

data_management::NumericTablePtr batchIndices;

Expand Down
11 changes: 0 additions & 11 deletions cpp/daal/include/daal.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,6 @@
#include "algorithms/linear_model/linear_model_training_batch.h"
#include "algorithms/linear_model/linear_model_predict.h"
#include "algorithms/engines/engine.h"
#include "algorithms/engines/mt19937/mt19937.h"
#include "algorithms/engines/mt19937/mt19937_types.h"
#include "algorithms/engines/mcg59/mcg59.h"
#include "algorithms/engines/mcg59/mcg59_types.h"
#include "algorithms/engines/engine_family.h"
#include "algorithms/engines/mt2203/mt2203.h"
#include "algorithms/engines/mt2203/mt2203_types.h"
#include "algorithms/engines/mrg32k3a/mrg32k3a.h"
#include "algorithms/engines/mrg32k3a/mrg32k3a_types.h"
#include "algorithms/engines/philox4x32x10/philox4x32x10.h"
#include "algorithms/engines/philox4x32x10/philox4x32x10_types.h"
#include "algorithms/dbscan/dbscan_types.h"
#include "algorithms/dbscan/dbscan_batch.h"
#include "algorithms/dbscan/dbscan_distributed.h"
Expand Down
11 changes: 0 additions & 11 deletions cpp/daal/include/daal_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,6 @@
#include "algorithms/linear_model/linear_model_training_batch.h"
#include "algorithms/linear_model/linear_model_predict.h"
#include "algorithms/engines/engine.h"
#include "algorithms/engines/mt19937/mt19937.h"
#include "algorithms/engines/mt19937/mt19937_types.h"
#include "algorithms/engines/mcg59/mcg59.h"
#include "algorithms/engines/mcg59/mcg59_types.h"
#include "algorithms/engines/engine_family.h"
#include "algorithms/engines/mt2203/mt2203.h"
#include "algorithms/engines/mt2203/mt2203_types.h"
#include "algorithms/engines/mrg32k3a/mrg32k3a.h"
#include "algorithms/engines/mrg32k3a/mrg32k3a_types.h"
#include "algorithms/engines/philox4x32x10/philox4x32x10.h"
#include "algorithms/engines/philox4x32x10/philox4x32x10_types.h"
#include "algorithms/dbscan/dbscan_types.h"
#include "algorithms/dbscan/dbscan_batch.h"
#include "algorithms/dbscan/dbscan_distributed.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "src/data_management/service_numeric_table.h"
#include "src/externals/service_rng.h"
#include "src/algorithms/distributions/uniform/uniform_kernel.h"
#include "src/algorithms/engines/engine_impl.h"

using namespace daal::services;
using namespace daal::data_management;
Expand Down
Loading
Loading