26 from daal.data_management
import BlockDescriptor, SOANumericTable, features, readOnly
28 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
29 if utils_folder
not in sys.path:
30 sys.path.insert(0, utils_folder)
31 from utils
import printArray
35 if v == features.DAAL_CATEGORICAL:
36 return "DAAL_CATEGORICAL"
37 elif v == features.DAAL_ORDINAL:
39 elif v == features.DAAL_CONTINUOUS:
40 return "DAAL_CONTINUOUS"
42 return "[Unknown FeatureType]"
45 if __name__ ==
"__main__":
46 print(
"Structure of array (SOA) numeric table example\n")
53 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)
54 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)
55 iDataSOA = np.array([-10, -20, -30, -40, -50, -60, -70, -80, -90, -100], dtype=np.int32)
56 cDataSOA = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5], dtype=np.uint8)
58 dataTable = SOANumericTable(nFeatures, nObservations)
59 dataTable.setArray(cDataSOA, 0)
60 dataTable.setArray(fDataSOA, 1)
61 dataTable.setArray(dDataSOA, 2)
62 dataTable.setArray(iDataSOA, 3)
64 doubleBlock = BlockDescriptor()
65 dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, doubleBlock)
67 doubleBlock.getArray(), nFeatures, doubleBlock.getNumberOfRows(), doubleBlock.getNumberOfColumns(),
68 "Print SOA data structures as double:"
70 dataTable.releaseBlockOfRows(doubleBlock)
73 intBlock = BlockDescriptor(ntype=np.intc)
74 dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nObservations, readOnly, intBlock)
76 intBlock.getArray(), 1, intBlock.getNumberOfRows(), intBlock.getNumberOfColumns(),
77 "Print the first feature of SOA:", flt64=
False
79 dataTable.releaseBlockOfColumnValues(intBlock)
81 pDictionary = dataTable.getDictionary()
82 print(
"Number of features in table: " + str(pDictionary.getNumberOfFeatures()))
85 print(
"Default type in autogenerated dictionary:")
86 for i
in range(0, nFeatures):
87 featureType = pDictionary[i].featureType
88 print(
"Type of " + str(i) +
" feature: " + toString(featureType))
91 categoricalFeature = pDictionary[0]
92 categoricalFeature.featureType = features.DAAL_CATEGORICAL
94 print(
"Modified type in the dictionary:")
95 for i
in range(0, nFeatures):
96 featureType = pDictionary[i].featureType
97 print(
"Type of " + str(i) +
" feature: " + toString(featureType))