Crates.io | burn-contracts |
lib.rs | burn-contracts |
version | 0.3.2 |
created_at | 2025-03-05 12:32:06.919281+00 |
updated_at | 2025-08-13 22:41:13.111715+00 |
description | Fluent Contracts for the Burn library |
homepage | |
repository | https://github.com/crutcher/burn-contracts |
max_upload_size | |
id | 1578953 |
size | 179,850 |
bimm-contracts
instead.See: bimm-contracts
This crate provides a fluent api for contract and test assertions for the Burn framework.
use burn_contracts::assert_tensor;
let tensor: Tensor<B, 4 > = Tensor::new(& [10, 3, 32, 17]);
assert_tensor( & tensor)
.has_named_dims([('N', 10), ('C', 3), ('H', 32), ('W', 32)]);
// Panics:
// "Expected tensor to have dimensions [('N', 10), ('C', 3), ('H', 32), ('W', 32)] but got [(10, 3, 32, 17)]"
The following assertions are available:
fn example<B: Backend>() {
let tensor = Tensor::<B, 4>::zeros([10, 3, 32, 17], &device);
assert_tensor(&tensor).has_dims([10, 3, 32, 17]).unwrap();
}
fn example<B: Backend>() {
let tensor = Tensor::<B, 4>::zeros([10, 3, 32, 17], &device);
assert_tensor(&tensor).has_named_dims(
[("N", 10), ("C", 3), ("H", 32), ("W", 17)],
).unwrap();
}
fn example<B: Backend>() {
let tensor = Tensor::<B, 6>::zeros([2, 2, 2, 5 * 4, 4 * 4, 3], &device);
let [b, h, w] = assert_tensor(&tensor).unpacks_shape(
["b", "h", "w"],
"b ... (h p) (w p) c",
&[("p", 4), ("c", 3)],
).unwrap();
assert_eq!(b, 2);
assert_eq!(h, 5);
assert_eq!(w, 4);
}
The "testing" feature enables the testing api; which provides expensive methods for testing tensor contents.
To ensure that the testing api is not used in production, the testing api is only available when the "testing" feature is enabled.
To enable the "testing" feature only for testing, add the following to your Cargo.toml
:
[dependencies]
burn-contracts = $VERSION
[dev-dependencies]
burn-contracts = { version = $VERSION, features = ["testing"] }
Added assert_tensor(&tensor).unpacks_shape(...)
assertion.
Initial release.