Skip to content

Incorrect sum for overlapping as_strided views #4573

Description

@sofinvalery

Regression from #3475. Noticed it while prepping for an interview:) This returns 140 on CPU and Metal instead of the expected 152.

import mlx.core as mx
x = mx.arange(16, dtype=mx.float32) ** 2
y = mx.as_strided(x, (2, 2, 2), (1, 1, 5))
print(mx.sum(y).item())

The element count equals the memory span, but the view has overlaps and gaps. It is incorrectly marked contiguous, so the reduction sums addresses 0–7.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions