Mentions légales du service

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

Minor changes and fix in pyfaust.poly and C++ backend.

parent b0cbfdda
Branches
Tags
No related merge requests found
...@@ -322,10 +322,10 @@ template<typename FPP> ...@@ -322,10 +322,10 @@ template<typename FPP>
auto d_K_plus_1 = d*K_plus_1; auto d_K_plus_1 = d*K_plus_1;
// #pragma omp parallel for // most likely counterproductive to use OpenMP here, Eigen is already multithreading scalar product in the loop // #pragma omp parallel for // most likely counterproductive to use OpenMP here, Eigen is already multithreading scalar product in the loop
Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> vec_out(out, d, n); Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> vec_out(out, d, n);
Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, 1>> vec_coeffs(const_cast<FPP*>(coeffs), K_plus_1);
for(int i=0;i<n;i++) for(int i=0;i<n;i++)
{ {
Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> mat_basisX(const_cast<FPP*>(basisX+d_K_plus_1*i), d, K_plus_1); //constcast is not dangerous, no modification is done later Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> mat_basisX(const_cast<FPP*>(basisX+d_K_plus_1*i), d, K_plus_1); //constcast is not dangerous, no modification is done later
Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, 1>> vec_coeffs(const_cast<FPP*>(coeffs), K_plus_1);
vec_out.block(0,i,d,1) = mat_basisX*vec_coeffs; vec_out.block(0,i,d,1) = mat_basisX*vec_coeffs;
} }
} }
......
...@@ -210,7 +210,7 @@ def poly(coeffs, basis='chebyshev', L=None, dev='cpu', impl='native'): ...@@ -210,7 +210,7 @@ def poly(coeffs, basis='chebyshev', L=None, dev='cpu', impl='native'):
else: else:
F = basis F = basis
if L == None: if L == None:
d = F.shape[1] d = F.shape[0]//(K+1)
else: else:
d = L.shape[0] d = L.shape[0]
if impl == 'py': if impl == 'py':
...@@ -243,13 +243,13 @@ def _poly_arr_py(coeffs, basisX, d, dev='cpu'): ...@@ -243,13 +243,13 @@ def _poly_arr_py(coeffs, basisX, d, dev='cpu'):
K_plus_1 = int(basisX.shape[0]/d) K_plus_1 = int(basisX.shape[0]/d)
Y = np.empty((d, n)) Y = np.empty((d, n))
if n == 1: if n == 1:
Y[:, 0] = basisX[:, 0].reshape(K_plus_1, d).T @ coeffs Y[:, 0] = basisX[:, 0].reshape(d, K_plus_1, order='F') @ coeffs
elif mt: elif mt:
nthreads = 4 nthreads = 4
threads = [] threads = []
def apply_coeffs(i, n): def apply_coeffs(i, n):
for i in range(i,n,nthreads): for i in range(i,n,nthreads):
Y[:, i] = basisX[:, i].reshape(K_plus_1, d).T @ coeffs Y[:, i] = basisX[:, i].reshape(d, K_plus_1, order='F') @ coeffs
for i in range(0,nthreads): for i in range(0,nthreads):
t = threading.Thread(target=apply_coeffs, args=([i,n])) t = threading.Thread(target=apply_coeffs, args=([i,n]))
threads.append(t) threads.append(t)
...@@ -258,11 +258,11 @@ def _poly_arr_py(coeffs, basisX, d, dev='cpu'): ...@@ -258,11 +258,11 @@ def _poly_arr_py(coeffs, basisX, d, dev='cpu'):
threads[i].join() threads[i].join()
else: else:
for i in range(n): for i in range(n):
Y[:, i] = basisX[:, i].reshape(K_plus_1, d).T @ coeffs Y[:, i] = basisX[:, i].reshape(d, K_plus_1, order='F') @ coeffs
# other way: # other way:
# Y = coeff[0] * basisX[0:d,:] # Y = coeffs[0] * basisX[0:d,:]
# for i in range(1,K+1): # for i in range(1,K_plus_1):
# Y += (basisX[d*i:(i+1)*d, :] * coeff[i]) # Y += (basisX[d*i:(i+1)*d, :] * coeffs[i])
return Y return Y
def _poly_arr_cpp(coeffs, basisX, d, dev='cpu'): def _poly_arr_cpp(coeffs, basisX, d, dev='cpu'):
......
...@@ -214,7 +214,7 @@ template<typename FPP, FDevice DEV> ...@@ -214,7 +214,7 @@ template<typename FPP, FDevice DEV>
{ {
Faust::TransformHelperPoly<FPP> *transform_poly = dynamic_cast<Faust::TransformHelperPoly<FPP>*>(this->transform); Faust::TransformHelperPoly<FPP> *transform_poly = dynamic_cast<Faust::TransformHelperPoly<FPP>*>(this->transform);
if(nullptr) if(nullptr)
throw std::runtime_error("polyCoeffs can only be used on a Poly. specialized Faust."); throw std::runtime_error("polyNext can only be used on a Poly. specialized Faust.");
auto th = transform_poly->next(); auto th = transform_poly->next();
FaustCoreCpp<FPP,DEV>* core = new FaustCoreCpp<FPP,DEV>(th); FaustCoreCpp<FPP,DEV>* core = new FaustCoreCpp<FPP,DEV>(th);
return core; return core;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment