コード例 #1
0
ファイル: mindist.C プロジェクト: SALAM2016/orbiter
int mindist(int n, int k, int q, int *G, 
	int f_v, int f_vv, int idx_zero, int idx_one, 
	INT *add_table, INT *mult_table)
//Main routine for the code minimum distance computation.
//The tables are only needed if $q = p^f$ with $f > 1$. 
//In the GF(p) case, just pass a NULL pointer. 
{
	MINDIST MD;
	int i, j, a, d;
	INT p, e;
	//vector vp, ve;
	INT wt_rows, w;

	factor_prime_power(q, p, e);
	MD.f_v = f_v;
	MD.f_vv = f_vv;
	MD.f_vvv = FALSE;
	MD.k = k;
	MD.n = n;
	MD.q = q;
	MD.p = p;
	MD.f = e;
	MD.idx_zero = idx_zero;
	MD.idx_one = idx_one;
	MD.ff_mult = (int *) malloc(sizeof(int) * q * q);
	MD.ff_add = (int *) malloc(sizeof(int) * q * q);
	MD.ff_inv = (int *) malloc(sizeof(int) * q);
	MD.weight_computations = 0;
	if (MD.f > 1) {
		if (f_v) {
			printf("multiplication table:\n");
			}
		for (i = 0; i < q; i++) {
			for (j = 0; j < q; j++) {
				a = mult_table[i * q + j];
				MD.ff_mult[i * q + j] = a;
				if (a == idx_one)  {
					MD.ff_inv[i] = j;
					if (i == j) 
						MD.idx_mone = i;
					}
				if (f_v) {
					printf("%d ", a);
					}
				}
			if (f_v) {
				printf("\n");
				}
			
			}
		if (f_v) {
			printf("addition table:\n");
			}
		for (i = 0; i < q; i++) {
			for (j = 0; j < q; j++) {
				a = add_table[i * q + j];
				MD.ff_add[i * q + j] = a;
				if (f_v) {
					printf("%d ", a);
					}
				}
			if (f_v) {
				printf("\n");
				}
			}
		}
	else {
		if (f_v) {
			printf("multiplication table:\n");
			}
		for (i = 0; i < q; i++) {
			for (j = 0; j < q; j++) {
				a = (i * j) % q;
				MD.ff_mult[i * q + j] = a;
				if (a == idx_one) {
					MD.ff_inv[i] = j;
					if (i == j) 
						MD.idx_mone = i;
					}
				if (f_v) {
					printf("%d ", a);
					}
				}
			if (f_v) {
				printf("\n");
				}
			}
		if (f_v) {
			printf("addition table:\n");
			}
		for (i = 0; i < q; i++) {
			for (j = 0; j < q; j++) {
				a = (i + j) % q;
				MD.ff_add[i * q + j] = a;
				if (f_v) {
					printf("%d ", a);
					}
				}
			if (f_v) {
				printf("\n");
				}
			}
		}
	if (f_v) {
		printf("the field: GF(%d) = GF(%d^%d)\nidx_zero = %d, idx_one = %d, idx_mone = %d\n", 
			MD.q, MD.p, MD.f, MD.idx_zero, MD.idx_one, MD.idx_mone);
		}

	if (MD.idx_zero != 0) {
		printf("at the moment, we assume that idx_zero == 0\n");
		fflush(stdout);
		exit(1);
		}
	
	MD.G = (int **) malloc((sizeof (int *))*(k+2));
	for (i = 1; i <= k; i++) {
		MD.G[i] = (int *)calloc(n+2,sizeof(int));
		}
	wt_rows = n;
	for (i = 0; i < k; i++) {
		w = 0;
		for (j = 0; j < n; j++) {
			if (G[i * n + j])
				w++;
			}
		wt_rows = MINIMUM(wt_rows, w);
		}

	for (i = 1; i <= k; i++) {
		for (j = 1; j <= n; j++) {
			a = G[(i-1)*n + j - 1];
			MD.G[i][j] = a;
			}
		}
	if (f_v) {
		printf("(%d,%d) code over GF(%d), generated by\n", n, k, q);
		print_matrix(&MD, MD.G);
		}

	MD.ZC = 0;
	d = min_weight(&MD);

	if (f_v) {
		cout << "the minimum distance is " << d 
			<< "\nThis was determined by looking at " << MD.weight_computations 
			<< " codewords\n(rather than " << i_power_j(q, k) << " codewords)" << endl;
		}
	
	if (d != wt_rows) {
		if (f_v) {
			cout << "min weight = " << d << 
				" is less than the weight of the vectors in the rows, which is " << wt_rows << endl;
			print_matrix(&MD, MD.G);
			}
		//cin >> i;
		}
	
	for (i = 1; i <= k; i++) {
		free(MD.G[i]);
		}
	free(MD.G);
	free(MD.ff_mult);
	free(MD.ff_add);
	free(MD.ff_inv);
	return d;
}
コード例 #2
0
    densities.at(0) = T(1.0);

    return T(1.0);
}

TEMPLATE_TEST_CASE("empty serialization", "[multi_channel_chkpt]", float, double, long double)
{
    using T = TestType;

    // create a checkpoint using five iterations with PLAIN
    auto chkpt1 = hep::make_multi_channel_chkpt<T>();

    chkpt1.channels(1);

    CHECK( chkpt1.beta()       == T(0.25) );
    CHECK( chkpt1.min_weight() == T() );

    // serialize checkpoint
    std::ostringstream stream1;
    chkpt1.serialize(stream1);

    // unserialize checkpoint
    auto in = std::istringstream(stream1.str());
    auto const chkpt2 = hep::make_multi_channel_chkpt<T, std::mt19937>(in);

    // serialize previous checkpoint
    std::ostringstream stream2;
    chkpt2.serialize(stream2);

    // string representation should be the same
    CHECK( stream1.str() == stream2.str() );