Skip to content

Tensor v1: contiguous N-D arrays #21

Description

@matajoh

Problem

bocpy ships a dense 2-D Matrix and nothing else. Anything users do that is naturally N-dimensional — image stacks, batched feature tensors, multi-channel audio, simulation grids, anything with a leading batch axis — has to be flattened by hand or coordinated as a Python list of Matrix objects. Both lose the in-place, cown-friendly arithmetic that makes Matrix worth using in the first place.

Desired functionality

A first-class Tensor Python type with arbitrary-rank contiguous storage of doubles, the same arithmetic surface as Matrix (elementwise binary, elementwise unary, scalar binary, aggregates with optional axis=), and the same cown / sub-interpreter round-trip story. Users should be able to put a Tensor inside a Cown, mutate it from a behavior, and observe the change in the next behavior, exactly as they do today with Matrix.

Constraints

  • Contiguous storage only — no strides, no views, no transpose-without-copy.
  • Same-shape binary ops only; mismatched shapes raise immediately.
  • No matmul on Tensor. Rank-2 linear algebra stays on Matrix.
  • Matrix is untouched by this work.

Out of scope

Broadcasting, full Matrix-parity indexing, Matrix/Tensor unification, views, reshape, fancy indexing.

Open questions

  • Are rank-0 tensors a valid shape?
  • Does a rank-reducing aggregate on a rank-k Tensor always return a rank-k-1 Tensor, including the rank-1 → rank-0 case?
  • Constructor shape: a single positional shape tuple, named factory methods, or both?

Metadata

Metadata

Assignees

No one assigned

    Labels

    mathsWork on the maths module

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions