DSPLIB User Guide
DSPLIB_cholesky_inplace_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 
30 
31 // #define ENABLE_ORIG_IN_PLACE
32 
33 /*Natural C implementation*/
34 template <typename dataType>
36 DSPLIB_cholesky_in_place_core_cn(dataType *A, const int32_t order, const int32_t colAStride, const int32_t enable_test)
37 {
38  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
39 
40  short i, j, k;
41  dataType sum = 0.0;
42  dataType sum1 = 0.0;
44 
45  if (enable_test) {
46  /* test A for positive definite matrix: */
47  /* z_transpose*A*z>0 where z=1,2,...order */
48  sum1 = 0;
49  for (i = 0; i < order; i++) {
50  sum = 0;
51  for (j = 0; j < order; j++) {
52  sum += A[i * colAStride + j] * (dataType) (j + 1);
53  }
54  sum1 += (dataType) (i + 1) * sum;
55  }
56  if (sum1 <= 0) {
57  status = DSPLIB_ERR_FAILURE;
58  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
59  }
60  }
61 
62 #ifdef ENABLE_ORIG_IN_PLACE
63 
64  /* cholesky outer product version from p 145 Matrix Computations by Golub and Loan */
65  for (k = 0; k < order; k++) {
66  A[k * colAStride + k] = (dataType) sqrt(A[k * colAStride + k]);
67  for (i = k + 1; i < order; i++) {
68  A[i * colAStride + k] = A[i * colAStride + k] / A[k * colAStride + k];
69  }
70  for (j = k + 1; j < order; j++) {
71  for (i = j; i < order; i++) {
72  A[i * colAStride + j] -= A[i * colAStride + k] * A[j * colAStride + k];
73  }
74  }
75  }
76 
77 #else
78 
79  if(status == DSPLIB_SUCCESS) {
80  /* slight mod from Ran Katzur */
81  /* The result is stored in upper triangular matrix */
82  for (k = 0; k < order; k++) {
83  A[k + k * colAStride] = (dataType) sqrt(A[k + k * colAStride]);
84  for (i = k + 1; i < order; i++) {
85  A[i + k * colAStride] /= A[k + k * colAStride];
86  for (j = k + 1; j <= i; j++) {
87  A[i + j * colAStride] -= A[i + k * colAStride] * A[j + k * colAStride];
88  }
89  }
90  }
91  }
92 #endif
93  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
94  return status;
95 }
96 
98  const int32_t order,
99  const int32_t colAStride,
100  const int32_t enable_test);
102  const int32_t order,
103  const int32_t colAStride,
104  const int32_t enable_test);
105 
106 template <typename dataType>
107 DSPLIB_STATUS DSPLIB_cholesky_inplace_exec_cn(DSPLIB_kernelHandle handle, void *restrict pA, void *restrict pMul)
108 {
109  DSPLIB_STATUS status = DSPLIB_SUCCESS;
110 
111  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
112 
114 
115  dataType *pLocalA = (dataType *) pA;
116 
117  int32_t order = pKerPrivArgs->order;
118  int32_t strideA = pKerPrivArgs->stride;
119  int32_t colAStride = strideA / sizeof(dataType);
120 
121  int32_t enable_test = pKerPrivArgs->enableTest;
122 
123  status = DSPLIB_cholesky_in_place_core_cn<dataType>(pLocalA, order, colAStride, enable_test);
124 
125  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
126  return status;
127 }
128 
129 // explicit instantiation for the different data type versions
131 DSPLIB_cholesky_inplace_exec_cn<float>(DSPLIB_kernelHandle handle, void *restrict pA, void *restrict pMul);
132 
134 DSPLIB_cholesky_inplace_exec_cn<double>(DSPLIB_kernelHandle handle, void *restrict pInA, void *restrict pMul);
135 
136 /* ======================================================================== */
137 /* End of file: DSPLIB_cholesky_inplace_cn.cpp */
138 /* ======================================================================== */
template DSPLIB_STATUS DSPLIB_cholesky_inplace_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pInA, void *restrict pMul)
template DSPLIB_STATUS DSPLIB_cholesky_in_place_core_cn< double >(double *A, const int32_t order, const int32_t colAStride, const int32_t enable_test)
template DSPLIB_STATUS DSPLIB_cholesky_in_place_core_cn< float >(float *A, const int32_t order, const int32_t colAStride, const int32_t enable_test)
DSPLIB_STATUS DSPLIB_cholesky_inplace_exec_cn(DSPLIB_kernelHandle handle, void *restrict pA, void *restrict pMul)
This function is the main execution function for the natural C implementation of the kernel....
template DSPLIB_STATUS DSPLIB_cholesky_inplace_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pA, void *restrict pMul)
DSPLIB_STATUS DSPLIB_cholesky_in_place_core_cn(dataType *A, const int32_t order, const int32_t colAStride, const int32_t enable_test)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_cholesky_inplace...
#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_inplace_init that will be retrieved and u...