Tensors¶

class
geoopt.tensor.
ManifoldTensor
[source]¶ Same as
torch.Tensor
that has information about its manifold.Other Parameters: manifold ( geoopt.Manifold
) – A manifold for the tensor, (default:geoopt.Euclidean
)
dist
(other: torch.Tensor, p: Union[int, float, bool, str] = 2, **kwargs) → torch.Tensor[source]¶ Return euclidean or geodesic distance between points on the manifold. Allows broadcasting.
Parameters:  other (tensor) –
 p (strint) – The norm to use. The default behaviour is not changed and is just euclidean distance.
To compute geodesic distance,
p
should be set to"g"
Returns: Return type: scalar

expmap
(u: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Perform an exponential map \(\operatorname{Exp}_x(u)\).
Parameters: u (torch.Tensor) – tangent vector at point \(x\) Returns: transported point Return type: torch.Tensor

expmap_transp
(u: torch.Tensor, v: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Perform an exponential map and vector transport from point \(x\) with given direction \(u\).
Parameters:  u (torch.Tensor) – tangent vector at point \(x\)
 v (torch.Tensor) – tangent vector at point \(x\) to be transported
Returns: transported point
Return type:

inner
(u: torch.Tensor, v: torch.Tensor = None, **kwargs) → torch.Tensor[source]¶ Inner product for tangent vectors at point \(x\).
Parameters:  u (torch.Tensor) – tangent vector at point \(x\)
 v (Optional[torch.Tensor]) – tangent vector at point \(x\)
 keepdim (bool) – keep the last dim?
Returns: inner product (broadcasted)
Return type:

logmap
(y: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Perform an logarithmic map \(\operatorname{Log}_{x}(y)\).
Parameters: y (torch.Tensor) – point on the manifold Returns: tangent vector Return type: torch.Tensor

proj_
() → torch.Tensor[source]¶ Inplace projection to the manifold.
Returns: same instance Return type: tensor

proju
(u: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Project vector \(u\) on a tangent space for \(x\), usually is the same as
egrad2rgrad()
.Parameters:  torch.Tensor (u) – point on the manifold
 torch.Tensor – vector to be projected
Returns: projected vector
Return type:

retr
(u: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Perform a retraction from point \(x\) with given direction \(u\).
Parameters: u (torch.Tensor) – tangent vector at point \(x\) Returns: transported point Return type: torch.Tensor

retr_transp
(u: torch.Tensor, v: torch.Tensor, **kwargs) → Tuple[torch.Tensor, torch.Tensor][source]¶ Perform a retraction + vector transport at once.
Parameters:  u (torch.Tensor) – tangent vector at point \(x\)
 v (torch.Tensor) – tangent vector at point \(x\) to be transported
Returns: transported point and vectors
Return type: Tuple[torch.Tensor, torch.Tensor]
Notes
Sometimes this is a far more optimal way to preform retraction + vector transport

transp
(y: torch.Tensor, v: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Perform vector transport \(\mathfrak{T}_{x\to y}(v)\).
Parameters:  y (torch.Tensor) – target point on the manifold
 v (torch.Tensor) – tangent vector at point \(x\)
Returns: transported tensor
Return type:

transp_follow_expmap
(u: torch.Tensor, v: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Perform vector transport following \(u\): \(\mathfrak{T}_{x\to\operatorname{Exp}(x, u)}(v)\).
Here, \(\operatorname{Exp}\) is the best possible approximation of the true exponential map. There are cases when the exact variant is hard or impossible implement, therefore a fallback, nonexact, implementation is used.
Parameters:  u (torch.Tensor) – tangent vector at point \(x\)
 v (torch.Tensor) – tangent vector at point \(x\) to be transported
Returns: transported tensor
Return type:

transp_follow_retr
(u: torch.Tensor, v: torch.Tensor, **kwargs) → torch.Tensor[source]¶ Perform vector transport following \(u\): \(\mathfrak{T}_{x\to\operatorname{retr}(x, u)}(v)\).
This operation is sometimes is much more simpler and can be optimized.
Parameters:  u (torch.Tensor) – tangent vector at point \(x\)
 v (torch.Tensor) – tangent vector at point \(x\) to be transported
Returns: transported tensor
Return type:

unpack_tensor
() → Union[torch.Tensor, Tuple[torch.Tensor]][source]¶ Construct a point on the manifold.
This method should help to work with product and compound manifolds. Internally all points on the manifold are stored in an intuitive format. However, there might be cases, when this representation is simpler or more efficient to store in a different way that is hard to use in practice.
Parameters: tensor (torch.Tensor) – Returns: Return type: torch.Tensor


class
geoopt.tensor.
ManifoldParameter
[source]¶ Same as
torch.nn.Parameter
that has information about its manifold.It should be used within
torch.nn.Module
to be recognized in parameter collection.Other Parameters: manifold ( geoopt.Manifold
(optional)) – A manifold for the tensor ifdata
is not ageoopt.ManifoldTensor