latexify_py icon indicating copy to clipboard operation
latexify_py copied to clipboard

Showing some special arrays

Open odashi opened this issue 2 years ago • 2 comments

Ref: #78

We can also support showing some special array functions as a fixed, well-known form. For example, ndarray.zeros((2, 3)) --> $\mathbf{0}$ or $\mathbf{0}^{2 \times 3}$

odashi avatar Nov 10 '22 01:11 odashi

Similar:

np.eye(N, M=None, k=0) --> $I_N$

np.identity(N) --> $I_N$

Casper-Guo avatar Nov 10 '22 02:11 Casper-Guo

I will do this once i figure out CI/CD on my other PR.

Once NDArray support is done, we can do the same for np.transpose() and np.inv() etc. as well

Casper-Guo avatar Nov 16 '22 17:11 Casper-Guo

What is the best place to check for function names for this issue? Should this be done in the function_expander.py file following #132 or should it be checked in visit_Call in function_codegen.py following #118 ?

Casper-Guo avatar Nov 28 '22 14:11 Casper-Guo

@Casper-Guo If you are planning to implement this on FunctionExpander, function_expander_test.py is the best place I think.

odashi avatar Nov 28 '22 22:11 odashi

Sorry I didn’t meant checking as in writing test cases. I was asking where best to extract numpy function names and generate the appropriate Latex. The two linked PRs seem to do this in different files

We will have a PR ready for this within the week

Cc: @lakeblair

Casper-Guo avatar Nov 29 '22 15:11 Casper-Guo

@odashi I just created a pull request for this feature. I wasn't too sure the best place to implement this feature so I added them to visit_call() in function_codegen.py. Could you review?

LakeBlair avatar Dec 04 '22 22:12 LakeBlair

@LakeBlair I checked it now. Overall it looks great, but it also requires some refactoring to support complete syntax and error handling. If you are okay, I will fix remaining things on behalf of you.

odashi avatar Dec 05 '22 01:12 odashi

@odashi I added a generalization for np.zeros function, please check my most recent commit. Additionally, for your second bullet point

I think these processes don't work if the subtree has unexpected syntax. It usually happens when users gave other functions with the same name. As the AST varies, we basically need complete check of the underlying structure of the given subtree.

I‘d love to implement a complete check for the subtree structure. Do you know in which file(s) I can find a similar example for such implementation?

LakeBlair avatar Dec 05 '22 05:12 LakeBlair

Okay, let's move onto the pull request to continue the discussion.

odashi avatar Dec 05 '22 05:12 odashi