mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-07 03:06:42 +01:00
Reducing constraints big array
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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];
|
||||||
|
|||||||
Reference in New Issue
Block a user