You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tri.rs
    path of file: ./repos/dfdx/dfdx-core/src/tensor_ops
    
    the code of the file until where you have to start completion: use crate::shapes::{Dtype, Shape};
use crate::tensor::{Error, Tape, Tensor, TriangleTensor};

use super::TryMul;

/// Applies a 2D lower triangular mask by setting values above the diagonal to `E::default()`.
///
/// See [`TriangleTensor::lower_tri`].
pub fn lower_tri<S: Shape, E: Dtype, D: TriangleTensor<E>, T: Tape<E, D>>(
    t: Tensor<S, E, D, T>,
    diagonal: impl Into<Option<isize>>,
) -> Tensor<S, E, D, T>
where
    Tensor<S, E, D, T>: TryMul<Tensor<S, E, D>, Output = Tensor<S, E, D, T>>,
{
    t.lower_tri(diagonal)
}

/// Applies a 2D upper triangular mask by setting values below the diagonal to `E::default()`.
///
/// See [`TriangleTensor::upper_tri`].
pub fn upper_tri<S: Shape, E: Dtype, D: TriangleTensor<E>, T: Tape<E, D>>(
    t: Tensor<S, E, D, T>,
    diagonal: impl Into<Option<isize>>,
) -> Tensor<S, E, D, T>
where
    Tensor<S, E, D, T>: TryMul<Tensor<S, E, D>, Output = Tensor<S, E, D, T>>,
{
    t.upper_tri(diagonal)
}

impl<S: Shape, E: Dtype, D: TriangleTensor<E>, T: Tape<E, D>> Tensor<S, E, D, T>
where
    Self: TryMul<Tensor<S, E, D>, Output = Self>,
{
    /// See [lower_tri]
    pub fn try_lower_tri(self, diagonal: impl Into
    
    fn test_tri() {
        let dev: TestDevice = Default::default();

        let t = dev
            .tensor(
                [[[
                    [1., 2., 3., 4., 5., 6.],
                    [1., 2., 3., 4., 5., 6.],
                    [1., 2., 3., 4., 5., 6.],
                    [1., 2., 3., 4., 5., 6.],
                    [1., 2., 3., 4., 5., 6.],
                ]; 4]; 3],
            )
            .to_dtype::<TestDtype>();
        assert_close_to_literal!(
            t.clone().lower_tri(None),
            [[[
                [1., 0., 0., 0., 0., 0.],
                [1., 2., 0., 0., 0., 0.],
                [1., 2., 3., 0., 0., 0.],
                [1., 2., 3., 4., 0., 0.],
                [1., 2., 3., 4., 5., 0.],
            ]; 4]; 3]
        );
        assert_close_to_literal!(
            t.clone().lower_tri(2),
            [[[
                [1., 2., 3., 0., 0., 0.],
                [1., 2., 3., 4., 0., 0.],
                [1., 2., 3., 4., 5., 0.],
                [1., 2., 3., 4., 5., 6.],
                [1., 2., 3., 4., 5., 6.],
            ]; 4]; 3]
        );
        assert_close_to_literal!(
            t.upper_tri(-1),
            [[[
                [1., 2., 3., 4., 5., 6.],
                [1., 2., 3., 4., 5., 6.],
                [0., 2., 3., 4., 5., 6.],
                [0., 0., 3., 4., 5., 6.],
                [0., 0., 0., 4., 5., 6.],
            ]; 4]; 3]
        );
    }