teeny_core/nn/conv3d.rs
1/*
2 * Copyright (c) 2026 Teenygrad.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use core::marker::PhantomData;
18
19use crate::{
20 dtype::{Dtype, EagerTensor, Tensor},
21 nn::Layer,
22};
23
24/// 3-D convolution layer: `output = conv3d(input, weight) [+ b]`
25///
26/// Input shape: `[N, C_in, D_in, H_in, W_in ]`
27/// Output shape: `[N, C_out, D_out, H_out, W_out]`
28pub struct Conv3d<D: Dtype, IT, OT, const RANK: usize> {
29 /// Number of input channels.
30 pub in_channels: usize,
31 /// Number of output channels.
32 pub out_channels: usize,
33 /// Convolution kernel depth.
34 pub kernel_d: usize,
35 /// Convolution kernel height.
36 pub kernel_h: usize,
37 /// Convolution kernel width.
38 pub kernel_w: usize,
39 /// Stride along the depth dimension.
40 pub stride_d: usize,
41 /// Stride along the height dimension.
42 pub stride_h: usize,
43 /// Stride along the width dimension.
44 pub stride_w: usize,
45 /// Zero-padding along the depth dimension.
46 pub padding_d: usize,
47 /// Zero-padding along the height dimension.
48 pub padding_h: usize,
49 /// Zero-padding along the width dimension.
50 pub padding_w: usize,
51 /// Whether to add a learned bias.
52 pub has_bias: bool,
53 _pd: PhantomData<(D, IT, OT)>,
54}
55
56impl<D: Dtype, IT, OT, const RANK: usize> Conv3d<D, IT, OT, RANK> {
57 /// Creates a new `Conv3d` layer.
58 pub fn new(
59 in_channels: usize,
60 out_channels: usize,
61 kernel_size: (usize, usize, usize),
62 stride: (usize, usize, usize),
63 padding: (usize, usize, usize),
64 has_bias: bool,
65 ) -> Self {
66 Self {
67 in_channels,
68 out_channels,
69 kernel_d: kernel_size.0,
70 kernel_h: kernel_size.1,
71 kernel_w: kernel_size.2,
72 stride_d: stride.0,
73 stride_h: stride.1,
74 stride_w: stride.2,
75 padding_d: padding.0,
76 padding_h: padding.1,
77 padding_w: padding.2,
78 has_bias,
79 _pd: PhantomData,
80 }
81 }
82}
83
84impl<D: Dtype, IT: Tensor<D, RANK> + EagerTensor, OT: Tensor<D, RANK>, const RANK: usize> Layer<IT>
85 for Conv3d<D, IT, OT, RANK>
86{
87 type Output = OT;
88 fn call(&self, _input: IT) -> Self::Output {
89 todo!()
90 }
91}