aprender 0.24.0

Next-generation machine learning library in pure Rust
Documentation
[workspace]
members = [".", "crates/aprender-shell", "crates/aprender-tsp", "crates/aprender-monte-carlo", "crates/apr-cli"]

[workspace.lints.rust]
# Safety
# Note: Using "deny" (not "forbid") to allow documented unsafe in mmap module.
# See bundle-mmap-spec.md Section 4 for safety justification.
unsafe_code = "deny"
unsafe_op_in_unsafe_fn = "warn"

# Code Quality
unreachable_pub = "warn"
missing_debug_implementations = "warn"
missing_docs = "allow"  # We have doc coverage checks separately

# Best Practices
rust_2018_idioms = { level = "warn", priority = -1 }  # Lower priority to avoid conflicts
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"

[workspace.lints.clippy]
# Base level
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }

# Correctness (high priority)
checked_conversions = "warn"
missing_errors_doc = "allow"  # We have comprehensive error docs
missing_panics_doc = "allow"  # We document via expect() messages

# Performance
inefficient_to_string = "warn"
explicit_iter_loop = "warn"
manual_ok_or = "warn"

# Style & Clarity
explicit_deref_methods = "warn"
implicit_clone = "warn"
inconsistent_struct_constructor = "warn"
redundant_closure_for_method_calls = "warn"
unnested_or_patterns = "warn"
used_underscore_binding = "warn"

# Allow pedantic lints that conflict with mathematical notation or ML patterns
many_single_char_names = "allow"
cast_precision_loss = "allow"
cast_possible_truncation = "allow"  # Common in ML with dimension conversions
cast_possible_wrap = "allow"  # Common in ML algorithms
cast_sign_loss = "allow"  # Common in ML with usize/isize conversions
similar_names = "allow"
doc_markdown = "allow"
missing_const_for_fn = "allow"
module_name_repetitions = "allow"
must_use_candidate = "allow"
return_self_not_must_use = "allow"
float_cmp = "allow"  # ML algorithms often compare floats
unreadable_literal = "allow"  # Test data often has long numeric literals
items_after_statements = "allow"  # ML algorithms often need mid-function declarations
large_stack_arrays = "allow"  # ML tests often need large data arrays
too_many_arguments = "allow"  # ML training functions often need many parameters
too_many_lines = "allow"  # ML algorithms can be long
needless_range_loop = "allow"  # Explicit indexing often clearer in ML code
assigning_clones = "allow"  # Common pattern in state reset
missing_fields_in_debug = "allow"  # Some fields intentionally omitted
derivable_impls = "allow"  # Sometimes explicit impls are clearer
uninlined_format_args = "allow"  # Format string style preference
type_complexity = "allow"  # Complex types common in ML
cloned_instead_of_copied = "allow"  # Style preference
unused_self = "allow"  # Method stubs common during development

[package]
name = "aprender"
version = "0.24.0"
edition = "2021"
rust-version = "1.70"
authors = ["Noah Gift <noah@paiml.com>"]
license = "MIT"
description = "Next-generation machine learning library in pure Rust"
repository = "https://github.com/paiml/aprender"
documentation = "https://docs.rs/aprender"
readme = "README.md"
keywords = ["machine-learning", "classification", "clustering", "statistics", "graph-algorithms"]
categories = ["science", "algorithms"]

[lints]
workspace = true

[dependencies]
# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"  # SafeTensors JSON metadata
bincode = "1.3"
rmp-serde = "1.3"  # MessagePack for .apr metadata (spec §2)

# Random number generation for model_selection
rand = { version = "0.8", features = ["small_rng"] }
rand_chacha = "0.3"  # ChaCha20 PRNG for Monte Carlo simulations

# Audio processing
rustfft = { version = "6.2", optional = true }  # FFT for mel spectrogram computation
thiserror = { version = "2.0", optional = true }  # Error handling for audio module

# Native audio capture (Linux ALSA)
alsa = { version = "0.9", optional = true }  # ALSA bindings for Linux audio capture

# Parallelization for graph algorithms (optional for WASM compatibility)
rayon = { version = "1.10", optional = true }

# Core compute primitives - SIMD-accelerated tensor operations
trueno = "0.11.0"

# Compression for .apr format (optional, spec §3.3)
lz4_flex = { version = "0.11", optional = true }
zstd = { version = "0.13", optional = true }

# Half-precision floats for quantization (spec §6.2)
half = { version = "2.4", optional = true, default-features = false, features = ["std"] }

# Digital signatures for .apr format (optional, spec §4.2)
ed25519-dalek = { version = "2.1", optional = true, default-features = false, features = ["std", "zeroize", "rand_core"] }

# Encryption for .apr format (optional, spec §4.1)
aes-gcm = { version = "0.10", optional = true }
argon2 = { version = "0.5", optional = true, default-features = false, features = ["std"] }
x25519-dalek = { version = "2.0", optional = true, default-features = false, features = ["static_secrets"] }
hkdf = { version = "0.12", optional = true }
sha2 = { version = "0.10", optional = true }  # For HKDF-SHA256

# Data loading
alimentar = { version = "0.2.2", optional = true }

# Inference monitoring and explainability (optional)
entrenar = { version = "0.5", optional = true }

# Hugging Face Hub integration (optional, spec §11.8)
hf-hub = { version = "0.4", optional = true, default-features = false, features = ["ureq"] }
dirs = { version = "6.0", optional = true }

# SafeTensors format parsing (optional, for HF model comparison)
safetensors = { version = "0.4", optional = true }

# WASM bindings for noise generator (optional, spec: noise-generator-apr-wasm-spec.md)
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true }
minijinja = { version = "2.14.0", features = ["loader", "serde"] }

[dev-dependencies]
proptest = "1.6"
criterion = "0.5"
renacer = "0.9.1"
tempfile = "3.14"  # For format module tests
jugar-probar = "0.5"  # TUI/GUI testing framework with coverage tracking (spec §8)

[features]
default = ["parallel"]
parallel = ["rayon"]  # Enable parallel graph algorithms (disable for WASM)
datasets = ["alimentar"]  # Enable data loading from alimentar
format-compression = ["lz4_flex", "zstd"]  # Enable LZ4/ZSTD compression for .apr format (spec §3.3, GH-146)
format-signing = ["ed25519-dalek"]  # Enable Ed25519 signatures for .apr format (spec §4.2)
format-encryption = ["aes-gcm", "argon2", "x25519-dalek", "hkdf", "sha2"]  # Enable encryption for .apr format (spec §4.1)
format-quantize = ["half"]  # Enable quantization for .apr format (spec §6.2)
format-homomorphic = []  # Enable homomorphic encryption for .apr format (spec: homomorphic-encryption-spec.md)
# Note: mmap is automatic on native platforms, no feature needed (spec: bundle-mmap-spec.md)
hf-hub-integration = ["hf-hub", "dirs"]  # Enable Hugging Face Hub integration (GH-100)
audio = ["rustfft", "thiserror"]  # Enable audio processing (mel spectrogram, resampling)
audio-capture = ["audio"]  # Enable audio capture base functionality
audio-alsa = ["audio-capture", "alsa"]  # Enable ALSA audio capture (Linux only)
audio-coreaudio = ["audio-capture"]  # Enable CoreAudio capture (macOS only)
audio-wasapi = ["audio-capture"]  # Enable WASAPI capture (Windows only)
audio-webaudio = ["audio-capture"]  # Enable WebAudio capture (WASM only)
audio-playback = ["audio"]  # Enable audio playback
audio-codec = ["audio"]  # Enable audio codec decoding (WAV, MP3, AAC, FLAC, Opus)
audio-noise = ["audio"]  # Enable ML-based noise generation (GH-144)
audio-noise-wasm = ["audio-noise", "wasm-bindgen", "js-sys"]  # Enable WASM bindings for noise generator
safetensors-compare = ["safetensors", "hf-hub-integration", "half"]  # Enable SafeTensors comparison (GH-121)
inference-monitoring = ["entrenar"]  # Enable inference monitoring and explainability
gpu = ["trueno/gpu"]  # Enable GPU acceleration via trueno wgpu backend
cuda = ["trueno/cuda-monitor"]  # Enable CUDA monitoring via trueno-gpu (NVIDIA GPUs)
cpu-only = []
# Chaos engineering features (from renacer)
chaos-basic = []
chaos-network = ["chaos-basic"]
chaos-byzantine = ["chaos-basic"]
chaos-full = ["chaos-network", "chaos-byzantine"]

# WASM support: enable getrandom's "js" feature for browser environments
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

# Memory-mapped I/O for native platforms (spec: bundle-mmap-spec.md)
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
memmap2 = "0.9"

[[test]]
name = "book"
path = "tests/book/mod.rs"

[[bench]]
name = "linear_regression"
harness = false

[[bench]]
name = "kmeans"
harness = false

[[bench]]
name = "dataframe"
harness = false

[[bench]]
name = "graph"
harness = false

[[bench]]
name = "recommend"
harness = false

[[bench]]
name = "citl"
harness = false

[[bench]]
name = "ollama_parity"
harness = false
required-features = ["format-quantize"]

[[example]]
name = "shell_encryption_demo"
required-features = ["format-encryption"]

[[example]]
name = "chat_template"

[[example]]
name = "text_preprocessing"

[[example]]
name = "time_series_forecasting"

[profile.release]
lto = true
codegen-units = 1
debug = true  # Enable debug info for flamegraph/profiling