Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
support 1D inputs in leaky relu
Browse files Browse the repository at this point in the history
  • Loading branch information
Hao Jin committed Jul 21, 2018
1 parent 11b69f2 commit fcf0ae6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/operator/leaky_relu-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class LeakyReLUOp : public Operator {
Tensor<xpu, 3, DType> out;
Tensor<xpu, 3, DType> mask;
int n = in_data[leakyrelu::kData].shape_[0];
int k = in_data[leakyrelu::kData].shape_[1];
int k = (in_data[leakyrelu::kData].ndim() > 1) ? in_data[leakyrelu::kData].shape_[1] : 1;
Shape<3> dshape = Shape3(n, k, in_data[leakyrelu::kData].Size()/n/k);
data = in_data[leakyrelu::kData].get_with_shape<xpu, 3, DType>(dshape, s);
out = out_data[leakyrelu::kOut].get_with_shape<xpu, 3, DType>(dshape, s);
Expand Down Expand Up @@ -207,7 +207,7 @@ class LeakyReLUOp : public Operator {
Tensor<xpu, 3, DType> grad;
Tensor<xpu, 3, DType> mask;
int n = out_grad[leakyrelu::kOut].shape_[0];
int k = out_grad[leakyrelu::kOut].shape_[1];
int k = (out_grad[leakyrelu::kOut].ndim() > 1) ? out_grad[leakyrelu::kOut].shape_[1] : 1;
Shape<3> dshape = Shape3(n, k, out_grad[leakyrelu::kOut].Size()/n/k);
grad = out_grad[leakyrelu::kOut].get_with_shape<xpu, 3, DType>(dshape, s);
gdata = in_grad[leakyrelu::kData].get_with_shape<xpu, 3, DType>(dshape, s);
Expand Down
3 changes: 2 additions & 1 deletion tests/python/unittest/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ def fleaky_relu_grad(grad, x, y, act_type, slope=0.25):
elif act_type == 'leaky':
out[neg_indices] = slope
return out * grad
shape = (3, 4)
ndim = random.randint(1, 4)
shape = rand_shape_nd(ndim)
x = mx.symbol.Variable("x")
slp = 0.25
for dtype in [np.float16, np.float32, np.float64]:
Expand Down

0 comments on commit fcf0ae6

Please sign in to comment.