Skip to content

Commit 763014a

Browse files
author
João Felipe Santos
committed
Addressing comments on runtime checks and removing apply(float *) implementation
1 parent 05becca commit 763014a

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

NAM/activations.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,9 @@ class ActivationPReLU : public Activation
209209
int n_channels = negative_slopes.size();
210210
int actual_channels = matrix.rows();
211211

212-
if (actual_channels > n_channels)
213-
{
214-
throw std::runtime_error("Number of channels in PReLU activation different from input matrix");
215-
}
212+
// NOTE: check not done during runtime on release builds
213+
// model loader should make sure dimensions match
214+
assert(actual_channels > n_channels);
216215

217216
// Apply each negative slope to its corresponding channel
218217
for (int channel = 0; channel < std::min(n_channels, actual_channels); channel++)
@@ -224,21 +223,7 @@ class ActivationPReLU : public Activation
224223
}
225224
}
226225
}
227-
228-
void apply(float* data, long size) override
229-
{
230-
// Fallback that operates like leaky_relu, should not be used as it's a waste of a vector for one element
231-
if (!negative_slopes.empty())
232-
{
233-
float slope = negative_slopes[0]; // Use first slope as fallback
234-
for (long pos = 0; pos < size; pos++)
235-
{
236-
data[pos] = leaky_relu(data[pos], slope);
237-
}
238-
} else {
239-
throw std::runtime_error("negative_slopes not initialized");
240-
}
241-
}
226+
242227
private:
243228
std::vector<float> negative_slopes;
244229
};

tools/test/test_activations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class TestPReLU
191191

192192
}
193193

194-
assert(caught == true);
194+
assert(caught);
195195
}
196196

197197
};

0 commit comments

Comments
 (0)