deep_causality_data_structures 0.10.19

Data structures for for deep_causality crate.
Documentation

🏁 Data structures 🏁

Crates.io Docs.rs MIT licensed

This crate provides two data structures used in DeepCausality: ArrayGrid and SlidingWindow.

ArrayGrid abstracts over scalars, vectors, and low-dimensional matrices, similar to a tensor but limited to 1 to 4 dimensions. Every ArrayGrid is a static, fixed-size const generic array. Because all structural parameters are known at compile time, the compiler can lay the data out cache-aligned, which makes ArrayGrid faster than a tensor.

The sliding window over-allocates, trading memory for time by delaying the rewind when it reaches the end of the underlying storage. A sliding window of size N holds approximately C-1 elements without any array copy, where the capacity C is NxM with N the window size and M a multiple. The crate implements the window over a vector and over a const generic array; the const generic version is significantly faster.

Why?

  1. Zero cost abstraction.
  2. Zero unsafe.
  3. Zero macros.
  4. Zero external dependencies.

Performance:

ArrayGrid

Set value:

Dimension Safe Implementation Unsafe Implementation Improvement
1D Grid 604.71 ps 271.38 ps 55.1%
2D Grid 581.33 ps 417.39 ps 28.2%
3D Grid 862.16 ps 577.04 ps 33.0%
4D Grid 1.137 ns 812.62 ps 28.5%

See the Performance section of the ArrayGrid document for details.

Sliding Window

Single Push:

Implementation Single Push Time Notes
ArrayStorage ~2.08ns Optimized for continuous access patterns
VectorStorage ~2.5ns Good for dynamic sizing
UnsafeVectorStorage ~2.3ns Better performance than safe vector
UnsafeArrayStorage ~1.9ns Best performance for sequential and batch operations

Sequential Operations:

Implementation Operation Time Notes
UnsafeArrayStorage ~550ps Best cache utilization
ArrayStorage ~605ps Excellent cache locality
UnsafeVectorStorage ~750ps Good for mixed workloads
VectorStorage ~850ps Most predictable

See the Performance section of the SlidingWindow document for details.

Install

Run:

cargo add deep_causality_data_structures

Docs

Usage

ArrayGrid:

Prior Art

The project took inspiration from:

Contribution

Contributions are welcome, especially documentation, example code, and fixes. If unsure where to start, open an issue and ask.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in deep_causality by you, shall be licensed under the MIT licence, without any additional terms or conditions.

Licence

This project is licensed under the MIT license.

Security

For details about security, please read the security policy.