sponge.function.GetDistance
- class sponge.function.GetDistance(use_pbc: bool = None, keepdims: bool = False, axis: int = - 1)[source]
The class to calculate distance with or without PBC box
- Parameters
use_pbc (bool) – Whether to calculate distance under periodic boundary condition. If this is "None", it will determine whether to calculate the distance under periodic boundary condition based on whether the pbc_box is given. Default:
None
.keepdims (bool) – Whether to keep the last dimension of the output Tensor of distance after norm. If this is "True", the last dimension of the output Tensor will be 1. Default:
False
.axis (int) – The axis of the space dimension of the coordinate. Default:
-1
.
Examples
>>> import mindspore as ms >>> import numpy as np >>> from sponge.function import GetDistance >>> from mindspore import Tensor >>> crd = Tensor(np.random.random((4, 3)), ms.float32) >>> pbc_box = Tensor([[0.5, 0.5, 0.5]], ms.float32) >>> gd = GetDistance(use_pbc=True, keepdims=False) >>> gd(crd[0], crd[1], pbc_box) Tensor(shape=[1], dtype=Float32, value= [ 1.39199302e-01]) >>> gd = GetDistance(use_pbc=False, keepdims=False) >>> gd(crd[0], crd[1]) Tensor(shape=[], dtype=Float32, value= 0.472336)