deepxde.backend package
Subpackages
- deepxde.backend.jax package
- Submodules
- deepxde.backend.jax.tensor module
Variable()
abs()
as_tensor()
concat()
cos()
data_type_dict()
elu()
from_numpy()
is_tensor()
max()
mean()
min()
minimum()
ndim()
prod()
reduce_max()
reduce_mean()
reduce_min()
reduce_prod()
reduce_sum()
relu()
reshape()
selu()
shape()
sigmoid()
silu()
sin()
square()
stack()
sum()
tanh()
to_numpy()
transpose()
zeros()
zeros_like()
- Module contents
- deepxde.backend.paddle package
- Submodules
- deepxde.backend.paddle.tensor module
Variable()
abs()
as_tensor()
concat()
cos()
data_type_dict()
elu()
exp()
expand_dims()
from_numpy()
is_gpu_available()
is_tensor()
lgamma()
matmul()
max()
mean()
min()
minimum()
ndim()
norm()
pow()
prod()
reduce_max()
reduce_mean()
reduce_min()
reduce_prod()
reduce_sum()
relu()
reshape()
reverse()
roll()
selu()
shape()
sigmoid()
silu()
sin()
size()
sparse_dense_matmul()
sparse_tensor()
square()
stack()
sum()
tanh()
to_numpy()
transpose()
zeros()
zeros_like()
- Module contents
- deepxde.backend.pytorch package
- Submodules
- deepxde.backend.pytorch.tensor module
Variable()
abs()
as_tensor()
concat()
cos()
data_type_dict()
elu()
exp()
expand_dims()
from_numpy()
gelu()
is_gpu_available()
is_tensor()
lgamma()
matmul()
max()
mean()
min()
minimum()
ndim()
norm()
pow()
prod()
reduce_max()
reduce_mean()
reduce_min()
reduce_prod()
reduce_sum()
relu()
reshape()
reverse()
roll()
selu()
shape()
sigmoid()
silu()
sin()
size()
sparse_dense_matmul()
sparse_tensor()
square()
stack()
sum()
tanh()
to_numpy()
transpose()
zeros()
zeros_like()
- Module contents
- deepxde.backend.tensorflow package
- deepxde.backend.tensorflow_compat_v1 package
- Submodules
- deepxde.backend.tensorflow_compat_v1.tensor module
Variable()
abs()
as_tensor()
concat()
cos()
data_type_dict()
elu()
exp()
expand_dims()
from_numpy()
is_gpu_available()
is_tensor()
lgamma()
matmul()
max()
mean()
min()
minimum()
ndim()
norm()
pow()
prod()
reduce_max()
reduce_mean()
reduce_min()
reduce_prod()
reduce_sum()
relu()
reshape()
reverse()
roll()
selu()
shape()
sigmoid()
silu()
sin()
size()
sparse_dense_matmul()
sparse_tensor()
square()
stack()
sum()
tanh()
transpose()
zeros()
zeros_like()
- Module contents
Submodules
deepxde.backend.backend module
This file defines the unified tensor framework interface required by DeepXDE.
The principles of this interface: * There should be as few interfaces as possible. * The interface is used by DeepXDE system so it is more important to have
clean definition rather than convenient usage.
Default arguments should be avoided.
Keyword or positional arguments should be avoided.
Argument type should be easier to understand.
It is recommended the frameworks implement all the interfaces. However, it is
also OK to skip some. The generated backend module has an is_enabled
function
that returns whether the interface is supported by the framework or not.
- deepxde.backend.backend.Variable(initial_value, dtype=None)[source]
Return a trainable variable.
- Parameters:
initial_value – The initial value of the variable.
dtype – The desired data type of returned tensor. Default: if None, infers data type from data.
- deepxde.backend.backend.as_tensor(data, dtype=None)[source]
Convert the data to a Tensor.
If the data is already a tensor and has the same dtype, directly return.
- Parameters:
object (data. Tensor)
array (numpy)
list (Python)
scalar. (and Python)
dtype (data type, optional) – If None, infers data type from data.
- Returns:
Tensor. A framework-specific tensor.
- deepxde.backend.backend.concat(values, axis)[source]
Returns the concatenation of the input tensors along the given dim.
- Parameters:
values (list or tuple of Tensor)
axis (int)
- Returns:
Concatenated tensor.
- Return type:
Tensor
- deepxde.backend.backend.data_type_dict()[source]
Returns a dictionary from data type string to the data type.
The dictionary should include at least: float16 float32 float64 uint8 int8 int16 int32 int64 bool
This function will be called only once during the initialization of the backend module. The returned dictionary will become the attributes of the backend module.
Examples
>>> import tensorflow as tf >>> def data_type_dict(): >>> return {'float16': tf.float16, 'float32': tf.float32, ...}
After the module is initialized.
>>> import backend as bkd >>> bkd.float16 # this will point to tf.float16
- Returns:
dict of str to data type. The data type dict.
- deepxde.backend.backend.expand_dims(tensor, axis)[source]
Expand dim for tensor along given axis.
- Parameters:
tensor (Tensor)
axis (int)
- Returns:
Expanded tensor.
- Return type:
Tensor
- deepxde.backend.backend.from_numpy(np_array)[source]
Create a tensor that shares the underlying numpy array memory, if possible.
- Parameters:
np_array (numpy.ndarray)
- Returns:
Tensor. A framework-specific tensor.
- deepxde.backend.backend.is_gpu_available()[source]
Returns a bool indicating if GPU is currently available.
- Returns:
True if a GPU device is available.
- deepxde.backend.backend.is_tensor(obj)[source]
Returns True if obj is a backend-native type tensor.
- deepxde.backend.backend.lgamma(x)[source]
Computes the natural logarithm of the absolute value of the gamma function of x element-wise.
- deepxde.backend.backend.matmul(x, y)[source]
Compute matrix multiplication for two matrices x and y.
- Parameters:
x (Tensor)
y (Tensor)
- Returns:
The multiplication result.
- Return type:
Tensor
- deepxde.backend.backend.max(input_tensor, dim, keepdims=False)[source]
Returns the maximum of the input tensor along the given dim.
- Parameters:
input_tensor (Tensor)
dim (int)
keepdims (bool)
- Returns:
A framework-specific tensor.
- Return type:
Tensor
- deepxde.backend.backend.mean(input_tensor, dim, keepdims=False)[source]
Returns the mean value of the input tensor in the given dimension dim.
- deepxde.backend.backend.min(input_tensor, dim, keepdims=False)[source]
Returns the minimum of the input tensor along the given dim.
- Parameters:
input_tensor (Tensor)
dim (int)
keepdims (bool)
- Returns:
A framework-specific tensor.
- Return type:
Tensor
- deepxde.backend.backend.minimum(x, y)[source]
Returns the minimum of x and y (i.e. x < y ? x : y) element-wise.
- deepxde.backend.backend.ndim(input_tensor)[source]
Returns the number of dimensions of the tensor.
- Parameters:
input (Tensor) – The input tensor.
- Returns:
The number of dimensions.
- Return type:
int
- deepxde.backend.backend.norm(tensor, ord=None, axis=None, keepdims=False)[source]
Computes a vector norm.
Due to the incompatibility of different backends, only some vector norms are supported, and matrix norm is not supported now. This API follows numpy.linalg.norm().
- Parameters:
tensor (Tensor)
ord (int, float, inf) – 1, 2, inf, and any positive real number. Default is 2-norm for vectors.
axis (int) – to compute the vector norms. If axis is None, then a vector norm (when tensor is 1-D) is returned. The default is None.
keepdims (bool) – in the result as dimensions with size one.
- Returns:
Norm of the vector(s).
- Return type:
Tensor
- deepxde.backend.backend.prod(input_tensor, dim, keepdims=False)[source]
Returns the product of the input tensor along the given dim.
- Parameters:
input_tensor (Tensor)
dim (int)
keepdims (bool)
- Returns:
A framework-specific tensor.
- Return type:
Tensor
- deepxde.backend.backend.reduce_max(input_tensor)[source]
Returns the maximum of all elements in the input tensor.
- Parameters:
input_tensor (Tensor)
- Returns:
Tensor.
- deepxde.backend.backend.reduce_mean(input_tensor)[source]
Returns the mean value of all elements in the input tensor.
- deepxde.backend.backend.reduce_min(input_tensor)[source]
Returns the minimum of all elements in the input tensor.
- Parameters:
input_tensor (Tensor)
- Returns:
Tensor.
- deepxde.backend.backend.reduce_prod(input_tensor)[source]
Returns the product of all elements in the input tensor.
- Parameters:
input_tensor (Tensor)
- Returns:
Tensor.
- deepxde.backend.backend.reduce_sum(input_tensor)[source]
Returns the sum of all elements in the input tensor.
- Parameters:
input_tensor (Tensor)
- Returns:
Tensor.
- deepxde.backend.backend.reshape(tensor, shape)[source]
Gives a new shape to a tensor without changing its data.
- Parameters:
tensor (Tensor) – The tensor to be reshaped.
shape (tuple of ints) – The new shape should be compatible with the original shape.
- Returns:
Reshaped tensor. This will be a new view object if possible.
- deepxde.backend.backend.reverse(tensor, axis)[source]
Reverse the order of elements along the given axis.
- Parameters:
tensor (Tensor)
axis (int)
- Returns:
Tensor which is flipped along given axis.
- Return type:
Tensor
- deepxde.backend.backend.roll(tensor, shift, axis)[source]
Roll the tensor along the given axis (axes).
- Parameters:
tensor (Tensor)
shift (int or tuple of ints) – tensor are shifted.
axis (int or tuple of ints). Axis (axes)
- Returns:
Rolled tensor.
- Return type:
Tensor
- deepxde.backend.backend.shape(input_tensor)[source]
Return the shape of the tensor.
- Parameters:
input (Tensor) – The input tensor.
- Returns:
The tensor shape.
- Return type:
tuple or list of ints
- deepxde.backend.backend.silu(x)[source]
Sigmoid Linear Unit (SiLU) function, also known as the swish function. silu(x) = x * sigmoid(x).
- deepxde.backend.backend.size(input_tensor)[source]
Return the total number of elements in the input tensor.
- Parameters:
input_tensor (Tensor)
- Returns:
The total number of elements in the input tensor.
- Return type:
int
- deepxde.backend.backend.sparse_dense_matmul(x, y)[source]
Compute matrix multiplication of a sparse matrix x and a sparse/dense matrix y.
- Parameters:
x (Sparse Tensor)
y (Sparse Tensor or Tensor)
- Returns:
The multiplication result.
- Return type:
Tensor
- deepxde.backend.backend.sparse_tensor(indices, values, shape)[source]
Construct a sparse tensor based on given indices, values and shape.
- Parameters:
indices (list of tuple) – the indices of the elements in the sparse tensor that contain nonzero values (elements are zero-indexed), such as [(x1, y1), (x2, y2), …, (xN, yN)].
values (Tensor)
shape (list or tuple)
- Returns:
A sparse tensor.
- Return type:
SparseTensor
- deepxde.backend.backend.stack(values, axis)[source]
Returns the stack of the input tensors along the given dim.
- Parameters:
values (list or tuple of Tensor)
axis (int)
- Returns:
Stacked tensor.
- Return type:
Tensor
- deepxde.backend.backend.sum(input_tensor, dim, keepdims=False)[source]
Returns the sum of the input tensor along the given dim.
- Parameters:
input_tensor (Tensor)
dim (int)
keepdims (bool)
- Returns:
A framework-specific tensor.
- Return type:
Tensor
- deepxde.backend.backend.to_numpy(input_tensor)[source]
Create a numpy ndarray that shares the same underlying storage, if possible.
- Parameters:
input_tensor (Tensor)
- Returns:
np_array (numpy.ndarray). The numpy ndarray.
- deepxde.backend.backend.transpose(tensor, axes=None)[source]
Reverse or permute the axes of a tensor; returns the modified array.
For a tensor with two axes, transpose gives the matrix transpose.
- Parameters:
tensor (Tensor) – Input tensor.
axes (tuple of ints) – A permutation of the dimensions.
- Returns:
A tensor with its axes permuted. A view is returned whenever possible.
deepxde.backend.set_default_backend module
deepxde.backend.utils module
- deepxde.backend.utils.generate_cmd(py_exec, platform, cuda_version=None, has_rocm=False)[source]
Generate command.
- Parameters:
py_exec (str) – python executable path.
platform (str) – User’s platform.
cuda_version (str) – Whether cuda is avaliable and its version if it is.
has_rocm (bool) – Whether ROCm4.0 has been installed.
- deepxde.backend.utils.get_cuda(platform)[source]
Check whether cuda is avaliable and get its version.
- Returns:
cuda_verion (str) or None
- deepxde.backend.utils.get_platform()[source]
Get user’s platform.
- Returns:
“windows”, “linux” or “darwin”
- Return type:
platform (str)
- deepxde.backend.utils.get_python_executable()[source]
Get user’s python executable.
- Returns:
python exection path
- Return type:
str
Module contents
- deepxde.backend.backend_message(backend_name)[source]
Show message about backend.
- Parameters:
backend_name – which backend used
- deepxde.backend.gelu(*args, **kwargs)
- deepxde.backend.is_enabled(api)[source]
Return true if the api is enabled by the current backend.
- Parameters:
api (string) – The api name.
- Returns:
True
if the API is enabled by the current backend.- Return type:
bool
- deepxde.backend.jax(*args, **kwargs)
- deepxde.backend.paddle(*args, **kwargs)
- deepxde.backend.to_numpy(*args, **kwargs)
- deepxde.backend.torch(*args, **kwargs)