srush / Tensor-Puzzles

Solve puzzles. Improve your pytorch.
MIT License
2.96k stars 242 forks source link

avoid cryptic SVG rendering error / check that solution output is actually a tensor #27

Open noahlt opened 5 months ago

noahlt commented 5 months ago

The problem: If the user's solution to a puzzle is a rank-0 tensor (eg, tensor(6)), running make_test results in a cryptic TypeError many levels deep in the SVG-rendering code. This is documented pretty well by @ikamensh in #23.

This solution: This change adds a check, torch.is_tensor(yours) and yours.ndim > 0, before adding the user's solution output to the data to be rendered to the SVG.

Caveats: The solution checker seems to accept tensor(6), tensor([6]), tensor([[6]]), equally. Before this change, the SVG-rendering code would error out before solution checker ran, so you could call that "failing". I don't completely understand the solution-checking code and I'm not sure whether that is intended behavior.

Hopefully this makes sense. I'm happy to discuss it or make changes if you'd like. Thanks in advance!