Python* API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

datastructures_merged.py

1 # file: datastructures_merged.py
2 #===============================================================================
3 # Copyright 2014-2020 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #===============================================================================
17 
18 
19 
20 
21 import os
22 import sys
23 
24 import numpy as np
25 
26 from daal.data_management import (
27  HomogenNumericTable, MergedNumericTable, BlockDescriptor, readWrite, readOnly
28 )
29 
30 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
31 if utils_folder not in sys.path:
32  sys.path.insert(0, utils_folder)
33 from utils import printArray
34 
35 
36 if __name__ == "__main__":
37 
38  print("Merged numeric table example\n")
39 
40  nFeatures1 = 5
41  nFeatures2 = 6
42  firstReadRow = 3
43  nRead = 1
44 
45  # Example of using homogeneous numeric table
46  data1 = np.array([
47  (0.0, 0.1, 0.2, 0.3, 0.4),
48  (1.0, 1.1, 1.2, 1.3, 1.4),
49  (2.0, 2.1, 2.2, 2.3, 2.4),
50  (3.0, 3.1, 3.2, 3.3, 3.4),
51  (4.0, 4.1, 4.2, 4.3, 4.4),
52  ])
53 
54  data2 = np.array([
55  (0.5, 0.6, 0.7, 0.8, 0.9, 1),
56  (1.5, 1.6, 1.7, 1.8, 1.9, 2),
57  (2.5, 2.6, 2.7, 2.8, 2.9, 3),
58  (3.5, 3.6, 3.7, 3.8, 3.9, 4),
59  (4.5, 4.6, 4.7, 4.8, 4.9, 5),
60  ])
61 
62  # Create two homogen numeric tables from data arrays
63  dataTable1 = HomogenNumericTable(data1)
64  dataTable2 = HomogenNumericTable(data2)
65 
66  # Create merged numeric table consisting of two homogen numeric tables
67  dataTable = MergedNumericTable()
68  dataTable.addNumericTable(dataTable1)
69  dataTable.addNumericTable(dataTable2)
70 
71  block = BlockDescriptor()
72 
73  # Read one row from merged numeric table
74  dataTable.getBlockOfRows(firstReadRow, nRead, readWrite, block)
75  printArray(
76  block.getArray(), nFeatures1 + nFeatures2, block.getNumberOfRows(),
77  block.getNumberOfColumns(), "Print 1 row from merged numeric table as double:"
78  )
79 
80  # Modify row of the merged numeric table
81  row = block.getArray()
82  for i in range(nFeatures1 + nFeatures2):
83  row[0][i] *= row[0][i]
84  dataTable.releaseBlockOfRows(block)
85 
86  # Read the same row from homogen numeric tables
87  dataTable1.getBlockOfRows(firstReadRow, nRead, readOnly, block)
88  printArray(
89  block.getArray(), nFeatures1, block.getNumberOfRows(),
90  block.getNumberOfColumns(), "Print 1 row from first homogen numeric table as double:"
91  )
92  dataTable1.releaseBlockOfRows(block)
93 
94  dataTable2.getBlockOfRows(firstReadRow, nRead, readOnly, block)
95  printArray(
96  block.getArray(), nFeatures2, block.getNumberOfRows(),
97  block.getNumberOfColumns(), "Print 1 row from second homogen numeric table as double:"
98  )
99  dataTable2.releaseBlockOfRows(block)

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