#include "daal.h"
#include "service.h"
using namespace daal;
const char *toString(data_feature_utils::FeatureType v);
const char *toString(data_feature_utils::InternalNumType v);
int main()
{
std::cout << "Structure of array (SOA) numeric table example" << std::endl << std::endl;
const size_t firstReadRow = 0;
const size_t nRead = 3;
size_t readFeatureIdx;
const size_t nObservations = 10;
const size_t nFeatures = 4;
double dDataSOA[nObservations] = {1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8};
float fDataSOA[nObservations] = {3.1f, 3.2f, 3.3f, 3.4f, 3.5f, 3.6f, 3.7f, 3.8f, 3.9f, 4.0f};
int iDataSOA[nObservations] = { -10, -20, -30, -40, -50, -60, -70, -80, -90, -100};
int cDataSOA[nObservations] = {1, 2, 3, 4, 5, 1, 2, 3, 4, 5};
SOANumericTable dataTable(nFeatures, nObservations);
dataTable.setArray<int> (cDataSOA, 0);
dataTable.setArray<float> (fDataSOA, 1);
dataTable.setArray<double>(dDataSOA, 2);
dataTable.setArray<int> (iDataSOA, 3);
BlockDescriptor<double> doubleBlock;
dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, doubleBlock);
printArray<double>(doubleBlock.getBlockPtr(), nFeatures, doubleBlock.getNumberOfRows(), "Print SOA data structures as double:");
dataTable.releaseBlockOfRows(doubleBlock);
readFeatureIdx = 0;
BlockDescriptor<int> intBlock;
dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nObservations, readOnly, intBlock);
printArray<int>(intBlock.getBlockPtr(), 1, intBlock.getNumberOfRows(), "Print the first feature of SOA:");
dataTable.releaseBlockOfColumnValues(intBlock);
NumericTableDictionary *pDictionary = dataTable.getDictionary();
std::cout << "Number of features in table: " << pDictionary->getNumberOfFeatures() << std::endl;
std::cout << std::endl;
std::cout << "Default type in autogenerated dictionary:" << std::endl;
for(size_t i = 0; i < nFeatures; i++)
{
data_feature_utils::FeatureType featureType = (*pDictionary)[i].featureType;
std::cout << "Type of " << i << " feature: " ;
std::cout << toString(featureType) << std::endl;
}
std::cout << std::endl;
NumericTableFeature &categoricalFeature = (*pDictionary)[0];
categoricalFeature.featureType = data_feature_utils::DAAL_CATEGORICAL;
std::cout << "Modified type in the dictionary:" << std::endl;
for(size_t i = 0; i < nFeatures; i++)
{
data_feature_utils::FeatureType featureType = (*pDictionary)[i].featureType;
std::cout << "Type of " << i << " feature: " ;
std::cout << toString(featureType) << std::endl;
}
std::cout << std::endl;
return 0;
}
const char *toString(data_feature_utils::FeatureType v)
{
switch (v)
{
case data_feature_utils::DAAL_CATEGORICAL: return "DAAL_CATEGORICAL";
case data_feature_utils::DAAL_ORDINAL: return "DAAL_ORDINAL";
case data_feature_utils::DAAL_CONTINUOUS: return "DAAL_CONTINUOUS";
default: return "[Unknown FeatureType]";
}
}