Skip to content

Commit

Permalink
[MOD] - GPC.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lpossner committed Jul 16, 2024
1 parent 8b13d04 commit b1b2199
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pygpc/GPC.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ def create_gpc_matrix(self, b, x, gradient=False, gradient_idx=None, weighted=Fa

iprint('Constructing gPC matrix...', verbose=verbose, tab=0)

# CPU backend (CPU single core)
if self.backend not in ["cpu", "omp", "cuda", "python"]:
raise NotImplementedError(f"Backend {self.backend} is not implemented")

if self.backend == "cpu":
# CPU backend (CPU single core)
try:
from .pygpc_extensions import create_gpc_matrix_cpu
if not gradient:
Expand All @@ -228,9 +231,8 @@ def create_gpc_matrix(self, b, x, gradient=False, gradient_idx=None, weighted=Fa
except (ImportError):
print("The CPU-extension is not installed. Fall back to pure Python as backend.")
self.backend = "python"

# OpenMP backend (CPU multi core)
elif self.backend == "omp":
# OpenMP backend (CPU multi core)
try:
from .pygpc_extensions import create_gpc_matrix_omp
if not gradient:
Expand All @@ -245,9 +247,8 @@ def create_gpc_matrix(self, b, x, gradient=False, gradient_idx=None, weighted=Fa
except (ImportError):
print("The OMP-extension is not installed. Fall back to pure Python as backend.")
self.backend = "python"

# CUDA backend (GPU multi core)
elif self.backend == "cuda":
# CUDA backend (GPU multi core)
try:
from .pygpc_extensions_cuda import create_gpc_matrix_cuda
if not gradient:
Expand All @@ -262,9 +263,9 @@ def create_gpc_matrix(self, b, x, gradient=False, gradient_idx=None, weighted=Fa
except (ImportError):
print("The CUDA-extension is not installed. Fall back to pure Python as backend.")
self.backend = "python"

# Python backend

if self.backend == "python":
# Python backend
if not gradient:
gpc_matrix = np.ones([x.shape[0], len(b)])
for i_basis in range(len(b)):
Expand All @@ -281,8 +282,6 @@ def create_gpc_matrix(self, b, x, gradient=False, gradient_idx=None, weighted=Fa
derivative = False
gpc_matrix[:, i_basis, i_dim_gradient] *= b[i_basis][i_dim](x[self.gradient_idx, i_dim],
derivative=derivative)
else:
raise NotImplementedError

if gpc_matrix.ndim == 1 and x.shape[0] == 1:
gpc_matrix = gpc_matrix[np.newaxis, :]
Expand Down

0 comments on commit b1b2199

Please sign in to comment.