-
Notifications
You must be signed in to change notification settings - Fork 93
Docs/internals architecture #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sudha09-git
wants to merge
2
commits into
mohu-org:main
Choose a base branch
from
sudha09-git:docs/internals-architecture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ __pycache__/ | |
| dist/ | ||
| *.egg-info/ | ||
| .DS_Store | ||
| docs/book/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # Architecture | ||
|
|
||
| mohu is organized as a Cargo workspace of layered crates. Each layer only depends on | ||
| the layers below it, which keeps compile times low and makes it possible to use | ||
| pieces of mohu (e.g. just the error types, or just the dtype system) without pulling | ||
| in the whole library. | ||
|
|
||
| ┌─────────────────────────────────────────────────────────────┐ | ||
| │ I/O & tooling mohu-io · mohu-testing │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ Data structures mohu-sparse · mohu-masked │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ Compute mohu-ops · mohu-fft · mohu-random · │ | ||
| │ mohu-special · mohu-stats │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ Dispatch & protocol mohu-simd · mohu-ufunc · mohu-index │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ Foundation mohu-error · mohu-dtype · mohu-buffer ·│ | ||
| │ mohu-array · mohu-core (facade) │ | ||
| └─────────────────────────────────────────────────────────────┘ | ||
|
|
||
| ## Foundation layer | ||
|
|
||
| - **`mohu-error`** has zero dependencies on the rest of the workspace and defines | ||
| `MohuError`, `MohuResult<T>`, error codes, and the `bail!`/`ensure!` macros used | ||
| everywhere else. Every other crate depends on it, directly or indirectly. | ||
| - **`mohu-dtype`** defines the `DType` enum (bool, signed/unsigned ints, floats, | ||
| complex) and the type-promotion rules used whenever two arrays of different | ||
| dtypes interact. | ||
| - **`mohu-buffer`** owns raw allocation, memory layout, and stride arithmetic — | ||
| this is where C-order vs. Fortran-order and DLPack interop live. | ||
| - **`mohu-array`** builds `NdArray<T>`, the core N-dimensional array type, on top | ||
| of `mohu-buffer` and `mohu-dtype`. | ||
| - **`mohu-core`** is a thin re-export facade over the four crates above, so | ||
| downstream code can depend on one crate instead of four. | ||
|
|
||
| ## Dispatch & protocol layer | ||
|
|
||
| - **`mohu-simd`** provides AVX2/AVX-512/NEON kernel primitives that the compute | ||
| layer dispatches into based on CPU features detected at runtime. | ||
| - **`mohu-ufunc`** implements the universal-function protocol — broadcasting, | ||
| reduce, accumulate, and outer — that NumPy-style element-wise operations are | ||
| built on. | ||
| - **`mohu-index`** implements advanced indexing: fancy indexing, boolean masks, | ||
| and take/put. | ||
|
|
||
| ## Compute layer | ||
|
|
||
| `mohu-ops`, `mohu-fft`, `mohu-random`, `mohu-special`, and `mohu-stats` each own | ||
| one area of numerical functionality (arithmetic/broadcasting, FFTs, PRNGs and | ||
| distributions, special functions, and descriptive statistics respectively). They | ||
| all sit on top of the dispatch layer rather than calling SIMD or ufunc logic | ||
| directly themselves, so a new compute crate only needs to implement its own | ||
| math, not its own broadcasting or SIMD dispatch. | ||
|
|
||
| ## Data structure extensions | ||
|
|
||
| - **`mohu-sparse`** adds COO/CSR/CSC sparse matrix formats. | ||
| - **`mohu-masked`** adds masked arrays for null/invalid value propagation. | ||
|
|
||
| Both extend the dense `NdArray<T>` model rather than replacing it. | ||
|
|
||
| ## I/O & tooling | ||
|
|
||
| - **`mohu-io`** handles `.npy`/`.npz`, CSV, and Arrow IPC, including | ||
| memory-mapped files. | ||
| - **`mohu-testing`** provides shared test fixtures, property-test strategies, and | ||
| array-comparison helpers (e.g. `assert_allclose`) used across the workspace's | ||
| test suites. | ||
|
|
||
| ## Python bindings (`mohu-py`, planned) | ||
|
|
||
| Python interop is not yet implemented, but the plan (see `ROADMAP.md`) is a | ||
| tiered rollout of standard protocols on top of `mohu-buffer`, so that a `mohu` | ||
| array works with existing libraries without those libraries knowing mohu | ||
| exists: | ||
|
|
||
| 1. **Buffer protocol / `__array__`** — zero-copy `np.asarray()`, pandas, PIL. | ||
| 2. **DLPack** — zero-copy exchange with PyTorch, JAX, CuPy, TensorFlow. | ||
| 3. **Array API standard / `__array_ufunc__` / `__array_function__`** — native | ||
| dispatch from scikit-learn, scipy, and NumPy's own function calls. | ||
|
|
||
| ## Where to look next | ||
|
|
||
| - [`CRATE_MAP.md`](../../../CRATE_MAP.md) — full per-crate module and public API | ||
| breakdown; the best starting point if you're unsure which crate owns a change. | ||
| - [`docs/design/`](../../design/) — architecture decision records for | ||
| cross-cutting design questions (dtype system, memory layout). | ||
| - [`docs/rfcs/`](../../rfcs/) — larger proposals, such as the public Array API | ||
| surface. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: mohu-org/mohu
Length of output: 151
🏁 Script executed:
Repository: mohu-org/mohu
Length of output: 15259
🏁 Script executed:
Repository: mohu-org/mohu
Length of output: 203
🏁 Script executed:
Repository: mohu-org/mohu
Length of output: 690
🏁 Script executed:
Repository: mohu-org/mohu
Length of output: 11113
Reword the compute-layer description to match the manifest graph. The workspace layering is fine, but the compute crates do not all route through the dispatch layer:
mohu-opsandmohu-statsdepend onmohu-core, whilemohu-random,mohu-special, andmohu-fftdepend on foundation crates directly.🤖 Prompt for AI Agents