49 from daal.data_management
import BlockDescriptor, SOANumericTable, data_feature_utils, readOnly
51 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
52 if utils_folder
not in sys.path:
53 sys.path.insert(0, utils_folder)
54 from utils
import printArray
58 if v == data_feature_utils.DAAL_CATEGORICAL:
59 return "DAAL_CATEGORICAL"
60 elif v == data_feature_utils.DAAL_ORDINAL:
62 elif v == data_feature_utils.DAAL_CONTINUOUS:
63 return "DAAL_CONTINUOUS"
65 return "[Unknown FeatureType]"
68 if __name__ ==
"__main__":
69 print(
"Structure of array (SOA) numeric table example\n")
76 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)
77 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)
78 iDataSOA = np.array([-10, -20, -30, -40, -50, -60, -70, -80, -90, -100], dtype=np.int32)
79 cDataSOA = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5], dtype=np.uint8)
81 dataTable = SOANumericTable(nFeatures, nObservations)
82 dataTable.setArray(cDataSOA, 0)
83 dataTable.setArray(fDataSOA, 1)
84 dataTable.setArray(dDataSOA, 2)
85 dataTable.setArray(iDataSOA, 3)
87 doubleBlock = BlockDescriptor()
88 dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, doubleBlock)
90 doubleBlock.getArray(), nFeatures, doubleBlock.getNumberOfRows(), doubleBlock.getNumberOfColumns(),
91 "Print SOA data structures as double:"
93 dataTable.releaseBlockOfRows(doubleBlock)
96 intBlock = BlockDescriptor(ntype=np.intc)
97 dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nObservations, readOnly, intBlock)
99 intBlock.getArray(), 1, intBlock.getNumberOfRows(), intBlock.getNumberOfColumns(),
100 "Print the first feature of SOA:", flt64=
False
102 dataTable.releaseBlockOfColumnValues(intBlock)
104 pDictionary = dataTable.getDictionary()
105 print(
"Number of features in table: " + str(pDictionary.getNumberOfFeatures()))
108 print(
"Default type in autogenerated dictionary:")
109 for i
in range(0, nFeatures):
110 featureType = pDictionary[i].featureType
111 print(
"Type of " + str(i) +
" feature: " + toString(featureType))
114 categoricalFeature = pDictionary[0]
115 categoricalFeature.featureType = data_feature_utils.DAAL_CATEGORICAL
117 print(
"Modified type in the dictionary:")
118 for i
in range(0, nFeatures):
119 featureType = pDictionary[i].featureType
120 print(
"Type of " + str(i) +
" feature: " + toString(featureType))