void LogLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { NeuronLayer<Dtype>::LayerSetUp(bottom, top); const Dtype base = this->layer_param_.log_param().base(); if (base != Dtype(-1)) { CHECK_GT(base, 0) << "base must be strictly positive."; } // If base == -1, interpret the base as e and set log_base = 1 exactly. // Otherwise, calculate its log explicitly. const Dtype log_base = (base == Dtype(-1)) ? Dtype(1) : log(base); CHECK(!_isnanf(log_base)) << "NaN result: log(base) = log(" << base << ") = " << log_base; CHECK(_finitef(log_base)) << "Inf result: log(base) = log(" << base << ") = " << log_base; base_scale_ = Dtype(1) / log_base; CHECK(!_isnanf(base_scale_)) << "NaN result: 1/log(base) = 1/log(" << base << ") = " << base_scale_; CHECK(_finitef(base_scale_)) << "Inf result: 1/log(base) = 1/log(" << base << ") = " << base_scale_; input_scale_ = this->layer_param_.log_param().scale(); input_shift_ = this->layer_param_.log_param().shift(); backward_num_scale_ = input_scale_ / log_base; }
extern "C" int __cdecl __isnanf(float x) { return _finitef(x)?0:1; }
int __cdecl main(int argc, char **argv) { /*non-finite numbers*/ UINT32 lsnan = 0xffffffffu; UINT32 lqnan = 0x7fffffffu; UINT32 lneginf = 0xff800000u; UINT32 lposinf = 0x7f800000u; float snan = TO_FLOAT(lsnan); float qnan = TO_FLOAT(lqnan); float neginf = TO_FLOAT(lneginf); float posinf = TO_FLOAT(lposinf); /*finite numbers*/ UINT32 lnegunnormalized = 0x807fffffu; UINT32 lposunnormalized = 0x007fffffu; UINT32 lnegzero = 0x80000000u; float negunnormalized = TO_FLOAT(lnegunnormalized); float posunnormalized = TO_FLOAT(lposunnormalized); float negzero = TO_FLOAT(lnegzero); /* * Initialize the PAL and return FAIL if this fails */ if (PAL_Initialize(argc, argv) != 0) { return FAIL; } /*non-finite numbers*/ if (_finitef(snan) || _finitef(qnan)) { Fail("_finitef() found NAN to be finite.\n"); } if (_finitef(neginf)) { Fail("_finitef() found negative infinity to be finite.\n"); } if (_finitef(posinf)) { Fail("_finitef() found infinity to be finite.\n"); } /*finite numbers*/ if (!_finitef(negunnormalized)) { Fail("_finitef() found a negative unnormalized value to be infinite.\n"); } if (!_finitef(posunnormalized)) { Fail("_finitef() found an unnormalized value to be infinite.\n"); } if (!_finitef(negzero)) { Fail("_finitef() found negative zero to be infinite.\n"); } if (!_finitef(+0.0f)) { Fail("_finitef() found zero to be infinite.\n"); } if (!_finitef(-123.456f)) { Fail("_finitef() found %f to be infinite.\n", -123.456f); } if (!_finitef(+123.456f)) { Fail("_finitef() found %f to be infinite.\n", +123.456f); } PAL_Terminate(); return PASS; }