perorm a partial pivot on the matrix. essentially move the largest row below-or-including the pivot and replace the pivot's row with it. a pivot matrix is returned so multiplication can perform the transform.
164006
function(k, j, P, A, L) {
            	var maxIndex = 0;
            	var maxValue = 0;

            	for(var i = k; i <= A.rows(); i++) {
            	    if(Math.abs(A.e(i, j)) > maxValue) {
            		maxValue = Math.abs(A.e(k, j));
            		maxIndex = i;
            	    }
            	}

            	if(maxIndex != k) {
            	    var tmp = A.elements[k - 1];
            	    A.elements[k - 1] = A.elements[maxIndex - 1];
            	    A.elements[maxIndex - 1] = tmp;
            	    
            	    P.elements[k - 1][k - 1] = 0;
            	    P.elements[k - 1][maxIndex - 1] = 1;
            	    P.elements[maxIndex - 1][maxIndex - 1] = 0;
            	    P.elements[maxIndex - 1][k - 1] = 1;
            	}
            	
            	return P;
                }
634177
private void reducedRowEchelonForm(int method) {
    final int rows = coeff.length;
    final int cols = coeff[0].length;

    int k = -1; // denotes current position on diagonal
    int pivotRow; // row index of pivot element
    int pivotCol; // column index of pivot element
    double pivot; // value of pivot element

    // main loop, transformation to reduced row echelon form
    boolean exitLoop = false;

    while(!exitLoop) {
      k++;

      // pivot search for entry in remaining matrix
      // (depends on chosen method in switch)
      // store position in pivotRow, pivotCol

      // TODO: Note that we're using "row, col", whereas "col, row" would be
      // more common?
      IntIntPair pivotPos = new IntIntPair(0, 0);
      IntIntPair currPos = new IntIntPair(k, k);

      switch(method){
      case TRIVAL_PIVOT_SEARCH:
        pivotPos = nonZeroPivotSearch(k);
        break;
      case TOTAL_PIVOT_SEARCH:
        pivotPos = totalPivotSearch(k);
        break;
      }
      pivotRow = pivotPos.first;
      pivotCol = pivotPos.second;
      pivot = coeff[this.row[pivotRow]][col[pivotCol]];

      if(LOG.isDebugging()) {
        StringBuilder msg = new StringBuilder();
        msg.append("equations ").append(equationsToString(4));
        msg.append("  *** pivot at (").append(pivotRow).append(',').append(pivotCol).append(") = ").append(pivot).append('\n');
        LOG.debugFine(msg.toString());
      }

      // permute rows and columns to get this entry onto
      // the diagonal
      permutePivot(pivotPos, currPos);

      // test conditions for exiting loop
      // after this iteration
      // reasons are: Math.abs(pivot) == 0
      if((Math.abs(pivot) <= DELTA)) {
        exitLoop = true;
      }

      // pivoting only if Math.abs(pivot) > 0
      // and k <= m - 1
      if((Math.abs(pivot) > DELTA)) {
        rank++;
        pivotOperation(k);
      }

      // test conditions for exiting loop
      // after this iteration
      // reasons are: k == rows-1 : no more rows
      // k == cols-1 : no more columns
      if(k == rows - 1 || k == cols - 1) {
        exitLoop = true;
      }
    } // end while

    reducedRowEchelonForm = true;
  }
73888
def transpose(self):
        
        if len(self._row_name_list) != len(self._rows):
            raise NotImplementedError("You can't rotate a FVM that doesn't have all rows keyed")

        fvm = FeatureVectorMatrix(default_value=self._default_value, default_to_hashed_rows=self._default_to_hashed_rows)
        fvm._update_internal_column_state(self._row_name_list)
        for idx, r in enumerate(self.get_matrix().transpose()):
            fvm.add_row(r.tolist(), self._column_name_list[idx])

        return fvm
88159
def build_permutation_matrix(permutation):
    
    matrix = lil_matrix((len(permutation), len(permutation)))
    column = 0
    for row in permutation:
        matrix[row, column] = 1
        column += 1
    return matrix
1194695
public static void swapPivot(Matrix source, long diag, Matrix s, Matrix t) {
		// get swap row and col
		long swapRow = diag;
		long swapCol = diag;
		double maxValue = Math.abs(source.getAsDouble(diag, diag));
		long rows = source.getRowCount();
		long cols = source.getColumnCount();
		double abs = 0;

		for (long row = diag; row < rows; row++) {
			for (long col = diag; col < cols; col++) {
				abs = Math.abs(source.getAsDouble(row, col));
				if (abs > maxValue) {
					maxValue = abs;
					swapRow = row;
					swapCol = col;
				}
			}
		}

		// swap rows and columns
		if (swapRow != diag) {
			swapRows(source, swapRow, diag);
			swapRows(t, swapRow, diag);
		}
		if (swapCol != diag) {
			swapCols(source, swapCol, diag);
			swapCols(s, swapCol, diag);
		}
	}
575707
function luDecomposition (A, inPlace) {
  const n = A.dimension;
  const AA = inPlace ? A : A.clone();
  const a = AA.elements; // indexed via a_ij = a[i + j * n]
  const P = [];

  const rowScalers = [];
  for (let i = 0; i < n; ++i) {
    P.push(i);
    const col = findLargestInRow(A, i);
    const scaler = a[col * n + i]; // row scaling
    if (scaler === 0) {
      throw new Error('luDecomposition(): matrix is singular and cannot be LU factorized.');
    }
    rowScalers[i] = scaler; // don't actually want to scale the matrix or else (PA != LU).
  }
  // iterate over columns to reduce the matrix
  // implicitly reduce the matrix
  for (let j = 0; j < n; ++j) {
    for (let i = 0; i < j; ++i) {
      // compute upper tri, computes values across the row
      let sum = 0;
      for (let k = 0; k < i; ++k) {
        sum += a[i + k * n] * a[k + j * n]; // avoid big + small roundoffs
      }
      a[i + j * n] = a[i + j * n] - sum;
    }
    let pivotLrgElem = 0;
    let pivotIndex = j;
    for (let i = j; i < n; ++i) {
      // compute lower tri and diagonal, computes values down the column
      let sum = 0;
      for (let k = 0; k < j; ++k) {
        sum += a[i + k * n] * a[k + j * n]; // avoid big + small roundoffs
      }
      a[i + j * n] = a[i + j * n] - sum;

      // find the pivot element
      const pivotTest = rowScalers[i] * Math.abs(a[i + j * n]);
      if (pivotTest > pivotLrgElem) {
        pivotLrgElem = pivotTest;
        pivotIndex = i;
      }
    }
    swapRowsInPlace(A, j, pivotIndex);
    swapValuesInArray(P, j, pivotIndex);
    swapValuesInArray(rowScalers, j, pivotIndex);
    if (j < n - 1) {
      const pivotScale = a[j + j * n];
      for (let i = j + 1; i < n; ++i) {
        a[i + j * n] /= pivotScale;
      }
    }
  }
  return {
    P,
    A
  };
}
1240852
public static void byRow(Matrix m) {
        for (int i = 0; i < m.rows(); ++i) {
            double rowSum = 0;
            for (int j = 0; j < m.columns(); ++j)
                rowSum += m.get(i,j);

            // Skip row whose sume is zero.
            if (rowSum == 0) 
                continue;
            for (int j = 0; j < m.columns(); ++j)
                m.set(i,j, m.get(i,j) / rowSum);
        }
    }
787514
def _transformBy(self, matrix, **kwargs):
        
        t = transform.Transform(*matrix)
        transformation = t.transform(self.transformation)
        self.transformation = tuple(transformation)
433269
public static double[][] matrixFromRange (double[] lower, double[] upper, int rows) {
        // Get the number of columns:
        final int cols = lower.length;

        // Initialize the return value:
        final double[][] matrix = new double[rows][cols];

        // Iterate over columns and fill the array:
        for (int col = 0; col < cols; col++) {
            // Get the sequence:
            final double[] sequence = DMatrixUtils.sequence(lower[col], upper[col], rows);

            // Assign to each row in the column:
            for (int row = 0; row < sequence.length; row++) {
                matrix[row][col] = sequence[row];
            }
        }

        // Done, return the populated matrix:
        return matrix;
    }
504128
def permute(self, ordering: np.ndarray, *, axis: int) -> None:
		
		if axis == 0:
			self.values = self.values[ordering, :]
		elif axis == 1:
			self.values = self.values[:, ordering]
		else:
			raise ValueError("axis must be 0 or 1")
1045323
public static void divideRowBy(DenseDoubleMatrix2D matrix, long aRow, long fromCol, double value) {
		long cols = matrix.getColumnCount();
		for (long col = fromCol; col < cols; col++) {
			matrix.setDouble(matrix.getDouble(aRow, col) / value, aRow, col);
		}
	}
1040734
function baseTranspose(matrix) {
  return map(head(matrix), function (column, index) {
    return map(matrix, function (row) {
      return row[index];
    });
  });
}
508465
@Override
    public FloatMatrix repelem(final int rowRepeats, final int colRepeats) {
        N.checkArgument(rowRepeats > 0 && colRepeats > 0, "rowRepeats=%s and colRepeats=%s must be bigger than 0", rowRepeats, colRepeats);

        final float[][] c = new float[rows * rowRepeats][cols * colRepeats];

        for (int i = 0; i < rows; i++) {
            final float[] fr = c[i * rowRepeats];

            for (int j = 0; j < cols; j++) {
                N.copy(Array.repeat(a[i][j], colRepeats), 0, fr, j * colRepeats, colRepeats);
            }

            for (int k = 1; k < rowRepeats; k++) {
                N.copy(fr, 0, c[i * rowRepeats + k], 0, fr.length);
            }
        }

        return new FloatMatrix(c);
    }
13407
def _column_reduction(self):
        
        #assign each column to its lowest cost row, ensuring that only row
        #or column is assigned once
        i1, j = np.unique(np.argmin(self.c, axis=0), return_index=True)
        self._x[i1] = j

        #if problem is solved, return
        if len(i1) == self.n:
            return False

        self._y[j] = i1

        #reduction_transfer
        #tempc is array with previously assigned matchings masked
        self._v = np.min(self.c, axis=0)
        tempc = self.c.copy()
        tempc[i1, j] = np.inf
        mu = np.min(tempc[i1, :] - self._v[None, :], axis=1)
        self._v[j] -= mu
        return True
1353269
function(shape, context, top) {
            var m = shape.getAbsoluteTransform(top).getMatrix();
            context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
        }
1006894
def apply_transform(self, matrix):
        
        matrix = np.asanyarray(matrix, dtype=np.float64)
        if matrix.shape != (4, 4):
            raise ValueError('shape must be 4,4')

        center = np.dot(matrix,
                        np.append(self.primitive.center, 1.0))[:3]
        self.primitive.center = center
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;
}