This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4e2178
commit 3674aef
Showing
3 changed files
with
119 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*! | ||
* Copyright (c) 2015 by Contributors | ||
* \file op.h | ||
* \brief extra mshadow operation for mxnet | ||
* \author Bing Xu | ||
*/ | ||
#ifndef SRC_OPERATOR_OP_H_ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
#define SRC_OPERATOR_OP_H_ | ||
#pragma once | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
#include <algorithm> | ||
|
||
namespace mxnet { | ||
/*! \brief operations for ActivationLayer */ | ||
namespace op { | ||
struct identity { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return a; | ||
} | ||
}; | ||
struct identity_grad { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return 1.0f; | ||
} | ||
}; | ||
|
||
/*! \brief sigmoid unit */ | ||
struct sigmoid { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return 1.0f / (1.0f + expf(-a)); | ||
} | ||
}; | ||
struct sigmoid_grad { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return a * (1.0f - a); | ||
} | ||
}; | ||
/*! \brief Rectified Linear Operation */ | ||
struct relu { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return std::max(a, 0.0f); | ||
} | ||
}; | ||
struct relu_grad { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return a > 0.0f ? 1.0f : 0.0f; | ||
} | ||
}; | ||
|
||
/*! \brief Leaky ReLU Operation */ | ||
struct xelu { | ||
MSHADOW_XINLINE static real_t Map(real_t a, real_t b) { | ||
return a > 0 ? a : a / b; | ||
} | ||
}; | ||
|
||
struct xelu_grad { | ||
MSHADOW_XINLINE static real_t Map(real_t a, real_t b) { | ||
return a > 0 ? 1 : 1.0f / b; | ||
} | ||
}; | ||
|
||
struct tanh { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return tanhf( a ); | ||
} | ||
}; | ||
|
||
struct tanh_grad { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return 1.0f - a * a; | ||
} | ||
}; | ||
|
||
|
||
struct square { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return a * a; | ||
} | ||
}; | ||
|
||
/*! \brief used for generate Bernoulli mask */ | ||
struct threshold { | ||
MSHADOW_XINLINE static real_t Map(real_t a, real_t b) { | ||
return a < b ? 1.0f : 0.0f; | ||
} | ||
}; | ||
|
||
/*! \brief used for generate element of power */ | ||
struct power { | ||
MSHADOW_XINLINE static real_t Map(real_t a, real_t b) { | ||
return powf( a, b ); | ||
} | ||
}; | ||
|
||
/*!\ \brief used for generate element sqrt */ | ||
struct square_root { | ||
MSHADOW_XINLINE static real_t Map(real_t a) { | ||
return sqrt(a); | ||
} | ||
}; | ||
|
||
} // namespace op | ||
} // namespace mxnet | ||
|
||
#endif // SRC_OPERATOR_OP_H_ | ||
|
||
|
||
|
do MXNET_OPERATOR_OP_H_