🏁 Data structures 🏁
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?
- Zero cost abstraction.
- Zero unsafe.
- Zero macros.
- 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:
Docs
Usage
ArrayGrid:
-
SlidingWindow:
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.