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

datastructures_homogentensor.py

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.

1 # file: datastructures_homogentensor.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 homogeneous tensor data structures
19 # !*****************************************************************************
20 
21 #
22 ## <a name ="DAAL-EXAMPLE-PY-DATASTRUCTURES_HOMOGENTENSOR"> </a>
23 ## \example datastructures_homogentensor.py
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.