/** * Multiply this vector with a permutation. * * @param p the permutation * @return <tt>this*p = p*this</tt> */ public Vector multiply(Permutation p) { int[] pVec = p.getVector(); if (length != pVec.length) { throw new ArithmeticException( "permutation size and vector size mismatch"); } int[] result = new int[length]; for (int i = 0; i < pVec.length; i++) { result[i] = vector[pVec[i]]; } return new GF2mVector(field, result); }
/** * Multiply this vector with a permutation. * * @param p the permutation * @return <tt>this*p = p*this</tt> */ public Vector multiply(Permutation p) { int[] pVec = p.getVector(); if (length != pVec.length) { throw new ArithmeticException("length mismatch"); } GF2Vector result = new GF2Vector(length); for (int i = 0; i < pVec.length; i++) { int e = v[pVec[i] >> 5] & (1 << (pVec[i] & 0x1f)); if (e != 0) { result.v[i >> 5] |= 1 << (i & 0x1f); } } return result; }
/** * Multiply this vector with a permutation. * * @param p the permutation * @return <tt>this*p = p*this</tt> */ public Vector multiply(Permutation p) { int[] pVec = p.getVector(); if (length != pVec.length) { throw new ArithmeticException( "permutation size and vector size mismatch"); } int[] result = new int[length]; for (int i = 0; i < pVec.length; i++) { result[i] = vector[pVec[i]]; } return new GF2mVector(field, result); }
/** * Compute the product of this matrix and a permutation matrix which is * generated from an n-permutation. * * @param p the permutation * @return {@link GF2Matrix} <tt>this*P</tt> */ public Matrix rightMultiply(Permutation p) { int[] pVec = p.getVector(); if (pVec.length != numColumns) { throw new ArithmeticException("length mismatch"); } GF2Matrix result = new GF2Matrix(numRows, numColumns); for (int i = numColumns - 1; i >= 0; i--) { int q = i >>> 5; int r = i & 0x1f; int pq = pVec[i] >>> 5; int pr = pVec[i] & 0x1f; for (int j = numRows - 1; j >= 0; j--) { result.matrix[j][q] |= ((matrix[j][pq] >>> pr) & 1) << r; } } return result; }
/** * Multiply this vector with a permutation. * * @param p the permutation * @return <tt>this*p = p*this</tt> */ public Vector multiply(Permutation p) { int[] pVec = p.getVector(); if (length != pVec.length) { throw new ArithmeticException("length mismatch"); } GF2Vector result = new GF2Vector(length); for (int i = 0; i < pVec.length; i++) { int e = v[pVec[i] >> 5] & (1 << (pVec[i] & 0x1f)); if (e != 0) { result.v[i >> 5] |= 1 << (i & 0x1f); } } return result; }
/** * Compute the product of this matrix and a permutation matrix which is * generated from an n-permutation. * * @param p the permutation * @return {@link GF2MatrixEx} <tt>this*P</tt> */ public Matrix rightMultiply(Permutation p) { int[] pVec = p.getVector(); if (pVec.length != numColumns) { throw new ArithmeticException("length mismatch"); } GF2MatrixEx result = new GF2MatrixEx(numRows, numColumns); for (int i = numColumns - 1; i >= 0; i--) { int q = i >>> BLOCKEXP; int r = i & 0x1f; int pq = pVec[i] >>> BLOCKEXP; int pr = pVec[i] & 0x1f; for (int j = numRows - 1; j >= 0; j--) { result.matrix[j][q] |= ((matrix[j][pq] >>> pr) & 1) << r; } } return result; }
/** * Compute the product of this matrix and a permutation matrix which is * generated from an n-permutation. * * @param p the permutation * @return {@link GF2Matrix} <tt>this*P</tt> */ public Matrix rightMultiply(Permutation p) { int[] pVec = p.getVector(); if (pVec.length != numColumns) { throw new ArithmeticException("length mismatch"); } GF2Matrix result = new GF2Matrix(numRows, numColumns); for (int i = numColumns - 1; i >= 0; i--) { int q = i >>> 5; int r = i & 0x1f; int pq = pVec[i] >>> 5; int pr = pVec[i] & 0x1f; for (int j = numRows - 1; j >= 0; j--) { result.matrix[j][q] |= ((matrix[j][pq] >>> pr) & 1) << r; } } return result; }
/** * Compute the product of a permutation matrix (which is generated from an * n-permutation) and this matrix. * * @param p the permutation * @return {@link GF2Matrix} <tt>P*this</tt> */ public Matrix leftMultiply(Permutation p) { int[] pVec = p.getVector(); if (pVec.length != numRows) { throw new ArithmeticException("length mismatch"); } int[][] result = new int[numRows][]; for (int i = numRows - 1; i >= 0; i--) { result[i] = IntUtils.clone(matrix[pVec[i]]); } return new GF2Matrix(numRows, result); }
/** * Compute the product of a permutation matrix (which is generated from an * n-permutation) and this matrix. * * @param p the permutation * @return {@link GF2Matrix} <tt>P*this</tt> */ public Matrix leftMultiply(Permutation p) { int[] pVec = p.getVector(); if (pVec.length != numRows) { throw new ArithmeticException("length mismatch"); } int[][] result = new int[numRows][]; for (int i = numRows - 1; i >= 0; i--) { result[i] = IntUtils.clone(matrix[pVec[i]]); } return new GF2Matrix(numRows, result); }
/** * Compute the product of a permutation matrix (which is generated from an * n-permutation) and this matrix. * * @param p the permutation * @return {@link GF2MatrixEx} <tt>P*this</tt> */ public Matrix leftMultiply(Permutation p) { int[] pVec = p.getVector(); if (pVec.length != numRows) { throw new ArithmeticException("length mismatch"); } int[][] result = new int[numRows][]; for (int i = numRows - 1; i >= 0; i--) { result[i] = IntUtils.clone(matrix[pVec[i]]); } return new GF2MatrixEx(numRows, result); }
/** * Create an nxn random regular matrix. * * @param n number of rows (and columns) * @param sr source of randomness */ private void assignRandomRegularMatrix(int n, SecureRandom sr) { numRows = n; numColumns = n; length = (n + 31) >>> 5; matrix = new int[numRows][length]; GF2Matrix lm = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_LT, sr); GF2Matrix um = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_UT, sr); GF2Matrix rm = (GF2Matrix)lm.rightMultiply(um); Permutation perm = new Permutation(n, sr); int[] p = perm.getVector(); for (int i = 0; i < n; i++) { System.arraycopy(rm.matrix[i], 0, matrix[p[i]], 0, length); } }
/** * Create an nxn random regular matrix. * * @param n number of rows (and columns) * @param sr source of randomness */ private void assignRandomRegularMatrix(int n, SecureRandom sr) { numRows = n; numColumns = n; length = (n + 31) >>> 5; matrix = new int[numRows][length]; GF2Matrix lm = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_LT, sr); GF2Matrix um = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_UT, sr); GF2Matrix rm = (GF2Matrix)lm.rightMultiply(um); Permutation perm = new Permutation(n, sr); int[] p = perm.getVector(); for (int i = 0; i < n; i++) { System.arraycopy(rm.matrix[i], 0, matrix[p[i]], 0, length); } }
/** * Create an nxn random regular matrix. * * @param n number of rows (and columns) * @param sr source of randomness */ public void assignRandomRegularMatrix(int n, SecureRandom sr) { numRows = n; numColumns = n; length = (n + (INTSIZE-1)) >>> BLOCKEXP; matrix = new int[numRows][length]; GF2MatrixEx lm = new GF2MatrixEx(n, Matrix.MATRIX_TYPE_RANDOM_LT, sr); GF2MatrixEx um = new GF2MatrixEx(n, Matrix.MATRIX_TYPE_RANDOM_UT, sr); GF2MatrixEx rm = (GF2MatrixEx)lm.rightMultiply(um); Permutation perm = new Permutation(n, sr); int[] p = perm.getVector(); for (int i = 0; i < n; i++) { System.arraycopy(rm.getIntArray()[i], 0, matrix[p[i]], 0, length); } }
GF2Matrix rm = (GF2Matrix)lm.rightMultiply(um); Permutation p = new Permutation(n, sr); int[] pVec = p.getVector();
GF2Matrix rm = (GF2Matrix)lm.rightMultiply(um); Permutation p = new Permutation(n, sr); int[] pVec = p.getVector();
GF2MatrixEx rm = (GF2MatrixEx)lm.rightMultiply(um); Permutation p = new Permutation(n, sr); int[] pVec = p.getVector();