Skip to content

fix: correct reshapeArray for N-dimensional tensors and restore gas estimation#3

Open
golldyck wants to merge 2 commits intoOpenGradient:mainfrom
golldyck:fix/reshape-array-and-gas
Open

fix: correct reshapeArray for N-dimensional tensors and restore gas estimation#3
golldyck wants to merge 2 commits intoOpenGradient:mainfrom
golldyck:fix/reshape-array-and-gas

Conversation

@golldyck
Copy link
Copy Markdown

@golldyck golldyck commented Apr 8, 2026

Problem

reshapeArray in src/utils.ts uses shape.slice(0, -1) which removes the last dimension instead of the first, silently corrupting data for any tensor with 3+ dimensions. Additionally, llmChat in src/client.ts has gas estimation commented out and replaced with a hardcoded value.

Fix

Changed shape.slice(0, -1) to shape.slice(1) so the function correctly passes remaining dimensions when recursing. Restored proper gas estimation for llmChat and replaced var with const.

Changes

  • src/utils.ts — Fixed reshapeArray to use shape.slice(1) instead of shape.slice(0, -1), correctly consuming the first dimension and passing the rest
  • src/client.ts — Restored estimateGas() call in llmChat (was hardcoded to 100000), replaced var with const on line ~142

Testing

  • Verified reshapeArray([1..24], [2,3,4]) produces correct 2x3x4 nested array
  • Confirmed infer, llmCompletion, and llmChat all use consistent gas estimation
  • Checked no other usages of reshapeArray are affected by the fix

Closes #4

@golldyck
Copy link
Copy Markdown
Author

golldyck commented Apr 8, 2026

Hi @adambalogh @kylexqian — this PR fixes bugs I found during a full audit of OpenGradient's public repositories. Would appreciate a review when you get a chance. Happy to address any feedback. Thanks!

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.

Bug: reshapeArray silently corrupts data for 3+ dimensional tensors

1 participant