Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-place naming convention #177

Open
certik opened this issue May 3, 2020 · 1 comment
Open

In-place naming convention #177

certik opened this issue May 3, 2020 · 1 comment
Labels
documentation Improvements or additions to documentation meta Related to this repository

Comments

@certik
Copy link
Member

certik commented May 3, 2020

We need to figure out a consistent naming convention for routines that return the result in-place, as many routines will have two versions: in-place (e.g., eig_inplace) and out-of-place (e.g. eig). I think a good idea is to have the out-of-place version the default (eig), and have special naming convention for in-place (eig_inplace or some of the other option from the list below).

This was originally discussed at #10 (comment). List of options for syntax (#10 (comment)):

  • eig_inplace
  • eig_i or eig_I
  • eigI

I'll update this list if more candidates are proposed.

A lot of people like eig_inplace. It's long, but presumably it won't be used as often as eig, and it is clear what it does.

Other languages:

I couldn't find any naming convention how NumPy and Matlab does it. Looks like only Julia has a naming convention for in-place?

Julia

out-of-place: svd
in-place: svd!

@certik certik changed the title Inplace naming convention In-place naming convention May 3, 2020
@ivan-pi
Copy link
Member

ivan-pi commented May 4, 2020

I couldn't find any naming convention how NumPy and Matlab does it. Looks like only Julia has a naming convention for in-place?

Certain functions in SciPy (perhaps also NumPy, but I couldn't find any) accept some logical arguments if they should overwrite the inputs or not. Take solve for instance:

 scipy.linalg.solve(a, b, sym_pos=False, lower=False, overwrite_a=False, overwrite_b=False, debug=None, check_finite=True, assume_a='gen', transposed=False)

For MATLAB I found this old blog post (https://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#8) which says that some of the built-in functions already obey in-place semantics (e.g. A=max(A,B) will not create an intermediate variable). Users can take advantage of this in their own functions (hoping the MATLAB JIT will do the right thing):

function y = myfunc(x)
y = sin(2*x.^2+3*x+4);

function x = myfuncIP(x)
x = sin(2*x.^2+3*x+4); 

Calling y = myfuncIP(x) would result in an error.

In the Eigen C++ library for linear algebra, they provide both options via template mechanisms and overloaded constructors (see https://eigen.tuxfamily.org/dox/group__InplaceDecomposition.html for details) :

PartialPivLU<Ref<MatrixXd> > lu(A); // in-place
PartialPivLU<MatrixXd> lu(A); // preserve A

@awvwgk awvwgk added documentation Improvements or additions to documentation meta Related to this repository labels Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation meta Related to this repository
Projects
None yet
Development

No branches or pull requests

3 participants