python daal test

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import sys
 
from daal.algorithms import low_order_moments
from daal.data_management import FileDataSource, DataSourceIface
from daal.data_management import (readOnly, NumericTableIface, BlockDescriptor, BlockDescriptor_Float32, BlockDescriptor_Intc, packed_mask)
 
#utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
#if utils_folder not in sys.path:
#    sys.path.insert(0, utils_folder)
#from utils import printNumericTable
 
dataFileName = 'covcormoments_dense.csv'
 
 
def getArrayFromNumericTable(data_table):
    num_rows = data_table.getNumberOfRows()
    num_cols = data_table.getNumberOfColumns()
    layout = data_table.getDataLayout()
    data_table_dict = data_table.getDictionary()
    try:
        # see # https://software.intel.com/sites/products/documentation/doclib/daal/daal-user-and-reference-guides/daal_cpp_api/data__utils_8h_source.htm
        # for numeral values of types
        data_type = data_table_dict[0].indexType
    except:
        data_type = 1 # default to Float64
 
    if data_type == 0:
        block = BlockDescriptor_Float32()
    elif data_type in [2, 4, 6, 8]:
        block = BlockDescriptor_Intc()
    else:
        block = BlockDescriptor() # Use Float64 by default
 
    data_table.getBlockOfRows(0, num_rows, readOnly, block)
    retValue = block.getArray()
    data_table.releaseBlockOfRows(block)
 
    return retValue
 
 
 
 
def printResults(res):
 
     mi = getArrayFromNumericTable(res.get(low_order_moments.minimum))
     print (value of minimum:)
     print (mi)
#    print(res.get(low_order_moments.minimum))
#    print(res.get(low_order_moments.minimum))
#    print(res.get(low_order_moments.maximum))
#    print(res.get(low_order_moments.sum))
#    print(res.get(low_order_moments.sumSquares))
#    print(res.get(low_order_moments.sumSquaresCentered))
#    print(res.get(low_order_moments.mean))
#    print(res.get(low_order_moments.secondOrderRawMoment))
#    print(res.get(low_order_moments.variance))
#    print(res.get(low_order_moments.standardDeviation))
#    print(res.get(low_order_moments.variation))
 
if __name__ == "__main__":
 
    # Initialize FileDataSource to retrieve input data from .csv file
    dataSource = FileDataSource(
        dataFileName,
        DataSourceIface.doAllocateNumericTable,
        DataSourceIface.doDictionaryFromContext
    )
 
    # Retrieve the data from input file
    dataSource.loadDataBlock()
 
    # Create algorithm for computing low order moments in batch processing mode
    algorithm = low_order_moments.Batch()
 
    # Set input arguments of the algorithm
    algorithm.input.set(low_order_moments.data, dataSource.getNumericTable())
 
    # Get computed low order moments
    res = algorithm.compute()
 
    printResults(res)

  

posted @   bonelee  阅读(270)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示