Update README and add LeakyReLU circuit and test

This commit is contained in:
drCathieSo.eth
2024-02-03 22:47:27 +08:00
parent b056c47b75
commit 3c60d84d73
4 changed files with 70 additions and 1 deletions

29
test/LeakyReLU.js Normal file
View 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)));
});
});

View 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();