Skip to content

Commit a5c203e

Browse files
author
emmanuel maggiori
committed
Solving issue with exp layer with base e
Deleting space after line Adding test
1 parent beb5cae commit a5c203e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/caffe/layers/exp_layer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ void ExpLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
2323
const Dtype input_scale = this->layer_param_.exp_param().scale();
2424
const Dtype input_shift = this->layer_param_.exp_param().shift();
2525
inner_scale_ = log_base * input_scale;
26-
outer_scale_ = (input_shift == Dtype(0)) ? Dtype(1) : pow(base, input_shift);
26+
outer_scale_ = (input_shift == Dtype(0)) ? Dtype(1) :
27+
( (base != Dtype(-1)) ? pow(base, input_shift) : exp(input_shift) );
2728
}
2829

2930
template <typename Dtype>

src/caffe/test/test_neuron_layer.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,26 @@ TYPED_TEST(NeuronLayerTest, TestExpGradient) {
394394
this->TestExpGradient(kBase, kScale, kShift);
395395
}
396396

397+
TYPED_TEST(NeuronLayerTest, TestExpLayerWithShift) {
398+
typedef typename TypeParam::Dtype Dtype;
399+
// Test default base of "-1" -- should actually set base := e,
400+
// with a non-zero shift
401+
const Dtype kBase = -1;
402+
const Dtype kScale = 1;
403+
const Dtype kShift = 1;
404+
this->TestExpForward(kBase, kScale, kShift);
405+
}
406+
407+
TYPED_TEST(NeuronLayerTest, TestExpGradientWithShift) {
408+
typedef typename TypeParam::Dtype Dtype;
409+
// Test default base of "-1" -- should actually set base := e,
410+
// with a non-zero shift
411+
const Dtype kBase = -1;
412+
const Dtype kScale = 1;
413+
const Dtype kShift = 1;
414+
this->TestExpGradient(kBase, kScale, kShift);
415+
}
416+
397417
TYPED_TEST(NeuronLayerTest, TestExpLayerBase2) {
398418
typedef typename TypeParam::Dtype Dtype;
399419
const Dtype kBase = 2;

0 commit comments

Comments
 (0)