Trait neuronika::nn::PaddingMode [−][src]
pub trait PaddingMode: Send + Sync + Clone { fn pad_inplace<D: ReflPad + ReplPad, S: DataMut<Elem = f32>, T: Data<Elem = f32>>(
&self,
array: &mut ArrayBase<S, D>,
original: &ArrayBase<T, D>,
padding: &[usize]
); fn pad<D: ReflPad + ReplPad, E: IntoDimension<Dim = D>>(
&self,
input: &Array<f32, D>,
padding: E
) -> Array<f32, D>; }
Expand description
Padding modes logic.
Required methods
Implementors
Pads the input array with a constant value.
Arguments
-
input
- the array to be padded. -
padding
- the amount of padding for each dimension. -
value
- the value for the padding.
Examples
use neuronika::nn::{PaddingMode, Constant}; let padding = Constant::new(8.); let arr = ndarray::array![ [1., 2., 3.], [4., 5., 6.], [7., 8., 9.] ]; let padded = padding.pad(&arr, (1, 1)); let result = ndarray::array![ [8., 8., 8., 8., 8.], [8., 1., 2., 3., 8.], [8., 4., 5., 6., 8.], [8., 7., 8., 9., 8.], [8., 8., 8., 8., 8.] ]; assert_eq!(padded, result);
Pads the input array in place using the reflection of its boundary.
See .pad()
for more informations.
Arguments
-
input
- array to be padded. -
original
- the original unpadded array. -
padding
- slice specifying the amount of padding for each dimension.
Panics
If padding
length doesn’t match input
’s dimensions.
Pads the input array using the reflection of the input boundary.
Only 1, 2 and 3 dimensional arrays support reflective padding.
Arguments
-
input
- the array to be padded. -
padding
- the amount of padding for each dimension.
Examples
use neuronika::nn::{PaddingMode, Reflective}; let padding = Reflective; let arr = ndarray::array![ [1., 2., 3.], [4., 5., 6.], [7., 8., 9.] ]; let padded = padding.pad(&arr, (1, 1)); let result = ndarray::array![ [5., 4., 5., 6., 5.], [2., 1., 2., 3., 2.], [5., 4., 5., 6., 5.], [8., 7., 8., 9., 8.], [5., 4., 5., 6., 5.] ]; assert_eq!(padded, result);
Pads the input array in place using the replication of its boundary.
See .pad()
for more informations.
Arguments
-
input
- array to be padded. -
original
- the original unpadded array. -
padding
- slice specifying the amount of padding for each dimension.
Panics
If padding
length doesn’t match input
’s dimensions.
Pads the input array using the replication of its boundary.
Only 1, 2 and 3 dimensional arrays support replicative padding.
Arguments
-
input
- the array to be padded. -
padding
- the amount of padding for each dimension.
Examples
use neuronika::nn::{Replicative, PaddingMode}; let padding = Replicative; let arr = ndarray::array![ [1., 2., 3.], [4., 5., 6.], [7., 8., 9.] ]; let padded = padding.pad(&arr, (1, 1)); let result = ndarray::array![ [1., 1., 2., 3., 3.], [1., 1., 2., 3., 3.], [4., 4., 5., 6., 6.], [7., 7., 8., 9., 9.], [7., 7., 8., 9., 9.] ]; assert_eq!(padded, result);
Pads the input array with zeros.
Arguments
-
input
- the array to be padded. -
padding
- the amount of padding for each dimension.
Examples
use neuronika::nn::{PaddingMode, Zero}; let padding = Zero; let arr = ndarray::array![ [1., 2., 3.], [4., 5., 6.], [7., 8., 9.] ]; let padded = padding.pad(&arr, (1, 1)); let result = ndarray::array![ [0., 0., 0., 0., 0.], [0., 1., 2., 3., 0.], [0., 4., 5., 6., 0.], [0., 7., 8., 9., 0.], [0., 0., 0., 0., 0.] ]; assert_eq!(padded, result);