From 2de79c9abf7d3839653c39d574c1c6ab25f1b5c0 Mon Sep 17 00:00:00 2001 From: lijialin03 <124568209+lijialin03@users.noreply.github.com> Date: Mon, 6 Jan 2025 12:23:15 +0800 Subject: [PATCH] Backend paddle: Add the type conversion of dde.data.MfDataSet to support examples (#1897) --- deepxde/data/mf.py | 26 +++++++++++++++----------- examples/function/func_uncertainty.py | 2 +- examples/function/mf_dataset.py | 2 +- examples/function/mf_func.py | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/deepxde/data/mf.py b/deepxde/data/mf.py index 90375c1bb..873e8372c 100644 --- a/deepxde/data/mf.py +++ b/deepxde/data/mf.py @@ -1,7 +1,8 @@ import numpy as np from .data import Data -from ..backend import tf +from .. import backend as bkd +from .. import config from ..utils import run_if_any_none, standardize @@ -83,20 +84,20 @@ def __init__( standardize=False, ): if X_lo_train is not None: - self.X_lo_train = X_lo_train - self.X_hi_train = X_hi_train - self.y_lo_train = y_lo_train - self.y_hi_train = y_hi_train - self.X_hi_test = X_hi_test - self.y_hi_test = y_hi_test + self.X_lo_train = X_lo_train.astype(config.real(np)) + self.X_hi_train = X_hi_train.astype(config.real(np)) + self.y_lo_train = y_lo_train.astype(config.real(np)) + self.y_hi_train = y_hi_train.astype(config.real(np)) + self.X_hi_test = X_hi_test.astype(config.real(np)) + self.y_hi_test = y_hi_test.astype(config.real(np)) elif fname_lo_train is not None: - data = np.loadtxt(fname_lo_train) + data = np.loadtxt(fname_lo_train).astype(config.real(np)) self.X_lo_train = data[:, col_x] self.y_lo_train = data[:, col_y] - data = np.loadtxt(fname_hi_train) + data = np.loadtxt(fname_hi_train).astype(config.real(np)) self.X_hi_train = data[:, col_x] self.y_hi_train = data[:, col_y] - data = np.loadtxt(fname_hi_test) + data = np.loadtxt(fname_hi_test).astype(config.real(np)) self.X_hi_test = data[:, col_x] self.y_hi_test = data[:, col_y] else: @@ -116,7 +117,10 @@ def losses_train(self, targets, outputs, loss_fn, inputs, model, aux=None): return [loss_lo, loss_hi] def losses_test(self, targets, outputs, loss_fn, inputs, model, aux=None): - return [0, loss_fn(targets[1], outputs[1])] + return [ + bkd.as_tensor(0, dtype=config.real(bkd.lib)), + loss_fn(targets[1], outputs[1]), + ] @run_if_any_none("X_train", "y_train") def train_next_batch(self, batch_size=None): diff --git a/examples/function/func_uncertainty.py b/examples/function/func_uncertainty.py index 06a86a13b..f52c01ebd 100644 --- a/examples/function/func_uncertainty.py +++ b/examples/function/func_uncertainty.py @@ -1,4 +1,4 @@ -"""Backend supported: tensorflow.compat.v1, tensorflow""" +"""Backend supported: tensorflow.compat.v1, tensorflow, paddle""" import deepxde as dde import numpy as np diff --git a/examples/function/mf_dataset.py b/examples/function/mf_dataset.py index 6acc2e7e5..5bb34f9ba 100644 --- a/examples/function/mf_dataset.py +++ b/examples/function/mf_dataset.py @@ -1,4 +1,4 @@ -"""Backend supported: tensorflow.compat.v1""" +"""Backend supported: tensorflow.compat.v1, paddle""" import deepxde as dde diff --git a/examples/function/mf_func.py b/examples/function/mf_func.py index 21fb1b28f..b206b6cff 100644 --- a/examples/function/mf_func.py +++ b/examples/function/mf_func.py @@ -1,4 +1,4 @@ -"""Backend supported: tensorflow.compat.v1""" +"""Backend supported: tensorflow.compat.v1, paddle""" import deepxde as dde import numpy as np