Skip to main content

sim_lib_numbers_tensor_bit/
lib.rs

1#![forbid(unsafe_code)]
2#![allow(deprecated)]
3#![deny(missing_docs)]
4
5//! Bit-tensor specialization: a packed-word boolean tensor element type and its
6//! `SpecTensor` backend, with bitwise operations over the tensor domain.
7//!
8//! [`BitTensor`] is the storage type (booleans packed into `u64` words) with
9//! element-wise [`bit_and`](BitTensor::bit_and), [`bit_or`](BitTensor::bit_or),
10//! and [`bit_xor`](BitTensor::bit_xor). [`BitTensorLib`] registers it as the
11//! `bool` element-type backend for the base tensor domain.
12//!
13//! # Examples
14//!
15//! Pack booleans, combine two tensors bit-for-bit, and unpack the result:
16//!
17//! ```
18//! use sim_lib_numbers_tensor_bit::BitTensor;
19//!
20//! let left = BitTensor::from_bools(vec![4], &[true, false, true, true]).unwrap();
21//! let right = BitTensor::from_bools(vec![4], &[true, true, false, true]).unwrap();
22//! let masked = left.bit_and(&right).unwrap();
23//! assert_eq!(masked.to_bools(), vec![true, false, false, true]);
24//! ```
25//!
26//! Shape mismatches fail closed rather than truncate:
27//!
28//! ```
29//! use sim_lib_numbers_tensor_bit::BitTensor;
30//!
31//! let a = BitTensor::from_bools(vec![2], &[true, false]).unwrap();
32//! let b = BitTensor::from_bools(vec![3], &[true, false, true]).unwrap();
33//! assert!(a.bit_or(&b).is_none());
34//! ```
35
36mod bit_tensor;
37
38pub use bit_tensor::{BitTensor, BitTensorLib, tensor_lib_symbol, tensor_spec_symbol};
39/// Cookbook recipes for this lib, embedded at build time.
40pub static RECIPES: sim_cookbook::EmbeddedDir =
41    include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));