S2kit  1.1
Toolkit for working with functions defined on the sphere
naive.c
Go to the documentation of this file.
1 
9 #include "s2kit/naive.h"
10 
11 #include <math.h>
12 #include <string.h>
13 
34 void DLTNaive(double* data, const int bw, const int m, double* weights, double* result, double* pml_table,
35  double* workspace) {
36  int size = 2 * bw;
37 
38  /*
39  Apply quadrature weights.
40 
41  We only have to differentiate between even and odd weights when doing something like seminaive,
42  something which involves the dct. In this naive case, the parity of the order of the transform
43  doesn't matter because we are not dividing by sin(x) when precomputing the Legendres
44  (because we are not taking their dct). The plain weights are just fine.
45  */
46  double* weighted_data = workspace;
47  for (int i = 0; i < size; ++i)
48  weighted_data[i] = data[i] * weights[i];
49 
50  for (int i = 0; i < bw - m; ++i) {
51  double sum = 0.;
52  for (int j = 0; j < size; ++j)
53  sum += weighted_data[j] * pml_table[j];
54 
55  result[i] = sum;
56 
57  pml_table += size;
58  }
59 }
60 
78 void InvDLTNaive(double* coeffs, const int bw, const int m, double* result, double* pml_table) {
79  int size = 2 * bw;
80 
81  memset(result, 0, sizeof(double) * size); // make sure result is zeroed out
82 
83  for (int i = 0; i < bw - m; ++i) {
84  double coeff = coeffs[i];
85 
86  if (coeff == 0.) {
87  pml_table += size;
88  continue;
89  }
90 
91  for (int j = 0; j < size; ++j)
92  result[j] += coeff * pml_table[j];
93 
94  pml_table += size;
95  }
96 }
naive.h
InvDLTNaive
void InvDLTNaive(double *coeffs, const int bw, const int m, double *result, double *pml_table)
The inverse discrete Legendre transform.
Definition: naive.c:78
DLTNaive
void DLTNaive(double *data, const int bw, const int m, double *weights, double *result, double *pml_table, double *workspace)
The naive forward discrete Legendre transform.
Definition: naive.c:34