Skip to content

Added multichannel PReLU#179

Merged
sdatkinson merged 6 commits into
sdatkinson:mainfrom
jfsantos:prelu
Jan 14, 2026
Merged

Added multichannel PReLU#179
sdatkinson merged 6 commits into
sdatkinson:mainfrom
jfsantos:prelu

Conversation

@jfsantos

Copy link
Copy Markdown
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

@sdatkinson sdatkinson left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Few changes noted

Comment thread NAM/activations.h Outdated
Comment thread NAM/activations.h Outdated
Comment thread NAM/activations.h Outdated

@sdatkinson sdatkinson left a comment

Copy link
Copy Markdown
Owner

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?

Comment thread NAM/activations.h Outdated
Comment thread NAM/activations.h
// 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
Copy Markdown
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.

Comment thread NAM/activations.h Outdated
Comment thread tools/test/test_activations.cpp Outdated
Comment thread tools/test/test_activations.cpp Outdated
// 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
Copy Markdown
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...

Comment thread tools/test/test_activations.cpp Outdated

@sdatkinson sdatkinson left a comment

Copy link
Copy Markdown
Owner

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