feat: add 1D array truncation, 2D matrix rendering, and numpy parameter support#257
Open
eng-ak wants to merge 1 commit into
Open
feat: add 1D array truncation, 2D matrix rendering, and numpy parameter support#257eng-ak wants to merge 1 commit into
eng-ak wants to merge 1 commit into
Conversation
…er support New features: - render_array: 1D list/array rendering with configurable truncation (array_truncate_threshold, array_truncate_end config options) - render_matrix: 2D matrix rendering using LaTeX matrix environments (matrix_environment config, default bmatrix; supports pmatrix, vmatrix, etc.) - 2D truncation: rows and columns independently controlled via scalar or (row, col) tuple -- uses \vdots, \cdots, \ddots at the truncation corner - set_truncation(): public helper accepting both int and tuple without set_option type restrictions - Vectors: column (nx1) and row (1xn) shapes handled automatically Bug fixes: - convert_parameter: extract raw Python values before swap_symbolic_calcs to prevent crashes when numpy arrays appear as ParameterLine values - latex_repr: check for sympy objects before arrays so sympy.Matrix is rendered correctly instead of falling into render_matrix Tests: - test_array_matrix.py: 112-test suite covering all new functions, truncation edge cases, numpy, pint units, convert_parameter guard, and set_truncation API
Author
|
Hi @connorferster, I noticed that many users have requested support for NumPy arrays, so I wanted to share my fork of handcalcs with array support for 1D arrays and matrix support for 2D arrays. I also implemented truncation for arrays, which may be useful for large arrays when you only want to output part of the matrix as an example calculation. Please feel free to review this feature and let me know if you would like me to modify the code. please see the demo file below to get an idea of how it works Best regards, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for rendering numpy arrays and matrices in handcalcs, along with a few bug fixes to handle edge cases when numpy types appear in parameter lines.
render_arrayfor 1D lists/arrays with configurable truncation viaarray_truncate_thresholdandarray_truncate_endconfig optionsrender_matrixfor 2D matrices using LaTeX matrix environments (matrix_environmentconfig, defaults tobmatrix; also supportspmatrix,vmatrix, etc.)(row, col)tuple, with\vdots,\cdots, and\ddotsat the truncation cornerset_truncation()as a public helper that accepts bothintandtuplewithout the type restrictions ofset_optionnx1) and row (1xn) vectors are handled automaticallyBug fixes
convert_parameterto extract raw Python values beforeswap_symbolic_calcs, preventing crashes when numpy arrays appear asParameterLinevalueslatex_reprto check for sympy objects before arrays, ensuringsympy.Matrixrenders correctly rather than being passed torender_matrixTest plan
test_array_matrix.pysuite (112 tests covering all new functions, truncation edge cases, numpy, pint units,convert_parameterguard, andset_truncationAPI)