Skip to content

Bug: reshapeArray silently corrupts data for 3+ dimensional tensors #4

@golldyck

Description

@golldyck

Problem

The reshapeArray function in src/utils.ts (line ~208) uses shape.slice(0, -1) when recursing into sub-dimensions. This removes the last dimension instead of the first (already consumed) dimension, causing silent data corruption for any tensor with 3 or more dimensions.

Steps to Reproduce

import { reshapeArray } from './utils';

const flat = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24];
const result = reshapeArray(flat, [2, 3, 4]);
// Expected: [[[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16],[17,18,19,20],[21,22,23,24]]]
// Actual: incorrectly shaped array due to wrong dimension slicing

Root Cause

Line 208: const subShape = shape.slice(0, -1);

For shape [2, 3, 4]:

  • Current (broken): consumes dim 0 (size=2), recurses with [2, 3] — reuses the already-consumed dimension
  • Correct: consumes dim 0 (size=2), recurses with [3, 4] — passes remaining dimensions

Fix: change to shape.slice(1)

Additional Issues

  • src/client.ts line ~302: llmChat has gas estimation commented out, replaced with hardcoded 100000. The infer and llmCompletion methods properly use estimateGas()
  • src/client.ts line ~142: uses var instead of const

Impact

Critical — any user working with 3D+ tensor model outputs through the TypeScript SDK gets silently corrupted data with no error or warning. This affects ML model inference results.

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