Python* API Reference for Intel® Data Analytics Acceleration Library 2018 Update 3

datastructures_homogentensor.py

1 # file: datastructures_homogentensor.py
2 #===============================================================================
3 # Copyright 2014-2018 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 homogeneous tensor data structures
19 # !*****************************************************************************
20 
21 #
22 
23 
24 #
25 from __future__ import print_function
26 
27 import numpy as np
28 
29 from daal.data_management import HomogenTensor, SubtensorDescriptor, readWrite
30 
31 if __name__ == "__main__":
32 
33  data = np.array([[[1,2,3],[4,5,6],[7,8,9]],[[11,12,13],[14,15,16],[17,18,19]],[[21,22,23],[24,25,26],[27,28,29]]],
34  dtype=np.float64)
35 
36  print("Initial data:")
37  for i in data.flatten():
38  print("{0:5.1f}".format(i), end=' ')
39  print()
40 
41  hc = HomogenTensor(data)
42 
43  subtensor = SubtensorDescriptor()
44  fDimN = 2
45  fDims = [0, 1]
46  hc.getSubtensor(fDims, 1, 2, readWrite, subtensor)
47 
48  d = subtensor.getNumberOfDims()
49  print("Subtensor dimensions: {}".format(d))
50  n = subtensor.getSize()
51  print("Subtensor size: {}".format(n))
52  p = subtensor.getArray()
53  print("Subtensor data:")
54  for i in p:
55  print("{0:5.1f}".format(i), end=' ')
56  print()
57 
58  p[0] = -1
59 
60  hc.releaseSubtensor(subtensor)
61 
62  print("Data after modification:")
63  for i in data.flatten():
64  print("{0:5.1f}".format(i), end=' ')
65  print()

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