50 from daal.data_management
import BlockDescriptor, SOANumericTable, data_feature_utils, readOnly
52 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
53 if utils_folder
not in sys.path:
54 sys.path.insert(0, utils_folder)
55 from utils
import printArray
59 if v == data_feature_utils.DAAL_CATEGORICAL:
60 return "DAAL_CATEGORICAL" 61 elif v == data_feature_utils.DAAL_ORDINAL:
63 elif v == data_feature_utils.DAAL_CONTINUOUS:
64 return "DAAL_CONTINUOUS" 66 return "[Unknown FeatureType]" 69 if __name__ ==
"__main__":
70 print(
"Structure of array (SOA) numeric table example\n")
77 dDataSOA = np.array([1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8], dtype=np.float64)
78 fDataSOA = np.array([3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0], dtype=np.float32)
79 iDataSOA = np.array([-10, -20, -30, -40, -50, -60, -70, -80, -90, -100], dtype=np.int32)
80 cDataSOA = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5], dtype=np.uint8)
82 dataTable = SOANumericTable(nFeatures, nObservations)
83 dataTable.setArray(cDataSOA, 0)
84 dataTable.setArray(fDataSOA, 1)
85 dataTable.setArray(dDataSOA, 2)
86 dataTable.setArray(iDataSOA, 3)
88 doubleBlock = BlockDescriptor()
89 dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, doubleBlock)
91 doubleBlock.getArray(), nFeatures, doubleBlock.getNumberOfRows(), doubleBlock.getNumberOfColumns(),
92 "Print SOA data structures as double:" 94 dataTable.releaseBlockOfRows(doubleBlock)
97 intBlock = BlockDescriptor(ntype=np.intc)
98 dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nObservations, readOnly, intBlock)
100 intBlock.getArray(), 1, intBlock.getNumberOfRows(), intBlock.getNumberOfColumns(),
101 "Print the first feature of SOA:", flt64=
False 103 dataTable.releaseBlockOfColumnValues(intBlock)
105 pDictionary = dataTable.getDictionary()
106 print(
"Number of features in table: " + str(pDictionary.getNumberOfFeatures()))
109 print(
"Default type in autogenerated dictionary:")
110 for i
in range(0, nFeatures):
111 featureType = pDictionary[i].featureType
112 print(
"Type of " + str(i) +
" feature: " + toString(featureType))
115 categoricalFeature = pDictionary[0]
116 categoricalFeature.featureType = data_feature_utils.DAAL_CATEGORICAL
118 print(
"Modified type in the dictionary:")
119 for i
in range(0, nFeatures):
120 featureType = pDictionary[i].featureType
121 print(
"Type of " + str(i) +
" feature: " + toString(featureType))