DSPLIB User Guide
DSPLIB_cholesky_cn.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 **+--------------------------------------------------------------------------+**
3 **| **** |**
4 **| **** |**
5 **| ******o*** |**
6 **| ********_///_**** |**
7 **| ***** /_//_/ **** |**
8 **| ** **(__/ **** |**
9 **| ********* |**
10 **| **** |**
11 **| *** |**
12 **| |**
13 **| Copyright(c) 2016 Texas Instruments Incorporated |**
14 **| ALL RIGHTS RESERVED |**
15 **| |**
16 **| Permission to use, copy, modify, or distribute this software, |**
17 **| whether in part or in whole, for any purpose is forbidden without |**
18 **| a signed licensing agreement and NDA from Texas Instruments |**
19 **| Incorporated(TI). |**
20 **| |**
21 **| TI makes no representation or warranties with respect to the |**
22 **| performance of this computer program, and specifically disclaims |**
23 **| any responsibility for any damages, special or consequential, |**
24 **| connected with the use of this program. |**
25 **| |**
26 **+--------------------------------------------------------------------------+**
27 *******************************************************************************/
28 
29 #include "DSPLIB_cholesky_priv.h"
30 
31 /*Natural C implementation*/
32 
33 // Functions to perform cholesky decomposition
34 template <typename dataType>
35 DSPLIB_STATUS DSPF_sp_cholesky_cn(int enable_test, DSPLIB_cholesky_PrivArgs *pKerPrivArgs, dataType *A, dataType *U)
36 {
37  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
39  int32_t i, j, k;
40  double sum, sum1;
41  int32_t order = pKerPrivArgs->order;
42  int32_t yStrideCn = pKerPrivArgs->strideCn / sizeof(dataType);
43  int32_t yStride = pKerPrivArgs->stride / sizeof(dataType);
44 
45  // Seems to be wrong
46  if (enable_test) {
47  /* test A for positive definite matrix: */
48  /* z_transpose*A*z>0 where z=1,2,...order */
49  sum1 = 0;
50  for (i = 0; i < order; i++) {
51  sum = 0;
52  for (j = 0; j < order; j++) {
53  // sum += A[i * order + j] * (dataType)(j + 1);
54  sum += (dataType) A[i * yStride + j] * (dataType) (j + 1);
55  }
56  sum1 += (dataType) (i + 1) * sum;
57  }
58  if (sum1 <= 0) {
59  // return DSPLIB_ERR_FAILURE;
60  status = DSPLIB_ERR_FAILURE;
61  }
62  }
63 
64  if (status == DSPLIB_SUCCESS) {
65  /* generate upper diagonal matrix L */
66  for (j = 0; j < order; j++) // j represents col
67  {
68  /* diagonal entry */
69  sum = 0.0;
70  for (k = 0; k <= j - 1; k++) {
71  sum += U[k * yStrideCn + j] * U[k * yStrideCn + j];
72  }
73 
74 
75  U[j * yStrideCn + j] = (dataType) sqrt((dataType) A[j * yStride + j] - sum);
76 
77  /* lower triangular entries */
78  for (i = j + 1; i < order; i++) {
79  sum = 0.0;
80  for (k = 0; k <= j - 1; k++) {
81  sum += U[k * yStrideCn + i] * U[k * yStrideCn + j];
82  }
83  U[j * yStrideCn + i] = ((dataType) A[j * yStride + i] - sum) / U[j * yStrideCn + j];
84  }
85  }
86  }
87  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
88 
89  return status;
90 }
91 
92 template <typename dataType>
94  void *restrict pInA,
95  void *restrict pOutU,
96  void *restrict multiplierPtr)
97 {
98 
99  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
100 
101  DSPLIB_cholesky_PrivArgs *pKerPrivArgs = (DSPLIB_cholesky_PrivArgs *) handle;
102  dataType *pInALocal = (dataType *) pInA;
103  dataType *pOutULocal = (dataType *) pOutU;
105  int32_t enable_test = pKerPrivArgs->enableTest;
106  status = DSPF_sp_cholesky_cn(enable_test, pKerPrivArgs, pInALocal, pOutULocal);
107 
108  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
109  return status;
110 }
111 
112 // explicit insaddtiation for the different data type versions
114  void *restrict pInA,
115  void *restrict pOutU,
116  void *restrict multiplierPtr);
117 
119  void *restrict pInA,
120  void *restrict pOutU,
121  void *restrict multiplierPtr);
122 /* ======================================================================== */
123 /* End of file: DSPLIB_cholesky_cn.cpp */
124 /* ======================================================================== */
template DSPLIB_STATUS DSPLIB_cholesky_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pInA, void *restrict pOutU, void *restrict multiplierPtr)
template DSPLIB_STATUS DSPLIB_cholesky_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pInA, void *restrict pOutU, void *restrict multiplierPtr)
DSPLIB_STATUS DSPF_sp_cholesky_cn(int enable_test, DSPLIB_cholesky_PrivArgs *pKerPrivArgs, dataType *A, dataType *U)
DSPLIB_STATUS DSPLIB_cholesky_exec_cn(DSPLIB_kernelHandle handle, void *restrict pInA, void *restrict pOutU, void *restrict multiplierPtr)
This function is the main execution function for the natural C implementation of the kernel....
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_cholesky.
#define DSPLIB_DEBUGPRINTFN(N, fmt,...)
Definition: DSPLIB_types.h:83
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:151
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:172
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
@ DSPLIB_ERR_FAILURE
Definition: DSPLIB_types.h:153
Structure that is reserved for internal use by the kernel.
int32_t order
Order of input buffer for different batches DSPLIB_cholesky_init that will be retrieved and used by D...