Skip to content

Commit

Permalink
Add relu and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
only4sim committed Oct 31, 2023
1 parent 7db1d0d commit 45b99aa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
35 changes: 35 additions & 0 deletions relu.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { relu } from './relu'; // Import your relu function from your implementation file

describe('relu', () => {
it('should apply ReLU activation correctly for positive input', () => {
// Define input and expected output for positive input
const input = 3; // Positive input
const expectedOutput = 3; // Expected output (same as input)

// Convert input to a Field (assuming you have a way to represent numbers as Fields)
const inputField = ...; // Convert input to a Field

// Call the relu function
const result = relu(inputField);

// Assert that the result matches the expected output
expect(result.toNumber()).toEqual(expectedOutput);
});

it('should apply ReLU activation correctly for negative input', () => {
// Define input and expected output for negative input
const input = -2; // Negative input
const expectedOutput = 0; // Expected output (ReLU turns negative input to zero)

// Convert input to a Field (assuming you have a way to represent numbers as Fields)
const inputField = ...; // Convert input to a Field

// Call the relu function
const result = relu(inputField);

// Assert that the result matches the expected output
expect(result.toNumber()).toEqual(expectedOutput);
});

// Add more test cases as needed
});
4 changes: 4 additions & 0 deletions relu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function relu(input) {
// If input is greater than or equal to zero, return input; otherwise, return zero.
return input.greaterThanOrEqual(0).ifElse(input, new Field(0));
}

0 comments on commit 45b99aa

Please sign in to comment.