1mod batch;
33mod cells;
34mod circuit;
35pub mod dsl;
36mod emit;
37mod gather;
38mod inline;
39mod numeric;
40mod prefix;
41mod springs;
42mod tensor;
43pub mod timing;
44mod wire;
45
46pub use batch::{BatchExecutor, LANES};
47pub use cells::{CellSpec, Policy, SourceTable, constant, event, input, input_bit, state, state_bit};
48pub use circuit::{
49 BackpropOptions, BooleanGradient, CandidateTable, Circuit, Comparison, ComparisonGradient, IndexGradient,
50 IndexRead, Macro, OneHotGroup, OpKind, Operation, OutOfRange, RoundingPointKind,
51};
52pub use emit::{
53 CompareOptions, Relation, emit_and, emit_argmax, emit_clamp_exact, emit_compare, emit_compare_with,
54 emit_first_active, emit_maximum, emit_maximum_exact, emit_minimum, emit_minimum_exact, emit_not, emit_or,
55 emit_relu, emit_round, emit_select, is_proven_bit,
56};
57pub use handwired_rs_macros::handwired;
58pub use numeric::Range;
59pub use prefix::{brent_kung_prefix, sklansky_prefix};
60pub use springs::{
61 AnimatedObject, AnimatedObjectOptions, AnimatedSpring, SpringMatrixWires, SpringState, emit_animated_object,
62 emit_apply_spring_matrix, emit_spring,
63};
64pub use tensor::{CompileOptions, GatherCompute, GatherRead, IndexReadRow, TensorExecutor, TensorLayer, TensorProgram};
65pub use wire::{Lin, Term, Wire};
66
67#[derive(Clone, Debug, PartialEq)]
68pub enum Error {
69 SourceLength {
70 expected: usize,
71 actual: usize,
72 },
73 SourceOutOfRange {
74 wire: Wire,
75 value: f64,
76 range: Range,
77 },
78 BooleanGradient {
80 wire: Wire,
81 },
82 IndexGradient {
84 wire: Wire,
85 },
86}
87
88impl std::fmt::Display for Error {
89 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 match self {
91 Error::SourceLength { expected, actual } => {
92 write!(formatter, "source table has {actual} cells, expected {expected}")
93 }
94 Error::SourceOutOfRange { wire, value, range } => write!(
95 formatter,
96 "source wire {} is {value}, outside its declared range {}..{}",
97 wire.index(),
98 range.min,
99 range.max
100 ),
101 Error::BooleanGradient { wire } => {
102 write!(formatter, "cannot backpropagate through the boolean atom at wire {}", wire.index())
103 }
104 Error::IndexGradient { wire } => {
105 write!(formatter, "cannot backpropagate into the index of the index read at wire {}", wire.index())
106 }
107 }
108 }
109}
110
111impl std::error::Error for Error {}