Skip to content

Commit

Permalink
add exp, log for ndarray
Browse files Browse the repository at this point in the history
  • Loading branch information
Kublai-Jing committed Oct 27, 2015
1 parent db1a5b5 commit 87c2492
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ndarray/unary_function-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ MXNET_REGISTER_TBLOB_FUN(sqrt, XPU)
.set_gradient(XPU::kDevMask, UnaryBackwardUseOut_<XPU, square_root_grad>, true)
.describe("Take square root of the src");

// exp
MXNET_REGISTER_TBLOB_FUN(exp, XPU)
.set_function(XPU::kDevMask, UnaryForward_<XPU, op::mshadow_op::exp>, true)
.set_gradient(XPU::kDevMask, UnaryBackwardUseOut_<XPU, op::mshadow_op::exp_grad>, true)
.describe("Take exp of the src");

//log
MXNET_REGISTER_TBLOB_FUN(log, XPU)
.set_function(XPU::kDevMask, UnaryForward_<XPU, op::mshadow_op::log>, true)
.set_gradient(XPU::kDevMask, UnaryBackwardUseOut_<XPU, op::mshadow_op::log_grad>, true)
.describe("Take log of the src");

// L2 norm
MXNET_REGISTER_TBLOB_FUN(norm, XPU)
.set_function(XPU::kDevMask, L2Norm<XPU>, false, false)
Expand Down
25 changes: 25 additions & 0 deletions src/operator/mshadow_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,31 @@ struct tanh_grad {
}
};


struct exp {
MSHADOW_XINLINE static real_t Map(real_t a) {
return expf(a);
}
};
struct exp_grad {
MSHADOW_XINLINE static real_t Map(real_t a) {
return expf(a);
}
};

struct log {
MSHADOW_XINLINE static real_t Map(real_t a) {
return logf(a);
}
};
struct log_grad {
MSHADOW_XINLINE static real_t Map(real_t a) {
return 1.0f/a;
}
};



struct square {
MSHADOW_XINLINE static real_t Map(real_t a) {
return a * a;
Expand Down

0 comments on commit 87c2492

Please sign in to comment.