Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a4d0843f authored by hhakim's avatar hhakim
Browse files

Add wrapper pyfaust.poly.basis_cpp and C++ implementation behind (for chebyshev).

parent cee71204
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
## @package pyfaust.poly @brief This module provides polynomials as Faust objects.
import scipy.sparse as sp
import _FaustCorePy
from scipy.sparse import csr_matrix
from pyfaust import (Faust, isFaust, eye as feye, vstack as fvstack, hstack as
fhstack)
......@@ -70,6 +71,14 @@ def basis(L, K, basis_name, ret_gen=False, dev='cpu', T0=None):
return Chebyshev(L, K, ret_gen=ret_gen, dev=dev, T0=T0)
def basis_cpp(L, K, basis_name, ret_gen=False, dev='cpu', T0=None):
"""
"""
F = Faust(core_obj=_FaustCorePy.FaustCore.polyBasis(L, K))
return F
def poly(coeffs, L=None, basis=Chebyshev, dev='cpu'):
"""
Returns the linear combination of the polynomials defined by basis.
......
......@@ -50,6 +50,7 @@
#include "faust_TransformHelper_gpu.h"
#endif
#include "faust_TransformHelper.h"
#include "faust_TransformHelperPoly.h"
#include <cstring>
template<typename FPP, FDevice DEV=Cpu>
......@@ -133,6 +134,7 @@ class FaustCoreCpp
static FaustCoreCpp<FPP,DEV>* hadamardFaust(unsigned int n, const bool norma);
static FaustCoreCpp<FPP,DEV>* fourierFaust(unsigned int n, const bool norma);
static FaustCoreCpp<FPP,DEV>* eyeFaust(unsigned int n, unsigned int m);
static FaustCoreCpp<FPP, DEV>* polyBasis(unsigned int L_nrows, unsigned int L_ncols, int* L_rowptr, int* L_colind, FPP* L_vals, unsigned int L_nnz, unsigned int K);
protected :
Faust::TransformHelper<FPP,DEV> *transform;
......
......@@ -576,6 +576,23 @@ FaustCoreCpp<FPP,DEV>* FaustCoreCpp<FPP, DEV>::clone() const
return core;
}
template<typename FPP, FDevice DEV>
FaustCoreCpp<FPP,DEV>* FaustCoreCpp<FPP,DEV>::polyBasis(
unsigned int L_nrows, unsigned int L_ncols,
int* L_rowptr,
int* L_colind,
FPP* L_vals,
unsigned int L_nnz,
unsigned int K)
{
Faust::MatSparse<FPP, DEV> L(L_nnz, L_nrows, L_ncols, L_vals, L_rowptr, L_colind);
Faust::TransformHelper<FPP,DEV>* th = Faust::basisChebyshev(&L, K);
if(!th) return NULL;
FaustCoreCpp<FPP,DEV>* core = new FaustCoreCpp<FPP,DEV>(th);
return core;
}
template<typename FPP, FDevice DEV>
FaustCoreCpp<FPP,DEV>::~FaustCoreCpp()
{
......
......@@ -128,6 +128,8 @@ cdef extern from "FaustCoreCpp.h":
@staticmethod
FaustCoreCpp[FPP]* hadamardFaust(unsigned int n, const bool norma)
@staticmethod
FaustCoreCpp[FPP]* polyBasis(unsigned int L_nrows, unsigned int L_ncols, int* L_rowptr, int* L_colind, FPP* L_vals, unsigned int L_nnz, unsigned int K);
@staticmethod
FaustCoreCpp[FPP]* fourierFaust(unsigned int n, const bool norma)
@staticmethod
FaustCoreCpp[FPP]* eyeFaust(unsigned int n, unsigned int m)
......
......@@ -257,6 +257,36 @@ cdef class FaustCore:
core._isReal = False
return core
@staticmethod
def polyBasis(L, K):
cdef int[:] colind_view, rowptr_view
cdef double[:] dbl_vals_view
cdef complex[:] cplx_vals_view
core = FaustCore(core=True)
colind_view = L.indices
rowptr_view = L.indptr
if L.dtype == np.complex:
cplx_vals_view = L.data
core.core_faust_cplx = \
FaustCoreCy.FaustCoreCpp[complex].polyBasis(L.shape[0], L.shape[1],
&rowptr_view[0],
&colind_view[0],
&cplx_vals_view[0],
L.nnz,
K)
core._isReal = False
else:
dbl_vals_view = L.data
core.core_faust_dbl = \
FaustCoreCy.FaustCoreCpp[double].polyBasis(L.shape[0], L.shape[1],
&rowptr_view[0],
&colind_view[0],
&dbl_vals_view[0],
L.nnz,
K)
core._isReal = True
return core
def shape(self):
cdef unsigned int nbrow = 0
cdef unsigned int nbcol = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment