/// <summary> /// Creates the matrix determined by a permutation /// </summary> /// <param name="src">The source permutation</param> public static BitMatrix32 ToBitMatrix(this Perm <N32> src) { var dst = BitMatrix32.Alloc(); for (var row = 0; row < src.Length; row++) { dst[row, src[row]] = Bit.On; } return(dst); }
public void bm_and_32x32x32g() { for (var i = 0; i < SampleSize; i++) { var A = Random.BitMatrix <N32, uint>(); var B = Random.BitMatrix <N32, uint>(); var C1 = BitMatrix.and(in A, in B); var C2 = BitMatrix32.From(C1); var C3 = BitMatrix32.From(A) & BitMatrix32.From(B); Claim.yea(C2 == C3); } }
public static BitMatrix32 bmm(BitMatrix32 lhs, BitMatrix32 rhs) { var dst = BitMatrix32.Alloc(); rhs = rhs.Transpose(); for (var i = 0; i < lhs.RowCount; i++) { var row = lhs.RowVector(i); for (var j = 0; j < rhs.ColCount; j++) { var col = rhs.RowVector(j); dst[i, j] = ModProd(row, col); } } return(dst); }
public void bm_and_32x32_check() { for (var i = 0; i < SampleSize; i++) { var A = Random.BitMatrix(n32); var B = Random.BitMatrix(n32); var xBytes = A.Bytes.Replicate(); var yBytes = B.Bytes.Replicate(); var zBytes = gbitspan.and(xBytes, yBytes); var expect = BitMatrix32.From(zBytes); var C = A & B; Claim.yea(expect == C); } }
/// <summary> /// Performs no allocation during the benchmark period /// </summary> /// <param name="sw">The counter</param> void bm_xor_32x32_bench_noalloc(SystemCounter sw = default) { var opname = "bm_xor_32x32"; var last = BitMatrix32.Alloc(); for (var i = 0; i < OpCount; i++) { var A = Random.BitMatrix(n32); var B = Random.BitMatrix(n32); sw.Start(); BitMatrix.xor(in A, in B, ref last); sw.Stop(); } Benchmark(opname, sw); }
public static ref Matrix <N32, T> unpack <T>(BitMatrix32 src, ref Matrix <N32, T> dst) where T : unmanaged { gbits.unpack(src.Data, dst.Data.AsSpan()); return(ref dst); }