🏁 Data structures 🏁
High performance GridArray and SlidingWindow datastructures used in DeepCausality.
The sliding window implementation over-allocates to trade space (memory) for time complexity by delaying the rewind operation when hitting the end of the underlying data structure. Specifically, a sliding window of size N can hold, without any array copy, approximately C-1 elements, where C is the total capacity defined as NxM with N as the window size and M as a multiple. This crate has two implementations, one over vector and the second over a const generic array. The const generic implementation is significantly faster than the vector-based version.
ArrayGrid is an abstraction over scalars, vectors, and low dimensional matrices similar to a tensor. In contrast to a tensor, an ArrayGrid is limited to low dimensions (1 to 4), only allowing a scalar, vector, or matrix type. Still, all of them are represented as a static fixed-size const generic array. Fixed-sized arrays allow for several compiler optimizations, including a cache-aligned data layout and the removal of runtime array boundary checks because all structural parameters are known upfront, providing a significant performance boost over tensors.
🤔 Why?
- Zero dependencies.
- Zero cost abstraction.
- Zero unsafe by default. Unsafe implementations are available through the
unsafefeature flag.
To enable unsafe implementations, add this to your Cargo.toml:
[]
= { = "0.4.7", = ["unsafe"] }
Performance:
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 |
More details on performance can be found in the Performance section of the SlidingWindow document.
🚀 Install
Just run:
Alternatively, add the following to your Cargo.toml
= "0.4.7"
📚 Docs
⭐ Usage
ArrayGrid:
SlidingWindow:
🙏 Prior Art
The project took inspiration from:
👨💻👩💻 Contribution
Contributions are welcomed especially related to documentation, example code, and fixes. If unsure where to start, just 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.
💻 Author
- Marvin Hansen.
- Github GPG key ID: 369D5A0B210D39BC
- GPG Fingerprint: 4B18 F7B2 04B9 7A72 967E 663E 369D 5A0B 210D 39BC