makes matrix weights and deltas all ones
@param {Matrix} product
979843
function allOnes(product) {
  for (var i = 0; i < product.weights.length; i++) {
    product.weights[i] = 1;
    product.deltas[i] = 0;
  }
}
871927
function set (d, s) {
        d[0] = s;
        for (var i = 1; i < UNPACKED_SIZE; ++i)
            d[i] = 0;
    }
1374113
function deltaE(labA, labB) {
      var deltaL = labA[0] - labB[0];
      var deltaA = labA[1] - labB[1];
      var deltaB = labA[2] - labB[2];

      return Math.sqrt(Math.pow(deltaL, 2) +
                       Math.pow(deltaA, 2) +
                       Math.pow(deltaB, 2));
    }
166601
function(vector) {
    var V = vector.elements || vector;
    var i, product = 0, n = this.elements.length;
    if (n != V.length) { return null; }
    do { product += this.elements[n-1] * V[n-1]; } while (--n);
    return product;
  }
739060
def delta_matrix(matrix, clusters):
    
    if isspmatrix(matrix):
        delta = dok_matrix(matrix.shape)
    else:
        delta = np.zeros(matrix.shape)

    for i in clusters :
        for j in permutations(i, 2):
            delta[j] = 1

    return delta
1211360
function(oneaccidental) {
    var key = this.key(), limit = oneaccidental ? 2 : 3;

    return ['m3', 'm2', 'm-2', 'm-3']
      .map(this.interval.bind(this))
      .filter(function(note) {
      var acc = note.accidentalValue();
      var diff = key - (note.key() - acc);

      if (diff < limit && diff > -limit) {
        var product = vector.mul(knowledge.sharp, diff - acc);
        note.coord = vector.add(note.coord, product);
        return true;
      }
    });
  }
1182020
function(matrix) {
  const rows = matrix.length;
  const columns = matrix[0].length;
  const res = [];
  for (let row = 0; row < rows; ++row) {
    res.push([]);
    for (let column = 0; column < columns; ++column) {
      res[row][column] = matrix[column][columns - row - 1];
    }
  }
  return res;
}
651586
function _apply (mat, dim, callback) {
  let i, ret, tran

  if (dim <= 0) {
    if (!Array.isArray(mat[0])) {
      return callback(mat)
    } else {
      tran = _switch(mat)
      ret = []
      for (i = 0; i < tran.length; i++) {
        ret[i] = _apply(tran[i], dim - 1, callback)
      }
      return ret
    }
  } else {
    ret = []
    for (i = 0; i < mat.length; i++) {
      ret[i] = _apply(mat[i], dim - 1, callback)
    }
    return ret
  }
}
399744
def update_weights(self, x, y):
        """"""
        m     = self._inputSize
        n     = self._outputSize
        W     = self._W
        Q     = self._Q
        t     = self._t
        alpha = self._alpha
        beta  = self._beta
        gamma = self._gamma
        p     = self._p

        for i in range(n):
            for j in range(n):
                Delta_W  = - alpha * ( y[i] * y[j] - p*p )
                W[i,j]  += Delta_W

                if i==j or W[i,j] > 0:
                    W[i,j] = 0.


        for i in range(n):
            for j in range(m):
                Delta_Q  = beta * y[i] * ( x[j] - Q[i,j] )
                Q[i,j]  += Delta_Q



        for i in range(n):
            Delta_t  = gamma * ( y[i] - p )
            t[i]    += Delta_t
866000
public void makeIndexDeltas(int[] indices) {
        assert indices.length % 3 == 0;

        for (int i = indices.length / 3 - 1; i >= 0; --i) {
            // Step 1: Calculate delta from second triangle index to the previous
            // second triangle index, if the previous triangle shares the same first
            // index, otherwise calculate the delta to the first triangle index
            if ((i >= 1) && (indices[i * 3] == indices[(i - 1) * 3])) {
                indices[i * 3 + 1] -= indices[(i - 1) * 3 + 1];
            } else {
                indices[i * 3 + 1] -= indices[i * 3];
            }

            // Step 2: Calculate delta from third triangle index to the first triangle
            // index
            indices[i * 3 + 2] -= indices[i * 3];

            // Step 3: Calculate derivative of the first triangle index
            if (i >= 1) {
                indices[i * 3] -= indices[(i - 1) * 3];
            }
        }
    }
375488
function fillMatrices(data, matrix, backtrackMatrix) {
  let nValues = matrix[0].length;

  // Shift values by the median to improve numeric stability
  let shift = data[Math.floor(nValues / 2)];

  // Cumulative sum and cumulative sum of squares for all values in data array
  let sums = [];
  let sumsOfSquares = [];

  // Initialize first column in matrix & backtrackMatrix
  for (let i = 0, shiftedValue; i < nValues; ++i) {
    shiftedValue = data[i] - shift;
    if (i === 0) {
      sums.push(shiftedValue);
      sumsOfSquares.push(shiftedValue * shiftedValue);
    } else {
      sums.push(sums[i - 1] + shiftedValue);
      sumsOfSquares.push(sumsOfSquares[i - 1] + shiftedValue * shiftedValue);
    }

    // Initialize for cluster = 0
    matrix[0][i] = ssq(0, i, sums, sumsOfSquares);
    backtrackMatrix[0][i] = 0;
  }

  // Initialize the rest of the columns
  let iMin;
  for (let cluster = 1; cluster < matrix.length; ++cluster) {
    if (cluster < matrix.length - 1) {
      iMin = cluster;
    } else {
      // No need to compute matrix[K-1][0] ... matrix[K-1][N-2]
      iMin = nValues - 1;
    }

    fillMatrixColumn(
      iMin,
      nValues - 1,
      cluster,
      matrix,
      backtrackMatrix,
      sums,
      sumsOfSquares
    );
  }
}
984774
function blockMult(a, b, rows, cols) {
                            // For small matrices, resort to naive multiplication.
                            if (rows <= 512 || cols <= 512) {
                                return a.mmul(b); // a is equivalent to this
                            }

                            // Apply dynamic padding.
                            if ((rows % 2 === 1) && (cols % 2 === 1)) {
                                a = embed(a, rows + 1, cols + 1);
                                b = embed(b, rows + 1, cols + 1);
                            } else if (rows % 2 === 1) {
                                a = embed(a, rows + 1, cols);
                                b = embed(b, rows + 1, cols);
                            } else if (cols % 2 === 1) {
                                a = embed(a, rows, cols + 1);
                                b = embed(b, rows, cols + 1);
                            }

                            var halfRows = parseInt(a.rows / 2);
                            var halfCols = parseInt(a.columns / 2);
                            // Subdivide input matrices.
                            var a11 = a.subMatrix(0, halfRows - 1, 0, halfCols - 1);
                            var b11 = b.subMatrix(0, halfRows - 1, 0, halfCols - 1);

                            var a12 = a.subMatrix(0, halfRows - 1, halfCols, a.columns - 1);
                            var b12 = b.subMatrix(0, halfRows - 1, halfCols, b.columns - 1);

                            var a21 = a.subMatrix(halfRows, a.rows - 1, 0, halfCols - 1);
                            var b21 = b.subMatrix(halfRows, b.rows - 1, 0, halfCols - 1);

                            var a22 = a.subMatrix(halfRows, a.rows - 1, halfCols, a.columns - 1);
                            var b22 = b.subMatrix(halfRows, b.rows - 1, halfCols, b.columns - 1);

                            // Compute intermediate values.
                            var m1 = blockMult(Matrix.add(a11, a22), Matrix.add(b11, b22), halfRows, halfCols);
                            var m2 = blockMult(Matrix.add(a21, a22), b11, halfRows, halfCols);
                            var m3 = blockMult(a11, Matrix.sub(b12, b22), halfRows, halfCols);
                            var m4 = blockMult(a22, Matrix.sub(b21, b11), halfRows, halfCols);
                            var m5 = blockMult(Matrix.add(a11, a12), b22, halfRows, halfCols);
                            var m6 = blockMult(Matrix.sub(a21, a11), Matrix.add(b11, b12), halfRows, halfCols);
                            var m7 = blockMult(Matrix.sub(a12, a22), Matrix.add(b21, b22), halfRows, halfCols);

                            // Combine intermediate values into the output.
                            var c11 = Matrix.add(m1, m4);
                            c11.sub(m5);
                            c11.add(m7);
                            var c12 = Matrix.add(m3, m5);
                            var c21 = Matrix.add(m2, m4);
                            var c22 = Matrix.sub(m1, m2);
                            c22.add(m3);
                            c22.add(m6);

                            //Crop output to the desired size (undo dynamic padding).
                            var resultat = Matrix.zeros(2 * c11.rows, 2 * c11.columns);
                            resultat = resultat.setSubMatrix(c11, 0, 0);
                            resultat = resultat.setSubMatrix(c12, c11.rows, 0);
                            resultat = resultat.setSubMatrix(c21, 0, c11.columns);
                            resultat = resultat.setSubMatrix(c22, c11.rows, c11.columns);
                            return resultat.subMatrix(0, rows - 1, 0, cols - 1);
                        }
125847
function _reduce (mat, dim, callback) {
  let i, ret, val, tran

  if (dim <= 0) {
    if (!Array.isArray(mat[0])) {
      val = mat[0]
      for (i = 1; i < mat.length; i++) {
        val = callback(val, mat[i])
      }
      return val
    } else {
      tran = _switch(mat)
      ret = []
      for (i = 0; i < tran.length; i++) {
        ret[i] = _reduce(tran[i], dim - 1, callback)
      }
      return ret
    }
  } else {
    ret = []
    for (i = 0; i < mat.length; i++) {
      ret[i] = _reduce(mat[i], dim - 1, callback)
    }
    return ret
  }
}
672067
function(matrix) {
    var M = matrix.elements || matrix;
    if (typeof(M[0][0]) == 'undefined') { M = Matrix.create(M).elements; }
    var T = this.dup(), cols = T.elements[0].length;
    var ni = T.elements.length, ki = ni, i, nj, kj = M[0].length, j;
    if (ni != M.length) { return null; }
    do { i = ki - ni;
      nj = kj;
      do { j = kj - nj;
        T.elements[i][cols + j] = M[i][j];
      } while (--nj);
    } while (--ni);
    return T;
  }
832976
function encodeArray_NUM_DELTA_FLOAT( encoder, data, n_from, n_to, pivot, f_scale ) {

	//
	// Pivot Float Numeric Array (NUM_DELTA_FLOAT)
	//
	// ...  ....       .   +   Data Length  +   Mean Value  +  Scale
	// 001 [DWS_TYPE] [LN]    [16bit/32bit]      [F32/F64]     [F32]
	//

	// Get downscale type
	var n_delta_type = deltaEncTypeFloat( n_from, n_to );
	if (n_delta_type === undefined) {
		throw new Errors.EncodeError('Non-viable float delta value from '+_NUMTYPE[n_from]+' to '+_NUMTYPE[n_to]+'!');
	}

	encoder.counters.arr_delta_float+=1;
	encoder.log(LOG.ARR, "array.numeric.delta.float, len="+data.length+
		", from="+_NUMTYPE[n_from]+", to="+_NUMTYPE[n_to]+
		", type="+_NUMTYPE_DOWNSCALE_DELTA_FLOAT[n_delta_type]+" ("+n_delta_type+")"+
		", pivot="+pivot+", scale="+f_scale);

	if (data.length < UINT16_MAX) { // 16-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_DELTA_FLOAT | NUMTYPE_LN.UINT16 | (n_delta_type << 1) ) );
		encoder.stream16.write( pack2b( data.length, false ) );
		encoder.counters.arr_hdr+=3;
	} else { // 32-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_DELTA_FLOAT | NUMTYPE_LN.UINT32 | (n_delta_type << 1) ) );
		encoder.stream32.write( pack4b( data.length, false ) );
		encoder.counters.arr_hdr+=5;
	}

	// Write pivot value
	pickStream( encoder, n_from )
		.write( packByNumType[n_from]( pivot ) );

	// Write scale
	encoder.stream64.write( pack8f( f_scale ) );

	// Pivot-encode floats
	var pivot_array = new NUMTYPE_CLASS[n_to]( data.length );
	for (var i=1; i<data.length; ++i) {
		pivot_array[i] = (data[i] - pivot) / f_scale;
		// console.log(">>>", data[i],"->", pivot_array[i]);
	}

	// Envode pivot array
	pickStream( encoder, n_to)
		.write( packTypedArray( pivot_array ) );

}
351348
function lu_custom(A) {
    // Outer product LU decomposition with partial pivoting
    // Ref: Algo 3.4.1 Golub and Van Loan
    if (A.shape.length != 2) {
        throw new Error('Input is not a Matrix (2D)');
    }
    if (A.shape[0] !== A.shape[1]) {
        throw new Error('Input is not a Square Matrix');
    }
    var n = A.shape[0];
    var perm = new common_1.NDArray({ shape: [n] });
    for (var i = 0; i < n; i++) {
        perm.set(i, i);
    }
    function recordPermutation(ri, rj) {
        var tmp = perm.get(ri);
        perm.set(ri, perm.get(rj));
        perm.set(rj, tmp);
    }
    for (var k = 0; k < n - 1; k++) {
        // Find the maximum absolute entry in k'th column
        var ipivot = 0;
        var pivot = -Infinity;
        for (var i = k; i < n; i++) {
            var val = Math.abs(A.get(i, k)); // TODO:Complex
            if (val > pivot) {
                pivot = val;
                ipivot = i;
            }
        }
        // Swap rows k and ipivot
        A.swaprows(k, ipivot);
        recordPermutation(k, ipivot);
        if (common_1.iszero(pivot)) {
            throw new Error('Can\'t perform LU decomp. 0 on diagonal');
        }
        for (var i = k + 1; i < n; i++) {
            A.set(i, k, A.get(i, k) / pivot); // TODO:Complex
        }
        for (var i = k + 1; i < n; i++) {
            for (var j = n - 1; j > k; j--) {
                // TODO:Complex
                A.set(i, j, A.get(i, j) - A.get(i, k) * A.get(k, j));
            }
        }
    }
    return perm;
}
839102
private void fillPsubMatrix( Coordinate[] controlPoints, GeneralMatrix L ) {
        int controlPointsNum = controlPoints.length;
        for( int i = 0; i < controlPointsNum; i++ ) {
            L.setElement(i, i, 0);

            L.setElement(i, controlPointsNum + 0, 1);
            L.setElement(i, controlPointsNum + 1, controlPoints[i].x);
            L.setElement(i, controlPointsNum + 2, controlPoints[i].y);

            L.setElement(controlPointsNum + 0, i, 1);
            L.setElement(controlPointsNum + 1, i, controlPoints[i].x);
            L.setElement(controlPointsNum + 2, i, controlPoints[i].y);
        }
    }