ferray_core/lib.rs
1// ferray-core: N-dimensional array type and foundational primitives
2//
3// This is the root crate for the ferray workspace. It provides NdArray<T, D>,
4// the full ownership model (Array, ArrayView, ArrayViewMut, ArcArray, CowArray),
5// the Element trait, DType system, FerrayError, and array introspection/iteration.
6//
7// ndarray is used internally but is NOT part of the public API.
8//
9// When the `no_std` feature is enabled, only the subset of functionality that
10// does not depend on `std` or `ndarray` is compiled: DType, Element, FerrayError
11// (simplified), dimension types (without ndarray conversions), constants, and
12// layout enums. The full Array type and related features require `std`.
13
14#![cfg_attr(not(feature = "std"), no_std)]
15// Core numerical kernels lift integer shape/index data into floating-point
16// (`linspace`, `arange`, `geomspace`), narrow `f64` boundaries back to
17// `usize` indices (`pad`, `tile`, broadcasting), and expose `finfo`/`iinfo`
18// limit constants that necessarily round-trip through cast-equivalent
19// types. Constants comparison and oracle tests assert exact float equality
20// against canonical values. These are part of the NumPy-compatible contract.
21#![allow(
22 clippy::cast_possible_truncation,
23 clippy::cast_possible_wrap,
24 clippy::cast_precision_loss,
25 clippy::cast_sign_loss,
26 clippy::cast_lossless,
27 clippy::float_cmp,
28 // Every public function in the workspace returns FerrayResult<T>. The
29 // FerrayError variants are documented once on the type, not on every
30 // returning function — that is a workspace-wide doc convention.
31 clippy::missing_errors_doc,
32 clippy::missing_panics_doc,
33 // Numerical / array code uses i, j, k, n, m as canonical loop and
34 // shape names — same as NumPy's reference docs and any linear algebra
35 // text. Renaming for clippy's taste hurts readability.
36 clippy::many_single_char_names,
37 clippy::similar_names,
38 // Items-after-statements covers local helper fns inside functions —
39 // a deliberate ferray pattern for keeping helper closures named.
40 clippy::items_after_statements,
41 // The `if let Some(x) = .. else ..` pattern is more readable than
42 // `Option::map_or_else` for non-trivial blocks; this is a
43 // nursery-level stylistic preference.
44 clippy::option_if_let_else,
45 // Pedantic readability preferences that don't apply to this codebase.
46 clippy::too_long_first_doc_paragraph,
47 clippy::needless_pass_by_value,
48 clippy::match_same_arms
49)]
50
51#[cfg(not(feature = "std"))]
52extern crate alloc;
53
54// Modules that work in both std and no_std modes
55pub mod constants;
56pub mod dimension;
57pub mod dtype;
58pub mod error;
59pub mod layout;
60pub mod record;
61
62// Modules that require std (depend on ndarray or std-only features)
63#[cfg(feature = "std")]
64pub mod array;
65#[cfg(feature = "std")]
66pub mod buffer;
67#[cfg(feature = "std")]
68pub mod creation;
69#[cfg(feature = "std")]
70pub mod dynarray;
71#[cfg(feature = "std")]
72pub mod indexing;
73#[cfg(feature = "std")]
74pub mod manipulation;
75#[cfg(feature = "std")]
76pub mod nditer;
77#[cfg(feature = "std")]
78pub mod ops;
79#[cfg(feature = "std")]
80pub mod prelude;
81
82// Re-export key types at crate root for ergonomics (std only)
83#[cfg(feature = "std")]
84pub use array::ArrayFlags;
85#[cfg(feature = "std")]
86pub use array::aliases;
87#[cfg(feature = "std")]
88pub use array::arc::ArcArray;
89#[cfg(feature = "std")]
90pub use array::cow::CowArray;
91#[cfg(feature = "std")]
92pub use array::display::{get_print_options, set_print_options};
93#[cfg(feature = "std")]
94pub use array::owned::Array;
95#[cfg(feature = "std")]
96pub use array::view::ArrayView;
97#[cfg(feature = "std")]
98pub use array::view_mut::ArrayViewMut;
99
100pub use dimension::{Axis, Dimension, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn};
101
102#[cfg(all(feature = "const_shapes", feature = "std"))]
103pub use dimension::static_shape::{
104 Assert, DefaultNdarrayDim, IsTrue, Shape1, Shape2, Shape3, Shape4, Shape5, Shape6,
105 StaticBroadcast, StaticMatMul, StaticSize, static_reshape_array,
106};
107
108pub use dtype::{DType, Element, SliceInfoElem};
109
110pub use error::{FerrayError, FerrayResult};
111
112pub use layout::MemoryLayout;
113
114#[cfg(feature = "std")]
115pub use buffer::AsRawBuffer;
116
117#[cfg(feature = "std")]
118pub use dynarray::DynArray;
119
120#[cfg(feature = "std")]
121pub use nditer::NdIter;
122
123pub use record::FieldDescriptor;
124
125// Re-export proc macros from ferray-core-macros.
126// The derive macro FerrayRecord shares its name with the trait in record::FerrayRecord.
127// Both are re-exported: the derive macro lives in macro namespace, the trait in type namespace.
128pub use ferray_core_macros::{FerrayRecord, promoted_type, s};
129pub use record::FerrayRecord;
130
131// Kani formal verification harnesses (only compiled during `cargo kani`)
132#[cfg(kani)]
133mod verification_kani;