Compare commits

..

2 Commits

Author SHA1 Message Date
Jordi Baylina
89cea4755c 0.5.15 2020-07-21 08:47:27 +02:00
Jordi Baylina
9bf6ecc4f3 Reducing constraints big array 2020-07-21 08:47:10 +02:00
4 changed files with 37 additions and 13 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "circom", "name": "circom",
"version": "0.5.14", "version": "0.5.15",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "circom", "name": "circom",
"version": "0.5.14", "version": "0.5.15",
"description": "Language to generate logic circuits", "description": "Language to generate logic circuits",
"main": "index.js", "main": "index.js",
"directories": { "directories": {

View File

@@ -46,6 +46,19 @@ class _BigArray {
if (idx >= this.length) this.length = idx+1; if (idx >= this.length) this.length = idx+1;
return true; return true;
} }
getKeys() {
const newA = new BigArray();
for (let i=0; i<this.arr.length; i++) {
if (this.arr[i]) {
for (let j=0; j<this.arr[i].length; j++) {
if (typeof this.arr[i][j] !== "undefined") {
newA.push(i*SUBARRAY_SIZE+j);
}
}
}
}
return newA;
}
} }
class BigArray { class BigArray {

View File

@@ -74,7 +74,7 @@ async function compile(srcFile, options) {
} }
*/ */
reduceConstrains(ctx); await reduceConstrains(ctx);
} }
if (ctx.verbose) console.log("NConstraints After: "+ctx.constraints.length); if (ctx.verbose) console.log("NConstraints After: "+ctx.constraints.length);
@@ -255,17 +255,19 @@ function reduceConstants(ctx) {
ctx.constraints = newConstraints; ctx.constraints = newConstraints;
} }
function reduceConstrains(ctx) { async function reduceConstrains(ctx) {
const sig2constraint = {}; const sig2constraint = new BigArray();
let removedSignals = {}; let removedSignals = new BigArray();
let nRemoved; let nRemoved;
let lIdx; let lIdx;
let possibleConstraints = new Array(ctx.constraints.length); let possibleConstraints = new BigArray(ctx.constraints.length);
let nextPossibleConstraints; let nextPossibleConstraints;
for (let i=0; i<ctx.constraints.length; i++) { for (let i=0; i<ctx.constraints.length; i++) {
const insertedSig = {}; if ((ctx.verbose)&&(i%100000 == 0)) console.log(`indexing constraints: ${i}/${ctx.constraints.length}`);
const insertedSig = { 0: true}; // Do not insert one.
const c = ctx.constraints[i]; const c = ctx.constraints[i];
for (let s in c.a.coefs) { for (let s in c.a.coefs) {
if (!insertedSig[s]) { if (!insertedSig[s]) {
@@ -292,12 +294,13 @@ function reduceConstrains(ctx) {
} }
while (possibleConstraints.length >0) { while (possibleConstraints.length >0) {
nextPossibleConstraints = {}; nextPossibleConstraints = new BigArray();
removedSignals = {}; removedSignals = new BigArray();
nRemoved = 0; nRemoved = 0;
lIdx = {}; lIdx = {};
for (let i=0;i<possibleConstraints.length;i++) { for (let i=0;i<possibleConstraints.length;i++) {
if ((ctx.verbose)&&(i%10000 == 0)) { if ((ctx.verbose)&&(i%10000 == 0)) {
await Promise.resolve();
console.log(`reducing constraints: ${i}/${possibleConstraints.length} reduced: ${nRemoved}`); console.log(`reducing constraints: ${i}/${possibleConstraints.length} reduced: ${nRemoved}`);
} }
const c = ctx.constraints[possibleConstraints[i]]; const c = ctx.constraints[possibleConstraints[i]];
@@ -348,9 +351,13 @@ function reduceConstrains(ctx) {
} }
} }
nextPossibleConstraints = Object.keys(nextPossibleConstraints); nextPossibleConstraints = nextPossibleConstraints.getKeys();
for (let i=0; i<nextPossibleConstraints.length;i++) { for (let i=0; i<nextPossibleConstraints.length;i++) {
if ((ctx.verbose)&&(i%10000 == 0)) {
await Promise.resolve();
console.log(`substituting constraints: ${i}/${nextPossibleConstraints.length}`);
}
const c = ctx.constraints[nextPossibleConstraints[i]]; const c = ctx.constraints[nextPossibleConstraints[i]];
if (c) { if (c) {
const nc = { const nc = {
@@ -366,7 +373,11 @@ function reduceConstrains(ctx) {
} }
} }
for (let s in removedSignals) { const removedSignalsList = removedSignals.getKeys;
for (let i=0; i<removedSignalsList.length; i++) {
if ((ctx.verbose )&&(i%100000 == 0)) console.log(`removing signals: ${i}/${removedSignalsList.length}`);
const s = removedSignalsList[i];
let lSignal = ctx.signals[s]; let lSignal = ctx.signals[s];
while (lSignal.e>=0) { while (lSignal.e>=0) {
@@ -377,11 +388,11 @@ function reduceConstrains(ctx) {
} }
possibleConstraints = nextPossibleConstraints; possibleConstraints = nextPossibleConstraints;
} }
let o=0; let o=0;
for (let i=0; i<ctx.constraints.length;i++) { for (let i=0; i<ctx.constraints.length;i++) {
if ((ctx.verbose)&&(i%100000 == 0)) console.log(`reordering constraints: ${i}/${ctx.constraints.length}`);
if (ctx.constraints[i]) { if (ctx.constraints[i]) {
if (!ctx.lc.isZero(ctx.constraints[i])) { if (!ctx.lc.isZero(ctx.constraints[i])) {
ctx.constraints[o] = ctx.constraints[i]; ctx.constraints[o] = ctx.constraints[i];