arnaucube
arnaucube/circomPublic Self-hosted repository
Reducing constraints big array
Jordi Baylina jordi@baylina.cat
Tue, 21 Jul 2020 08:47:10 +0200
commit

9bf6ecc4f380262a0a6f301a6a38de3c999d6a57

parent

59d591c988eb348bb4d0389c8a9897acd9753954

2 files changed, 35 insertions(+), 11 deletions(-)

jump to
M src/bigarray.js → src/bigarray.js

@@ -46,6 +46,19 @@ this.arr[idx1][idx2] = value;

if (idx >= this.length) this.length = idx+1; 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 {
M src/compiler.js → src/compiler.js

@@ -74,7 +74,7 @@ reduceConstrains(ctx);

} */ - reduceConstrains(ctx); + await reduceConstrains(ctx); } if (ctx.verbose) console.log("NConstraints After: "+ctx.constraints.length);

@@ -255,17 +255,19 @@ }

ctx.constraints = newConstraints; } -function reduceConstrains(ctx) { - const sig2constraint = {}; - let removedSignals = {}; +async function reduceConstrains(ctx) { + const sig2constraint = new BigArray(); + let removedSignals = new BigArray(); let nRemoved; let lIdx; - let possibleConstraints = new Array(ctx.constraints.length); + let possibleConstraints = new BigArray(ctx.constraints.length); let nextPossibleConstraints; 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]; for (let s in c.a.coefs) { if (!insertedSig[s]) {

@@ -292,12 +294,13 @@ possibleConstraints[i] = i;

} while (possibleConstraints.length >0) { - nextPossibleConstraints = {}; - removedSignals = {}; + nextPossibleConstraints = new BigArray(); + removedSignals = new BigArray(); nRemoved = 0; lIdx = {}; for (let i=0;i<possibleConstraints.length;i++) { if ((ctx.verbose)&&(i%10000 == 0)) { + await Promise.resolve(); console.log(`reducing constraints: ${i}/${possibleConstraints.length} reduced: ${nRemoved}`); } const c = ctx.constraints[possibleConstraints[i]];

@@ -348,9 +351,13 @@ }

} } - nextPossibleConstraints = Object.keys(nextPossibleConstraints); + nextPossibleConstraints = nextPossibleConstraints.getKeys(); 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]]; if (c) { const nc = {

@@ -366,7 +373,11 @@ }

} } - 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]; while (lSignal.e>=0) {

@@ -377,11 +388,11 @@ lSignal.c = ctx.stDISCARDED;

} possibleConstraints = nextPossibleConstraints; - } let o=0; 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.lc.isZero(ctx.constraints[i])) { ctx.constraints[o] = ctx.constraints[i];