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
// gradcheck — finite-difference gradient checking for Rust ML frameworks.
// Copyright (c) 2026 Henos D <henosd19@gmail.com> (GitHub: @4ktLuffy)
// Repository: https://github.com/4ktLuffy/gradcheck
// SPDX-License-Identifier: MIT OR Apache-2.0
//! The framework abstraction.
//!
//! Implement [`Backend`] once for a framework and every check in this crate works against it.
//! The trait is deliberately small: build a tensor, read it back, and evaluate a function
//! either forward-only or with its analytic gradient.
/// A machine-learning framework that `gradcheck` can verify.
///
/// The core of this crate never touches framework types directly — it only speaks `f64`
/// slices and shapes. Adapters convert at the boundary. That is what keeps the numerical
/// oracle independent of the autodiff engine under test.
///
/// # Implementing for a new framework
///
/// ```ignore
/// struct MyBackend;
///
/// impl Backend for MyBackend {
/// type Tensor = my_framework::Tensor;
///
/// fn from_slice(data: &[f64], shape: &[usize]) -> Self::Tensor { /* ... */ }
/// fn to_vec(t: &Self::Tensor) -> Vec<f64> { /* ... */ }
/// fn forward_sum(f: &dyn Fn(Self::Tensor) -> Self::Tensor, x: &Self::Tensor) -> f64 { /* ... */ }
/// fn analytic_grad(f: &dyn Fn(Self::Tensor) -> Self::Tensor, x: &Self::Tensor) -> Vec<f64> { /* ... */ }
/// }
/// ```