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

sorting_dense_batch.py

1 # file: sorting_dense_batch.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 ## <a name="DAAL-EXAMPLE-PY-SORTING_BATCH"></a>
17 ## \example sorting_dense_batch.py
18 
19 import os
20 import sys
21 
22 from daal.algorithms import sorting
23 from daal.data_management import DataSourceIface, FileDataSource
24 
25 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
26 if utils_folder not in sys.path:
27  sys.path.insert(0, utils_folder)
28 from utils import printNumericTable
29 
30 # Input data set parameters
31 datasetFileName = os.path.join('..', 'data', 'batch', 'sorting.csv')
32 
33 if __name__ == "__main__":
34 
35  # Initialize FileDataSource<CSVFeatureManager> to retrieve the input data from a .csv file
36  dataSource = FileDataSource(
37  datasetFileName, DataSourceIface.doAllocateNumericTable,
38  DataSourceIface.doDictionaryFromContext
39  )
40 
41  # Retrieve the data from the input file
42  dataSource.loadDataBlock()
43 
44  # Create algorithm objects to sort data using the default (radix) method
45  algorithm = sorting.Batch()
46 
47  # Print the input observations matrix
48  printNumericTable(dataSource.getNumericTable(), "Initial matrix of observations:")
49 
50  # Set input objects for the algorithm
51  algorithm.input.set(sorting.data, dataSource.getNumericTable())
52 
53  # Sort data observations
54  res = algorithm.compute()
55 
56  printNumericTable(res.get(sorting.sortedData), "Sorted matrix of observations:")

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