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

add :neg() :csub(tensor) :csub(scalar), inplace subtraction operators #392

Merged
merged 1 commit into from
Oct 21, 2015

Conversation

hughperkins
Copy link
Contributor

Use like this:

a = torch.Tensor(3,2):uniform()
b = torch.Tensor(3,2):uniform()

a:neg()           -- like a = -a,       but in-place
a:csub(1.5)       -- like a = a - 1.5,  but in-place
a:csub(b)         -- like a = a - b,    but in-place

@hughperkins
Copy link
Contributor Author

Hmmm, the TH C functions sub and csub can probably just wrap add and cadd, just with negative value.

@hughperkins
Copy link
Contributor Author

(Updated to be better factorized)

@hughperkins
Copy link
Contributor Author

(we could also implement neg by multiplying by -1, instead of putting - in the LAB_IMPLEMENT_BASIC_FUNCTION macro. Advantage: less weird than putting - in this macro parameters)

@andreaskoepf
Copy link
Contributor

@hughperkins Thanks a lot for creating the PR!

soumith added a commit that referenced this pull request Oct 21, 2015
add :neg() :csub(tensor) :csub(scalar), inplace subtraction operators
@soumith soumith merged commit 2546dc6 into torch:master Oct 21, 2015
@soumith
Copy link
Member

soumith commented Oct 21, 2015

I merged it, but realized that there's no documentation added. Can you send a follow-up PR with documentation.

@hughperkins
Copy link
Contributor Author

Fair point :-) Submitted pull request for this.

@hughperkins hughperkins deleted the inplace-subtraction branch October 22, 2015 10:22
colesbury pushed a commit to colesbury/torch7 that referenced this pull request Nov 3, 2016
add :neg() :csub(tensor) :csub(scalar), inplace subtraction operators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants