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.
22 from daal
import step1Local, step2Master, step3Local
23 from daal.algorithms
import qr
24 from daal.data_management
import FileDataSource, DataSourceIface
26 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
27 if utils_folder
not in sys.path:
28 sys.path.insert(0, utils_folder)
29 from utils
import printNumericTable
31 DAAL_PREFIX = os.path.join(
'..',
'data')
37 os.path.join(DAAL_PREFIX,
'distributed',
'qr_1.csv'),
38 os.path.join(DAAL_PREFIX,
'distributed',
'qr_2.csv'),
39 os.path.join(DAAL_PREFIX,
'distributed',
'qr_3.csv'),
40 os.path.join(DAAL_PREFIX,
'distributed',
'qr_4.csv')
43 dataFromStep1ForStep2 = [0] * nBlocks
44 dataFromStep1ForStep3 = [0] * nBlocks
45 dataFromStep2ForStep3 = [0] * nBlocks
50 def computestep1Local(block):
51 global dataFromStep1ForStep2, dataFromStep1ForStep3
54 dataSource = FileDataSource(
55 datasetFileNames[block],
56 DataSourceIface.doAllocateNumericTable,
57 DataSourceIface.doDictionaryFromContext
61 dataSource.loadDataBlock()
64 algorithm = qr.Distributed(step1Local)
66 algorithm.input.set(qr.data, dataSource.getNumericTable())
69 pres = algorithm.compute()
71 dataFromStep1ForStep2[block] = pres.get(qr.outputOfStep1ForStep2)
72 dataFromStep1ForStep3[block] = pres.get(qr.outputOfStep1ForStep3)
75 def computeOnMasterNode():
76 global R, dataFromStep2ForStep3
79 algorithm = qr.Distributed(step2Master)
81 for i
in range(nBlocks):
82 algorithm.input.add(qr.inputOfStep2FromStep1, i, dataFromStep1ForStep2[i])
85 pres = algorithm.compute()
87 for i
in range(nBlocks):
88 dataFromStep2ForStep3[i] = pres.getCollection(qr.outputOfStep2ForStep3, i)
90 res = algorithm.finalizeCompute()
91 R = res.get(qr.matrixR)
94 def finalizeComputestep1Local(block):
98 algorithm = qr.Distributed(step3Local)
100 algorithm.input.set(qr.inputOfStep3FromStep1, dataFromStep1ForStep3[block])
101 algorithm.input.set(qr.inputOfStep3FromStep2, dataFromStep2ForStep3[block])
106 res = algorithm.finalizeCompute()
108 Qi[block] = res.get(qr.matrixQ)
110 if __name__ ==
"__main__":
112 for i
in range(nBlocks):
115 computeOnMasterNode()
117 for i
in range(nBlocks):
118 finalizeComputestep1Local(i)
121 printNumericTable(Qi[0],
"Part of orthogonal matrix Q from 1st node:", 10)
122 printNumericTable(R,
"Triangular matrix R:")