Trait dfdx::tensor::TriangleTensor
source · pub trait TriangleTensor<E>: Storage<E> {
// Required methods
fn try_upper_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S::Shape, E, Self>, Self::Err>;
fn try_lower_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S::Shape, E, Self>, Self::Err>;
// Provided methods
fn upper_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S, E, Self> { ... }
fn try_upper_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S, E, Self>, Self::Err> { ... }
fn upper_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S::Shape, E, Self> { ... }
fn lower_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S, E, Self> { ... }
fn try_lower_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S, E, Self>, Self::Err> { ... }
fn lower_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S::Shape, E, Self> { ... }
}
Expand description
Build upper & lower triangle tensors.
Required Methods§
Provided Methods§
sourcefn upper_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S, E, Self>
fn upper_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S, E, Self>
Build a tensor containing the upper triangle part of each lowest 2D matrix
set to the given value, along the given diagonal. The other values will be E::default()
.
Given a 2D matrix M x N
, diagonal values will shift the values in the
-M/+N
direction.
Examples
let a: Tensor<Rank2<3, 3>, f32, _> = dev.upper_tri(1.0, None);
assert_eq!(a.array(),
[[1.0, 1.0, 1.0],
[0.0, 1.0, 1.0],
[0.0, 0.0, 1.0]]
);
let b: Tensor<_, f32, _> = dev.upper_tri_like(&a, 1.0, -1);
assert_eq!(b.array(),
[[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0],
[0.0, 1.0, 1.0]]
);
let c: Tensor<_, f32, _> = dev.upper_tri_like(&b, 1.0, 1);
assert_eq!(c.array(),
[[0.0, 1.0, 1.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, 0.0]]
);
sourcefn try_upper_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_upper_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Result<Tensor<S, E, Self>, Self::Err>
Fallible version of TriangleTensor::upper_tri
sourcefn upper_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S::Shape, E, Self>
fn upper_tri_like<S: HasShape>( &self, src: &S, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S::Shape, E, Self>
Build an upper triangular tensor with the given shape. See TriangleTensor::upper_tri.
sourcefn lower_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S, E, Self>
fn lower_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S, E, Self>
Build a tensor containing the lower triangle part of each lowest 2D matrix
set to the given value, along the given diagonal. The other values will be E::default()
.
Given a 2D matrix M x N
, diagonal values will shift the values in the
-M/+N
direction.
Examples
let a: Tensor<Rank2<3, 3>, f32, _> = dev.lower_tri(1.0, None);
assert_eq!(a.array(),
[[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 1.0]]
);
let b: Tensor<_, f32, _> = dev.lower_tri_like(&a, 1.0, -1);
assert_eq!(b.array(),
[[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0]]
);
let c: Tensor<_, f32, _> = dev.lower_tri_like(&b, 1.0, 1);
assert_eq!(c.array(),
[[1.0, 1.0, 0.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0]]
);
sourcefn try_lower_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_lower_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Result<Tensor<S, E, Self>, Self::Err>
Fallible version of TriangleTensor::lower_tri
sourcefn lower_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S::Shape, E, Self>
fn lower_tri_like<S: HasShape>( &self, src: &S, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S::Shape, E, Self>
Build a lower triangular tensor with the given shape. See TriangleTensor::lower_tri.