- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On Linux, with version 2016.0.069 (the most recent beta version) it looks like it is possible to get a NumericTable from a daal::algorithms::classifier::prediction::Result. However, if I try to do this with the multinomial_naive_bayes example, adding the following lines to the end of the trainModel() function:
/* Retrieve algorithm results */ trainingResult = algorithm.getResult(); /* Additional lines below */ SharedPtr<NumericTable> t = trainingResult->get(classifier::training::model); std::cout << t->getNumberOfRows() << std::endl; std::cout << t->getNumberOfColumns() << std::endl;
then getNumberOfRows() returns 0, and getNumberOfColumns() segfaults:
Program received signal SIGSEGV, Segmentation fault. 0x000000000041f116 in daal::data_management::Dictionary<daal::data_management::NumericTableFeature>::getNumberOfFeatures (this=0x0) at /opt/intel/compilers_and_libraries_2016.0.069/linux/daal/include/data_management/data/data_dictionary.h:344 344 return _nfeat; (gdb) bt #0 0x000000000041f116 in daal::data_management::Dictionary<daal::data_management::NumericTableFeature>::getNumberOfFeatures (this=0x0) at /opt/intel/compilers_and_libraries_2016.0.069/linux/daal/include/data_management/data/data_dictionary.h:344 #1 0x000000000041647e in daal::data_management::NumericTable::getNumberOfColumns ( this=0x67a740) at /opt/intel/compilers_and_libraries_2016.0.069/linux/daal/include/data_management/data/numeric_table.h:506 #2 0x00000000004142d9 in trainModel () at naive_bayes2.cpp:107
where it appears that the NumericTable's _ddict is null.
Should it always be possible to call getNumberOfRows() and getNumberOfColumns() on a NumericTable? If it isn't the case, then should these methods be throwing an exception (or setting an error status) instead of segfaulting when called?
Many thanks in advance.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Graham,
we will have a look at your question. Meanwhile, as a quick observation: you extract the pointer to the model from the Naïve Bayes training result and assign it to the pointer to the Numeric Table.
SharedPtr<NumericTable> t = trainingResult->get(classifier::training::model);
Please, double check this line.
Thanks,
Andrey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Andrey,
Thanks for the quick response and pinpointing the problem. If I now understand correctly, t = trainingResult->get(classifier::training::model) returns a SharedPtr<classifier::Model>, not a SharedPtr<NumericTable>, which is likely the source of my subsequent problems - does this sound correct?
Many thanks,
Graham.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Andrey,
As a follow-up, I was quite surprised to discover that my original example even compiles, since a NumericTable and a Model are different classes. But then I found at line 155 of daal_shared_ptr.h:
template<class T> template<class U> SharedPtr<T>::SharedPtr(const SharedPtr<U> &other) : _ptr((T*)(other._ptr)), _refCount(other._refCount), _deleter(other._deleter) { (*_refCount)++; }
So as far as I can understand, any shared pointer will copy-construct to a shared pointer of any other type. For example, I can compile the following:
#include "data_management/data/daal_shared_ptr.h" // g++ test-intel-sp.cpp -c -std=c++11 -Wall -Werror -Wno-unused-variable -I/opt/intel/compilers_and_libraries_2016.0.069/linux/daal/include using namespace std; using namespace daal; class A {}; class B {}; void f() { SharedPtr<A> a = SharedPtr<A>(new A()); SharedPtr<B> b = a; }
Whereas the equivalvent using the C++11 shared_ptr:
#include <memory> // g++ test-sp.cpp -c -std=c++11 -Wall -Werror using namespace std; class A {}; class B {}; void f() { shared_ptr<A> a = shared_ptr<A>(new A()); shared_ptr<B> b = a; }
fails to compile, with the error:
test-sp.cpp: In function ‘void f()’: test-sp.cpp:12:23: error: conversion from ‘std::shared_ptr<A>’ to non-scalar type ‘std::shared_ptr<B>’ requested shared_ptr<B> b = a; ^
which is what I would usually expect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Graham,
Yes, trainingResult->get(classifier::training::model) returns a SharedPtr<classifier::Model>. Please, keep in mind that you need to apply casting to SharedPtr<classifier::Model> using, for example, SharedPtr<T> staticPointerCast(const SharedPtr<U> &r), to get the model of the Naïve Bayes. We would analyze what can be done in the library to avoid this extra casting in the user's application.
For your second observation, you are correct - compile-time error should be the right behavior of the library. We would analyze how to address it as well.
Thank you for your useful comments and feedback. Please, let us know if you have more questions, and we will gladly help.
Andrey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Andrey,
Thanks for the answers. Regarding the staticPointerCast that is needed to get the multinomial_naive_bayes::Model from the classifier::Model - I can understand the need for this, and see that I can get a couple of different NumericTables from the multinomial_naive_bayes::Model via different methods.
As a more general question, why does DAAL include its own SharedPtr class instead of just using the shared_ptr from the <memory> header?
Many thanks,
Graham.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Graham,
There are some reasons for providing the shared pointer in the library including the need to support applications that rely on elder C++ as well as minimizing dependence of Intel(R) DAAL on the external implementations/libraries.
Thanks,
Andrey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page