code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
toString(format = Format.EXACT) {
let data = this.rows().
map(row => row.
map(e => e.toString(format)).
join(format.itemSeparator)).
join("}" + format.itemSeparator + "{");
return "{{" + data + "}}";
} | Returns a text representation of the receiving matrix.
(It uses curly braces so you can paste it into wolfram alpha.)
@param {=Format} format
@returns {!string} | toString | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static parse(text) {
text = text.replace(/\s/g, "");
if (text.length < 4 || text.substr(0, 2) !== "{{" || text.substr(text.length - 2, 2) !== "}}") {
throw new Error("Not surrounded by {{}}.");
}
// Some kind of recursive descent parser would be a better idea, but here we a... | @param {!string} text
@returns {!Matrix}
@throws | parse | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static generate(width, height, coefficientRowColGenerator) {
let buf = new Float64Array(width*height*2);
for (let r = 0; r < height; r++) {
for (let c = 0; c < width; c++) {
let k = (r*width + c)*2;
let v = coefficientRowColGenerator(r, c);
buf... | Returns a matrix of the given dimensions, using the given function to generate the coefficients.
@param {!int} width
@param {!int} height
@param {!function(row: !int, col: !int): (!number|!Complex)} coefficientRowColGenerator
@returns {!Matrix} | generate | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static generateDiagonal(size, coefficientFunc) {
let buf = new Float64Array(size*size*2);
for (let i = 0; i < size; i++) {
let k = i*(size+1)*2;
let v = coefficientFunc(i);
buf[k] = Complex.realPartOf(v);
buf[k+1] = Complex.imagPartOf(v);
}
... | Returns a diagonal matrix of the given size, using the given function to generate the diagonal coefficients.
@param {!int} size
@param {!function(!int): (!number|!Complex)} coefficientFunc
@returns {!Matrix} | generateDiagonal | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static generateTransition(size, transitionFunc) {
let buf = new Float64Array(size*size*2);
for (let c = 0; c < size; c++) {
let r = transitionFunc(c);
let k = (r*size + c)*2;
buf[k] = 1;
}
return new Matrix(size, size, buf);
} | Returns a matrix of the given size, with each column being mapped to a row by the transition function.
@param {!int} size
@param {!function(!int): !int} transitionFunc
@returns {!Matrix} | generateTransition | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static zero(width, height) {
return new Matrix(width, height, new Float64Array(width*height*2));
} | Returns a zero matrix of the given size.
@param {!number} width
@param {!number} height
@returns {!Matrix} | zero | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static solo(coef) {
return new Matrix(1, 1, new Float64Array([Complex.realPartOf(coef), Complex.imagPartOf(coef)]));
} | Returns a 1x1 matrix containing the given value.
@param {!number|!Complex} coef
@returns {!Matrix} | solo | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static square(...coefs) {
Util.need(Array.isArray(coefs), "Array.isArray(coefs)", arguments);
let n = Math.round(Math.sqrt(coefs.length));
Util.need(n * n === coefs.length, "Matrix.square: non-square number of arguments");
return Matrix.generate(n, n, (r, c) => coefs[r * n + c]);
} | Converts the given square block of coefficients into a square complex matrix.
@param {!number|!Complex} coefs The coefficients of the matrix,
arranged in a flat array of square length with the coefficients (which can be numeric or complex) in row order.
@returns {!Matrix} | square | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static col(...coefs) {
Util.need(Array.isArray(coefs), "Array.isArray(coefs)", arguments);
return Matrix.generate(1, coefs.length, r => coefs[r]);
} | Converts the array of complex coefficients into a column vector.
@param {!number|!Complex} coefs
@returns {!Matrix} | col | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static row(...coefs) {
Util.need(Array.isArray(coefs), "Array.isArray(coefs)", arguments);
return Matrix.generate(coefs.length, 1, (r, c) => coefs[c]);
} | Converts the array of complex coefficients into a row vector.
@param {!number|!Complex} coefs
@returns {!Matrix} | row | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
width() {
return this._width;
} | Returns the width of the receiving matrix.
@returns {!int} | width | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
height() {
return this._height;
} | Returns the height of the receiving matrix.
@returns {!int} | height | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
isUnitary(epsilon) {
let n = this.width();
if (this.height() !== n) {
return false;
}
return this.times(this.adjoint()).isApproximatelyEqualTo(Matrix.identity(n), epsilon);
} | Determines if the matrix is approximately unitary or not.
@param {!number} epsilon Distance away from unitary the matrix is allowed to be. Defaults to 0.
@returns {!boolean} | isUnitary | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
isPhasedPermutation(epsilon = 0) {
if (this._width !== this._height) {
return false;
}
let n = this._width;
let colCounts = new Uint32Array(n);
let rowCounts = new Uint32Array(n);
// Count number of non-zero elements in each row and column.
for (let ... | Determines if the matrix can be factored into a permutation matrix times a diagonal matrix.
@param {!number=} epsilon
@returns {!boolean} | isPhasedPermutation | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
isApproximatelyHermitian(epsilon) {
if (this._width !== this._height) {
return false;
}
for (let c = 0; c < this._width; c++) {
for (let r = 0; r < this._height; r++) {
let i = (this._width*r + c)*2;
let j = (this._width*c + r)*2;
... | Determines if the matrix is approximately equal to its own conjugate transpose or not.
@param {!number} epsilon Maximum error per entry.
@returns {!boolean} | isApproximatelyHermitian | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
isIdentity(epsilon=0) {
if (this._width !== this._height) {
return false;
}
for (let c = 0; c < this._width; c++) {
for (let r = 0; r < this._height; r++) {
let i = (this._width*r + c)*2;
let dr = Math.abs(this._buffer[i] - (r === c ? 1 : 0... | Determines if the matrix is an identity matrix.
@param {!number} epsilon
@returns {!boolean} | isIdentity | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
isScaler(epsilon=0) {
if (this._width !== this._height) {
return false;
}
let sr = this._buffer[0];
let si = this._buffer[1];
for (let c = 0; c < this._width; c++) {
for (let r = 0; r < this._height; r++) {
let i = (this._width*r + c)*2;
... | Determines if the matrix is a scaled identity matrix.
@param {!number} epsilon
@returns {!boolean} | isScaler | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
hasNaN() {
for (let i = 0; i < this._buffer.length; i++) {
if (isNaN(this._buffer[i])) {
return true;
}
}
return false;
} | Determines if the matrix contains a NaN.
@returns {!boolean} | hasNaN | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
isDiagonal(epsilon=0) {
for (let c = 0; c < this._width; c++) {
for (let r = 0; r < this._height; r++) {
if (r === c) {
continue;
}
let k = (this._width*r + c)*2;
let dr = Math.abs(this._buffer[k]);
l... | Determines if the matrix is square and only has entries along its main diagonal.
@param {!number=} epsilon
@returns {!boolean} | isDiagonal | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
adjoint() {
let w = this._height;
let h = this._width;
let newBuf = new Float64Array(w*h*2);
for (let r = 0; r < h; r++) {
for (let c = 0; c < w; c++) {
let kIn = (c*this._width + r)*2;
let kOut = (r*w + c)*2;
newBuf[kOut] = thi... | Returns the conjugate transpose of the receiving operation (the adjoint is the inverse when the matrix is unitary).
@returns {!Matrix} | adjoint | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
transpose() {
let w = this._height;
let h = this._width;
let newBuf = new Float64Array(w*h*2);
for (let r = 0; r < h; r++) {
for (let c = 0; c < w; c++) {
let kIn = (c*this._width + r)*2;
let kOut = (r*w + c)*2;
newBuf[kOut] = t... | @returns {!Matrix} The transpose of the receiving matrix. | transpose | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
trace() {
let total_r = 0;
let total_i = 0;
let d = this._width*2 + 2;
for (let i = 0; i < this._buffer.length; i += d) {
total_r += this._buffer[i];
total_i += this._buffer[i+1];
}
return new Complex(total_r, total_i);
} | Returns the matrix' trace (i.e. the sum of its diagonal elements, i.e. the sum of its eigenvalues
if it's square).
@returns {!Complex} | trace | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
_timesScalar(v) {
let newBuffer = new Float64Array(this._buffer.length);
let sr = Complex.realPartOf(v);
let si = Complex.imagPartOf(v);
for (let i = 0; i < newBuffer.length; i += 2) {
let vr = this._buffer[i];
let vi = this._buffer[i + 1];
newBuffer[i... | Returns the result of scaling the receiving matrix by the given scalar factor.
@param {!number|!Complex} v
@returns {!Matrix}
@private | _timesScalar | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
plus(other) {
let {_width: w, _height: h, _buffer: b1} = this;
let b2 = other._buffer;
Util.need(other._width === w && other._height === h, "Matrix.plus: compatible sizes");
let newBuffer = new Float64Array(this._buffer.length);
for (let i = 0; i < newBuffer.length; i++) {
... | Returns the sum of the receiving matrix and the given matrix.
@param {!Matrix} other
@returns {!Matrix} | plus | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
minus(other) {
let {_width: w, _height: h, _buffer: b1} = this;
let b2 = other._buffer;
Util.need(other._width === w && other._height === h, "Matrix.minus: compatible sizes");
let newBuffer = new Float64Array(this._buffer.length);
for (let i = 0; i < newBuffer.length; i++) {
... | Returns the difference from the receiving matrix to the given matrix.
@param {!Matrix} other
@returns {!Matrix} | minus | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
_timesMatrix(other) {
if (this._width !== other._height) {
throw new DetailedError("Incompatible sizes.", {'this': this, other})
}
let w = other._width;
let h = this._height;
let n = this._width;
let newBuffer = new Float64Array(w*h*2);
for (let r = 0;... | Returns the matrix product (i.e. the composition) of the receiving matrix and the given matrix.
@param {!Matrix} other
@returns {!Matrix}
@private | _timesMatrix | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
times(other) {
//noinspection JSCheckFunctionSignatures
return other instanceof Matrix ? this._timesMatrix(other) : this._timesScalar(other);
} | Returns the product of the receiving matrix and the given matrix or scalar.
@param {!Matrix|!number|!Complex} other A matrix or a scalar value.
@returns {!Matrix} | times | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
expandedForQubitInRegister(targetQubitOffset, registerSize, controls) {
let used = Math.round(Math.log2(this._width));
let result = Matrix.identity(1 << (registerSize - targetQubitOffset - used)).
tensorProduct(this).
tensorProduct(Matrix.identity(1 << targetQubitOffset)).
... | Expands a qubit operation so that it applies to a larger register of qubits, with optional controls.
@param {!int} targetQubitOffset
@param {!int} registerSize
@param {!Controls} controls
@returns {!Matrix} | expandedForQubitInRegister | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
applyToStateVectorAtQubitWithControls(stateVector, qubitIndex, controls) {
let chunkSize = this._width*2;
let chunkBuf = stateVector._buffer.slice(0, chunkSize);
let strideLength = 2 << qubitIndex;
let strideChunkSize = strideLength*chunkSize >> 1;
let resultBuf = stateVector._bu... | @param {!Matrix} stateVector
@param {!int} qubitIndex
@param {!Controls} controls
@returns {!Matrix} | applyToStateVectorAtQubitWithControls | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
norm2() {
let t = 0;
for (let e of this._buffer) {
t += e*e;
}
return t;
} | Returns the receiving matrix's squared euclidean length.
@returns {!number} | norm2 | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
tensorProduct(other) {
let w1 = this._width;
let h1 = this._height;
let w2 = other._width;
let h2 = other._height;
let w = w1*w2;
let h = h1*h2;
let newBuffer = new Float64Array(w*h*2);
for (let r1 = 0; r1 < h1; r1++) {
for (let r2 = 0; r2 < h2... | Returns the tensor product of the receiving matrix and the given matrix.
@param {!Matrix} other
@returns {!Matrix} | tensorProduct | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
timesQubitOperation(operation2x2, qubitIndex, controlMask, desiredValueMask) {
Util.need((controlMask & (1 << qubitIndex)) === 0, "Matrix.timesQubitOperation: self-controlled");
Util.need(operation2x2._width === 2 && operation2x2._height === 2, "Matrix.timesQubitOperation: not 2x2");
let {_widt... | Returns the tensor product of the receiving matrix and the given matrix.
@param {!Matrix} other
@returns {!Matrix} | timesQubitOperation | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
tensorPower(exponent) {
if (!Number.isInteger(exponent) || exponent < 0) {
throw new DetailedError("Bad exponent", {exponent});
}
let t = Matrix.identity(1);
let p = this;
for (let m = 1; m <= exponent; m *= 2) {
if ((m & exponent) !== 0) {
... | Returns the result of tensor-product-ing the receiving matrix with itself the given number of times.
@param {!int} exponent The number of times the matrix is tensor-product-ed with itself.
@returns {!Matrix} | tensorPower | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
transformRealAndImagComponentsWith(func) {
let buf = this._buffer.slice();
for (let i = 0; i < buf.length; i++) {
buf[i] = func(buf[i]);
}
return new Matrix(this._width, this._height, buf);
} | @param {!function(!number) : !number} func
@returns {!Matrix}
@private | transformRealAndImagComponentsWith | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static fromWireSwap(numWires, swapWire1, swapWire2) {
let bitSwap = n => {
let m1 = 1 << swapWire1;
let m2 = 1 << swapWire2;
let s = n & ~(m1 | m2);
if ((n & m1) !== 0) { s |= m2; }
if ((n & m2) !== 0) { s |= m1; }
return s;
};
... | Returns a matrix for an n-wire circuit that swaps wires i and j.
@param {!int} numWires
@param {!int} swapWire1
@param {!int} swapWire2 | fromWireSwap | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
bitSwap = n => {
let m1 = 1 << swapWire1;
let m2 = 1 << swapWire2;
let s = n & ~(m1 | m2);
if ((n & m1) !== 0) { s |= m2; }
if ((n & m2) !== 0) { s |= m1; }
return s;
} | Returns a matrix for an n-wire circuit that swaps wires i and j.
@param {!int} numWires
@param {!int} swapWire1
@param {!int} swapWire2 | bitSwap | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
bitSwap = n => {
let m1 = 1 << swapWire1;
let m2 = 1 << swapWire2;
let s = n & ~(m1 | m2);
if ((n & m1) !== 0) { s |= m2; }
if ((n & m2) !== 0) { s |= m1; }
return s;
} | Returns a matrix for an n-wire circuit that swaps wires i and j.
@param {!int} numWires
@param {!int} swapWire1
@param {!int} swapWire2 | bitSwap | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static identity(size) {
if (!Number.isInteger(size) || size <= 0) {
throw new DetailedError("Bad size", {size});
}
let buf = new Float64Array(size*size*2);
for (let k = 0; k < size; k++) {
buf[k*(size + 1)*2] = 1;
}
return new Matrix(size, size, bu... | Returns the identity matrix, with 1s on the main diagonal and all other entries zero.
@param size The dimension of the returned identity matrix.
@returns {!Matrix} | identity | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
static rotation(theta) {
let c = Math.cos(theta);
let s = Math.sin(theta);
return Matrix.square(
c, -s,
s, c);
} | Returns a rotation matrix that rotations by the given angle.
@param {!number} theta The angle the matrix should rotate by, in radians.
@returns {!Matrix} A real matrix. | rotation | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
_inline_rowScale_preMultiply(row, scale) {
for (let col = 0; col < this._width; col++) {
let v1 = this.cell(col, row);
let v2 = v1.times(scale);
let k = (row*this._width + col)*2;
this._buffer[k] = v2.real;
this._buffer[k+1] = v2.imag;
}
} | @param {!int} row
@param {!Complex} scale
@private | _inline_rowScale_preMultiply | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
_inline_colScale_postMultiply(col, scale) {
for (let row = 0; row < this._height; row++) {
let v1 = this.cell(col, row);
let v2 = v1.times(scale);
let k = (row*this._width + col)*2;
this._buffer[k] = v2.real;
this._buffer[k+1] = v2.imag;
}
... | @param {!int} col
@param {!Complex} scale
@private | _inline_colScale_postMultiply | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
_inline_rowMix_preMultiply(row1, row2, op) {
let [a, b, c, d] = op._2x2Breakdown();
for (let col = 0; col < this._width; col++) {
let x = this.cell(col, row1);
let y = this.cell(col, row2);
let v1 = x.times(a).plus(y.times(b));
let v2 = x.times(c).plus(y.t... | @param {!int} row1
@param {!int} row2
@param {!Matrix} op
@private | _inline_rowMix_preMultiply | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
_inline_colMix_postMultiply(col1, col2, op) {
let [a, b, c, d] = op._2x2Breakdown();
for (let row = 0; row < this._width; row++) {
let x = this.cell(col1, row);
let y = this.cell(col2, row);
let v1 = x.times(a).plus(y.times(c));
let v2 = x.times(b).plus(y.... | @param {!int} col1
@param {!int} col2
@param {!Matrix} op
@private | _inline_colMix_postMultiply | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
qrDecomposition() {
if (this._width !== this._height) {
throw new DetailedError("Expected a square matrix.", this);
}
let Q = Matrix.identity(this._width);
let R = this._clone();
for (let row = 0; row < this._height; row++) {
for (let col = 0; col < row &&... | Factors the receiving square matrix into a unitary matrix Q times an upper diagonal matrix R.
@returns {!{Q: !Matrix, R: !Matrix}} where Q.times(R).isEqualTo(this) && Q.isUnitary() && R.isUpperTriangular() | qrDecomposition | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
lqDecomposition() {
let {Q, R} = this.adjoint().qrDecomposition();
return {L: R.adjoint(), Q: Q.adjoint()};
} | Factors the receiving square matrix into a lower diagonal matrix L times a unitary matrix Q.
@returns {!{L: !Matrix, Q: !Matrix}} where L.times(Q).isEqualTo(this) && Q.isUnitary() && R.isLowerTriangular() | lqDecomposition | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
eigenvalueMagnitudes(epsilon, maxIterations = 1000) {
if (this._width !== this._height) {
throw new DetailedError("Expected a square matrix.", this);
}
let iteration = 0;
let m = this;
while (!m.isUpperTriangular(epsilon) && iteration < maxIterations) {
le... | Computes the magnitudes of the eigenvalues of the matrix, using the QR algorithm.
@param {!number} epsilon
@param {!number=} maxIterations
@returns {!Array.<!Complex>} | eigenvalueMagnitudes | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
eigenDecomposition() {
if (this.width() !== 2 || this.height() !== 2) {
throw new Error("Not implemented: non-2x2 eigen decomposition");
}
let [a, b, c, d] = this._2x2Breakdown();
let vals = Complex.rootsOfQuadratic(
Complex.ONE,
a.plus(d).times(-1),
... | Computes the eigenvalues and eigenvectors of a 2x2 matrix.
@returns {!Array.<!{val: !Complex, vec: !Matrix}>} | eigenDecomposition | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
liftApply(complexFunction) {
let t = this.times(0);
for (let {val, vec} of this.eigenDecomposition()) {
//noinspection JSUnusedAssignment
let fVal = complexFunction(val);
//noinspection JSUnusedAssignment
let part = vec.times(vec.adjoint());
t ... | Lifts a numeric function so that it applies to matrices by using the eigendecomposition and applying the function
to the eigenvalue coefficients.
@param {!function(!Complex) : !Complex} complexFunction
@returns {!Matrix} | liftApply | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
determinant() {
Util.need(this.width() === this.height(), "Must be square");
let n = this.width();
if (n === 1) {
return this.cell(0, 0);
}
return Seq.range(n).
map(k => {
let cutColMatrix = Matrix.generate(n - 1, n - 1, (r, c) => this.cell... | Returns the square matrix' determinant (i.e. the product of its eigenvalues).
@returns {!Complex} | determinant | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
cross3(other) {
Util.need(this.width() === 1 && this.height() === 3, "This isn't a 3d column vector.");
Util.need(other.width() === 1 && other.height() === 3, "Other's not a 3d column vector.");
return Matrix.generate(1, 3, r => {
let [i, j] = [(r+1) % 3, (r+2) % 3];
let ... | Computes the cross product of two 3d column vectors.
@param {!Matrix} other
@returns {!Matrix} | cross3 | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
_unordered_singularValueDecomposition_iterative(epsilon=0, maxIterations=100) {
let U = Matrix.identity(this._width);
let S = this._clone();
let V = Matrix.identity(this._width);
let iter = 0;
while (!S.isDiagonal(epsilon) && iter++ < maxIterations) {
let {Q: Ql, R: S... | @param {!number=} epsilon
@param {!int=} maxIterations
@returns {!{U: !Matrix, S: !Matrix, V: !Matrix}} | _unordered_singularValueDecomposition_iterative | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
singularValueDecomposition(epsilon=0, maxIterations=100) {
if (this._width !== this._height) {
throw new DetailedError("Expected a square matrix.", this);
}
let {U, S, V} = this._width === 2 ?
this._unordered_singularValueDecomposition_2x2() :
this._unordered... | Factors the matrix int u*s*v parts, where u and v are unitary matrices and s is a real diagonal matrix.
@param {!number=} epsilon
@param {!int=} maxIterations
@returns {!{U: !Matrix, S: !Matrix, V: !Matrix}} | singularValueDecomposition | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
getColumn(colIndex) {
Util.need(colIndex >= 0 && colIndex <= this.width(), "colIndex >= 0 && colIndex <= this.width()");
let col = [];
for (let r = 0; r < this._height; r++) {
col.push(this.cell(colIndex, r));
}
return col;
} | @param {!int} colIndex
@returns {!Array.<!Complex>} | getColumn | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
getRow(rowIndex) {
Util.need(rowIndex >= 0 && rowIndex <= this.height(), "rowIndex >= 0 && rowIndex <= this.height()");
let row = [];
for (let c = 0; c < this._width; c++) {
row.push(this.cell(c, rowIndex));
}
return row;
} | @param {!int} rowIndex
@returns {!Array.<!Complex>} | getRow | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
closestUnitary(epsilon=0, maxIterations=100) {
let svd = this.singularValueDecomposition(epsilon, maxIterations);
return svd.U.times(svd.V);
} | Returns the unitary matrix closest to the receiving matrix, "repairing" it into a unitary form.
@returns {!Matrix} | closestUnitary | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
function complexVectorToReadableJson(vector) {
return seq(vector).map(e => {return {r: Complex.realPartOf(e), i: Complex.imagPartOf(e)}; }).toArray();
} | Encodes a complex vector into JSON that could easily be read by humans or processed by external programs.
@param {!Iterable.<!Complex>} vector
@returns {*} | complexVectorToReadableJson | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
function realVectorToReadableJson(vector) {
return seq(vector).map(Complex.realPartOf).toArray();
} | Encodes a real vector into JSON that could easily be read by humans or processed by external programs.
@param {!Iterable.<!Complex>} vector
@returns {*} | realVectorToReadableJson | javascript | Strilanc/Quirk | src/math/Matrix.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Matrix.js | Apache-2.0 |
constructor(x, y) {
/**
* The point's x coordinate.
* @type {!number}
*/
this.x = x;
/**
* The point's y coordinate.
* @member Point#y
* @type {!number}
*/
this.y = y;
} | @param {!number} x The new point's x coordinate.
@param {!number} y The new point's y coordinate. | constructor | javascript | Strilanc/Quirk | src/math/Point.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Point.js | Apache-2.0 |
isEqualTo(obj) {
if (!(obj instanceof Point)) {
return false;
}
/** @type {!Point} */
let other = obj;
return other.x === this.x && other.y === this.y;
} | Determines if the given value is a point with the same coordinates as the receiving point.
@param {!Point|*} obj The point, or other value, to compare against.
@returns {!boolean} | isEqualTo | javascript | Strilanc/Quirk | src/math/Point.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Point.js | Apache-2.0 |
offsetBy(dx, dy) {
return new Point(this.x + dx, this.y + dy);
} | Returns the result of adding the receiving point's coordinates to the given offset values.
@param {!number} dx The x offset.
@param {!number} dy The y offset.
@returns {!Point} | offsetBy | javascript | Strilanc/Quirk | src/math/Point.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Point.js | Apache-2.0 |
plus(p) {
return new Point(this.x + p.x, this.y + p.y);
} | Returns the result of pairing and adding the receiving point's, and the given point's, coordinates.
@param {!Point} p
@returns {!Point} | plus | javascript | Strilanc/Quirk | src/math/Point.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Point.js | Apache-2.0 |
minus(p) {
return new Point(this.x - p.x, this.y - p.y);
} | Returns the result of subtracting the given point's coordinates from the receiving point.
@param {!Point} p
@returns {!Point} | minus | javascript | Strilanc/Quirk | src/math/Point.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Point.js | Apache-2.0 |
times(c) {
return new Point(this.x * c, this.y * c);
} | Returns the result of scaling the receiving point's coordinates by the given factor.
@param {!number} c The scaling factor.
@returns {!Point} | times | javascript | Strilanc/Quirk | src/math/Point.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Point.js | Apache-2.0 |
distanceTo(other) {
let dx = this.x - other.x;
let dy = this.y - other.y;
return Math.sqrt(dx*dx + dy*dy);
} | Returns the Euclidean distance between the receiving point and the given point.
@param {!Point} other
@returns {!number} | distanceTo | javascript | Strilanc/Quirk | src/math/Point.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Point.js | Apache-2.0 |
constructor(x, y, w, h) {
/**
* The x-coordinate of the left of the rectangle.
* @type {!number}
*/
this.x = x;
/**
* The y-coordinate of the top of the rectangle.
* @type {!number}
*/
this.y = y;
/**
* The width of t... | @param {!number} x
@param {!number} y
@param {!number} w
@param {!number} h | constructor | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
isApproximatelyEqualTo(obj, epsilon) {
if (!(obj instanceof Rect)) {
return false;
}
/** @type {Rect!} */
let other = obj;
return Math.abs(other.x - this.x) <= epsilon &&
Math.abs(other.y - this.y) <= epsilon &&
Math.abs(other.right() - this.ri... | @param {!Rect|*} obj
@param {!number} epsilon
@returns {!boolean} | isApproximatelyEqualTo | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
static centeredSquareWithRadius(center, radius) {
return new Rect(center.x - radius, center.y - radius, radius*2, radius*2);
} | @param {!Point} center The x/y point at the center of the square.
@param {!number} radius Half of the diameter of the square.
@returns {!Rect} | centeredSquareWithRadius | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
skipLeft(lostWidth) {
let d = Math.min(lostWidth, this.w);
return new Rect(this.x + d, this.y, this.w - d, this.h);
} | Returns the result of removing the given width from the left side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} lostWidth
@returns !Rect | skipLeft | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
skipRight(lostWidth) {
let d = Math.min(lostWidth, this.w);
return new Rect(this.x, this.y, this.w - d, this.h);
} | Returns the result of removing the given width from the right side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} lostWidth
@returns !Rect | skipRight | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
skipTop(lostHeight) {
let d = Math.min(lostHeight, this.h);
return new Rect(this.x, this.y + d, this.w, this.h - d);
} | Returns the result of removing the given height from the top side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} lostHeight
@returns !Rect | skipTop | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
skipBottom(lostHeight) {
let d = Math.min(lostHeight, this.h);
return new Rect(this.x, this.y, this.w, this.h - d);
} | Returns the result of removing the given height from the bottom side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} lostHeight
@returns !Rect | skipBottom | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
takeLeft(keptWidth) {
let d = Math.max(keptWidth, 0);
return new Rect(this.x, this.y, d, this.h);
} | Returns the result of removing all but the given width from the left side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} keptWidth
@returns !Rect | takeLeft | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
takeRight(keptWidth) {
let d = Math.max(keptWidth, 0);
return new Rect(this.x + this.w - d, this.y, d, this.h);
} | Returns the result of removing all but the given width from the right side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} keptWidth
@returns !Rect | takeRight | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
takeTop(keptHeight) {
let d = Math.max(keptHeight, 0);
return new Rect(this.x, this.y, this.w, d);
} | Returns the result of removing all but the given height from the top side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} keptHeight
@returns !Rect | takeTop | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
takeBottom(keptHeight) {
let d = Math.max(keptHeight, 0);
return new Rect(this.x, this.y + this.h - d, this.w, d);
} | Returns the result of removing all but the given height from the bottom side of the rectangle.
The cut is clamped so it doesn't go into negative heights.
@param {!number} keptHeight
@returns !Rect | takeBottom | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
paddedBy(p) {
return new Rect(this.x - p, this.y - p, this.w + p * 2, this.h + p * 2);
} | Returns the result of padding to each side of the rectangle by the given amount.
@param {!number} p The margin from the receiving rect's outside to the returned rect's inside.
@returns !Rect | paddedBy | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
scaledOutwardBy(factor) {
let c = this.center();
let w2 = this.w * factor;
let h2 = this.h * factor;
return new Rect(c.x - w2/2, c.y - h2/2, w2, h2);
} | Returns the result of scaling the rectangle w.r.t. its center by the given scaling factor.
@param {!number} factor
@returns {!Rect} | scaledOutwardBy | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
containsPoint(p) {
return p.x >= this.x &&
p.x < this.x + this.w &&
p.y >= this.y &&
p.y < this.y + this.h;
} | Determines if the given point is in the receiving rect or not.
Note that the top and left of the rectangle are inclusive, but the bottom and right are exclusive.
@param {!Point} p The query point.
@returns {!boolean} | containsPoint | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
shiftedBy(dx, dy) {
return new Rect(this.x + dx, this.y + dy, this.w, this.h);
} | @param {!number} dx The displacement to move the rect horizontally.
@param {!number} dy The displacement to move the rect vertically.
@returns {!Rect} | shiftedBy | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
proportionalShiftedBy(dx, dy) {
return this.shiftedBy(dx * this.w, dy * this.h);
} | @param {!number} dx The proportional amount to move the rect horizontally.
@param {!number} dy The proportional amount to move the rect vertically.
@returns {!Rect} | proportionalShiftedBy | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
snapInside(boundingRect) {
let w = Math.min(boundingRect.w, this.w);
let h = Math.min(boundingRect.h, this.h);
let x = Math.max(Math.min(this.x, boundingRect.right() - w), boundingRect.x);
let y = Math.max(Math.min(this.y, boundingRect.bottom() - h), boundingRect.y);
return new R... | Returns the result of repositioning the receiving rect so that it is inside the paintable area. Also shrinks the
receiving rect, if necessary.
@param {!Rect} boundingRect
@returns {!Rect} | snapInside | javascript | Strilanc/Quirk | src/math/Rect.js | https://github.com/Strilanc/Quirk/blob/master/src/math/Rect.js | Apache-2.0 |
function initClear(revision, obsIsAnyOverlayShowing) {
const EMPTY_STATE = '{"cols":[]}';
const clearAllButton = /** @type {!HTMLButtonElement} */ document.getElementById('clear-all-button');
revision.latestActiveCommit().zipLatest(obsIsAnyOverlayShowing, (r, v) => ({r, v})).subscribe(({r, v}) => {
... | @param {!Revision} revision
@param {!Observable.<boolean>} obsIsAnyOverlayShowing | initClear | javascript | Strilanc/Quirk | src/ui/clear.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/clear.js | Apache-2.0 |
function _getEmptyCircuitState(revision) {
let val = JSON.parse(revision.peekActiveCommit());
val["cols"] = [];
return JSON.stringify(val);
} | Returns current state without circuit. Keeps all custom gates.
@param {!Revision} revision
@returns {!string} | _getEmptyCircuitState | javascript | Strilanc/Quirk | src/ui/clear.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/clear.js | Apache-2.0 |
constructor(top, circuitDefinition, compressedColumnIndex, highlightedSlot, extraWireStartIndex) {
if (!Number.isFinite(top)) {
throw new DetailedError("Bad top", {top, circuitDefinition});
}
if (!(circuitDefinition instanceof CircuitDefinition)) {
throw new DetailedError... | @param {!number} top
@param {!CircuitDefinition} circuitDefinition
@param {undefined|!int} compressedColumnIndex
@param {undefined|!{col: !int, row: undefined|!int, resizeStyle: !boolean}} highlightedSlot
@param {undefined|!int} extraWireStartIndex
@private | constructor | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
_groundedWireCount() {
let pseudoCount =
this._extraWireStartIndex !== undefined && this._extraWireStartIndex !== Config.MAX_WIRE_COUNT ? 1 : 0;
let n = Math.max(Config.MIN_WIRE_COUNT, this.circuitDefinition.numWires) - pseudoCount;
return Math.max(n, this.circuitDefinition.minimumR... | The number of wires that were in the circuit before picking up a gate, or the number that will be in the circuit
after dropping a gate; whichever is larger.
@returns {!int}
@private | _groundedWireCount | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
desiredHeight(forTooltip=false) {
if (forTooltip) {
return this.circuitDefinition.numWires * Config.WIRE_SPACING;
}
return this._groundedWireCount() * Config.WIRE_SPACING + 55;
} | @param {!boolean=true} forTooltip
@returns {!number} | desiredHeight | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
desiredWidth(forTooltip=false) {
if (forTooltip) {
return this.opRect(this.circuitDefinition.columns.length - 1).right() + CIRCUIT_OP_LEFT_SPACING;
}
return this._rectForSuperpositionDisplay().right() + 101;
} | @param {!boolean=true} forTooltip
@returns {!number} | desiredWidth | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
toColumnSpaceCoordinate(x) {
let spacing = (CIRCUIT_OP_HORIZONTAL_SPACING + Config.GATE_RADIUS * 2);
let left = CIRCUIT_OP_LEFT_SPACING - CIRCUIT_OP_HORIZONTAL_SPACING / 2;
return (x - left) / spacing - 0.5;
} | @param {!number} x
@returns {!number} The continuous column-space coordinate corresponding to the given display-space coordinate.
@private | toColumnSpaceCoordinate | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
_findModificationIndex_helperColRow(hand) {
if (hand.pos === undefined || hand.heldGate === undefined) {
return undefined;
}
let pos = hand.pos.minus(hand.holdOffset).plus(new Point(Config.GATE_RADIUS, Config.GATE_RADIUS));
let halfColIndex = this.findOpHalfColumnAt(pos);
... | @param {!Hand} hand
@returns {undefined|!{col: !int, row: !int, halfColIndex: !number}}
@private | _findModificationIndex_helperColRow | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
findModificationIndex(hand) {
let loc = this._findModificationIndex_helperColRow(hand);
if (loc === undefined) {
return undefined;
}
let {col, row, halfColIndex} = loc;
let isInsert = Math.abs(halfColIndex % 1) === 0.5;
if (col >= this.circuitDefinition.colum... | @param {!Hand} hand
@returns {?{ col : !number, row : !number, isInsert : !boolean }} | findModificationIndex | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
gateRect(wireIndex, operationIndex, width=1, height=1) {
let op = this.opRect(operationIndex);
let wire = this.wireRect(wireIndex);
let r = new Rect(
op.center().x - Config.GATE_RADIUS,
wire.center().y - Config.GATE_RADIUS,
2*Config.GATE_RADIUS + (width-1)*Con... | @param {!int} wireIndex
@param {!int} operationIndex
@param {!int=} width
@param {!int=} height | gateRect | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
paint(painter, hand, stats, forTooltip=false, showWires=true) {
if (showWires) {
this._drawWires(painter, !forTooltip, hand);
}
for (let col = 0; col < this.circuitDefinition.columns.length; col++) {
this._drawColumn(painter, this.circuitDefinition.columns[col], col, han... | @param {!Painter} painter
@param {!Hand} hand
@param {!CircuitStats} stats
@param {!boolean=false} forTooltip
@param {!boolean} showWires | paint | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
_highlightStatusAt(col, row, focusPosPts) {
if (this._highlightedSlot !== undefined) {
if (this._highlightedSlot.col === col && this._highlightedSlot.row === row) {
return {
isResizeShowing: true,
isResizeHighlighted: this._highlightedSlot.resi... | @param {!int} col
@param {!int} row
@param {!Array.<!Point>} focusPosPts
@returns {!{isHighlighted: !boolean, isResizeShowing: !boolean, isResizeHighlighted: !boolean}}
@private | _highlightStatusAt | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
isOverGate = pos => {
let overGate = this.findGateOverlappingPos(pos);
return overGate !== undefined && overGate.col === col && overGate.row === row;
} | @param {!int} col
@param {!int} row
@param {!Array.<!Point>} focusPosPts
@returns {!{isHighlighted: !boolean, isResizeShowing: !boolean, isResizeHighlighted: !boolean}}
@private | isOverGate | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
isOverGate = pos => {
let overGate = this.findGateOverlappingPos(pos);
return overGate !== undefined && overGate.col === col && overGate.row === row;
} | @param {!int} col
@param {!int} row
@param {!Array.<!Point>} focusPosPts
@returns {!{isHighlighted: !boolean, isResizeShowing: !boolean, isResizeHighlighted: !boolean}}
@private | isOverGate | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
isNotCoveredAt = pos => {
let g = this.findGateOverlappingPos(pos);
return g === undefined || (g.col === col && g.row === row);
} | @param {!int} col
@param {!int} row
@param {!Array.<!Point>} focusPosPts
@returns {!{isHighlighted: !boolean, isResizeShowing: !boolean, isResizeHighlighted: !boolean}}
@private | isNotCoveredAt | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
isNotCoveredAt = pos => {
let g = this.findGateOverlappingPos(pos);
return g === undefined || (g.col === col && g.row === row);
} | @param {!int} col
@param {!int} row
@param {!Array.<!Point>} focusPosPts
@returns {!{isHighlighted: !boolean, isResizeShowing: !boolean, isResizeHighlighted: !boolean}}
@private | isNotCoveredAt | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
_drawGate_disabledReason(painter, col, row, gateRect, isHighlighted) {
let isDisabledReason = this.circuitDefinition.gateAtLocIsDisabledReason(col, row);
if (isDisabledReason === undefined) {
return;
}
painter.ctx.save();
if (isHighlighted) {
painter.ctx.... | @param {!Painter} painter
@param {!int} col
@param {!int} row
@param {!Rect} gateRect
@param {!boolean} isHighlighted
@private | _drawGate_disabledReason | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
_drawColumn(painter, gateColumn, col, hand, stats) {
this._drawColumnControlWires(painter, col);
this._drawColumnDragHighlight(painter, col);
for (let row = 0; row < this.circuitDefinition.numWires; row++) {
if (gateColumn.gates[row] === undefined) {
continue;
... | @param {!Painter} painter
@param {!GateColumn} gateColumn
@param {!int} col
@param {!Hand} hand
@param {!CircuitStats} stats
@private | _drawColumn | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
_drawColumnSurvivalRate(painter, gateColumn, col, stats) {
if (gateColumn.indexOfNonUnitaryGate() === undefined) {
return;
}
let preRate = stats.survivalRate(col - 1);
let postRate = stats.survivalRate(col);
let marginalRate = (postRate - preRate) / preRate;
... | @param {!Painter} painter
@param {!GateColumn} gateColumn
@param {!int} col
@param {!CircuitStats} stats
@private | _drawColumnSurvivalRate | javascript | Strilanc/Quirk | src/ui/DisplayedCircuit.js | https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.