Python* API Reference for Intel® Data Analytics Acceleration Library 2019 Update 4

datastructures_packedsymmetric.py

1 # file: datastructures_packedsymmetric.py
2 #===============================================================================
3 # Copyright 2014-2019 Intel Corporation.
4 #
5 # This software and the related documents are Intel copyrighted materials, and
6 # your use of them is governed by the express license under which they were
7 # provided to you (License). Unless the License provides otherwise, you may not
8 # use, modify, copy, publish, distribute, disclose or transmit this software or
9 # the related documents without Intel's prior written permission.
10 #
11 # This software and the related documents are provided as is, with no express
12 # or implied warranties, other than those that are expressly stated in the
13 # License.
14 #===============================================================================
15 
16 #
17 # ! Content:
18 # ! Python example of using packed data structures
19 # !*****************************************************************************
20 
21 #
22 
23 
24 #
25 
26 import os
27 import sys
28 
29 import numpy as np
30 
31 from daal.data_management import PackedSymmetricMatrix, NumericTableIface, BlockDescriptor, readOnly, readWrite
32 
33 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
34 if utils_folder not in sys.path:
35  sys.path.insert(0, utils_folder)
36 from utils import printArray
37 
38 
39 if __name__ == "__main__":
40 
41  print("Packed symmetric matrix example\n")
42 
43  nDim = 5
44  firstReadRow = 0
45  nRead = 5
46 
47  # Example of using a packed symmetric matrix
48  data = np.array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4], dtype=np.float64)
49 
50  dataTable = PackedSymmetricMatrix(NumericTableIface.lowerPackedSymmetricMatrix, data)
51 
52  block = BlockDescriptor()
53 
54  # Read a block of rows
55  dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, block)
56  print("{} rows are read".format(block.getNumberOfRows()))
57  printArray(block.getArray(), nDim, block.getNumberOfRows(), block.getNumberOfColumns(),
58  "Print 3 rows from packed symmetric matrix as float:")
59 
60  # Read a feature(column) and write into it
61  readFeatureIdx = 2
62  dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nDim, readWrite, block)
63  printArray(block.getArray(), 1, block.getNumberOfRows(), block.getNumberOfColumns(),
64  "Print the third feature of packed symmetric matrix:")
65 
66  # Set new value to a buffer and release it
67  dataBlock = block.getArray()
68  dataBlock[readFeatureIdx - 1] = -1
69  dataBlock[readFeatureIdx + 1] = -2
70  dataTable.releaseBlockOfColumnValues(block)
71 
72  # Read a block of rows. Ensure that data has changed
73  dataTable.getBlockOfRows(firstReadRow, nRead, readOnly, block)
74  print("{} rows are read".format(block.getNumberOfRows()))
75  printArray(block.getArray(), nDim, block.getNumberOfRows(), block.getNumberOfColumns(),
76  "Print 3 rows from packed symmetric matrix as float:")

For more complete information about compiler optimizations, see our Optimization Notice.