1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use ndarray::*;
pub trait NdArray {
type Elem: LinalgScalar;
type Dim: Dimension;
fn shape(&self) -> <Self::Dim as Dimension>::Pattern;
fn as_view(&self) -> ArrayView<Self::Elem, Self::Dim>;
fn as_view_mut(&mut self) -> ArrayViewMut<Self::Elem, Self::Dim>;
}
pub trait Manifold: NdArray {
type Coordinate;
fn dx(&self) -> Self::Coordinate;
fn coordinate_fill<F>(&mut self, F)
where
F: Fn(Self::Coordinate) -> Self::Elem;
fn coordinate_map<F>(&mut self, F)
where
F: Fn(Self::Coordinate, Self::Elem) -> Self::Elem;
}
impl<A: LinalgScalar, S: DataMut<Elem = A>, D: Dimension> NdArray for ArrayBase<S, D> {
type Elem = A;
type Dim = D;
fn shape(&self) -> <Self::Dim as Dimension>::Pattern {
self.dim()
}
fn as_view(&self) -> ArrayView<Self::Elem, Self::Dim> {
self.view()
}
fn as_view_mut(&mut self) -> ArrayViewMut<Self::Elem, Self::Dim> {
self.view_mut()
}
}