Skip to content

: add new module 'view' (#109) #112

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shayne-fletcher
Copy link
Contributor

Summary: Pull Request resolved: #109

Differential Revision: D75747680

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 1, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75747680

shayne-fletcher added a commit to shayne-fletcher/monarch-1 that referenced this pull request Jun 1, 2025
Summary:


Differential Revision: D75747680
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75747680

Summary:

this diff introduces `LayoutMap` and `LayoutMapInverse` traits and implements them for `Slice`, extracting core layout logic (`offset_of`, `coord_of`) into dedicated abstractions.

motivation: this sets up `view()` — and other shape-preserving transforms — to share layout logic without duplicating or entangling with `Slice`. by extracting `offset_of` and `coord_of` into `LayoutMap` traits, we make the layout logic reusable. this lets future features like `view()` reuse indexing without tying everything to `Slice`.
- defines `LayoutMap` trait for `affine` memory layouts, providing `offset_of()`
- defines `LayoutMapInverse` for invertible layouts, providing `coord_of()`
- implements both traits for `Slice` using existing logic
- rewrites `location()` and `coordinates()` to delegate to the traits
- isolates layout logic and enables future generalization (e.g., `view`s, `reshape`s)
- no behavior change; covered by existing test suite

this extracts the core logic for layout/indexing into dedicated traits, simplifying `Slice` and preparing for shape-preserving transformations

Differential Revision: D75746358
Summary:

introduces `View<'a>`: a lazy, composable layout reinterpretation over a base `LayoutMap`, modeled after `torch.Tensor.view`. enables shape reparametrization (e.g. `[6] → [2, 3]`) without copying, deferring validation until finalization (`into_slice`, not yet implemented).

adds `LayoutTransformExt` for ergonomic `.view(&[...])?` construction on any `LayoutMap`. implements `LayoutMap` for `View` to support forward address computation.

note: `View` is not yet usable in practice — `validate_layout` and `into_slice` are missing, and there are no tests. compatibility checks are limited to element count and reachability of the view origin.

Differential Revision: D75747680
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75747680

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants