mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
git-subtree-dir: torch/lib/THNN git-subtree-mainline:c3f0c1e2e0git-subtree-split:4fe7059a31
28 lines
622 B
C
28 lines
622 B
C
#ifndef TH_GENERIC_FILE
|
|
#define TH_GENERIC_FILE "generic/Abs.c"
|
|
#else
|
|
|
|
void THNN_(Abs_updateOutput)(
|
|
THNNState *state,
|
|
THTensor *input,
|
|
THTensor *output)
|
|
{
|
|
THTensor_(resizeAs)(output, input);
|
|
THTensor_(abs)(output, input);
|
|
}
|
|
|
|
void THNN_(Abs_updateGradInput)(
|
|
THNNState *state,
|
|
THTensor *input,
|
|
THTensor *gradOutput,
|
|
THTensor *gradInput)
|
|
{
|
|
THTensor_(resizeAs)(gradInput, input);
|
|
TH_TENSOR_APPLY3(real, gradInput, real, gradOutput, real, input,
|
|
real z = *input_data;
|
|
*gradInput_data = *gradOutput_data * (z >= 0 ? 1 : -1);
|
|
);
|
|
}
|
|
|
|
#endif
|