Deprecation Notice: With the introduction of daal4py, a package that supersedes PyDAAL, Intel is deprecating PyDAAL and will discontinue support starting with Intel® DAAL 2021 and Intel® Distribution for Python 2021. Until then Intel will continue to provide compatible pyDAAL pip and conda packages for newer releases of Intel DAAL and make it available in open source. However, Intel will not add the new features of Intel DAAL to pyDAAL. Intel recommends developers switch to and use daal4py.
Note: To find daal4py examples, refer to daal4py documentation or browse github repository.
24 from daal.data_management
import BlockDescriptor, CSRBlockDescriptor, CSRNumericTable, readOnly, readWrite
26 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
27 if utils_folder
not in sys.path:
28 sys.path.insert(0, utils_folder)
29 from utils
import printArray
32 if __name__ ==
"__main__":
34 print(
"Compressed spares rows (CSR) numeric table example\n")
42 values = np.array([1, -1, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, -5], dtype=np.float64)
43 colIndices = np.array([1, 2, 4, 1, 2, 3, 4, 5, 1, 3, 4, 2, 5], dtype=np.uint64)
44 rowOffsets = np.array([1, 4, 6, 9, 12, 14], dtype=np.uint64)
46 dataTable = CSRNumericTable(values, colIndices, rowOffsets, nFeatures, nObservations)
49 block = BlockDescriptor(ntype=np.float64)
50 dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, block)
51 print(str(block.getNumberOfRows()) +
" rows are read\n")
53 block.getArray(), nFeatures, block.getNumberOfRows(), block.getNumberOfColumns(),
54 "Print 3 rows from CSR data array as dense double array:"
56 dataTable.releaseBlockOfRows(block)
59 csrBlock = CSRBlockDescriptor(ntpye=np.float32)
60 num_cols = csrBlock.getNumberOfColumns()
61 dataTable.getSparseBlock(firstReadRow, nRead, readWrite, csrBlock)
62 valuesBlock = csrBlock.getBlockValues()
63 nValuesInBlock = csrBlock.getDataSize()
64 printArray(valuesBlock, nValuesInBlock, 1, num_cols,
"Values in 3 rows from CSR data array:")
66 csrBlock.getBlockColumnIndices(), nValuesInBlock, 1, num_cols,
67 "Columns indices in 3 rows from CSR data array:", flt64=
False
70 csrBlock.getBlockRowIndices(), nRead + 1, 1, num_cols,
71 "Rows offsets in 3 rows from CSR data array:", flt64=
False
74 for i
in range(nValuesInBlock):
75 valuesBlock[i] = -(1.0 + i)
77 dataTable.releaseSparseBlock(csrBlock)
80 dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, block)
81 print(str(block.getNumberOfRows()) +
" rows are read\n")
83 block.getArray(), nFeatures, block.getNumberOfRows(), block.getNumberOfColumns(),
84 "Print 3 rows from CSR data array as dense double array:"
86 dataTable.releaseBlockOfRows(block)