mirror of
https://github.com/socathie/circomlib-ml.git
synced 2026-01-09 14:08:04 -05:00
Update README and add LeakyReLU circuit and test
This commit is contained in:
29
test/LeakyReLU.js
Normal file
29
test/LeakyReLU.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const chai = require("chai");
|
||||
const path = require("path");
|
||||
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
|
||||
const F1Field = require("ffjavascript").F1Field;
|
||||
const Scalar = require("ffjavascript").Scalar;
|
||||
exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
||||
const Fr = new F1Field(exports.p);
|
||||
|
||||
const assert = chai.assert;
|
||||
|
||||
describe("LeakyReLU layer test", function () {
|
||||
this.timeout(100000000);
|
||||
|
||||
it("3 nodes", async () => {
|
||||
const circuit = await wasm_tester(path.join(__dirname, "circuits", "LeakyReLU_test.circom"));
|
||||
|
||||
const INPUT = {
|
||||
"in": [Fr.e(-11),"0","3"],
|
||||
"out": [Fr.e(-4),"0","3"],
|
||||
"remainder": ["7","0","0"]
|
||||
}
|
||||
|
||||
const witness = await circuit.calculateWitness(INPUT, true);
|
||||
|
||||
assert(Fr.eq(Fr.e(witness[0]),Fr.e(1)));
|
||||
});
|
||||
});
|
||||
21
test/circuits/LeakyReLU_test.circom
Normal file
21
test/circuits/LeakyReLU_test.circom
Normal file
@@ -0,0 +1,21 @@
|
||||
pragma circom 2.0.0;
|
||||
|
||||
include "../../circuits/LeakyReLU.circom";
|
||||
|
||||
template leaky_relu_test() {
|
||||
signal input in[3];
|
||||
signal input out[3];
|
||||
signal input remainder[3];
|
||||
|
||||
component leaky_relu[3];
|
||||
|
||||
for (var i=0; i<3; i++) {
|
||||
leaky_relu[i] = LeakyReLU(3);
|
||||
|
||||
leaky_relu[i].in <== in[i];
|
||||
leaky_relu[i].out <== out[i];
|
||||
leaky_relu[i].remainder <== remainder[i];
|
||||
}
|
||||
}
|
||||
|
||||
component main = leaky_relu_test();
|
||||
Reference in New Issue
Block a user