Skip to content

Conversation

@jfsantos
Copy link
Contributor

Adding a multichannel PReLU to activations. This activation is different from the others because it can have one negative slope for each channel, so it needs to know how many channels the input has. API for activation was extended to include an apply(MatrixXf matrix) for that case. The basic apply(float* data, long size) call will behave exactly like LeakyReLU and ignore the input shape.

Developed with support and sponsorship from TONE3000

@jfsantos jfsantos mentioned this pull request Jan 13, 2026
5 tasks
Copy link
Owner

@sdatkinson sdatkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few changes noted

Copy link
Owner

@sdatkinson sdatkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_per_channel_behavior seems sus. Mind checking for me?

// Apply the negative slope to all time steps in this channel
for (int time_step = 0; time_step < matrix.rows(); time_step++)
{
matrix(channel, time_step) = leaky_relu(matrix(channel, time_step), negative_slopes[channel]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Feels inefficient since there's no vectorized ops being used, but we'll see.

// Channel 1 (slope = 0.05):
assert(fabs(data(1, 0) - (-0.10f)) < 1e-6); // -2.0 * 0.05 = -0.10
assert(fabs(data(1, 1) - (-0.025f)) < 1e-6); // -0.5 * 0.05 = -0.025
assert(fabs(data(1, 2) - 0.0f) < 1e-6); // 0.0 (unchanged)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange that these would pass if I'm not mistaken...

Copy link
Owner

@sdatkinson sdatkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

@sdatkinson sdatkinson merged commit 0516183 into sdatkinson:main Jan 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants