Intel® oneAPI Data Analytics Library
Learn from community members on how to build compute-intensive applications that run efficiently on Intel® architecture.

Unsafe SharedPtr?


In the svm_two_class_batch.cpp example, it has:

SharedPtr<svm::training::Result> trainingResult;
    /* Retrieve algorithm results */
    trainingResult = algorithm.getResult();

However, it turns out that the object at the end of the pointer is not an instance of svm::training::Result (!).

In svm_train.h, the Batch template has:

    void allocateResult()
        SharedPtr<Result> res = staticPointerCast<Result, two_class_classifier::training::Result>(_result);
        res->template allocate<algorithmFPType>(&input, _par, (int) method);
        _res = _result.get();

As can be seen, it allocates the superclass of svm::training::Result, two_class_classifier::training::Result.

It was confusing when I was trying to hold the trainingResult in a SharedPtr< ::daal::algorithm::Result> and could not dynamicPointerCast< svm::training::Result>(p).

Would be nice to have the option for SharedPtr to do runtime checking to ensure that it is, indeed, pointing to an instance of what it says it's pointing to.



0 Kudos
1 Reply

Hello Alvin,

Thank you for the feedback.
The issues you describe below have already been fixed and would be available in the upcoming releases of Intel® DAAL. The modifications implemented in the library are as follows:

  • getResult() method of the classification algorithms now returns the shared pointer to the respective Result class, in your case, it is SharedPtr<svm::training::Result>
  • Behavior of operator=() method in Intel® DAAL shared pointer is aligned with shared pointer in C++ standard library. In the Beta release of the library, this operator allowed implicit upcasts, thus, the code of the example worked fine.

Please, let us know, if you have other questions on the methods of classifiers, shared pointers, or other features of the Intel® DAAL

Best regards,

0 Kudos