Path: blob/master/build/pkgs/iml/patches/examples.patch
8820 views
diff -ruN iml-1.0.1-sage/examples/exam-nullspace.c src/examples/exam-nullspace.c1--- iml-1.0.1-sage/examples/exam-nullspace.c 2006-11-23 22:45:00.000000000 +01002+++ src/examples/exam-nullspace.c 2007-03-01 06:25:06.000000000 +01003@@ -46,6 +46,7 @@45#include <stdio.h>6#include <stdlib.h>7+#include <time.h>8#include "gmp.h"9#include "iml.h"1011@@ -57,29 +58,41 @@12{13long i, j, n, m, bd, s, *A;14mpz_t *mp_B, *mp_N;15+ clock_t c;1617/* generate a n x m random left hand side matrix A */18n = 5;19- m = 10;20- bd = 34; /* entris of A satisfying -2^bd < e < 2^bd */21+ m = 6;22+ bd = 3; /* entris of A satisfying -2^bd < e < 2^bd */23A = randomLongMat (n, m, bd);24+ c = clock();25+ s = nullspaceLong (n, m, A, &mp_N);26+ printf("Time to compute nullspace: %f\n", (clock() - c)/((float)CLOCKS_PER_SEC));27+ fprintf (stdout, "Dimension of nullspace: ");28+ fprintf (stdout, " %ld\n", s);29+30fprintf (stdout, "Input system:\n");31+ fprintf (stdout, "[");32for (i = 0; i < n; i++)33{34- fprintf (stdout, " ");35- for (j = 0; j < m; j++)36- fprintf (stdout, "%ld\t", A[i * m + j]);37- fprintf (stdout, "\n");38+ for (j = 0; j < m; j++) {39+ fprintf (stdout, "%ld", A[i * m + j]);40+ if (!(i==n-1 && j == m-1))41+ fprintf(stdout, ",");42+ }43}44- s = nullspaceLong (n, m, A, &mp_N);45- fprintf (stdout, "Dimension of nullspace: ");46- fprintf (stdout, " %ld\n", s);47+ fprintf(stdout, "]\n");48+49+ fprintf (stdout, "[");50for (i = 0; i < m; i++)51{52- for (j = 0; j < s; j++)53- gmp_fprintf (stdout, " %Zd", mp_N[i * s + j]);54- fprintf (stdout, "\n");55+ for (j = 0; j < s; j++) {56+ gmp_fprintf (stdout, "%Zd", mp_N[i * s + j]);57+ if (!(i==m-1 && j == s-1))58+ fprintf(stdout, ",");59+ }60}61+ fprintf(stdout, "]\n");62free (A);63for (i = 0; i < m * s; i++)64mpz_clear (mp_N[i]);65diff -ruN iml-1.0.1-sage/examples/exam-nullspace2.c src/examples/exam-nullspace2.c66--- iml-1.0.1-sage/examples/exam-nullspace2.c 1970-01-01 01:00:00.000000000 +010067+++ src/examples/exam-nullspace2.c 2007-03-01 06:25:06.000000000 +010068@@ -0,0 +1,146 @@69+/* ---------------------------------------------------------------------70+ *71+ * -- Integer Matrix Library (IML)72+ * (C) Copyright 2004, 2006 All Rights Reserved73+ *74+ * -- IML routines -- Version 1.0.1 -- November, 200675+ *76+ * Author : Zhuliang Chen77+ * Contributor(s) : Arne Storjohann78+ * University of Waterloo -- School of Computer Science79+ * Waterloo, Ontario, N2L3G1 Canada80+ *81+ * ---------------------------------------------------------------------82+ *83+ * -- Copyright notice and Licensing terms:84+ *85+ * Redistribution and use in source and binary forms, with or without86+ * modification, are permitted provided that the following conditions87+ * are met:88+ *89+ * 1. Redistributions of source code must retain the above copyright90+ * notice, this list of conditions and the following disclaimer.91+ * 2. Redistributions in binary form must reproduce the above copyright92+ * notice, this list of conditions, and the following disclaimer in93+ * the documentation and/or other materials provided with the distri-94+ * bution.95+ * 3. The name of the University, the IML group, or the names of its96+ * contributors may not be used to endorse or promote products deri-97+ * ved from this software without specific written permission.98+ *99+ * -- Disclaimer:100+ *101+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS102+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT103+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR104+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY105+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-106+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED107+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,108+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-109+ * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN-110+ * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF111+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.112+ *113+ */114+115+#include <stdio.h>116+#include <stdlib.h>117+#include <time.h>118+#include "gmp.h"119+#include "iml.h"120+121+long *randomLongMat (const long n, const long m, const long bd);122+mpz_t *randomMPMat (const long n, const long m, const mpz_t mp_bd);123+124+int125+main (void)126+{127+ long i, j, n, m, bd, s, *A;128+ mpz_t *mp_B, *mp_N;129+ clock_t c;130+131+ /* generate a n x m random left hand side matrix A */132+ printf("1\n");133+ n = 20;134+ m = 21;135+ bd = 3;136+ /* entris of A satisfying -2^bd < e < 2^bd */137+ A = randomLongMat (n, m, bd);138+ printf("2\n");139+ c = clock();140+ printf("3\n");141+ fprintf (stdout, "Input system:\n");142+ for (i = 0; i < n; i++)143+ {144+ fprintf (stdout, " ");145+ for (j = 0; j < m; j++)146+ fprintf (stdout, "%ld\t", A[i * m + j]);147+ fprintf (stdout, "\n");148+ }149+ s = nullspaceLong (n, m, A, &mp_N);150+ printf("4\n");151+ printf("Time to compute nullspace: %f\n", (clock() - c)/((float)CLOCKS_PER_SEC));152+ fprintf (stdout, "Dimension of nullspace: ");153+ fprintf (stdout, " %ld\n", s);154+155+156+ for (i = 0; i < m; i++)157+ {158+ for (j = 0; j < s; j++)159+ gmp_fprintf (stdout, " %Zd", mp_N[i * s + j]);160+ fprintf (stdout, "\n");161+ }162+ free (A);163+ for (i = 0; i < m * s; i++)164+ mpz_clear (mp_N[i]);165+ free (mp_N);166+ return 0;167+}168+169+170+/* generate a n x m random dense signed long matrix with entries lying in171+ * (-2^bd, 2^bd)172+ */173+long *174+randomLongMat (const long n, const long m, const long bd)175+{176+ long i, j;177+ mpz_t mp_rand, mp_sign;178+ gmp_randstate_t state;179+ unsigned long seed;180+ FILE *devrandom;181+ long *M;182+ static unsigned long inc = 0;183+184+ M = (long *) malloc (n * m * sizeof (long));185+ mpz_init (mp_sign);186+ mpz_init (mp_rand);187+ gmp_randinit_default (state);188+ seed = 387439;189+190+191+ /* generate random seed using /dev/random */192+ if ((devrandom = fopen ("/dev/urandom", "r")) != NULL)193+ {194+ fread (&seed, sizeof (seed), 1, devrandom);195+ fclose (devrandom);196+ }197+ seed += inc;198+ inc += 1;199+ gmp_randseed_ui (state, seed);200+201+202+ for (i = 0; i < n * m; i++)203+ {204+ mpz_urandomb (mp_rand, state, bd);205+ mpz_urandomb (mp_sign, state, 1);206+ if (mpz_sgn (mp_sign) == 0)207+ mpz_neg (mp_rand, mp_rand);208+ M[i] = mpz_get_si (mp_rand);209+ }210+ mpz_clear (mp_rand);211+ gmp_randclear (state);212+ mpz_clear (mp_sign);213+ return M;214+}215216217