Skip to content

[PyMNN:Bugfix] Honor shape overrides in array-like creation - #5017

Closed
hulkbig wants to merge 1 commit into
alibaba:masterfrom
hulkbig:feature/numpy-like-shape
Closed

hulkbig wants to merge 1 commit into
alibaba:masterfrom
hulkbig:feature/numpy-like-shape

Conversation

@hulkbig

@hulkbig hulkbig commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Honor an explicit shape in empty_like, full_like, ones_like, and zeros_like when using the default order='K'.
  • Preserve dtype selection and the existing behavior when shape is omitted.
  • Extend the existing array-creation test with shape overrides instead of adding a separate test module.

The shared helper currently checks order != 'K' before accepting shape, so the documented override is silently ignored with the default order. For example, ones_like(a, shape=(3,)) retains a (2, 2) input shape instead of returning (3,).

Validation

  • The extended existing regression fails on the original wrapper (17 failures) and passes with this change.
  • An external 576-case matrix covers four APIs, omitted/K/C order, dtype inheritance and overrides, multiple template/result shapes, and template immutability. All shape/dtype/input checks pass with the change; 432 initialized-value checks also pass. empty_like values are intentionally not read.
  • These are local CPU tests using a source-built Expr binding, pristine older 45a002ab19f9021e982ed153826586bb79e41837 native libraries and a namespace bootstrap. They are not full-package validation, a latest-native-baseline rebuild, GPU/hardware coverage or online CI.

Scope

empty_like(shape=()) is covered. Scalar filled-array creation (shape=() or shape=[]) has an existing limitation in full (also present with order='C') and is not addressed here; this does not claim support for every shape. No native backend or order/layout behavior is changed.

The added regression covers a documented option absent from the existing test and exercises the shared helper through all four callers.

Review

AI-assisted implementation and testing. A separate reviewer tested 384 additional cases, including integer shape overrides: all shape/dtype/template checks and 288 initialized-value checks passed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant