| Crates.io | digit-layout |
| lib.rs | digit-layout |
| version | 0.3.1 |
| created_at | 2024-06-21 02:31:07.52088+00 |
| updated_at | 2025-05-15 02:42:39.492346+00 |
| description | This crate provides a unified data type definition across various libraries, efficiently encodes types in a compact layout, thus avoiding the redundancy of enumerating definitions for data types. |
| homepage | |
| repository | https://github.com/InfiniTensor/digit-layout.git |
| max_upload_size | |
| id | 1279049 |
| size | 27,767 |
这个库提供了一个统一的数据类型定义,可以高效地编码类型信息,避免重复定义数据类型。
use digit_layout::{DigitLayout, LayoutContent};
// 创建无符号整数类型布局
let u8_layout = DigitLayout::unsigned(8, 1);
assert_eq!(u8_layout.to_string(), "u8");
// 创建浮点数类型布局
let f32_layout = DigitLayout::real(8, 23, 1);
assert_eq!(f32_layout.to_string(), "f32_e8m23");
// 创建自定义类型布局
let custom_layout = DigitLayout::named("custom", 1, 4);
assert_eq!(custom_layout.to_string(), "custom");
use digit_layout::DigitLayout;
// 创建无符号整数数组布局
let u8_array = DigitLayout::unsigned(8, 4);
assert_eq!(u8_array.to_string(), "[u8; 4]");
// 创建浮点数数组布局
let f32_array = DigitLayout::real(8, 23, 4);
assert_eq!(f32_array.to_string(), "[f32_e8m23; 4]");
use digit_layout::{DigitLayout, LayoutContent};
// 解码无符号整数布局
let u8_layout = DigitLayout::unsigned(8, 1);
match u8_layout.decode() {
LayoutContent::Unsigned { width } => {
assert_eq!(width, 8);
}
_ => panic!("Expected unsigned layout"),
}
// 解码浮点数布局
let f32_layout = DigitLayout::real(8, 23, 1);
match f32_layout.decode() {
LayoutContent::Real { exponent, mantissa } => {
assert_eq!(exponent, 8);
assert_eq!(mantissa, 23);
}
_ => panic!("Expected real layout"),
}
项目包含一个性能测试示例,可以测量各种操作的执行时间。运行性能测试:
cargo run --example benchmark
性能测试会测量以下操作的执行时间:
创建布局
解码布局
测试结果会显示每个操作的平均执行时间。
完整的 API 文档可以在 docs.rs 上找到。
欢迎提交 Issue 和 Pull Request!
本项目采用 MIT 许可证 - 详见 LICENSE 文件。