Skip to content

Add Buffer::is_square() and Buffer::is_vector() convenience predicates - #258

Open
prince0-7 wants to merge 1 commit into
mohu-org:mainfrom
prince0-7:add-buffer-predicates
Open

Add Buffer::is_square() and Buffer::is_vector() convenience predicates#258
prince0-7 wants to merge 1 commit into
mohu-org:mainfrom
prince0-7:add-buffer-predicates

Conversation

@prince0-7

@prince0-7 prince0-7 commented May 30, 2026

Copy link
Copy Markdown

Summary

  • Added is_square()
  • Added is_vector()
  • Added is_matrix()
  • Added is_scalar_shape()
  • Added documentation comments
  • Added tests for shape predicates

Fixes #61

Summary by CodeRabbit

  • New Features

    • Introduced four shape helper methods to Buffer for identifying scalar, vector, matrix, and square matrix configurations.
  • Tests

    • Added comprehensive integration tests validating shape predicates across diverse buffer configurations.

Review Change Stack

Signed-off-by: prince0-7 <priyanshumondal720@gmail.com>
@prince0-7
prince0-7 requested a review from Bbn08 as a code owner May 30, 2026 21:48
@github-actions
github-actions Bot requested a review from mugiwaraluffy56 May 30, 2026 21:48
@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR adds four shape classification methods to Buffer: is_scalar_shape, is_vector, is_matrix, and is_square. These query methods enable callers to check common buffer structural properties without manual dimension inspection. Integration tests validate predicates across scalar, vector, matrix, and edge-case shapes.

Changes

Buffer Shape Predicates

Layer / File(s) Summary
Buffer shape predicate methods and tests
crates/mohu-buffer/src/buffer.rs, crates/mohu-buffer/tests/integration.rs
Adds is_scalar_shape(), is_vector(), is_matrix(), and is_square() methods to Buffer. Each method is a simple dimension check: 0D, 1D, 2D, and 2D with equal dimensions respectively. Integration tests cover scalar (empty shape), 1D vector, 2D matrix, 1x1 square, rectangular (non-square), and higher-rank tensor cases to validate correct predicate behavior.

🎯 1 (Trivial) | ⏱️ ~3 minutes

🐰 Four tiny methods, one cohesive thought—
Scalars, vectors, matrices brought!
Square shapes now shine with a simple call,
Shape predicates answer them all! 📦✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes, mentioning two of the four new convenience predicates added to Buffer. However, it omits is_matrix() and is_scalar_shape().
Linked Issues check ✅ Passed The pull request implements all four required methods (is_square, is_vector, is_matrix, is_scalar_shape) with documentation, and includes comprehensive tests covering edge cases (empty buffer, 1x1 matrix, rectangular matrix). All acceptance criteria from issue #61 are satisfied.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the shape predicates from issue #61. No out-of-scope modifications detected; additions are limited to the four new methods and their corresponding tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/mohu-buffer/src/buffer.rs (1)

560-569: ⚡ Quick win

Fix documentation style to match existing predicates.

The documentation comments should use backticks around true to be consistent with existing predicate methods (lines 551-559).

📝 Proposed documentation style fix
-    /// Returns true if the buffer is 0D (a scalar).
+    /// Returns `true` if the buffer is 0D (a scalar).
     pub fn is_scalar_shape(&self) -> bool { self.ndim() == 0 }
-    /// Returns true if the buffer is 1D (a vector).
+    /// Returns `true` if the buffer is 1D (a vector).
     pub fn is_vector(&self) -> bool { self.ndim() == 1 }
-    /// Returns true if the buffer is 2D (a matrix).
+    /// Returns `true` if the buffer is 2D (a matrix).
     pub fn is_matrix(&self) -> bool { self.ndim() == 2 }
-    /// Returns true if the buffer is 2D and both dimensions are equal.
+    /// Returns `true` if the buffer is 2D and both dimensions are equal.
     pub fn is_square(&self) -> bool {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/mohu-buffer/src/buffer.rs` around lines 560 - 569, Update the doc
comments for the predicate methods is_scalar_shape, is_vector, is_matrix, and
is_square to use backticks around `true` (e.g., "Returns `true` if the buffer is
0D (a scalar).") so they match the style of the existing predicate methods;
leave the signatures and logic unchanged and only modify the triple-slash
comments above each function.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/mohu-buffer/src/buffer.rs`:
- Around line 560-569: Update the doc comments for the predicate methods
is_scalar_shape, is_vector, is_matrix, and is_square to use backticks around
`true` (e.g., "Returns `true` if the buffer is 0D (a scalar).") so they match
the style of the existing predicate methods; leave the signatures and logic
unchanged and only modify the triple-slash comments above each function.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 334567c7-91a6-460e-b8e1-403ecab1d380

📥 Commits

Reviewing files that changed from the base of the PR and between 1de1da3 and f183ff3.

📒 Files selected for processing (2)
  • crates/mohu-buffer/src/buffer.rs
  • crates/mohu-buffer/tests/integration.rs

@prince0-7

Copy link
Copy Markdown
Author

Submitted a PR for this issue: #258

@mugiwaraluffy56

Copy link
Copy Markdown
Contributor

hi @prince0-7, thanks for adding these shape helpers. the api shape looks right, but this cannot merge while ci is red. please run rustfmt on the touched files and check the clippy output from the failing job. once those are green this should be easy to take, especially since the commit is already signed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Buffer::is_square() and Buffer::is_vector() convenience predicates

2 participants