Skip to content

Conversation

@WhoBrokeTheBuild
Copy link
Member

This builtin was never implemented, but the opcode was allocated and it existed in the original documentation. The similarity to numpy's reshape function means users might actually want to use this, and throwing a terse error is less than helpful.

This implements RESHAPE() with only the first two arguments of SOURCE and SHAPE. The optional arguments of PAD and ORDER described in the original documetnation are not implemented, and won't be included in the new documentation for this function.

TDI> reshape(1:6, [2, 3])
[[1,2], [3,4], [5,6]]

TDI> reshape(1:6, [3, 2])
[[1,2,3], [4,5,6]]

TDI> reshape(1:8, [2, 2, 2])
[[[1,2], [3,4]], [[5,6], [7,8]]]

TDI> reshape(reshape(1:8, [2, 4]), [8])
[1,2,3,4,5,6,7,8]

TDI> reshape([[1,2], [3,4]], [1, 4])
[[1], [2], [3], [4]]

@WhoBrokeTheBuild WhoBrokeTheBuild self-assigned this Jan 12, 2026
@WhoBrokeTheBuild WhoBrokeTheBuild added feature Indicates new feature requests or implementations tool/tdi Relates to the TDI language or prompts (tditest, tdic) core Relates to the core libraries and scripts labels Jan 12, 2026
Copy link
Contributor

@joshStillerman joshStillerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it points at the same memory - good
Do you check if it is the right size for the dimensions ?


new_array.aflags.coeff = 1;
new_array.dimct = dimct;
new_array.a0 = new_array.pointer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it points at the same memory - good
Do you check if it is the right size for the dimensions ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! That's done up on line 77, I compare the original count to the product of the shape, which should be the new size

This builtin was never implemented, but the opcode was allocated and it existed in the original documentation. The similarity to numpy's reshape function means users might actually want to use this, and throwing a terse error is less than helpful.

This implements RESHAPE() with only the first two arguments of SOURCE and SHAPE. The optional arguments of PAD and ORDER described in the original documetnation are not implemented, and won't be included in the new documentation for this function.

```
TDI> reshape(1:6, [2, 3])
[[1,2], [3,4], [5,6]]

TDI> reshape(1:6, [3, 2])
[[1,2,3], [4,5,6]]

TDI> reshape(1:8, [2, 2, 2])
[[[1,2], [3,4]], [[5,6], [7,8]]]

TDI> reshape(reshape(1:8, [2, 4]), [8])
[1,2,3,4,5,6,7,8]

TDI> reshape([[1,2], [3,4]], [1, 4])
[[1], [2], [3], [4]]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Relates to the core libraries and scripts feature Indicates new feature requests or implementations tool/tdi Relates to the TDI language or prompts (tditest, tdic)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants