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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! `ndarray-conv` provides N-dimensional convolution operations for `ndarray` arrays.
//!
//! This crate extends the `ndarray` library with both standard and
//! FFT-accelerated convolution methods.
//!
//! # Getting Started
//!
//! To start performing convolutions, you'll interact with the following:
//!
//! 1. **Input Arrays:** Use `ndarray`'s [`Array`](https://docs.rs/ndarray/latest/ndarray/type.Array.html)
//! or [`ArrayView`](https://docs.rs/ndarray/latest/ndarray/type.ArrayView.html)
//! as your input data and convolution kernel.
//! 2. **Convolution Methods:** Call `array.conv(...)` or `array.conv_fft(...)`.
//! These methods are added to `ArrayBase` types via the traits
//! [`ConvExt::conv`] and [`ConvFFTExt::conv_fft`].
//! 3. **Convolution Mode:** [`ConvMode`] specifies the size of the output.
//! 4. **Padding Mode:** [`PaddingMode`] specifies how to handle array boundaries.
//!
//! # Basic Example:
//!
//! Here's a simple example of how to perform a 2D convolution using `ndarray-conv`:
//!
//! ```rust
//! use ndarray::prelude::*;
//! use ndarray_conv::{ConvExt, ConvFFTExt, ConvMode, PaddingMode};
//!
//! // Input data
//! let input = array![[1, 2, 3], [4, 5, 6], [7, 8, 9]];
//!
//! // Convolution kernel
//! let kernel = array![[1, 1], [1, 1]];
//!
//! // Perform standard convolution with "same" output size and zero padding
//! let output = input.conv(
//! &kernel,
//! ConvMode::Same,
//! PaddingMode::Zeros,
//! ).unwrap();
//!
//! println!("Standard Convolution Output:\n{:?}", output);
//!
//! // Perform FFT-accelerated convolution with "same" output size and zero padding
//! let output_fft = input.map(|&x| x as f32).conv_fft(
//! &kernel.map(|&x| x as f32),
//! ConvMode::Same,
//! PaddingMode::Zeros,
//! ).unwrap();
//!
//! println!("FFT Convolution Output:\n{:?}", output_fft);
//! ```
//!
//! # Choosing a convolution method
//!
//! * Use [`ConvExt::conv`] for standard convolution
//! * Use [`ConvFFTExt::conv_fft`] for FFT accelerated convolution.
//! FFT accelerated convolution is generally faster for larger kernels, but
//! standard convolution may be faster for smaller kernels.
//!
//! # Key Structs, Enums and Traits
//!
//! * [`ConvMode`]: Specifies how to determine the size of the convolution output (e.g., `Full`, `Same`, `Valid`).
//! * [`PaddingMode`]: Specifies how to handle array boundaries (e.g., `Zeros`, `Reflect`, `Replicate`). You can also use `PaddingMode::Custom` or `PaddingMode::Explicit` to combine different [`BorderType`] strategies for each dimension or for each side of each dimension.
//! * [`BorderType`]: Used with [`PaddingMode`] for `Custom` and `Explicit`, specifies the padding strategy (e.g., `Zeros`, `Reflect`, `Replicate`, `Circular`).
//! * [`ConvExt`]: The trait that adds the `conv` method, extending `ndarray` arrays with standard convolution functionality.
//! * [`ConvFFTExt`]: The trait that adds the `conv_fft` method, extending `ndarray` arrays with FFT-accelerated convolution functionality.
pub use ExplicitPadding;
pub use ConvExt;
pub use ;
pub use ;
/// Specifies the convolution mode, which determines the output size.
/// Specifies the padding mode, which determines how to handle borders.
///
/// The padding mode can be either a single `BorderType` applied on all sides
/// or a custom tuple of two `BorderTypes` for each dimension or a `BorderType`
/// for each side of each dimension.
/// Used with [`PaddingMode`]. Specifies the padding mode for a single dimension
/// or a single side of a dimension.
use Error;
/// Error type for convolution operations.