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

datastructures_homogentensor.py

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

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