Skip to content

Commit

Permalink
Merge branch 'oneapi-src:main' into dev/coverity-2025_0
Browse files Browse the repository at this point in the history
  • Loading branch information
icfaust authored Sep 6, 2024
2 parents e6528a6 + 8c4ba82 commit f8a8ea6
Show file tree
Hide file tree
Showing 19 changed files with 405 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNode(const TreeId treeId, const NodeId parentId, const size_t position, const size_t classLabel)
{
return addLeafNode(treeId, parentId, position, classLabel, 0);
}

/**
* Create Leaf node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -143,14 +135,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNodeByProba(const TreeId treeId, const NodeId parentId, const size_t position, const double * const proba)
{
return addLeafNodeByProba(treeId, parentId, position, proba, 0);
}

/**
* Create Split node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -171,15 +155,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addSplitNode(const TreeId treeId, const NodeId parentId, const size_t position, const size_t featureIndex,
const double featureValue)
{
return addSplitNode(treeId, parentId, position, featureIndex, featureValue, 0, 0);
}

void setNFeatures(size_t nFeatures)
{
if (!_model.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNode(TreeId treeId, NodeId parentId, size_t position, double response)
{
return addLeafNode(treeId, parentId, position, response, 0);
}

/**
* Create Split node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -147,14 +139,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addSplitNode(TreeId treeId, NodeId parentId, size_t position, size_t featureIndex, double featureValue)
{
return addSplitNode(treeId, parentId, position, featureIndex, featureValue, 0, 0);
}

/**
* Get built model
* \return Model pointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DAAL_EXPORT Batch : public classifier::prediction::Batch

typedef algorithms::gbt::classification::prediction::Input InputType;
typedef algorithms::gbt::classification::prediction::Parameter ParameterType;
typedef typename super::ResultType ResultType;
typedef algorithms::gbt::classification::prediction::Result ResultType;

InputType input; /*!< %Input objects of the algorithm */

Expand Down Expand Up @@ -152,6 +152,12 @@ class DAAL_EXPORT Batch : public classifier::prediction::Batch
*/
virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }

/**
* Returns the structure that contains the result of model-based prediction
* \return Structure that contains the result of the model-based prediction
*/
ResultPtr getResult() { return ResultType::cast(_result); }

/**
* Returns a pointer to the newly allocated gradient boosted trees prediction algorithm with a copy of input objects
* and parameters of this gradient boosted trees prediction algorithm
Expand All @@ -164,7 +170,7 @@ class DAAL_EXPORT Batch : public classifier::prediction::Batch

services::Status allocateResult() DAAL_C11_OVERRIDE
{
services::Status s = _result->allocate<algorithmFPType>(&input, _par, 0);
services::Status s = getResult()->template allocate<algorithmFPType>(&input, _par, 0);
_res = _result.get();
return s;
}
Expand All @@ -173,6 +179,7 @@ class DAAL_EXPORT Batch : public classifier::prediction::Batch
{
_in = &input;
_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
_result.reset(new ResultType());
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ enum Method
defaultDense = 0 /*!< Default method */
};

/**
* <a name="DAAL-ENUM-ALGORITHMS__GBT__CLASSIFICATION__PREDICTION__MODELINPUTID"></a>
* \brief Available identifiers of input models for making model-based prediction
*/
enum ModelInputId
{
model = algorithms::classifier::prediction::model, /*!< Trained gradient boosted trees model */
lastModelInputId = model
};

/**
* <a name="DAAL-ENUM-ALGORITHMS__GBT__CLASSIFICATION__PREDICTION__RESULTID"></a>
* \brief Available identifiers of the result for making model-based prediction
*/
enum ResultId
{
prediction = algorithms::classifier::prediction::prediction,
probabilities = algorithms::classifier::prediction::probabilities,
logProbabilities = algorithms::classifier::prediction::logProbabilities,
lastResultId = logProbabilities
};

/**
* <a name="DAAL-ENUM-ALGORITHMS__GBT__CLASSIFICATION__PREDICTION__RESULTTOCOMPUTEID"></a>
* Available identifiers to specify the result to compute - results are mutually exclusive
Expand Down Expand Up @@ -89,6 +111,62 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::classifier::Parameter
DAAL_UINT64 resultsToCompute; /*!< 64 bit integer flag that indicates the results to compute */
};
/* [Parameter source code] */

/**
* <a name="DAAL-CLASS-ALGORITHMS__GBT__CLASSIFICATION__RESULT"></a>
* \brief Provides interface for the result of model-based prediction
*/
class DAAL_EXPORT Result : public algorithms::classifier::prediction::Result
{
public:
DECLARE_SERIALIZABLE_CAST(Result)
Result();

/**
* Returns the result of model-based prediction
* \param[in] id Identifier of the result
* \return Result that corresponds to the given identifier
*/
data_management::NumericTablePtr get(ResultId id) const;

/**
* Sets the result of model-based prediction
* \param[in] id Identifier of the input object
* \param[in] value %Input object
*/
void set(ResultId id, const data_management::NumericTablePtr & value);

/**
* Allocates memory to store a partial result of model-based prediction
* \param[in] input %Input object
* \param[in] par %Parameter of the algorithm
* \param[in] method Algorithm method
* \return Status of allocation
*/
template <typename algorithmFPType>
DAAL_EXPORT services::Status allocate(const daal::algorithms::Input * input, const daal::algorithms::Parameter * par, const int method);

/**
* Checks the result of model-based prediction
* \param[in] input %Input object
* \param[in] par %Parameter of the algorithm
* \param[in] method Computation method
* \return Status of checking
*/
services::Status check(const daal::algorithms::Input * input, const daal::algorithms::Parameter * par, int method) const DAAL_C11_OVERRIDE;

protected:
using daal::algorithms::Result::check;

/** \private */
template <typename Archive, bool onDeserialize>
services::Status serialImpl(Archive * arch)
{
return daal::algorithms::Result::serialImpl<Archive, onDeserialize>(arch);
}
};

typedef services::SharedPtr<Result> ResultPtr;
} // namespace interface2

/**
Expand Down Expand Up @@ -124,7 +202,7 @@ class DAAL_EXPORT Input : public classifier::prediction::Input
* \param[in] id Identifier of the input Model object
* \return %Input object that corresponds to the given identifier
*/
gbt::classification::ModelPtr get(classifier::prediction::ModelInputId id) const;
gbt::classification::ModelPtr get(ModelInputId id) const;

/**
* Sets the input NumericTable object in the prediction stage of the classification algorithm
Expand All @@ -138,7 +216,7 @@ class DAAL_EXPORT Input : public classifier::prediction::Input
* \param[in] id Identifier of the input object
* \param[in] ptr Pointer to the input object
*/
void set(classifier::prediction::ModelInputId id, const gbt::classification::ModelPtr & ptr);
void set(ModelInputId id, const gbt::classification::ModelPtr & ptr);

/**
* Checks the correctness of the input object
Expand All @@ -151,6 +229,8 @@ class DAAL_EXPORT Input : public classifier::prediction::Input

} // namespace interface1
using interface2::Parameter;
using interface2::Result;
using interface2::ResultPtr;
using interface1::Input;
} // namespace prediction
/** @} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNode(TreeId treeId, NodeId parentId, size_t position, double response)
{
return addLeafNode(treeId, parentId, position, response, 0);
}

/**
* Create Split node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -145,14 +137,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addSplitNode(TreeId treeId, NodeId parentId, size_t position, size_t featureIndex, double featureValue)
{
return addSplitNode(treeId, parentId, position, featureIndex, featureValue, 0, 0);
}

/**
* Get built model
* \return Model pointer
Expand Down
3 changes: 2 additions & 1 deletion cpp/daal/include/services/error_indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ enum ErrorID
// GBT error: -30000..-30099
ErrorGbtIncorrectNumberOfTrees = -30000, /*!< Number of trees in the model is not consistent with the number of classes */
ErrorGbtPredictIncorrectNumberOfIterations = -30001, /*!< Number of iterations value in GBT parameter is not consistent with the model */
ErrorGbtPredictShapOptions = -30002, /*< For SHAP values, calculate either contributions or interactions, not both */
ErrorGbtPredictShapOptions = -30002, /*!< For SHAP values, calculate either contributions or interactions, not both */
ErrorGbtPredictShapMulticlassNotSupported = -30003, /*!< For classification, SHAP values currently only support binary classification */

// Data management errors: -80001..
ErrorUserAllocatedMemory = -80001, /*!< Couldn't free memory allocated by user */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ services::Status BatchContainer<algorithmFPType, method, cpu>::compute()
result->get(classifier::prediction::probabilities).get() :
nullptr);

const bool predShapContributions = par->resultsToCompute & shapContributions;
const bool predShapInteractions = par->resultsToCompute & shapInteractions;
__DAAL_CALL_KERNEL(env, internal::PredictKernel, __DAAL_KERNEL_ARGUMENTS(algorithmFPType, method), compute,
daal::services::internal::hostApp(*input), a, m, r, prob, par->nClasses, par->nIterations);
daal::services::internal::hostApp(*input), a, m, r, prob, par->nClasses, par->nIterations, predShapContributions,
predShapInteractions);
}

} // namespace interface2
Expand Down
Loading

0 comments on commit f8a8ea6

Please sign in to comment.