diff --git a/TESTU01/TestU01-1.2.3/AUTHORS b/TESTU01/TestU01-1.2.3/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/TESTU01/TestU01-1.2.3/COPYING b/TESTU01/TestU01-1.2.3/COPYING new file mode 100644 index 0000000..53be945 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/COPYING @@ -0,0 +1,31 @@ + + PACKAGE: TestU01 + + LANGUAGE: ANSI C + + Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + e-mail: lecuyer@iro.umontreal.ca + http://www.iro.umontreal.ca/~lecuyer/ + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted without a fee for private, research, + academic, or other non-commercial purposes. + Any use of this software in a commercial environment requires a + written licence from the copyright owner. + + Any changes made to this package must be clearly identified as such. + + In scientific publications which used this software, a reference to it + would be appreciated. + + Redistributions of source code must retain this copyright notice + and the following disclaimer. + + THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + + + diff --git a/TESTU01/TestU01-1.2.3/ChangeLog b/TESTU01/TestU01-1.2.3/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/TESTU01/TestU01-1.2.3/INSTALL b/TESTU01/TestU01-1.2.3/INSTALL new file mode 100644 index 0000000..d106e9b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/INSTALL @@ -0,0 +1 @@ +Read the file README. diff --git a/TESTU01/TestU01-1.2.3/Makefile.am b/TESTU01/TestU01-1.2.3/Makefile.am new file mode 100644 index 0000000..72bc898 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/Makefile.am @@ -0,0 +1,8 @@ +INCLUDES = -I${top_builddir} + +SUBDIRS = . include mylib probdist testu01 examples doc param + +bin_PROGRAMS = tcode +tcode_SOURCES = ${top_srcdir}/mylib/tcode.c + +noinst_SCRIPTS = bootstrap diff --git a/TESTU01/TestU01-1.2.3/Makefile.in b/TESTU01/TestU01-1.2.3/Makefile.in new file mode 100644 index 0000000..e9b8e28 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/Makefile.in @@ -0,0 +1,718 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +bin_PROGRAMS = tcode$(EXEEXT) +subdir = . +DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(top_srcdir)/configure AUTHORS COPYING \ + ChangeLog INSTALL NEWS config.guess config.sub depcomp \ + install-sh ltmain.sh missing mkinstalldirs +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ + configure.lineno config.status.lineno +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h \ + $(top_builddir)/include/gdefconf.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +PROGRAMS = $(bin_PROGRAMS) +am_tcode_OBJECTS = tcode.$(OBJEXT) +tcode_OBJECTS = $(am_tcode_OBJECTS) +tcode_LDADD = $(LDADD) +SCRIPTS = $(noinst_SCRIPTS) +DEFAULT_INCLUDES = -I. -I$(top_builddir)/include@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(tcode_SOURCES) +DIST_SOURCES = $(tcode_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-dvi-recursive install-exec-recursive \ + install-html-recursive install-info-recursive \ + install-pdf-recursive install-ps-recursive install-recursive \ + installcheck-recursive installdirs-recursive pdf-recursive \ + ps-recursive uninstall-recursive +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +distdir = $(PACKAGE)-$(VERSION) +top_distdir = $(distdir) +am__remove_distdir = \ + { test ! -d $(distdir) \ + || { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \ + && rm -fr $(distdir); }; } +DIST_ARCHIVES = $(distdir).tar.gz +GZIP_ENV = --best +distuninstallcheck_listfiles = find . -type f -print +distcleancheck_listfiles = find . -type f -print +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +INCLUDES = -I${top_builddir} +SUBDIRS = . include mylib probdist testu01 examples doc param +tcode_SOURCES = ${top_srcdir}/mylib/tcode.c +noinst_SCRIPTS = bootstrap +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +am--refresh: + @: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + echo ' cd $(srcdir) && $(AUTOMAKE) --gnu '; \ + cd $(srcdir) && $(AUTOMAKE) --gnu \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + echo ' $(SHELL) ./config.status'; \ + $(SHELL) ./config.status;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + $(SHELL) ./config.status --recheck + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(srcdir) && $(AUTOCONF) +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + || test -f $$p1 \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ + rm -f "$(DESTDIR)$(bindir)/$$f"; \ + done + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +tcode$(EXEEXT): $(tcode_OBJECTS) $(tcode_DEPENDENCIES) + @rm -f tcode$(EXEEXT) + $(LINK) $(tcode_OBJECTS) $(tcode_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcode.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +tcode.o: ${top_srcdir}/mylib/tcode.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tcode.o -MD -MP -MF $(DEPDIR)/tcode.Tpo -c -o tcode.o `test -f '${top_srcdir}/mylib/tcode.c' || echo '$(srcdir)/'`${top_srcdir}/mylib/tcode.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/tcode.Tpo $(DEPDIR)/tcode.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='${top_srcdir}/mylib/tcode.c' object='tcode.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tcode.o `test -f '${top_srcdir}/mylib/tcode.c' || echo '$(srcdir)/'`${top_srcdir}/mylib/tcode.c + +tcode.obj: ${top_srcdir}/mylib/tcode.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tcode.obj -MD -MP -MF $(DEPDIR)/tcode.Tpo -c -o tcode.obj `if test -f '${top_srcdir}/mylib/tcode.c'; then $(CYGPATH_W) '${top_srcdir}/mylib/tcode.c'; else $(CYGPATH_W) '$(srcdir)/${top_srcdir}/mylib/tcode.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/tcode.Tpo $(DEPDIR)/tcode.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='${top_srcdir}/mylib/tcode.c' object='tcode.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tcode.obj `if test -f '${top_srcdir}/mylib/tcode.c'; then $(CYGPATH_W) '${top_srcdir}/mylib/tcode.c'; else $(CYGPATH_W) '$(srcdir)/${top_srcdir}/mylib/tcode.c'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + $(am__remove_distdir) + test -d $(distdir) || mkdir $(distdir) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done + list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + distdir=`$(am__cd) $(distdir) && pwd`; \ + top_distdir=`$(am__cd) $(top_distdir) && pwd`; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$top_distdir" \ + distdir="$$distdir/$$subdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + distdir) \ + || exit 1; \ + fi; \ + done + -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \ + ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ + || chmod -R a+r $(distdir) +dist-gzip: distdir + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + $(am__remove_distdir) + +dist-bzip2: distdir + tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2 + $(am__remove_distdir) + +dist-tarZ: distdir + tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z + $(am__remove_distdir) + +dist-shar: distdir + shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + $(am__remove_distdir) + +dist-zip: distdir + -rm -f $(distdir).zip + zip -rq $(distdir).zip $(distdir) + $(am__remove_distdir) + +dist dist-all: distdir + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + $(am__remove_distdir) + +# This target untars the dist file and tries a VPATH configuration. Then +# it guarantees that the distribution is self-contained by making another +# tarfile. +distcheck: dist + case '$(DIST_ARCHIVES)' in \ + *.tar.gz*) \ + GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\ + *.tar.bz2*) \ + bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\ + *.tar.Z*) \ + uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ + *.shar.gz*) \ + GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\ + *.zip*) \ + unzip $(distdir).zip ;;\ + esac + chmod -R a-w $(distdir); chmod a+w $(distdir) + mkdir $(distdir)/_build + mkdir $(distdir)/_inst + chmod a-w $(distdir) + dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ + && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ + && cd $(distdir)/_build \ + && ../configure --srcdir=.. --prefix="$$dc_install_base" \ + $(DISTCHECK_CONFIGURE_FLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) check \ + && $(MAKE) $(AM_MAKEFLAGS) install \ + && $(MAKE) $(AM_MAKEFLAGS) installcheck \ + && $(MAKE) $(AM_MAKEFLAGS) uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ + distuninstallcheck \ + && chmod -R a-w "$$dc_install_base" \ + && ({ \ + (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ + distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ + } || { rm -rf "$$dc_destdir"; exit 1; }) \ + && rm -rf "$$dc_destdir" \ + && $(MAKE) $(AM_MAKEFLAGS) dist \ + && rm -rf $(DIST_ARCHIVES) \ + && $(MAKE) $(AM_MAKEFLAGS) distcleancheck + $(am__remove_distdir) + @(echo "$(distdir) archives ready for distribution: "; \ + list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ + sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' +distuninstallcheck: + @cd $(distuninstallcheck_dir) \ + && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \ + || { echo "ERROR: files left after uninstall:" ; \ + if test -n "$(DESTDIR)"; then \ + echo " (check DESTDIR support)"; \ + fi ; \ + $(distuninstallcheck_listfiles) ; \ + exit 1; } >&2 +distcleancheck: distclean + @if test '$(srcdir)' = . ; then \ + echo "ERROR: distcleancheck can only run from a VPATH build" ; \ + exit 1 ; \ + fi + @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left in build directory after distclean:" ; \ + $(distcleancheck_listfiles) ; \ + exit 1; } >&2 +check-am: all-am +check: check-recursive +all-am: Makefile $(PROGRAMS) $(SCRIPTS) +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-exec-am: install-binPROGRAMS + +install-html: install-html-recursive + +install-info: install-info-recursive + +install-man: + +install-pdf: install-pdf-recursive + +install-ps: install-ps-recursive + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf $(top_srcdir)/autom4te.cache + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) install-am \ + install-strip + +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ + all all-am am--refresh check check-am clean clean-binPROGRAMS \ + clean-generic clean-libtool ctags ctags-recursive dist \ + dist-all dist-bzip2 dist-gzip dist-shar dist-tarZ dist-zip \ + distcheck distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distcleancheck distdir \ + distuninstallcheck dvi dvi-am html html-am info info-am \ + install install-am install-binPROGRAMS install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-recursive uninstall uninstall-am \ + uninstall-binPROGRAMS + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/NEWS b/TESTU01/TestU01-1.2.3/NEWS new file mode 100644 index 0000000..6aee47d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/NEWS @@ -0,0 +1,197 @@ +============================================================================ +What is new in version TestU01-1.2.2 +------------------------------------ + +- Module mylib/num2: new function num2_Digamma, the logarithmic derivative + of the Gamma function. + +- Module probdist/fdist: better approximations of fdist_Student1 in the tails. + +- Module probdist/fdist: new version of fdist_KS1 + +- Module probdist/fbar: new version of fbar_KS1 + +- Module testu01/smultin: bug correction in smultin_MultinomialBitsOver. For + small L, the wrong statistic was printed. + + + +============================================================================ +What is new in version TestU01-1.2.2 +------------------------------------ + +- Changed type boolean into type lebool to avoid conflicts on some platforms + where boolean is already defined. + +- Module probdist/fbar: better approximations for fbar_ChiSquare, fbar_KSPlus, + fbar_KS1 + +- Module probdist/fdist: better approximations for fdist_KSPlus, fdist_KS1 + +- Module testu01/ulcg: the generator ulcg_CreateLCGCarta has been renamed + ulcg_CreateLCGPayne. + + + +============================================================================ +What is new in version TestU01-1.2.1 +------------------------------------ + +** This version contains only small corrections. It eliminates warnings for + extreme values in probability distributions and protects against arguments + that could give overflows on some compilers for a few calls to pow and exp + functions. + + + +============================================================================ +What is new in version TestU01-1.2 +------------------------------------ + +** Module probdist/fdist, fbar: replaced the bivariate normal distribution + fdist_BiNormal1 and fbar_BiNormal1 with a better algorithm due to Donnelly. + +** Module testu01/unif01: new filter unif01_CreateParallelGen to test parallel + generators or multiple streams of a generator. + +** Module testu01/ucrypto: new cryptographic generators based on SHA-1 and on AES. + +** Module testu01/ubrent: added the new version (2006) of Brent's xorgens RNGs. + +** Module testu01/sknuth_Run test: bug correction: + n random numbers are now generated instead of the incorrect n+1 in previous + versions. The coefficients of the inverse covariance matrix A have been com- + puted with better precision. The new version of the run test in Knuth (3rd ed.) + is now used. Thanks to Paul C. Leopardi for these corrections. + + +============================================================================ +What is new in version TestU01-1.1 +------------------------------------ + +** Module testu01/bbattery: Changed the parameters of 1 birthday spacings test + in bbattery_Crush and in bbattery_BigCrush in the case of 32-bit machines. + +** Module testu01/u*: Added the modules uxorshift and ubrent implementing some + xorshift generators. + + + +============================================================================ +What is new in version TestU01-1.0 +------------------------------------ + +** Module testu01/bbattery: Changed the parameters of some tests in + bbattery_Crush and bbattery_BigCrush. + Added many new tests in bbattery_BigCrush. + +** Module testu01/s*: all tests that use normal or chi-square distributions + now have additionnal tests based on the sum of the N replicated statistics. + These statistics are calculated in module sres. + +** Module testu01/smarsa: renamed the Monkey test as the CAT test, and + MonkeyBits test as the CATBits test. + +** Module testu01/usoft: Added generators of well-known softwares. + +** Module testu01/unif01: Added the luxury filter unif01_CreateLuxGen. + +** Module testu01/umrg: umrg_CreateLagFib has one more parameter and is + more general than the last version. + +** Module testu01/ulec: L'Ecuyer's MRG32k3a is implemented with 64-bit integers + in ulec_CreateMRG32k3aL. + +** Module testu01/ulcg: Added Payne's et al. fast implementation + ulcg_CreateLCGPayne for linear congruential generator with m = 2^31 - 1. + +** Module probdist/fdist, finv: added the symmetrical Beta distribution. + +** Module probdist/fdist, fbar, finv: improved some distributions in the + far tails. + +** Module probdist/fdist, fbar: added a better approximation of the + Gamma distribution for very large parameter. + +** Module probdist/fdist, fbar: added the bivariate normal distributions + BiNormal1, BiNormal2 + +** Module probdist/fmass: added fmass_BinomialTerm3 and fmass_BinomialTerm4. + +** Module probdist/gofw: added the values gofw_Var and gofw_Sum in type + gofw_TestType + + +============================================================================ +What is new in version TestU01-0.6.1 +------------------------------------ + +** Module testu01/bbattery, bbattery_Crush: bug correction + in tests 92 and 94 (sstring_AutoCor with N = 1), the wrong index was + used to access the array of p-values: the printed p-values were meaningless. + +** Module testu01/s*.c: now print the number of degrees of freedom with + the results of a test when the statistic obeys a chi-square law. + (Thanks to Brian Wichmann and David Hill for this suggestion) + +** Module probdist/fdist, fdist_Beta: bug correction + for some values of p, q ~ 1000, the last elements of the recurrences + underflowed and the function returned 0 instead of the correct value. + + + +============================================================================ +What is new in version TestU01-0.6.0 +------------------------------------ + +** Module mylib/gdef: Added new macros in gdef.tex and removed some others. + +** Module mylib/gdef: Added the macros PRIdLEAST64 and PRIuLEAST64 in +gdef.tex and use them in a few files to correctly print 64-bit integers +(although these macros are part of the new ISO C99 standard). + +** Module mylib/chrono.c: Fixed a bug in chrono.c. +The chrono timers sometimes returned negative CPU times under Cygwin. +The number of clock ticks was put in a 32-bit integer which overflowed. +Now a 64-bit integer is used. + +------------------- +** Modules probdist/fmass, fdist, fbar: Compute the Poisson, the binomial +and some continuous probability distributions with better accuracy far in +the tails. + +** Module probdist/fbar: Added the fbar_LogNormal, fbar_JohnsonSB, +fbar_JohnsonSU probability distributions. + +** Modules probdist/fdist, finv: Added Marsaglia's et al fast method for +the CDF of the normal probability distribution in fdist_Normal4, and his +method for the inverse normal distribution in finv_Normal2. + +** Module probdist/fdist: Added Marsaglia's Anderson-Darling distribution +in fdist_AndersonDarling2. + +** Module probdist/finv: Added a fast method for the inversion of the +symmetrical beta distribution in finv_BetaSymmetric. + +------------------- +** Module testu01/bbattery: Changed some parameters for some tests in +bbattery_SmallCrush, bbattery_Crush, bbattery_BigCrush. Added several new +tests in bbattery_Crush and bbattery_BigCrush. + +** Module testu01/bbattery: Added the functions bbattery_Repeat* that make +it very easy to repeat one of more tests from the predefined batteries of +tests. + +** Modules testu01/u*: Some predefined generators in the u modules did not +work correctly on 64-bit machines because they explicitly assume long int +of 32 bits. This has been corrected and they should work consistently on +all machines. + +** Module testu01/umarsa: Added several new generators proposed by George +Marsaglia. + +** Module testu01/unif01: Added two functions that will make it very easy to +test generators that are not pre-programmed in TestU01: +unif01_CreateExternGen01 and unif01_CreateExternGenBits. + +============================================================================ diff --git a/TESTU01/TestU01-1.2.3/README b/TESTU01/TestU01-1.2.3/README new file mode 100644 index 0000000..78d2406 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/README @@ -0,0 +1,177 @@ +*********************************************************** + + TestU01: Testing Random Number Generators + +*********************************************************** + +TestU01 is a package implemented in ANSI C. It is designed to make it +reasonably simple to perform statistical tests on arbitrary random +number generators (RNG). + +It is copyrighted by Pierre L'Ecuyer. + +e-mail: lecuyer@iro.umontreal.ca +http://www.iro.umontreal.ca/~lecuyer/ + + +--------------------------------------------------------------------------- +DIRECTORY STRUCTURE + +-- examples: program examples showing how to use TestU01. + +-- testu01: source files and user guide. Contains many random number + generators (RNG), some specific, and others in a generic form. + It contains also many well-known and not so well-known statistical + tests for RNG and predefined batteries of tests for RNG. + +-- probdist: source files and user guide. Contains probability distributions + and a few methods useful for statistics computations. + +-- mylib: source files and user guide. Miscelleanous useful tools. + +-- include: header files + +-- param: parameter files for family of generators (modules f*). + + + + + +--------------------------------------------------------------------------- +DOCUMENTATION + +The main documentation of this package was written originally in +Latex format; it has been used to create doc in PDF format. +In each of the 3 source directories, there is a file named guide....pdf +containing the documentation on the modules in this directory +and giving a description of the public variables and functions. +The *.pdf file may be viewed with a PDF reader like Acrobat. + +In directory testu01, there is a short and a long version of the +user guide: guideshorttestu01.pdf and guidelongtestu01.pdf. +The short version may be sufficient for the typical user. +The longer version contains more details on functions and types and +their possible uses. + + +--------------------------------------------------------------------------- +COMPILATION of the Package: + +- Before compiling the package, you may have to set some global constants + in file mylib/gdef.tex to their appropriate values if the default values + are not accepted by your platform (the mylib/gdef.h will be created + automatically). + +- All the header files (*.h) of the package will be created automatically + from the corresponding *.tex files when building the package libraries. + + + +---------------- Note for Windows + +The packages MinGW32 and MSYS are required to make TestU01 work on Windows. +And the configure command must be called with the option --disable-shared +--------------------------------- + + + +- Call configure (or sh ./configure) to configure the package for your system. + Give also the name of the directory where you want to install the libraries + and binaries. It is advised to set the install directory completely + separate from the package directory. + + ./configure --prefix= + + For example, if you want to install it in the directory usr in the + user's home directory, call (directory usr MUST EXIST) + ./configure --prefix=$HOME/usr + + If no prefix is given in the configure command above, then the libraries + will be installed in the standard directory /usr/local, but only the + system administrator has the permissions to do that. + + +- Call + make + to compile everything and build the libraries. + +- Call + make install + to install the libraries in the chosen directory. + + +--------------------------------------------------------------------------- +DOC + +If the installation process has worked without glitch, there will be a +subdirectory + share/TestU01/doc +in the install directory containing the user guides in pdf format. These guides +describe all the public functions and public identifiers of the package. + + +--------------------------------------------------------------------------- +USAGE + +If the installation process has worked without glitch, there will be a +subdirectory + share/TestU01/examples +containing a few small example programs. In order to compile the small programs, +the 3 following paths must be added to the environment variables. + +LD_LIBRARY_PATH /lib +LIBRARY_PATH /lib +C_INCLUDE_PATH /include + +[ If the libraries have been installed in /usr/local, it may be + necessary for some Unix/Linux systems to redefine these 3 paths. + More specifically, the environment variables LD_LIBRARY_PATH and LIBRARY_PATH + point to the /usr/local/lib (or /usr/local/lib64 for x86_64) directory. Use + echo $LD_LIBRARY_PATH + echo $LIBRARY_PATH + to get the current library paths, and check that the appropriate directory is + included. If it is not included, you need to redefine them as follows. ] + +In a c-shell, they can be added or set with + + setenv LD_LIBRARY_PATH /lib:${LD_LIBRARY_PATH} + setenv LIBRARY_PATH /lib:${LIBRARY_PATH} + setenv C_INCLUDE_PATH /include:${C_INCLUDE_PATH} + +or perhaps simply + + setenv LD_LIBRARY_PATH /lib + setenv LIBRARY_PATH /lib + setenv C_INCLUDE_PATH /include + + +In a Bourne shell, they can be added or set with + + export LD_LIBRARY_PATH=/lib:${LD_LIBRARY_PATH} + export LIBRARY_PATH=/lib:${LIBRARY_PATH} + export C_INCLUDE_PATH=/include:${C_INCLUDE_PATH} + +or perhaps simply + + export LD_LIBRARY_PATH=/lib + export LIBRARY_PATH=/lib + export C_INCLUDE_PATH=/include + + +Then the small example birth1.c in directory examples can be compiled with +the C compiler + +gcc birth1.c -o birth1 -ltestu01 -lprobdist -lmylib -lm + + +---------------- Note for Windows users ----------------- +For MinGW, the user may have to compile-link as + +gcc birth1.c -o birth1.exe -ltestu01 -lprobdist -lmylib -lwsock32 + +--------------------------------------------------------- +For Cygwin, before running the program, the user may have to set + +export PATH=/bin:${PATH} + +--------------------------------------------------------- diff --git a/TESTU01/TestU01-1.2.3/aclocal.m4 b/TESTU01/TestU01-1.2.3/aclocal.m4 new file mode 100644 index 0000000..d42b76d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/aclocal.m4 @@ -0,0 +1,7258 @@ +# generated automatically by aclocal 1.10 -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +m4_if(m4_PACKAGE_VERSION, [2.61],, +[m4_fatal([this file was generated for autoconf 2.61. +You have another version of autoconf. If you want to use that, +you should regenerate the build system entirely.], [63])]) + +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- + +# serial 48 AC_PROG_LIBTOOL + + +# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED) +# ----------------------------------------------------------- +# If this macro is not defined by Autoconf, define it here. +m4_ifdef([AC_PROVIDE_IFELSE], + [], + [m4_define([AC_PROVIDE_IFELSE], + [m4_ifdef([AC_PROVIDE_$1], + [$2], [$3])])]) + + +# AC_PROG_LIBTOOL +# --------------- +AC_DEFUN([AC_PROG_LIBTOOL], +[AC_REQUIRE([_AC_PROG_LIBTOOL])dnl +dnl If AC_PROG_CXX has already been expanded, run AC_LIBTOOL_CXX +dnl immediately, otherwise, hook it in at the end of AC_PROG_CXX. + AC_PROVIDE_IFELSE([AC_PROG_CXX], + [AC_LIBTOOL_CXX], + [define([AC_PROG_CXX], defn([AC_PROG_CXX])[AC_LIBTOOL_CXX + ])]) +dnl And a similar setup for Fortran 77 support + AC_PROVIDE_IFELSE([AC_PROG_F77], + [AC_LIBTOOL_F77], + [define([AC_PROG_F77], defn([AC_PROG_F77])[AC_LIBTOOL_F77 +])]) + +dnl Quote A][M_PROG_GCJ so that aclocal doesn't bring it in needlessly. +dnl If either AC_PROG_GCJ or A][M_PROG_GCJ have already been expanded, run +dnl AC_LIBTOOL_GCJ immediately, otherwise, hook it in at the end of both. + AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [AC_LIBTOOL_GCJ], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [AC_LIBTOOL_GCJ], + [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ], + [AC_LIBTOOL_GCJ], + [ifdef([AC_PROG_GCJ], + [define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[AC_LIBTOOL_GCJ])]) + ifdef([A][M_PROG_GCJ], + [define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[AC_LIBTOOL_GCJ])]) + ifdef([LT_AC_PROG_GCJ], + [define([LT_AC_PROG_GCJ], + defn([LT_AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])])]) +])])# AC_PROG_LIBTOOL + + +# _AC_PROG_LIBTOOL +# ---------------- +AC_DEFUN([_AC_PROG_LIBTOOL], +[AC_REQUIRE([AC_LIBTOOL_SETUP])dnl +AC_BEFORE([$0],[AC_LIBTOOL_CXX])dnl +AC_BEFORE([$0],[AC_LIBTOOL_F77])dnl +AC_BEFORE([$0],[AC_LIBTOOL_GCJ])dnl + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS="$ac_aux_dir/ltmain.sh" + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +# Prevent multiple expansion +define([AC_PROG_LIBTOOL], []) +])# _AC_PROG_LIBTOOL + + +# AC_LIBTOOL_SETUP +# ---------------- +AC_DEFUN([AC_LIBTOOL_SETUP], +[AC_PREREQ(2.50)dnl +AC_REQUIRE([AC_ENABLE_SHARED])dnl +AC_REQUIRE([AC_ENABLE_STATIC])dnl +AC_REQUIRE([AC_ENABLE_FAST_INSTALL])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_PROG_LD])dnl +AC_REQUIRE([AC_PROG_LD_RELOAD_FLAG])dnl +AC_REQUIRE([AC_PROG_NM])dnl + +AC_REQUIRE([AC_PROG_LN_S])dnl +AC_REQUIRE([AC_DEPLIBS_CHECK_METHOD])dnl +# Autoconf 2.13's AC_OBJEXT and AC_EXEEXT macros only works for C compilers! +AC_REQUIRE([AC_OBJEXT])dnl +AC_REQUIRE([AC_EXEEXT])dnl +dnl + +AC_LIBTOOL_SYS_MAX_CMD_LEN +AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE +AC_LIBTOOL_OBJDIR + +AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl +_LT_AC_PROG_ECHO_BACKSLASH + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='sed -e 1s/^X//' +[sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g'] + +# Same as above, but do not quote variable references. +[double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g'] + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Constants: +rm="rm -f" + +# Global variables: +default_ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a +ltmain="$ac_aux_dir/ltmain.sh" +ofile="$default_ofile" +with_gnu_ld="$lt_cv_prog_gnu_ld" + +AC_CHECK_TOOL(AR, ar, false) +AC_CHECK_TOOL(RANLIB, ranlib, :) +AC_CHECK_TOOL(STRIP, strip, :) + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru +test -z "$AS" && AS=as +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$DLLTOOL" && DLLTOOL=dlltool +test -z "$LD" && LD=ld +test -z "$LN_S" && LN_S="ln -s" +test -z "$MAGIC_CMD" && MAGIC_CMD=file +test -z "$NM" && NM=nm +test -z "$SED" && SED=sed +test -z "$OBJDUMP" && OBJDUMP=objdump +test -z "$RANLIB" && RANLIB=: +test -z "$STRIP" && STRIP=: +test -z "$ac_objext" && ac_objext=o + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + AC_PATH_MAGIC + fi + ;; +esac + +AC_PROVIDE_IFELSE([AC_LIBTOOL_DLOPEN], enable_dlopen=yes, enable_dlopen=no) +AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL], +enable_win32_dll=yes, enable_win32_dll=no) + +AC_ARG_ENABLE([libtool-lock], + [AC_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +AC_ARG_WITH([pic], + [AC_HELP_STRING([--with-pic], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [pic_mode="$withval"], + [pic_mode=default]) +test -z "$pic_mode" && pic_mode=default + +# Use C for the default configuration in the libtool script +tagname= +AC_LIBTOOL_LANG_C_CONFIG +_LT_AC_TAGCONFIG +])# AC_LIBTOOL_SETUP + + +# _LT_AC_SYS_COMPILER +# ------------------- +AC_DEFUN([_LT_AC_SYS_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_AC_SYS_COMPILER + + +# _LT_CC_BASENAME(CC) +# ------------------- +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +AC_DEFUN([_LT_CC_BASENAME], +[for cc_temp in $1""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` +]) + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +AC_DEFUN([_LT_COMPILER_BOILERPLATE], +[ac_outfile=conftest.$ac_objext +printf "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$rm conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +AC_DEFUN([_LT_LINKER_BOILERPLATE], +[ac_outfile=conftest.$ac_objext +printf "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$rm conftest* +])# _LT_LINKER_BOILERPLATE + + +# _LT_AC_SYS_LIBPATH_AIX +# ---------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX], +[AC_LINK_IFELSE(AC_LANG_PROGRAM,[ +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi],[]) +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi +])# _LT_AC_SYS_LIBPATH_AIX + + +# _LT_AC_SHELL_INIT(ARG) +# ---------------------- +AC_DEFUN([_LT_AC_SHELL_INIT], +[ifdef([AC_DIVERSION_NOTICE], + [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)], + [AC_DIVERT_PUSH(NOTICE)]) +$1 +AC_DIVERT_POP +])# _LT_AC_SHELL_INIT + + +# _LT_AC_PROG_ECHO_BACKSLASH +# -------------------------- +# Add some code to the start of the generated configure script which +# will find an echo command which doesn't interpret backslashes. +AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH], +[_LT_AC_SHELL_INIT([ +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','` + ;; +esac + +echo=${ECHO-echo} +if test "X[$]1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X[$]1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then + # Yippee, $echo works! + : +else + # Restart under the correct shell. + exec $SHELL "[$]0" --no-reexec ${1+"[$]@"} +fi + +if test "X[$]1" = X--fallback-echo; then + # used as fallback echo + shift + cat </dev/null 2>&1 && unset CDPATH + +if test -z "$ECHO"; then +if test "X${echo_test_string+set}" != Xset; then +# find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if (echo_test_string=`eval $cmd`) 2>/dev/null && + echo_test_string=`eval $cmd` && + (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null + then + break + fi + done +fi + +if test "X`($echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : +else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + echo="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$echo" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + echo='print -r' + elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"} + else + # Try using printf. + echo='printf %s\n' + if test "X`($echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + echo="$CONFIG_SHELL [$]0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + echo="$CONFIG_SHELL [$]0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do + if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "[$]0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"} + else + # Oops. We lost completely, so just stick with echo. + echo=echo + fi + fi + fi + fi +fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +ECHO=$echo +if test "X$ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then + ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo" +fi + +AC_SUBST(ECHO) +])])# _LT_AC_PROG_ECHO_BACKSLASH + + +# _LT_AC_LOCK +# ----------- +AC_DEFUN([_LT_AC_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AC_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out which ABI we are using. + echo '[#]line __oline__ "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*|s390*-*linux*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_TRY_LINK([],[],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test x"$lt_cv_cc_needs_belf" != x"yes"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS="$SAVE_CFLAGS" + fi + ;; +sparc*-*solaris*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) LD="${LD-ld} -m elf64_sparc" ;; + *) LD="${LD-ld} -64" ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL], +[*-*-cygwin* | *-*-mingw* | *-*-pw32*) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; + ]) +esac + +need_locks="$enable_libtool_lock" + +])# _LT_AC_LOCK + + +# AC_LIBTOOL_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], +[AC_REQUIRE([LT_AC_PROG_SED]) +AC_CACHE_CHECK([$1], [$2], + [$2=no + ifelse([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $rm conftest* +]) + +if test x"[$]$2" = xyes; then + ifelse([$5], , :, [$5]) +else + ifelse([$6], , :, [$6]) +fi +])# AC_LIBTOOL_COMPILER_OPTION + + +# AC_LIBTOOL_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ------------------------------------------------------------ +# Check whether the given compiler option works +AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], +[AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $3" + printf "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $rm conftest* + LDFLAGS="$save_LDFLAGS" +]) + +if test x"[$]$2" = xyes; then + ifelse([$4], , :, [$4]) +else + ifelse([$5], , :, [$5]) +fi +])# AC_LIBTOOL_LINKER_OPTION + + +# AC_LIBTOOL_SYS_MAX_CMD_LEN +# -------------------------- +AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], +[# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + while (test "X"`$SHELL [$]0 --fallback-echo "X$teststring" 2>/dev/null` \ + = "XX$teststring") >/dev/null 2>&1 && + new_result=`expr "X$teststring" : ".*" 2>&1` && + lt_cv_sys_max_cmd_len=$new_result && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + teststring= + # Add a significant safety factor because C++ compilers can tack on massive + # amounts of additional arguments before passing them to the linker. + # It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + ;; + esac +]) +if test -n $lt_cv_sys_max_cmd_len ; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +])# AC_LIBTOOL_SYS_MAX_CMD_LEN + + +# _LT_AC_CHECK_DLFCN +# ------------------ +AC_DEFUN([_LT_AC_CHECK_DLFCN], +[AC_CHECK_HEADERS(dlfcn.h)dnl +])# _LT_AC_CHECK_DLFCN + + +# _LT_AC_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# --------------------------------------------------------------------- +AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF], +[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl +if test "$cross_compiling" = yes; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext < +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +#ifdef __cplusplus +extern "C" void exit (int); +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + exit (status); +}] +EOF + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_AC_TRY_DLOPEN_SELF + + +# AC_LIBTOOL_DLOPEN_SELF +# ---------------------- +AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], +[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl +if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen="shl_load"], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-dld"], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen="dlopen"], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-dld"]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_AC_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test "x$lt_cv_dlopen_self" = xyes; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_AC_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +])# AC_LIBTOOL_DLOPEN_SELF + + +# AC_LIBTOOL_PROG_CC_C_O([TAGNAME]) +# --------------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler +AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O], +[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $rm -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $rm conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files + $rm out/* && rmdir out + cd .. + rmdir conftest + $rm conftest* +]) +])# AC_LIBTOOL_PROG_CC_C_O + + +# AC_LIBTOOL_SYS_HARD_LINK_LOCKS([TAGNAME]) +# ----------------------------------------- +# Check to see if we can do hard links to lock some files if needed +AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], +[AC_REQUIRE([_LT_AC_LOCK])dnl + +hard_links="nottested" +if test "$_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $rm conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test "$hard_links" = no; then + AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +])# AC_LIBTOOL_SYS_HARD_LINK_LOCKS + + +# AC_LIBTOOL_OBJDIR +# ----------------- +AC_DEFUN([AC_LIBTOOL_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +])# AC_LIBTOOL_OBJDIR + + +# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH([TAGNAME]) +# ---------------------------------------------- +# Check hardcoding attributes. +AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_AC_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)" || \ + test -n "$_LT_AC_TAGVAR(runpath_var, $1)" || \ + test "X$_LT_AC_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then + + # We can hardcode non-existant directories. + if test "$_LT_AC_TAGVAR(hardcode_direct, $1)" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)" != no && + test "$_LT_AC_TAGVAR(hardcode_minus_L, $1)" != no; then + # Linking always hardcodes the temporary library directory. + _LT_AC_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_AC_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_AC_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_AC_TAGVAR(hardcode_action, $1)]) + +if test "$_LT_AC_TAGVAR(hardcode_action, $1)" = relink; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi +])# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH + + +# AC_LIBTOOL_SYS_LIB_STRIP +# ------------------------ +AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP], +[striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) +fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +])# AC_LIBTOOL_SYS_LIB_STRIP + + +# AC_LIBTOOL_SYS_DYNAMIC_LINKER +# ----------------------------- +# PORTME Fill in your ld.so characteristics +AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER], +[AC_MSG_CHECKING([dynamic linker characteristics]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix4* | aix5*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $rm \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | [grep ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + # Apple's gcc prints 'gcc -print-search-dirs' doesn't operate the same. + if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | tr "\n" "$PATH_SEPARATOR" | sed -e 's/libraries:/@libraries:/' | tr "@" "\n" | grep "^libraries:" | sed -e "s/^libraries://" -e "s,=/,/,g" -e "s,$PATH_SEPARATOR, ,g" -e "s,.*,& /lib /usr/lib /usr/local/lib,g"` + else + sys_lib_search_path_spec='/lib /usr/lib /usr/local/lib' + fi + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +kfreebsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[123]]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + freebsd*) # from 4.6 on + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix3*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # find out which ABI we are using + libsuff= + case "$host_cpu" in + x86_64*|s390x*|powerpc64*) + echo '[#]line __oline__ "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *64-bit*) + libsuff=64 + sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" + ;; + esac + fi + rm -rf conftest* + ;; + esac + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/^[ ]*//;s/#.*//;/^[^\/]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +knetbsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +nto-qnx*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[[89]] | openbsd2.[[89]].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + export_dynamic_flag_spec='${wl}-Blargedynsym' + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + shlibpath_overrides_runpath=no + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + shlibpath_overrides_runpath=yes + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi +])# AC_LIBTOOL_SYS_DYNAMIC_LINKER + + +# _LT_AC_TAGCONFIG +# ---------------- +AC_DEFUN([_LT_AC_TAGCONFIG], +[AC_ARG_WITH([tags], + [AC_HELP_STRING([--with-tags@<:@=TAGS@:>@], + [include additional configurations @<:@automatic@:>@])], + [tagnames="$withval"]) + +if test -f "$ltmain" && test -n "$tagnames"; then + if test ! -f "${ofile}"; then + AC_MSG_WARN([output file `$ofile' does not exist]) + fi + + if test -z "$LTCC"; then + eval "`$SHELL ${ofile} --config | grep '^LTCC='`" + if test -z "$LTCC"; then + AC_MSG_WARN([output file `$ofile' does not look like a libtool script]) + else + AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile']) + fi + fi + if test -z "$LTCFLAGS"; then + eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`" + fi + + # Extract list of available tagged configurations in $ofile. + # Note that this assumes the entire list is on one line. + available_tags=`grep "^available_tags=" "${ofile}" | $SED -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'` + + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for tagname in $tagnames; do + IFS="$lt_save_ifs" + # Check whether tagname contains only valid characters + case `$echo "X$tagname" | $Xsed -e 's:[[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]]::g'` in + "") ;; + *) AC_MSG_ERROR([invalid tag name: $tagname]) + ;; + esac + + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "${ofile}" > /dev/null + then + AC_MSG_ERROR([tag name \"$tagname\" already exists]) + fi + + # Update the list of available tags. + if test -n "$tagname"; then + echo appending configuration tag \"$tagname\" to $ofile + + case $tagname in + CXX) + if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_LIBTOOL_LANG_CXX_CONFIG + else + tagname="" + fi + ;; + + F77) + if test -n "$F77" && test "X$F77" != "Xno"; then + AC_LIBTOOL_LANG_F77_CONFIG + else + tagname="" + fi + ;; + + GCJ) + if test -n "$GCJ" && test "X$GCJ" != "Xno"; then + AC_LIBTOOL_LANG_GCJ_CONFIG + else + tagname="" + fi + ;; + + RC) + AC_LIBTOOL_LANG_RC_CONFIG + ;; + + *) + AC_MSG_ERROR([Unsupported tag name: $tagname]) + ;; + esac + + # Append the new tag name to the list of available tags. + if test -n "$tagname" ; then + available_tags="$available_tags $tagname" + fi + fi + done + IFS="$lt_save_ifs" + + # Now substitute the updated list of available tags. + if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' \"$ofile\" > \"${ofile}T\""; then + mv "${ofile}T" "$ofile" + chmod +x "$ofile" + else + rm -f "${ofile}T" + AC_MSG_ERROR([unable to update list of available tagged configurations.]) + fi +fi +])# _LT_AC_TAGCONFIG + + +# AC_LIBTOOL_DLOPEN +# ----------------- +# enable checks for dlopen support +AC_DEFUN([AC_LIBTOOL_DLOPEN], + [AC_BEFORE([$0],[AC_LIBTOOL_SETUP]) +])# AC_LIBTOOL_DLOPEN + + +# AC_LIBTOOL_WIN32_DLL +# -------------------- +# declare package support for building win32 DLLs +AC_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_BEFORE([$0], [AC_LIBTOOL_SETUP]) +])# AC_LIBTOOL_WIN32_DLL + + +# AC_ENABLE_SHARED([DEFAULT]) +# --------------------------- +# implement the --enable-shared flag +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +AC_DEFUN([AC_ENABLE_SHARED], +[define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE([shared], + [AC_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]AC_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_shared=]AC_ENABLE_SHARED_DEFAULT) +])# AC_ENABLE_SHARED + + +# AC_DISABLE_SHARED +# ----------------- +# set the default shared flag to --disable-shared +AC_DEFUN([AC_DISABLE_SHARED], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +AC_ENABLE_SHARED(no) +])# AC_DISABLE_SHARED + + +# AC_ENABLE_STATIC([DEFAULT]) +# --------------------------- +# implement the --enable-static flag +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +AC_DEFUN([AC_ENABLE_STATIC], +[define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE([static], + [AC_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]AC_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_static=]AC_ENABLE_STATIC_DEFAULT) +])# AC_ENABLE_STATIC + + +# AC_DISABLE_STATIC +# ----------------- +# set the default static flag to --disable-static +AC_DEFUN([AC_DISABLE_STATIC], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +AC_ENABLE_STATIC(no) +])# AC_DISABLE_STATIC + + +# AC_ENABLE_FAST_INSTALL([DEFAULT]) +# --------------------------------- +# implement the --enable-fast-install flag +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +AC_DEFUN([AC_ENABLE_FAST_INSTALL], +[define([AC_ENABLE_FAST_INSTALL_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE([fast-install], + [AC_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]AC_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_fast_install=]AC_ENABLE_FAST_INSTALL_DEFAULT) +])# AC_ENABLE_FAST_INSTALL + + +# AC_DISABLE_FAST_INSTALL +# ----------------------- +# set the default to --disable-fast-install +AC_DEFUN([AC_DISABLE_FAST_INSTALL], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +AC_ENABLE_FAST_INSTALL(no) +])# AC_DISABLE_FAST_INSTALL + + +# AC_LIBTOOL_PICMODE([MODE]) +# -------------------------- +# implement the --with-pic flag +# MODE is either `yes' or `no'. If omitted, it defaults to `both'. +AC_DEFUN([AC_LIBTOOL_PICMODE], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +pic_mode=ifelse($#,1,$1,default) +])# AC_LIBTOOL_PICMODE + + +# AC_PROG_EGREP +# ------------- +# This is predefined starting with Autoconf 2.54, so this conditional +# definition can be removed once we require Autoconf 2.54 or later. +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP], +[AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep], + [if echo a | (grep -E '(a|b)') >/dev/null 2>&1 + then ac_cv_prog_egrep='grep -E' + else ac_cv_prog_egrep='egrep' + fi]) + EGREP=$ac_cv_prog_egrep + AC_SUBST([EGREP]) +])]) + + +# AC_PATH_TOOL_PREFIX +# ------------------- +# find a file program which can recognise shared library +AC_DEFUN([AC_PATH_TOOL_PREFIX], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="ifelse([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$1; then + lt_cv_path_MAGIC_CMD="$ac_dir/$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac]) +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +])# AC_PATH_TOOL_PREFIX + + +# AC_PATH_MAGIC +# ------------- +# find a file program which can recognise a shared library +AC_DEFUN([AC_PATH_MAGIC], +[AC_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + AC_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# AC_PATH_MAGIC + + +# AC_PROG_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([AC_PROG_LD], +[AC_ARG_WITH([gnu-ld], + [AC_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test "$withval" = no || with_gnu_ld=yes], + [with_gnu_ld=no]) +AC_REQUIRE([LT_AC_PROG_SED])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'` + while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix3*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +nto-qnx*) + lt_cv_deplibs_check_method=unknown + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown +])# AC_DEPLIBS_CHECK_METHOD + + +# AC_PROG_NM +# ---------- +# find the pathname to a BSD-compatible name lister +AC_DEFUN([AC_PROG_NM], +[AC_CACHE_CHECK([for BSD-compatible nm], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_nm_to_check="${ac_tool_prefix}nm" + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/$lt_tmp_nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS="$lt_save_ifs" + done + test -z "$lt_cv_path_NM" && lt_cv_path_NM=nm +fi]) +NM="$lt_cv_path_NM" +])# AC_PROG_NM + + +# AC_CHECK_LIBM +# ------------- +# check for math library +AC_DEFUN([AC_CHECK_LIBM], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM="-lm") + ;; +esac +])# AC_CHECK_LIBM + + +# AC_LIBLTDL_CONVENIENCE([DIRECTORY]) +# ----------------------------------- +# sets LIBLTDL to the link flags for the libltdl convenience library and +# LTDLINCL to the include flags for the libltdl header and adds +# --enable-ltdl-convenience to the configure arguments. Note that +# AC_CONFIG_SUBDIRS is not called here. If DIRECTORY is not provided, +# it is assumed to be `libltdl'. LIBLTDL will be prefixed with +# '${top_builddir}/' and LTDLINCL will be prefixed with '${top_srcdir}/' +# (note the single quotes!). If your package is not flat and you're not +# using automake, define top_builddir and top_srcdir appropriately in +# the Makefiles. +AC_DEFUN([AC_LIBLTDL_CONVENIENCE], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl + case $enable_ltdl_convenience in + no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;; + "") enable_ltdl_convenience=yes + ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;; + esac + LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la + LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl']) + # For backwards non-gettext consistent compatibility... + INCLTDL="$LTDLINCL" +])# AC_LIBLTDL_CONVENIENCE + + +# AC_LIBLTDL_INSTALLABLE([DIRECTORY]) +# ----------------------------------- +# sets LIBLTDL to the link flags for the libltdl installable library and +# LTDLINCL to the include flags for the libltdl header and adds +# --enable-ltdl-install to the configure arguments. Note that +# AC_CONFIG_SUBDIRS is not called here. If DIRECTORY is not provided, +# and an installed libltdl is not found, it is assumed to be `libltdl'. +# LIBLTDL will be prefixed with '${top_builddir}/'# and LTDLINCL with +# '${top_srcdir}/' (note the single quotes!). If your package is not +# flat and you're not using automake, define top_builddir and top_srcdir +# appropriately in the Makefiles. +# In the future, this macro may have to be called after AC_PROG_LIBTOOL. +AC_DEFUN([AC_LIBLTDL_INSTALLABLE], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl + AC_CHECK_LIB(ltdl, lt_dlinit, + [test x"$enable_ltdl_install" != xyes && enable_ltdl_install=no], + [if test x"$enable_ltdl_install" = xno; then + AC_MSG_WARN([libltdl not installed, but installation disabled]) + else + enable_ltdl_install=yes + fi + ]) + if test x"$enable_ltdl_install" = x"yes"; then + ac_configure_args="$ac_configure_args --enable-ltdl-install" + LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la + LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl']) + else + ac_configure_args="$ac_configure_args --enable-ltdl-install=no" + LIBLTDL="-lltdl" + LTDLINCL= + fi + # For backwards non-gettext consistent compatibility... + INCLTDL="$LTDLINCL" +])# AC_LIBLTDL_INSTALLABLE + + +# AC_LIBTOOL_CXX +# -------------- +# enable support for C++ libraries +AC_DEFUN([AC_LIBTOOL_CXX], +[AC_REQUIRE([_LT_AC_LANG_CXX]) +])# AC_LIBTOOL_CXX + + +# _LT_AC_LANG_CXX +# --------------- +AC_DEFUN([_LT_AC_LANG_CXX], +[AC_REQUIRE([AC_PROG_CXX]) +AC_REQUIRE([_LT_AC_PROG_CXXCPP]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}CXX]) +])# _LT_AC_LANG_CXX + +# _LT_AC_PROG_CXXCPP +# ------------------ +AC_DEFUN([_LT_AC_PROG_CXXCPP], +[ +AC_REQUIRE([AC_PROG_CXX]) +if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_PROG_CXXCPP +fi +])# _LT_AC_PROG_CXXCPP + +# AC_LIBTOOL_F77 +# -------------- +# enable support for Fortran 77 libraries +AC_DEFUN([AC_LIBTOOL_F77], +[AC_REQUIRE([_LT_AC_LANG_F77]) +])# AC_LIBTOOL_F77 + + +# _LT_AC_LANG_F77 +# --------------- +AC_DEFUN([_LT_AC_LANG_F77], +[AC_REQUIRE([AC_PROG_F77]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}F77]) +])# _LT_AC_LANG_F77 + + +# AC_LIBTOOL_GCJ +# -------------- +# enable support for GCJ libraries +AC_DEFUN([AC_LIBTOOL_GCJ], +[AC_REQUIRE([_LT_AC_LANG_GCJ]) +])# AC_LIBTOOL_GCJ + + +# _LT_AC_LANG_GCJ +# --------------- +AC_DEFUN([_LT_AC_LANG_GCJ], +[AC_PROVIDE_IFELSE([AC_PROG_GCJ],[], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],[], + [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],[], + [ifdef([AC_PROG_GCJ],[AC_REQUIRE([AC_PROG_GCJ])], + [ifdef([A][M_PROG_GCJ],[AC_REQUIRE([A][M_PROG_GCJ])], + [AC_REQUIRE([A][C_PROG_GCJ_OR_A][M_PROG_GCJ])])])])])]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}GCJ]) +])# _LT_AC_LANG_GCJ + + +# AC_LIBTOOL_RC +# ------------- +# enable support for Windows resource files +AC_DEFUN([AC_LIBTOOL_RC], +[AC_REQUIRE([LT_AC_PROG_RC]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}RC]) +])# AC_LIBTOOL_RC + + +# AC_LIBTOOL_LANG_C_CONFIG +# ------------------------ +# Ensure that the configuration vars for the C compiler are +# suitably defined. Those variables are subsequently used by +# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'. +AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG], [_LT_AC_LANG_C_CONFIG]) +AC_DEFUN([_LT_AC_LANG_C_CONFIG], +[lt_save_CC="$CC" +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_AC_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;\n" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}\n' + +_LT_AC_SYS_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1) +AC_LIBTOOL_PROG_COMPILER_PIC($1) +AC_LIBTOOL_PROG_CC_C_O($1) +AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1) +AC_LIBTOOL_PROG_LD_SHLIBS($1) +AC_LIBTOOL_SYS_DYNAMIC_LINKER($1) +AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1) +AC_LIBTOOL_SYS_LIB_STRIP +AC_LIBTOOL_DLOPEN_SELF + +# Report which library types will actually be built +AC_MSG_CHECKING([if libtool supports shared libraries]) +AC_MSG_RESULT([$can_build_shared]) + +AC_MSG_CHECKING([whether to build shared libraries]) +test "$can_build_shared" = "no" && enable_shared=no + +# On AIX, shared libraries and static libraries use the same namespace, and +# are all built from PIC. +case $host_os in +aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + +aix4* | aix5*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; +esac +AC_MSG_RESULT([$enable_shared]) + +AC_MSG_CHECKING([whether to build static libraries]) +# Make sure either enable_shared or enable_static is yes. +test "$enable_shared" = yes || enable_static=yes +AC_MSG_RESULT([$enable_static]) + +AC_LIBTOOL_CONFIG($1) + +AC_LANG_POP +CC="$lt_save_CC" +])# AC_LIBTOOL_LANG_C_CONFIG + + +# AC_LIBTOOL_LANG_CXX_CONFIG +# -------------------------- +# Ensure that the configuration vars for the C compiler are +# suitably defined. Those variables are subsequently used by +# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'. +AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG], [_LT_AC_LANG_CXX_CONFIG(CXX)]) +AC_DEFUN([_LT_AC_LANG_CXX_CONFIG], +[AC_LANG_PUSH(C++) +AC_REQUIRE([AC_PROG_CXX]) +AC_REQUIRE([_LT_AC_PROG_CXXCPP]) + +_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_AC_TAGVAR(allow_undefined_flag, $1)= +_LT_AC_TAGVAR(always_export_symbols, $1)=no +_LT_AC_TAGVAR(archive_expsym_cmds, $1)= +_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_AC_TAGVAR(hardcode_direct, $1)=no +_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_AC_TAGVAR(hardcode_libdir_separator, $1)= +_LT_AC_TAGVAR(hardcode_minus_L, $1)=no +_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_AC_TAGVAR(hardcode_automatic, $1)=no +_LT_AC_TAGVAR(module_cmds, $1)= +_LT_AC_TAGVAR(module_expsym_cmds, $1)= +_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown +_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_AC_TAGVAR(no_undefined_flag, $1)= +_LT_AC_TAGVAR(whole_archive_flag_spec, $1)= +_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Dependencies to place before and after the object being linked: +_LT_AC_TAGVAR(predep_objects, $1)= +_LT_AC_TAGVAR(postdep_objects, $1)= +_LT_AC_TAGVAR(predeps, $1)= +_LT_AC_TAGVAR(postdeps, $1)= +_LT_AC_TAGVAR(compiler_lib_search_path, $1)= + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_AC_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;\n" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }\n' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_AC_SYS_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_LD=$LD +lt_save_GCC=$GCC +GCC=$GXX +lt_save_with_gnu_ld=$with_gnu_ld +lt_save_path_LD=$lt_cv_path_LD +if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx +else + $as_unset lt_cv_prog_gnu_ld +fi +if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX +else + $as_unset lt_cv_path_LD +fi +test -z "${LDCXX+set}" || LD=$LDCXX +CC=${CXX-"c++"} +compiler=$CC +_LT_AC_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) + +# We don't want -fno-exception wen compiling C++ code, so set the +# no_builtin_flag separately +if test "$GXX" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' +else + _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= +fi + +if test "$GXX" = yes; then + # Set up default GNU C++ configuration + + AC_PROG_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test "$with_gnu_ld" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='${wl}' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | \ + grep 'no-whole-archive' > /dev/null; then + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + +else + GXX=no + with_gnu_ld=no + wlarc= +fi + +# PORTME: fill in a description of your system's C++ link characteristics +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +_LT_AC_TAGVAR(ld_shlibs, $1)=yes +case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_AC_TAGVAR(archive_cmds, $1)='' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + if test "$GXX" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + else + # We have old collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared libraries. + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(always_export_symbols, $1)=no + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + darwin* | rhapsody*) + case $host_os in + rhapsody* | darwin1.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_automatic, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + if test "$GXX" = yes ; then + lt_int_apple_cc_single_mod=no + output_verbose_link_cmd='echo' + if $CC -dumpspecs 2>&1 | $EGREP 'single_module' >/dev/null ; then + lt_int_apple_cc_single_mod=yes + fi + if test "X$lt_int_apple_cc_single_mod" = Xyes ; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + fi + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + if test "X$lt_int_apple_cc_single_mod" = Xyes ; then + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + fi + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + freebsd[[12]]*) + # C++ shared libraries reported to be fairly broken before switch to ELF + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + freebsd-elf*) + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + freebsd* | kfreebsd*-gnu | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_AC_TAGVAR(ld_shlibs, $1)=yes + ;; + gnu*) + ;; + hpux9*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "[[-]]L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + hpux10*|hpux11*) + if test $with_gnu_ld = no; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + ;; + *) + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes; then + if test $with_gnu_ld = no; then + case $host_cpu in + hppa*64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + interix3*) + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test "$GXX" = yes; then + if test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` -o $lib' + fi + fi + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + linux*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | grep "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc*) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' + ;; + pgCC*) + # Portland Group C++ compiler + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + esac + ;; + lynxos*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + m88k*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + openbsd2*) + # C++ shared libraries are fairly broken + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + openbsd*) + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + fi + output_verbose_link_cmd='echo' + ;; + osf3*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && echo ${wl}-set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname -Wl,-input -Wl,$lib.exp `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~ + $rm $lib.exp' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + psos*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_AC_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_AC_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The C++ compiler is used as linker so we must use $wl + # flag to pass the commands to the underlying system + # linker. We must also pass each convience library through + # to the system linker between allextract/defaultextract. + # The C++ compiler will combine linker options so we + # cannot just pass the convience library names through + # without $wl. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' + ;; + esac + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' + if $CC --version | grep -v '^2\.7' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\"" + else + # g++ 2.7 appears to require `-G' NOT `-shared' on this + # platform. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd="$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\"" + fi + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' + fi + ;; + esac + ;; + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + # So that behaviour is only enabled if SCOABSPATH is set to a + # non-empty value in the environment. Most likely only useful for + # creating official distributions of packages. + # This is a hack until libtool officially supports absolute path + # names for shared libraries. + _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + vxworks*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; +esac +AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)]) +test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +_LT_AC_TAGVAR(GCC, $1)="$GXX" +_LT_AC_TAGVAR(LD, $1)="$LD" + +AC_LIBTOOL_POSTDEP_PREDEP($1) +AC_LIBTOOL_PROG_COMPILER_PIC($1) +AC_LIBTOOL_PROG_CC_C_O($1) +AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1) +AC_LIBTOOL_PROG_LD_SHLIBS($1) +AC_LIBTOOL_SYS_DYNAMIC_LINKER($1) +AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1) + +AC_LIBTOOL_CONFIG($1) + +AC_LANG_POP +CC=$lt_save_CC +LDCXX=$LD +LD=$lt_save_LD +GCC=$lt_save_GCC +with_gnu_ldcxx=$with_gnu_ld +with_gnu_ld=$lt_save_with_gnu_ld +lt_cv_path_LDCXX=$lt_cv_path_LD +lt_cv_path_LD=$lt_save_path_LD +lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld +lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +])# AC_LIBTOOL_LANG_CXX_CONFIG + +# AC_LIBTOOL_POSTDEP_PREDEP([TAGNAME]) +# ------------------------------------ +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP],[ +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +ifelse([$1],[],[cat > conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext <> "$cfgfile" +ifelse([$1], [], +[#! $SHELL + +# `$echo "$cfgfile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP) +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. +# +# This file is part of GNU Libtool: +# Originally by Gordon Matzigkeit , 1996 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="$SED -e 1s/^X//" + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# The names of the tagged configurations supported by this script. +available_tags= + +# ### BEGIN LIBTOOL CONFIG], +[# ### BEGIN LIBTOOL TAG CONFIG: $tagname]) + +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$_LT_AC_TAGVAR(archive_cmds_need_lc, $1) + +# Whether or not to disallow shared libs when runtime libs are static +allow_libtool_libs_with_static_runtimes=$_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1) + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# An echo program that does not interpret backslashes. +echo=$lt_echo + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A C compiler. +LTCC=$lt_LTCC + +# LTCC compiler flags. +LTCFLAGS=$lt_LTCFLAGS + +# A language-specific compiler. +CC=$lt_[]_LT_AC_TAGVAR(compiler, $1) + +# Is the compiler the GNU C compiler? +with_gcc=$_LT_AC_TAGVAR(GCC, $1) + +# An ERE matcher. +EGREP=$lt_EGREP + +# The linker used to build libraries. +LD=$lt_[]_LT_AC_TAGVAR(LD, $1) + +# Whether we need hard or soft links. +LN_S=$lt_LN_S + +# A BSD-compatible nm program. +NM=$lt_NM + +# A symbol stripping program +STRIP=$lt_STRIP + +# Used to examine libraries when file_magic_cmd begins "file" +MAGIC_CMD=$MAGIC_CMD + +# Used on cygwin: DLL creation program. +DLLTOOL="$DLLTOOL" + +# Used on cygwin: object dumper. +OBJDUMP="$OBJDUMP" + +# Used on cygwin: assembler. +AS="$AS" + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# How to pass a linker flag through the compiler. +wl=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_wl, $1) + +# Object file suffix (normally "o"). +objext="$ac_objext" + +# Old archive suffix (normally "a"). +libext="$libext" + +# Shared library suffix (normally ".so"). +shrext_cmds='$shrext_cmds' + +# Executable file suffix (normally ""). +exeext="$exeext" + +# Additional compiler flags for building library objects. +pic_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) +pic_mode=$pic_mode + +# What is the maximum length of a command? +max_cmd_len=$lt_cv_sys_max_cmd_len + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_[]_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1) + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Do we need the lib prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_static, $1) + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_[]_LT_AC_TAGVAR(export_dynamic_flag_spec, $1) + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_[]_LT_AC_TAGVAR(whole_archive_flag_spec, $1) + +# Compiler flag to generate thread-safe objects. +thread_safe_flag_spec=$lt_[]_LT_AC_TAGVAR(thread_safe_flag_spec, $1) + +# Library versioning type. +version_type=$version_type + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME. +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Commands used to build and install an old-style archive. +RANLIB=$lt_RANLIB +old_archive_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_cmds, $1) +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_new_cmds, $1) + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) + +# Commands used to build and install a shared archive. +archive_cmds=$lt_[]_LT_AC_TAGVAR(archive_cmds, $1) +archive_expsym_cmds=$lt_[]_LT_AC_TAGVAR(archive_expsym_cmds, $1) +postinstall_cmds=$lt_postinstall_cmds +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to build a loadable module (assumed same as above if empty) +module_cmds=$lt_[]_LT_AC_TAGVAR(module_cmds, $1) +module_expsym_cmds=$lt_[]_LT_AC_TAGVAR(module_expsym_cmds, $1) + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + +# Dependencies to place before the objects being linked to create a +# shared library. +predep_objects=$lt_[]_LT_AC_TAGVAR(predep_objects, $1) + +# Dependencies to place after the objects being linked to create a +# shared library. +postdep_objects=$lt_[]_LT_AC_TAGVAR(postdep_objects, $1) + +# Dependencies to place before the objects being linked to create a +# shared library. +predeps=$lt_[]_LT_AC_TAGVAR(predeps, $1) + +# Dependencies to place after the objects being linked to create a +# shared library. +postdeps=$lt_[]_LT_AC_TAGVAR(postdeps, $1) + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_[]_LT_AC_TAGVAR(compiler_lib_search_path, $1) + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == file_magic. +file_magic_cmd=$lt_file_magic_cmd + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_[]_LT_AC_TAGVAR(allow_undefined_flag, $1) + +# Flag that forces no undefined symbols. +no_undefined_flag=$lt_[]_LT_AC_TAGVAR(no_undefined_flag, $1) + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# Same as above, but a single script fragment to be evaled but not shown. +finish_eval=$lt_finish_eval + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# This is the shared library runtime path variable. +runpath_var=$runpath_var + +# This is the shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# How to hardcode a shared library path into an executable. +hardcode_action=$_LT_AC_TAGVAR(hardcode_action, $1) + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) + +# If ld is used when linking, flag to hardcode \$libdir into +# a binary during linking. This must work even if \$libdir does +# not exist. +hardcode_libdir_flag_spec_ld=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1) + +# Whether we need a single -rpath flag with a separated argument. +hardcode_libdir_separator=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_separator, $1) + +# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the +# resulting binary. +hardcode_direct=$_LT_AC_TAGVAR(hardcode_direct, $1) + +# Set to yes if using the -LDIR flag during linking hardcodes DIR into the +# resulting binary. +hardcode_minus_L=$_LT_AC_TAGVAR(hardcode_minus_L, $1) + +# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into +# the resulting binary. +hardcode_shlibpath_var=$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1) + +# Set to yes if building a shared library automatically hardcodes DIR into the library +# and all subsequent libraries and executables linked against it. +hardcode_automatic=$_LT_AC_TAGVAR(hardcode_automatic, $1) + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at relink time. +variables_saved_for_relink="$variables_saved_for_relink" + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$_LT_AC_TAGVAR(link_all_deplibs, $1) + +# Compile-time system search path for libraries +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path="$_LT_AC_TAGVAR(fix_srcfile_path, $1)" + +# Set to yes if exported symbols are required. +always_export_symbols=$_LT_AC_TAGVAR(always_export_symbols, $1) + +# The commands to list exported symbols. +export_symbols_cmds=$lt_[]_LT_AC_TAGVAR(export_symbols_cmds, $1) + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_[]_LT_AC_TAGVAR(exclude_expsyms, $1) + +# Symbols that must always be exported. +include_expsyms=$lt_[]_LT_AC_TAGVAR(include_expsyms, $1) + +ifelse([$1],[], +[# ### END LIBTOOL CONFIG], +[# ### END LIBTOOL TAG CONFIG: $tagname]) + +__EOF__ + +ifelse([$1],[], [ + case $host_os in + aix3*) + cat <<\EOF >> "$cfgfile" + +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +EOF + ;; + esac + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || \ + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +]) +else + # If there is no Makefile yet, we rely on a make rule to execute + # `config.status --recheck' to rerun these tests and create the + # libtool script then. + ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'` + if test -f "$ltmain_in"; then + test -f Makefile && make "$ltmain" + fi +fi +])# AC_LIBTOOL_CONFIG + + +# AC_LIBTOOL_PROG_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------------------- +AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], +[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl + +_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test "$GCC" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + + AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +])# AC_LIBTOOL_PROG_COMPILER_NO_RTTI + + +# AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE +# --------------------------------- +AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], +[AC_REQUIRE([AC_CANONICAL_HOST]) +AC_REQUIRE([AC_PROG_NM]) +AC_REQUIRE([AC_OBJEXT]) +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Transform an extracted symbol line into a proper C declaration +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern int \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) # Its linker distinguishes data from code symbols + if test "$host_cpu" = ia64; then + symcode='[[ABCDEGRST]]' + fi + lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + ;; +linux*) + if test "$host_cpu" = ia64; then + symcode='[[ABCDGIRSTW]]' + lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +# Try without a prefix undercore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext < $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if grep ' nm_test_var$' "$nlist" >/dev/null; then + if grep ' nm_test_func$' "$nlist" >/dev/null; then + cat < conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | grep -v main >> conftest.$ac_ext' + + cat <> conftest.$ac_ext +#if defined (__STDC__) && __STDC__ +# define lt_ptr_t void * +#else +# define lt_ptr_t char * +# define const +#endif + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + lt_ptr_t address; +} +lt_preloaded_symbols[[]] = +{ +EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" | grep -v main >> conftest.$ac_ext + cat <<\EOF >> conftest.$ac_ext + {0, (lt_ptr_t) 0} +}; + +#ifdef __cplusplus +} +#endif +EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -f conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi +]) # AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE + + +# AC_LIBTOOL_PROG_COMPILER_PIC([TAGNAME]) +# --------------------------------------- +AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC], +[_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_AC_TAGVAR(lt_prog_compiler_static, $1)= + +AC_MSG_CHECKING([for $compiler option to produce PIC]) + ifelse([$1],[CXX],[ + # C++ specific cases for pic, static, wl, etc. + if test "$GXX" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | os2* | pw32*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT' + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + interix3*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix4* | aix5*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon' + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + esac + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | kfreebsd*-gnu | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + if test "$host_cpu" != ia64; then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + icpc* | ecpc*) + # Intel C++ + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC*) + # Portland Group C++ compiler. + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test "$GCC" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT' + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + interix3*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon' + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + esac + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT' + ;; + + hpux9* | hpux10* | hpux11*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + newsos6) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + linux*) + case $cc_basename in + icc* | ecc*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + esac + ;; + + osf3* | osf4* | osf5*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +AC_MSG_RESULT([$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)]) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)"; then + AC_LIBTOOL_COMPILER_OPTION([if $compiler PIC flag $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) works], + _LT_AC_TAGVAR(lt_prog_compiler_pic_works, $1), + [$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])" + ;; +esac + +# +# Check to make sure the static flag actually works. +# +wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_AC_TAGVAR(lt_prog_compiler_static, $1)\" +AC_LIBTOOL_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_AC_TAGVAR(lt_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=]) +]) + + +# AC_LIBTOOL_PROG_LD_SHLIBS([TAGNAME]) +# ------------------------------------ +# See if the linker supports building shared libraries. +AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS], +[AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +ifelse([$1],[CXX],[ + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + case $host_os in + aix4* | aix5*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + else + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_AC_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" + ;; + cygwin* | mingw*) + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]] /s/.* \([[^ ]]*\)/\1 DATA/;/^.* __nm__/s/^.* __nm__\([[^ ]]*\) [[^ ]]*/\1 DATA/;/^I /d;/^[[AITW]] /s/.* //'\'' | sort | uniq > $export_symbols' + ;; + *) + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac +],[ + runpath_var= + _LT_AC_TAGVAR(allow_undefined_flag, $1)= + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_AC_TAGVAR(archive_cmds, $1)= + _LT_AC_TAGVAR(archive_expsym_cmds, $1)= + _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)= + _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + _LT_AC_TAGVAR(thread_safe_flag_spec, $1)= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)= + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_minus_L, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_AC_TAGVAR(link_all_deplibs, $1)=unknown + _LT_AC_TAGVAR(hardcode_automatic, $1)=no + _LT_AC_TAGVAR(module_cmds, $1)= + _LT_AC_TAGVAR(module_expsym_cmds, $1)= + _LT_AC_TAGVAR(always_export_symbols, $1)=no + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_AC_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + _LT_AC_TAGVAR(exclude_expsyms, $1)="_GLOBAL_OFFSET_TABLE_" + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + extract_expsyms_cmds= + # Just being paranoid about ensuring that cc_basename is set. + _LT_CC_BASENAME([$compiler]) + case $host_os in + cygwin* | mingw* | pw32*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + esac + + _LT_AC_TAGVAR(ld_shlibs, $1)=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v 2>/dev/null` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix3* | aix4* | aix5*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + _LT_AC_TAGVAR(ld_shlibs, $1)=no + cat <&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +EOF + fi + ;; + + amigaos*) + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + + # Samuel A. Falvo II reports + # that the semantics of dynamic libraries on AmigaOS, at least up + # to version 4, is to share data among multiple programs linked + # with the same dynamic library. Since this doesn't match the + # behavior of shared libraries on other platforms, we can't use + # them. + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(always_export_symbols, $1)=no + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]] /s/.* \([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]] /s/.* //'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + interix3*) + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + linux*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + tmp_addflag= + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + esac + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test $supports_anon_versioning = yes; then + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + $echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then + _LT_AC_TAGVAR(ld_shlibs, $1)=no + cat <&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +EOF + elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no; then + runpath_var= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + else + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_AC_TAGVAR(archive_cmds, $1)='' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + if test "$GCC" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + else + # We have old collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared libraries. + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + # see comment about different semantics on the GNU ld section + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + + bsdi[[45]]*) + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_AC_TAGVAR(old_archive_cmds, $1)='lib /OUT:$oldlib$oldobjs$old_deplibs' + _LT_AC_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`' + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + darwin* | rhapsody*) + case $host_os in + rhapsody* | darwin1.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_automatic, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + if test "$GCC" = yes ; then + output_verbose_link_cmd='echo' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + fi + ;; + + dgux*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + freebsd1*) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | kfreebsd*-gnu | dragonfly*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test "$GCC" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + openbsd*) + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + else + case $host_os in + openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + ;; + esac + fi + ;; + + os2*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(archive_cmds, $1)='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + else + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~ + $LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_AC_TAGVAR(no_undefined_flag, $1)=' -z text' + if test "$GCC" = yes; then + wlarc='${wl}' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp' + else + wlarc='' + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine linker options so we + # cannot just pass the convience library names through + # without $wl, iff we do not link with $LD. + # Luckily, gcc supports the same syntax we need for Sun Studio. + # Supported since Solaris 2.6 (maybe 2.5.1?) + case $wlarc in + '') + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' ;; + *) + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' ;; + esac ;; + esac + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_AC_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_AC_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7*) + _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + fi +]) +AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)]) +test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +# +# Do we need to explicitly link libc? +# +case "x$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $_LT_AC_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_MSG_CHECKING([whether -lc should be explicitly linked in]) + $rm conftest* + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_AC_TAGVAR(allow_undefined_flag, $1) + _LT_AC_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_AC_TAGVAR(archive_cmds, $1) 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) + then + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + else + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_AC_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $rm conftest* + AC_MSG_RESULT([$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)]) + ;; + esac + fi + ;; +esac +])# AC_LIBTOOL_PROG_LD_SHLIBS + + +# _LT_AC_FILE_LTDLL_C +# ------------------- +# Be careful that the start marker always follows a newline. +AC_DEFUN([_LT_AC_FILE_LTDLL_C], [ +# /* ltdll.c starts here */ +# #define WIN32_LEAN_AND_MEAN +# #include +# #undef WIN32_LEAN_AND_MEAN +# #include +# +# #ifndef __CYGWIN__ +# # ifdef __CYGWIN32__ +# # define __CYGWIN__ __CYGWIN32__ +# # endif +# #endif +# +# #ifdef __cplusplus +# extern "C" { +# #endif +# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved); +# #ifdef __cplusplus +# } +# #endif +# +# #ifdef __CYGWIN__ +# #include +# DECLARE_CYGWIN_DLL( DllMain ); +# #endif +# HINSTANCE __hDllInstance_base; +# +# BOOL APIENTRY +# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved) +# { +# __hDllInstance_base = hInst; +# return TRUE; +# } +# /* ltdll.c ends here */ +])# _LT_AC_FILE_LTDLL_C + + +# _LT_AC_TAGVAR(VARNAME, [TAGNAME]) +# --------------------------------- +AC_DEFUN([_LT_AC_TAGVAR], [ifelse([$2], [], [$1], [$1_$2])]) + + +# old names +AC_DEFUN([AM_PROG_LIBTOOL], [AC_PROG_LIBTOOL]) +AC_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AC_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AC_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) +AC_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) +AC_DEFUN([AM_PROG_LD], [AC_PROG_LD]) +AC_DEFUN([AM_PROG_NM], [AC_PROG_NM]) + +# This is just to silence aclocal about the macro not being used +ifelse([AC_DISABLE_FAST_INSTALL]) + +AC_DEFUN([LT_AC_PROG_GCJ], +[AC_CHECK_TOOL(GCJ, gcj, no) + test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS) +]) + +AC_DEFUN([LT_AC_PROG_RC], +[AC_CHECK_TOOL(RC, windres, no) +]) + +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +# LT_AC_PROG_SED +# -------------- +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +AC_DEFUN([LT_AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f $lt_ac_sed && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test $lt_ac_count -gt 10 && break + lt_ac_count=`expr $lt_ac_count + 1` + if test $lt_ac_count -gt $lt_ac_max; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +]) + +# Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_AUTOMAKE_VERSION(VERSION) +# ---------------------------- +# Automake X.Y traces this macro to ensure aclocal.m4 has been +# generated from the m4 files accompanying Automake X.Y. +# (This private macro should not be called outside this file.) +AC_DEFUN([AM_AUTOMAKE_VERSION], +[am__api_version='1.10' +dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to +dnl require some minimum version. Point them to the right macro. +m4_if([$1], [1.10], [], + [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl +]) + +# _AM_AUTOCONF_VERSION(VERSION) +# ----------------------------- +# aclocal traces this macro to find the Autoconf version. +# This is a private macro too. Using m4_define simplifies +# the logic in aclocal, which can simply ignore this definition. +m4_define([_AM_AUTOCONF_VERSION], []) + +# AM_SET_CURRENT_AUTOMAKE_VERSION +# ------------------------------- +# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. +# This function is AC_REQUIREd by AC_INIT_AUTOMAKE. +AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], +[AM_AUTOMAKE_VERSION([1.10])dnl +_AM_AUTOCONF_VERSION(m4_PACKAGE_VERSION)]) + +# AM_AUX_DIR_EXPAND -*- Autoconf -*- + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets +# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to +# `$srcdir', `$srcdir/..', or `$srcdir/../..'. +# +# Of course, Automake must honor this variable whenever it calls a +# tool from the auxiliary directory. The problem is that $srcdir (and +# therefore $ac_aux_dir as well) can be either absolute or relative, +# depending on how configure is run. This is pretty annoying, since +# it makes $ac_aux_dir quite unusable in subdirectories: in the top +# source directory, any form will work fine, but in subdirectories a +# relative path needs to be adjusted first. +# +# $ac_aux_dir/missing +# fails when called from a subdirectory if $ac_aux_dir is relative +# $top_srcdir/$ac_aux_dir/missing +# fails if $ac_aux_dir is absolute, +# fails when called from a subdirectory in a VPATH build with +# a relative $ac_aux_dir +# +# The reason of the latter failure is that $top_srcdir and $ac_aux_dir +# are both prefixed by $srcdir. In an in-source build this is usually +# harmless because $srcdir is `.', but things will broke when you +# start a VPATH build or use an absolute $srcdir. +# +# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, +# iff we strip the leading $srcdir from $ac_aux_dir. That would be: +# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` +# and then we would define $MISSING as +# MISSING="\${SHELL} $am_aux_dir/missing" +# This will work as long as MISSING is not called from configure, because +# unfortunately $(top_srcdir) has no meaning in configure. +# However there are other variables, like CC, which are often used in +# configure, and could therefore not use this "fixed" $ac_aux_dir. +# +# Another solution, used here, is to always expand $ac_aux_dir to an +# absolute PATH. The drawback is that using absolute paths prevent a +# configured tree to be moved without reconfiguration. + +AC_DEFUN([AM_AUX_DIR_EXPAND], +[dnl Rely on autoconf to set up CDPATH properly. +AC_PREREQ([2.50])dnl +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` +]) + +# AM_CONDITIONAL -*- Autoconf -*- + +# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 8 + +# AM_CONDITIONAL(NAME, SHELL-CONDITION) +# ------------------------------------- +# Define a conditional. +AC_DEFUN([AM_CONDITIONAL], +[AC_PREREQ(2.52)dnl + ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE])dnl +AC_SUBST([$1_FALSE])dnl +_AM_SUBST_NOTMAKE([$1_TRUE])dnl +_AM_SUBST_NOTMAKE([$1_FALSE])dnl +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 9 + +# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be +# written in clear, in which case automake, when reading aclocal.m4, +# will think it sees a *use*, and therefore will trigger all it's +# C support machinery. Also note that it means that autoscan, seeing +# CC etc. in the Makefile, will ask for an AC_PROG_CC use... + + +# _AM_DEPENDENCIES(NAME) +# ---------------------- +# See how the compiler implements dependency checking. +# NAME is "CC", "CXX", "GCJ", or "OBJC". +# We try a few techniques and use that to set a single cache variable. +# +# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was +# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular +# dependency, and given that the user is not expected to run this macro, +# just rely on AC_PROG_CC. +AC_DEFUN([_AM_DEPENDENCIES], +[AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +ifelse([$1], CC, [depcc="$CC" am_compiler_list=], + [$1], CXX, [depcc="$CXX" am_compiler_list=], + [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], UPC, [depcc="$UPC" am_compiler_list=], + [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + case $depmode in + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + none) break ;; + esac + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. + if depmode=$depmode \ + source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) + + +# AM_SET_DEPDIR +# ------------- +# Choose a directory name for dependency files. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES +AC_DEFUN([AM_SET_DEPDIR], +[AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) + + +# AM_DEP_TRACK +# ------------ +AC_DEFUN([AM_DEP_TRACK], +[AC_ARG_ENABLE(dependency-tracking, +[ --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH])dnl +_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl +]) + +# Generate code to set up dependency tracking. -*- Autoconf -*- + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +#serial 3 + +# _AM_OUTPUT_DEPENDENCY_COMMANDS +# ------------------------------ +AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], +[for mf in $CONFIG_FILES; do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named `Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed 10q "$mf" | grep '^#.*generated by automake' > /dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running `make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done +done +])# _AM_OUTPUT_DEPENDENCY_COMMANDS + + +# AM_OUTPUT_DEPENDENCY_COMMANDS +# ----------------------------- +# This macro should only be invoked once -- use via AC_REQUIRE. +# +# This code is only required when automatic dependency tracking +# is enabled. FIXME. This creates each `.P' file that we will +# need in order to bootstrap the dependency handling code. +AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], +[AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) + +# Do all the work for Automake. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 12 + +# This macro actually does too much. Some checks are only needed if +# your package does certain things. But this isn't really a big deal. + +# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) +# AM_INIT_AUTOMAKE([OPTIONS]) +# ----------------------------------------------- +# The call with PACKAGE and VERSION arguments is the old style +# call (pre autoconf-2.50), which is being phased out. PACKAGE +# and VERSION should now be passed to AC_INIT and removed from +# the call to AM_INIT_AUTOMAKE. +# We support both call styles for the transition. After +# the next Automake release, Autoconf can make the AC_INIT +# arguments mandatory, and then we can depend on a new Autoconf +# release and drop the old call support. +AC_DEFUN([AM_INIT_AUTOMAKE], +[AC_PREREQ([2.60])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl +dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. +m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, + [m4_fatal([AC_INIT should be called with package and version arguments])])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) + AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) +AM_MISSING_PROG(AUTOCONF, autoconf) +AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) +AM_MISSING_PROG(AUTOHEADER, autoheader) +AM_MISSING_PROG(MAKEINFO, makeinfo) +AM_PROG_INSTALL_SH +AM_PROG_INSTALL_STRIP +AC_REQUIRE([AM_PROG_MKDIR_P])dnl +# We need awk for the "check" target. The system "awk" is bad on +# some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES(CC)], + [define([AC_PROG_CC], + defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES(CXX)], + [define([AC_PROG_CXX], + defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJC], + [_AM_DEPENDENCIES(OBJC)], + [define([AC_PROG_OBJC], + defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl +]) +]) + + +# When config.status generates a header, we must update the stamp-h file. +# This file resides in the same directory as the config header +# that is generated. The stamp files are numbered to have different names. + +# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the +# loop where config.status creates the headers, so we can generate +# our stamp files there. +AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], +[# Compute $1's index in $config_headers. +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $1 | $1:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_SH +# ------------------ +# Define $install_sh. +AC_DEFUN([AM_PROG_INSTALL_SH], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"} +AC_SUBST(install_sh)]) + +# Copyright (C) 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# Check whether the underlying file-system supports filenames +# with a leading dot. For instance MS-DOS doesn't. +AC_DEFUN([AM_SET_LEADING_DOT], +[rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) + +# Check to see how 'make' treats includes. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 3 + +# AM_MAKE_INCLUDE() +# ----------------- +# Check to see how make treats includes. +AC_DEFUN([AM_MAKE_INCLUDE], +[am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo done +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# We grep out `Entering directory' and `Leaving directory' +# messages which can occur if `w' ends up in MAKEFLAGS. +# In particular we don't look at `^make:' because GNU make might +# be invoked under some other name (usually "gmake"), in which +# case it prints its new name instead of `make'. +if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then + am__include=include + am__quote= + _am_result=GNU +fi +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then + am__include=.include + am__quote="\"" + _am_result=BSD + fi +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) + +# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- + +# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 5 + +# AM_MISSING_PROG(NAME, PROGRAM) +# ------------------------------ +AC_DEFUN([AM_MISSING_PROG], +[AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) + + +# AM_MISSING_HAS_RUN +# ------------------ +# Define MISSING if not defined so far and test if it supports --run. +# If it does, set am_missing_run to use it, otherwise, to nothing. +AC_DEFUN([AM_MISSING_HAS_RUN], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([missing])dnl +test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" +# Use eval to expand $SHELL +if eval "$MISSING --run true"; then + am_missing_run="$MISSING --run " +else + am_missing_run= + AC_MSG_WARN([`missing' script is too old or missing]) +fi +]) + +# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_MKDIR_P +# --------------- +# Check for `mkdir -p'. +AC_DEFUN([AM_PROG_MKDIR_P], +[AC_PREREQ([2.60])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, +dnl while keeping a definition of mkdir_p for backward compatibility. +dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. +dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of +dnl Makefile.ins that do not define MKDIR_P, so we do our own +dnl adjustment using top_builddir (which is defined more often than +dnl MKDIR_P). +AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl +case $mkdir_p in + [[\\/$]]* | ?:[[\\/]]*) ;; + */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; +esac +]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 3 + +# _AM_MANGLE_OPTION(NAME) +# ----------------------- +AC_DEFUN([_AM_MANGLE_OPTION], +[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) + +# _AM_SET_OPTION(NAME) +# ------------------------------ +# Set option NAME. Presently that only means defining a flag for this option. +AC_DEFUN([_AM_SET_OPTION], +[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) + +# _AM_SET_OPTIONS(OPTIONS) +# ---------------------------------- +# OPTIONS is a space-separated list of Automake options. +AC_DEFUN([_AM_SET_OPTIONS], +[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) + +# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) +# ------------------------------------------- +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +AC_DEFUN([_AM_IF_OPTION], +[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) + +# Check to make sure that the build environment is sane. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# AM_SANITY_CHECK +# --------------- +AC_DEFUN([AM_SANITY_CHECK], +[AC_MSG_CHECKING([whether build environment is sane]) +# Just in case +sleep 1 +echo timestamp > conftest.file +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t $srcdir/configure conftest.file` + fi + rm -f conftest.file + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken +alias in your environment]) + fi + + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT(yes)]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_STRIP +# --------------------- +# One issue with vendor `install' (even GNU) is that you can't +# specify the program used to strip binaries. This is especially +# annoying in cross-compiling environments, where the build's strip +# is unlikely to handle the host's binaries. +# Fortunately install-sh will honor a STRIPPROG variable, so we +# always use install-sh in `make install-strip', and initialize +# STRIPPROG with the value of the STRIP variable (set by the user). +AC_DEFUN([AM_PROG_INSTALL_STRIP], +[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the `STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be `maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) + +# Copyright (C) 2006 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_SUBST_NOTMAKE(VARIABLE) +# --------------------------- +# Prevent Automake from outputing VARIABLE = @VARIABLE@ in Makefile.in. +# This macro is traced by Automake. +AC_DEFUN([_AM_SUBST_NOTMAKE]) + +# Check how to create a tarball. -*- Autoconf -*- + +# Copyright (C) 2004, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# _AM_PROG_TAR(FORMAT) +# -------------------- +# Check how to create a tarball in format FORMAT. +# FORMAT should be one of `v7', `ustar', or `pax'. +# +# Substitute a variable $(am__tar) that is a command +# writing to stdout a FORMAT-tarball containing the directory +# $tardir. +# tardir=directory && $(am__tar) > result.tar +# +# Substitute a variable $(am__untar) that extract such +# a tarball read from stdin. +# $(am__untar) < result.tar +AC_DEFUN([_AM_PROG_TAR], +[# Always define AMTAR for backward compatibility. +AM_MISSING_PROG([AMTAR], [tar]) +m4_if([$1], [v7], + [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'], + [m4_case([$1], [ustar],, [pax],, + [m4_fatal([Unknown tar format])]) +AC_MSG_CHECKING([how to create a $1 tar archive]) +# Loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' +_am_tools=${am_cv_prog_tar_$1-$_am_tools} +# Do not fold the above two line into one, because Tru64 sh and +# Solaris sh will not grok spaces in the rhs of `-'. +for _am_tool in $_am_tools +do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; + do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi +done +rm -rf conftest.dir + +AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) +AC_MSG_RESULT([$am_cv_prog_tar_$1])]) +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) # _AM_PROG_TAR + diff --git a/TESTU01/TestU01-1.2.3/bootstrap b/TESTU01/TestU01-1.2.3/bootstrap new file mode 100755 index 0000000..bc45649 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/bootstrap @@ -0,0 +1,15 @@ +#!/bin/sh + +# This script can be used to rebuild the derived configuration files +# whenever the primary configuration files have been changed or when +# a new source file is added or removed. +# This script should not be used by the user compiling the package. + +cd include +./makedef +cd .. +libtoolize --copy --force +aclocal +autoheader +automake --add-missing --copy +autoconf diff --git a/TESTU01/TestU01-1.2.3/config.guess b/TESTU01/TestU01-1.2.3/config.guess new file mode 100755 index 0000000..396482d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/config.guess @@ -0,0 +1,1500 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2006-07-02' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + i*:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + x86:Interix*:[3456]*) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T:Interix*:[3456]*) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/TESTU01/TestU01-1.2.3/config.sub b/TESTU01/TestU01-1.2.3/config.sub new file mode 100755 index 0000000..fab0aa3 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/config.sub @@ -0,0 +1,1616 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2006-09-20' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64vr | mips64vrel \ + | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | mt \ + | msp430 \ + | nios | nios2 \ + | ns16k | ns32k \ + | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | score \ + | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16c) + basic_machine=cr16c-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -zvmoe) + os=-zvmoe + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/TESTU01/TestU01-1.2.3/configure b/TESTU01/TestU01-1.2.3/configure new file mode 100755 index 0000000..1d8776e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/configure @@ -0,0 +1,22042 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.61 for TestU01 1.2.3. +# +# Report bugs to . +# +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + +if test "x$CONFIG_SHELL" = x; then + if (eval ":") 2>/dev/null; then + as_have_required=yes +else + as_have_required=no +fi + + if test $as_have_required = yes && (eval ": +(as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=\$LINENO + as_lineno_2=\$LINENO + test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" && + test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; } +") 2> /dev/null; then + : +else + as_candidate_shells= + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + case $as_dir in + /*) + for as_base in sh bash ksh sh5; do + as_candidate_shells="$as_candidate_shells $as_dir/$as_base" + done;; + esac +done +IFS=$as_save_IFS + + + for as_shell in $as_candidate_shells $SHELL; do + # Try only shells that exist, to save several forks. + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { ("$as_shell") 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +_ASEOF +}; then + CONFIG_SHELL=$as_shell + as_have_required=yes + if { "$as_shell" 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +(as_func_return () { + (exit $1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = "$1" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test $exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; } + +_ASEOF +}; then + break +fi + +fi + + done + + if test "x$CONFIG_SHELL" != x; then + for as_var in BASH_ENV ENV + do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + done + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + + if test $as_have_required = no; then + echo This script requires a shell more modern than all the + echo shells that I found on your system. Please install a + echo modern shell, or manually run the script under such a + echo shell if you do have one. + { (exit 1); exit 1; } +fi + + +fi + +fi + + + +(eval "as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0") || { + echo No shell found that supports shell functions. + echo Please tell autoconf@gnu.org about your system, + echo including any error possibly output before this + echo message +} + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + + + +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$ECHO" | sed 's,\\\\\$\\$0,'$0','` + ;; +esac + +echo=${ECHO-echo} +if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X$1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then + # Yippee, $echo works! + : +else + # Restart under the correct shell. + exec $SHELL "$0" --no-reexec ${1+"$@"} +fi + +if test "X$1" = X--fallback-echo; then + # used as fallback echo + shift + cat </dev/null 2>&1 && unset CDPATH + +if test -z "$ECHO"; then +if test "X${echo_test_string+set}" != Xset; then +# find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if (echo_test_string=`eval $cmd`) 2>/dev/null && + echo_test_string=`eval $cmd` && + (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null + then + break + fi + done +fi + +if test "X`($echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : +else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + echo="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$echo" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + echo='print -r' + elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"} + else + # Try using printf. + echo='printf %s\n' + if test "X`($echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + echo="$CONFIG_SHELL $0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + echo="$CONFIG_SHELL $0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do + if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "$0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"} + else + # Oops. We lost completely, so just stick with echo. + echo=echo + fi + fi + fi + fi +fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +ECHO=$echo +if test "X$ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then + ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo" +fi + + + + +tagnames=${tagnames+${tagnames},}CXX + +tagnames=${tagnames+${tagnames},}F77 + +exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Identity of this package. +PACKAGE_NAME='TestU01' +PACKAGE_TARNAME='testu01' +PACKAGE_VERSION='1.2.3' +PACKAGE_STRING='TestU01 1.2.3' +PACKAGE_BUGREPORT='lecuyer@iro.umontreal.ca' + +ac_unique_file="mylib/num.c" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='SHELL +PATH_SEPARATOR +PACKAGE_NAME +PACKAGE_TARNAME +PACKAGE_VERSION +PACKAGE_STRING +PACKAGE_BUGREPORT +exec_prefix +prefix +program_transform_name +bindir +sbindir +libexecdir +datarootdir +datadir +sysconfdir +sharedstatedir +localstatedir +includedir +oldincludedir +docdir +infodir +htmldir +dvidir +pdfdir +psdir +libdir +localedir +mandir +DEFS +ECHO_C +ECHO_N +ECHO_T +LIBS +build_alias +host_alias +target_alias +INSTALL_PROGRAM +INSTALL_SCRIPT +INSTALL_DATA +am__isrc +CYGPATH_W +PACKAGE +VERSION +ACLOCAL +AUTOCONF +AUTOMAKE +AUTOHEADER +MAKEINFO +install_sh +STRIP +INSTALL_STRIP_PROGRAM +mkdir_p +AWK +SET_MAKE +am__leading_dot +AMTAR +am__tar +am__untar +build +build_cpu +build_vendor +build_os +host +host_cpu +host_vendor +host_os +CC +CFLAGS +LDFLAGS +CPPFLAGS +ac_ct_CC +EXEEXT +OBJEXT +DEPDIR +am__include +am__quote +AMDEP_TRUE +AMDEP_FALSE +AMDEPBACKSLASH +CCDEPMODE +am__fastdepCC_TRUE +am__fastdepCC_FALSE +CPP +LN_S +SED +GREP +EGREP +ECHO +AR +RANLIB +CXX +CXXFLAGS +ac_ct_CXX +CXXDEPMODE +am__fastdepCXX_TRUE +am__fastdepCXX_FALSE +CXXCPP +F77 +FFLAGS +ac_ct_F77 +LIBTOOL +have_mathematica +LIBM +LIBOBJS +LTLIBOBJS' +ac_subst_files='' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CPP +CXX +CXXFLAGS +CCC +CXXCPP +F77 +FFLAGS' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=\$ac_optarg ;; + + -without-* | --without-*) + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } +fi + +# Be sure to have absolute directory names. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; } +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + { echo "$as_me: error: Working directory cannot be determined" >&2 + { (exit 1); exit 1; }; } +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + { echo "$as_me: error: pwd does not report name of working directory" >&2 + { (exit 1); exit 1; }; } + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$0" || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2 + { (exit 1); exit 1; }; } + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures TestU01 1.2.3 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/testu01] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +Program names: + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM run sed PROGRAM on installed program names + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of TestU01 1.2.3:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors + --enable-shared[=PKGS] build shared libraries [default=yes] + --enable-static[=PKGS] build static libraries [default=yes] + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-gnu-ld assume the C compiler uses GNU ld [default=no] + --with-pic try to use only PIC/non-PIC objects [default=use + both] + --with-tags[=TAGS] include additional configurations [automatic] + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + CXX C++ compiler command + CXXFLAGS C++ compiler flags + CXXCPP C++ preprocessor + F77 Fortran 77 compiler command + FFLAGS Fortran 77 compiler flags + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +TestU01 configure 1.2.3 +generated by GNU Autoconf 2.61 + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by TestU01 $as_me 1.2.3, which was +generated by GNU Autoconf 2.61. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args '$ac_arg'" + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -n "$CONFIG_SITE"; then + set x "$CONFIG_SITE" +elif test "x$prefix" != xNONE; then + set x "$prefix/share/config.site" "$prefix/etc/config.site" +else + set x "$ac_default_prefix/share/config.site" \ + "$ac_default_prefix/etc/config.site" +fi +shift +for ac_site_file +do + if test -r "$ac_site_file"; then + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } +fi + + + + + + + + + + + + + + + + + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +am__api_version='1.10' + +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&5 +echo "$as_me: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&2;} + { (exit 1); exit 1; }; } +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +{ echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 +echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6; } +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in + ./ | .// | /cC/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + done + done + ;; +esac +done +IFS=$as_save_IFS + + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ echo "$as_me:$LINENO: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +{ echo "$as_me:$LINENO: checking whether build environment is sane" >&5 +echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6; } +# Just in case +sleep 1 +echo timestamp > conftest.file +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t $srcdir/configure conftest.file` + fi + rm -f conftest.file + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + { { echo "$as_me:$LINENO: error: ls -t appears to fail. Make sure there is not a broken +alias in your environment" >&5 +echo "$as_me: error: ls -t appears to fail. Make sure there is not a broken +alias in your environment" >&2;} + { (exit 1); exit 1; }; } + fi + + test "$2" = conftest.file + ) +then + # Ok. + : +else + { { echo "$as_me:$LINENO: error: newly created file is older than distributed files! +Check your system clock" >&5 +echo "$as_me: error: newly created file is older than distributed files! +Check your system clock" >&2;} + { (exit 1); exit 1; }; } +fi +{ echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } +test "$program_prefix" != NONE && + program_transform_name="s&^&$program_prefix&;$program_transform_name" +# Use a double $ so make ignores it. +test "$program_suffix" != NONE && + program_transform_name="s&\$&$program_suffix&;$program_transform_name" +# Double any \ or $. echo might interpret backslashes. +# By default was `s,x,x', remove it if useless. +cat <<\_ACEOF >conftest.sed +s/[\\$]/&&/g;s/;s,x,x,$// +_ACEOF +program_transform_name=`echo $program_transform_name | sed -f conftest.sed` +rm -f conftest.sed + +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` + +test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" +# Use eval to expand $SHELL +if eval "$MISSING --run true"; then + am_missing_run="$MISSING --run " +else + am_missing_run= + { echo "$as_me:$LINENO: WARNING: \`missing' script is too old or missing" >&5 +echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} +fi + +{ echo "$as_me:$LINENO: checking for a thread-safe mkdir -p" >&5 +echo $ECHO_N "checking for a thread-safe mkdir -p... $ECHO_C" >&6; } +if test -z "$MKDIR_P"; then + if test "${ac_cv_path_mkdir+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done +done +IFS=$as_save_IFS + +fi + + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + test -d ./--version && rmdir ./--version + MKDIR_P="$ac_install_sh -d" + fi +fi +{ echo "$as_me:$LINENO: result: $MKDIR_P" >&5 +echo "${ECHO_T}$MKDIR_P" >&6; } + +mkdir_p="$MKDIR_P" +case $mkdir_p in + [\\/$]* | ?:[\\/]*) ;; + */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; +esac + +for ac_prog in gawk mawk nawk awk +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_AWK+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$AWK"; then + ac_cv_prog_AWK="$AWK" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_AWK="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +AWK=$ac_cv_prog_AWK +if test -n "$AWK"; then + { echo "$as_me:$LINENO: result: $AWK" >&5 +echo "${ECHO_T}$AWK" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$AWK" && break +done + +{ echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6; } +set x ${MAKE-make}; ac_make=`echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + SET_MAKE= +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null + +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + am__isrc=' -I$(srcdir)' + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + { { echo "$as_me:$LINENO: error: source directory already configured; run \"make distclean\" there first" >&5 +echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;} + { (exit 1); exit 1; }; } + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi + + +# Define the identity of the package. + PACKAGE='testu01' + VERSION='1.2.3' + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE "$PACKAGE" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define VERSION "$VERSION" +_ACEOF + +# Some tools Automake needs. + +ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} + + +AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} + + +AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} + + +AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} + + +MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} + +install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"} + +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the `STRIP' environment variable to overrule this program. +if test "$cross_compiling" != no; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_STRIP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { echo "$as_me:$LINENO: result: $STRIP" >&5 +echo "${ECHO_T}$STRIP" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_STRIP="strip" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { echo "$as_me:$LINENO: result: $ac_ct_STRIP" >&5 +echo "${ECHO_T}$ac_ct_STRIP" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" + +# We need awk for the "check" target. The system "awk" is bad on +# some platforms. +# Always define AMTAR for backward compatibility. + +AMTAR=${AMTAR-"${am_missing_run}tar"} + +am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -' + + + + + +ac_config_headers="$ac_config_headers include/config.h" + +ac_config_headers="$ac_config_headers include/gdefconf.h" + + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + { { echo "$as_me:$LINENO: error: cannot run $SHELL $ac_aux_dir/config.sub" >&5 +echo "$as_me: error: cannot run $SHELL $ac_aux_dir/config.sub" >&2;} + { (exit 1); exit 1; }; } + +{ echo "$as_me:$LINENO: checking build system type" >&5 +echo $ECHO_N "checking build system type... $ECHO_C" >&6; } +if test "${ac_cv_build+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + { { echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5 +echo "$as_me: error: cannot guess build type; you must specify one" >&2;} + { (exit 1); exit 1; }; } +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&5 +echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&2;} + { (exit 1); exit 1; }; } + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_build" >&5 +echo "${ECHO_T}$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) { { echo "$as_me:$LINENO: error: invalid value of canonical build" >&5 +echo "$as_me: error: invalid value of canonical build" >&2;} + { (exit 1); exit 1; }; };; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ echo "$as_me:$LINENO: checking host system type" >&5 +echo $ECHO_N "checking host system type... $ECHO_C" >&6; } +if test "${ac_cv_host+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&5 +echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&2;} + { (exit 1); exit 1; }; } +fi + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_host" >&5 +echo "${ECHO_T}$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) { { echo "$as_me:$LINENO: error: invalid value of canonical host" >&5 +echo "$as_me: error: invalid value of canonical host" >&2;} + { (exit 1); exit 1; }; };; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + + +# Checks for programs. +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&5 +echo "$as_me: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ echo "$as_me:$LINENO: checking for C compiler default output file name" >&5 +echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6; } +ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +# +# List of possible output files, starting from the most likely. +# The algorithm is not robust to junk in `.', hence go to wildcards (a.*) +# only as a last resort. b.out is created by i960 compilers. +ac_files='a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out' +# +# The IRIX 6 linker writes into existing files which may not be +# executable, retaining their permissions. Remove them first so a +# subsequent execution test works. +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { (ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi + +{ echo "$as_me:$LINENO: result: $ac_file" >&5 +echo "${ECHO_T}$ac_file" >&6; } +if test -z "$ac_file"; then + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: C compiler cannot create executables +See \`config.log' for more details." >&5 +echo "$as_me: error: C compiler cannot create executables +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi + +ac_exeext=$ac_cv_exeext + +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether the C compiler works" >&5 +echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6; } +# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { echo "$as_me:$LINENO: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + fi + fi +fi +{ echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + +rm -f a.out a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 +echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6; } +{ echo "$as_me:$LINENO: result: $cross_compiling" >&5 +echo "${ECHO_T}$cross_compiling" >&6; } + +{ echo "$as_me:$LINENO: checking for suffix of executables" >&5 +echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6; } +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest$ac_cv_exeext +{ echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 +echo "${ECHO_T}$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +{ echo "$as_me:$LINENO: checking for suffix of object files" >&5 +echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6; } +if test "${ac_cv_objext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 +echo "${ECHO_T}$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6; } +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5 +echo $ECHO_N "checking for $CC option to accept ISO C89... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cc_c89=$ac_arg +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { echo "$as_me:$LINENO: result: none needed" >&5 +echo "${ECHO_T}none needed" >&6; } ;; + xno) + { echo "$as_me:$LINENO: result: unsupported" >&5 +echo "${ECHO_T}unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_c89" >&6; } ;; +esac + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +DEPDIR="${am__leading_dot}deps" + +ac_config_commands="$ac_config_commands depfiles" + + +am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo done +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +{ echo "$as_me:$LINENO: checking for style of include used by $am_make" >&5 +echo $ECHO_N "checking for style of include used by $am_make... $ECHO_C" >&6; } +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# We grep out `Entering directory' and `Leaving directory' +# messages which can occur if `w' ends up in MAKEFLAGS. +# In particular we don't look at `^make:' because GNU make might +# be invoked under some other name (usually "gmake"), in which +# case it prints its new name instead of `make'. +if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then + am__include=include + am__quote= + _am_result=GNU +fi +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then + am__include=.include + am__quote="\"" + _am_result=BSD + fi +fi + + +{ echo "$as_me:$LINENO: result: $_am_result" >&5 +echo "${ECHO_T}$_am_result" >&6; } +rm -f confinc confmf + +# Check whether --enable-dependency-tracking was given. +if test "${enable_dependency_tracking+set}" = set; then + enableval=$enable_dependency_tracking; +fi + +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' +fi + if test "x$enable_dependency_tracking" != xno; then + AMDEP_TRUE= + AMDEP_FALSE='#' +else + AMDEP_TRUE='#' + AMDEP_FALSE= +fi + + + +depcc="$CC" am_compiler_list= + +{ echo "$as_me:$LINENO: checking dependency style of $depcc" >&5 +echo $ECHO_N "checking dependency style of $depcc... $ECHO_C" >&6; } +if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CC_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + case $depmode in + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + none) break ;; + esac + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. + if depmode=$depmode \ + source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CC_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CC_dependencies_compiler_type=none +fi + +fi +{ echo "$as_me:$LINENO: result: $am_cv_CC_dependencies_compiler_type" >&5 +echo "${ECHO_T}$am_cv_CC_dependencies_compiler_type" >&6; } +CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then + am__fastdepCC_TRUE= + am__fastdepCC_FALSE='#' +else + am__fastdepCC_TRUE='#' + am__fastdepCC_FALSE= +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 +echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if test "${ac_cv_prog_CPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ echo "$as_me:$LINENO: result: $CPP" >&5 +echo "${ECHO_T}$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +{ echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 +echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6; } +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in + ./ | .// | /cC/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + done + done + ;; +esac +done +IFS=$as_save_IFS + + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ echo "$as_me:$LINENO: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +{ echo "$as_me:$LINENO: checking whether ln -s works" >&5 +echo $ECHO_N "checking whether ln -s works... $ECHO_C" >&6; } +LN_S=$as_ln_s +if test "$LN_S" = "ln -s"; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } +else + { echo "$as_me:$LINENO: result: no, using $LN_S" >&5 +echo "${ECHO_T}no, using $LN_S" >&6; } +fi + +{ echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6; } +set x ${MAKE-make}; ac_make=`echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + SET_MAKE= +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +# Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then + enableval=$enable_shared; p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac +else + enable_shared=yes +fi + + +# Check whether --enable-static was given. +if test "${enable_static+set}" = set; then + enableval=$enable_static; p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac +else + enable_static=yes +fi + + +# Check whether --enable-fast-install was given. +if test "${enable_fast_install+set}" = set; then + enableval=$enable_fast_install; p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac +else + enable_fast_install=yes +fi + + +{ echo "$as_me:$LINENO: checking for a sed that does not truncate output" >&5 +echo $ECHO_N "checking for a sed that does not truncate output... $ECHO_C" >&6; } +if test "${lt_cv_path_SED+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f $lt_ac_sed && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test $lt_ac_count -gt 10 && break + lt_ac_count=`expr $lt_ac_count + 1` + if test $lt_ac_count -gt $lt_ac_max; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done + +fi + +SED=$lt_cv_path_SED + +{ echo "$as_me:$LINENO: result: $SED" >&5 +echo "${ECHO_T}$SED" >&6; } + +{ echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5 +echo $ECHO_N "checking for grep that handles long lines and -e... $ECHO_C" >&6; } +if test "${ac_cv_path_GREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Extract the first word of "grep ggrep" to use in msg output +if test -z "$GREP"; then +set dummy grep ggrep; ac_prog_name=$2 +if test "${ac_cv_path_GREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_path_GREP_found=false +# Loop through the user's path and test for each of PROGNAME-LIST +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue + # Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + ac_count=`expr $ac_count + 1` + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + + $ac_path_GREP_found && break 3 + done +done + +done +IFS=$as_save_IFS + + +fi + +GREP="$ac_cv_path_GREP" +if test -z "$GREP"; then + { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 +echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} + { (exit 1); exit 1; }; } +fi + +else + ac_cv_path_GREP=$GREP +fi + + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5 +echo "${ECHO_T}$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ echo "$as_me:$LINENO: checking for egrep" >&5 +echo $ECHO_N "checking for egrep... $ECHO_C" >&6; } +if test "${ac_cv_path_EGREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + # Extract the first word of "egrep" to use in msg output +if test -z "$EGREP"; then +set dummy egrep; ac_prog_name=$2 +if test "${ac_cv_path_EGREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_path_EGREP_found=false +# Loop through the user's path and test for each of PROGNAME-LIST +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue + # Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + ac_count=`expr $ac_count + 1` + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + + $ac_path_EGREP_found && break 3 + done +done + +done +IFS=$as_save_IFS + + +fi + +EGREP="$ac_cv_path_EGREP" +if test -z "$EGREP"; then + { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 +echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} + { (exit 1); exit 1; }; } +fi + +else + ac_cv_path_EGREP=$EGREP +fi + + + fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5 +echo "${ECHO_T}$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + + +# Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then + withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + { echo "$as_me:$LINENO: checking for ld used by $CC" >&5 +echo $ECHO_N "checking for ld used by $CC... $ECHO_C" >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'` + while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + { echo "$as_me:$LINENO: checking for GNU ld" >&5 +echo $ECHO_N "checking for GNU ld... $ECHO_C" >&6; } +else + { echo "$as_me:$LINENO: checking for non-GNU ld" >&5 +echo $ECHO_N "checking for non-GNU ld... $ECHO_C" >&6; } +fi +if test "${lt_cv_path_LD+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +echo "${ECHO_T}$LD" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi +test -z "$LD" && { { echo "$as_me:$LINENO: error: no acceptable ld found in \$PATH" >&5 +echo "$as_me: error: no acceptable ld found in \$PATH" >&2;} + { (exit 1); exit 1; }; } +{ echo "$as_me:$LINENO: checking if the linker ($LD) is GNU ld" >&5 +echo $ECHO_N "checking if the linker ($LD) is GNU ld... $ECHO_C" >&6; } +if test "${lt_cv_prog_gnu_ld+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +echo "${ECHO_T}$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + +{ echo "$as_me:$LINENO: checking for $LD option to reload object files" >&5 +echo $ECHO_N "checking for $LD option to reload object files... $ECHO_C" >&6; } +if test "${lt_cv_ld_reload_flag+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_ld_reload_flag='-r' +fi +{ echo "$as_me:$LINENO: result: $lt_cv_ld_reload_flag" >&5 +echo "${ECHO_T}$lt_cv_ld_reload_flag" >&6; } +reload_flag=$lt_cv_ld_reload_flag +case $reload_flag in +"" | " "*) ;; +*) reload_flag=" $reload_flag" ;; +esac +reload_cmds='$LD$reload_flag -o $output$reload_objs' +case $host_os in + darwin*) + if test "$GCC" = yes; then + reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs' + else + reload_cmds='$LD$reload_flag -o $output$reload_objs' + fi + ;; +esac + +{ echo "$as_me:$LINENO: checking for BSD-compatible nm" >&5 +echo $ECHO_N "checking for BSD-compatible nm... $ECHO_C" >&6; } +if test "${lt_cv_path_NM+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_nm_to_check="${ac_tool_prefix}nm" + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/$lt_tmp_nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS="$lt_save_ifs" + done + test -z "$lt_cv_path_NM" && lt_cv_path_NM=nm +fi +fi +{ echo "$as_me:$LINENO: result: $lt_cv_path_NM" >&5 +echo "${ECHO_T}$lt_cv_path_NM" >&6; } +NM="$lt_cv_path_NM" + +{ echo "$as_me:$LINENO: checking how to recognise dependent libraries" >&5 +echo $ECHO_N "checking how to recognise dependent libraries... $ECHO_C" >&6; } +if test "${lt_cv_deplibs_check_method+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# `unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# which responds to the $file_magic_cmd with a given extended regex. +# If you have `file' or equivalent on your system and you're not sure +# whether `pass_all' will *always* work, you probably want this one. + +case $host_os in +aix4* | aix5*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[45]*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump'. + lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | kfreebsd*-gnu | dragonfly*) + if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]' + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9].[0-9]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix3*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +nto-qnx*) + lt_cv_deplibs_check_method=unknown + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_deplibs_check_method" >&5 +echo "${ECHO_T}$lt_cv_deplibs_check_method" >&6; } +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# Check whether --enable-libtool-lock was given. +if test "${enable_libtool_lock+set}" = set; then + enableval=$enable_libtool_lock; +fi + +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out which ABI we are using. + echo '#line 4653 "configure"' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*|s390*-*linux*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -belf" + { echo "$as_me:$LINENO: checking whether the C compiler needs -belf" >&5 +echo $ECHO_N "checking whether the C compiler needs -belf... $ECHO_C" >&6; } +if test "${lt_cv_cc_needs_belf+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + lt_cv_cc_needs_belf=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + lt_cv_cc_needs_belf=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_cc_needs_belf" >&5 +echo "${ECHO_T}$lt_cv_cc_needs_belf" >&6; } + if test x"$lt_cv_cc_needs_belf" != x"yes"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS="$SAVE_CFLAGS" + fi + ;; +sparc*-*solaris*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) LD="${LD-ld} -m elf64_sparc" ;; + *) LD="${LD-ld} -64" ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + + +esac + +need_locks="$enable_libtool_lock" + + + +{ echo "$as_me:$LINENO: checking for ANSI C header files" >&5 +echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; } +if test "${ac_cv_header_stdc+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_header_stdc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_header_stdc=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then + : +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + +fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 +echo "${ECHO_T}$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +cat >>confdefs.h <<\_ACEOF +#define STDC_HEADERS 1 +_ACEOF + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. + + + + + + + + + +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + eval "$as_ac_Header=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_Header=no" +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + + +for ac_header in dlfcn.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + { echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +else + # Is the header compilable? +{ echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_compiler=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6; } + +# Is the header present? +{ echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi + +rm -f conftest.err conftest.$ac_ext +{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + ( cat <<\_ASBOX +## --------------------------------------- ## +## Report this to lecuyer@iro.umontreal.ca ## +## --------------------------------------- ## +_ASBOX + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +{ echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CXX"; then + ac_cv_prog_CXX="$CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { echo "$as_me:$LINENO: result: $CXX" >&5 +echo "${ECHO_T}$CXX" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5 +echo "${ECHO_T}$ac_ct_CXX" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C++ compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +{ echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6; } +if test "${ac_cv_cxx_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6; } +GXX=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5 +echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cxx_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cxx_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CXXFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cxx_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6; } +if test "$ac_test_CXXFLAGS" = set; then + CXXFLAGS=$ac_save_CXXFLAGS +elif test $ac_cv_prog_cxx_g = yes; then + if test "$GXX" = yes; then + CXXFLAGS="-g -O2" + else + CXXFLAGS="-g" + fi +else + if test "$GXX" = yes; then + CXXFLAGS="-O2" + else + CXXFLAGS= + fi +fi +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +depcc="$CXX" am_compiler_list= + +{ echo "$as_me:$LINENO: checking dependency style of $depcc" >&5 +echo $ECHO_N "checking dependency style of $depcc... $ECHO_C" >&6; } +if test "${am_cv_CXX_dependencies_compiler_type+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CXX_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + case $depmode in + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + none) break ;; + esac + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. + if depmode=$depmode \ + source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CXX_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CXX_dependencies_compiler_type=none +fi + +fi +{ echo "$as_me:$LINENO: result: $am_cv_CXX_dependencies_compiler_type" >&5 +echo "${ECHO_T}$am_cv_CXX_dependencies_compiler_type" >&6; } +CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then + am__fastdepCXX_TRUE= + am__fastdepCXX_FALSE='#' +else + am__fastdepCXX_TRUE='#' + am__fastdepCXX_FALSE= +fi + + + + +if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +{ echo "$as_me:$LINENO: checking how to run the C++ preprocessor" >&5 +echo $ECHO_N "checking how to run the C++ preprocessor... $ECHO_C" >&6; } +if test -z "$CXXCPP"; then + if test "${ac_cv_prog_CXXCPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Double quotes because CXXCPP needs to be expanded + for CXXCPP in "$CXX -E" "/lib/cpp" + do + ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CXXCPP=$CXXCPP + +fi + CXXCPP=$ac_cv_prog_CXXCPP +else + ac_cv_prog_CXXCPP=$CXXCPP +fi +{ echo "$as_me:$LINENO: result: $CXXCPP" >&5 +echo "${ECHO_T}$CXXCPP" >&6; } +ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +fi + + +ac_ext=f +ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5' +ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_f77_compiler_gnu +if test -n "$ac_tool_prefix"; then + for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_F77+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$F77"; then + ac_cv_prog_F77="$F77" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_F77="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +F77=$ac_cv_prog_F77 +if test -n "$F77"; then + { echo "$as_me:$LINENO: result: $F77" >&5 +echo "${ECHO_T}$F77" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$F77" && break + done +fi +if test -z "$F77"; then + ac_ct_F77=$F77 + for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_F77+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_F77"; then + ac_cv_prog_ac_ct_F77="$ac_ct_F77" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_F77="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_F77=$ac_cv_prog_ac_ct_F77 +if test -n "$ac_ct_F77"; then + { echo "$as_me:$LINENO: result: $ac_ct_F77" >&5 +echo "${ECHO_T}$ac_ct_F77" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$ac_ct_F77" && break +done + + if test "x$ac_ct_F77" = x; then + F77="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + F77=$ac_ct_F77 + fi +fi + + +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for Fortran 77 compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +rm -f a.out + +# If we don't use `.F' as extension, the preprocessor is not run on the +# input file. (Note that this only needs to work for GNU compilers.) +ac_save_ext=$ac_ext +ac_ext=F +{ echo "$as_me:$LINENO: checking whether we are using the GNU Fortran 77 compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU Fortran 77 compiler... $ECHO_C" >&6; } +if test "${ac_cv_f77_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF + program main +#ifndef __GNUC__ + choke me +#endif + + end +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_f77_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_f77_compiler_gnu=$ac_compiler_gnu + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_f77_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_f77_compiler_gnu" >&6; } +ac_ext=$ac_save_ext +ac_test_FFLAGS=${FFLAGS+set} +ac_save_FFLAGS=$FFLAGS +FFLAGS= +{ echo "$as_me:$LINENO: checking whether $F77 accepts -g" >&5 +echo $ECHO_N "checking whether $F77 accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_f77_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + FFLAGS=-g +cat >conftest.$ac_ext <<_ACEOF + program main + + end +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_f77_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_f77_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_prog_f77_g=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_f77_g" >&5 +echo "${ECHO_T}$ac_cv_prog_f77_g" >&6; } +if test "$ac_test_FFLAGS" = set; then + FFLAGS=$ac_save_FFLAGS +elif test $ac_cv_prog_f77_g = yes; then + if test "x$ac_cv_f77_compiler_gnu" = xyes; then + FFLAGS="-g -O2" + else + FFLAGS="-g" + fi +else + if test "x$ac_cv_f77_compiler_gnu" = xyes; then + FFLAGS="-O2" + else + FFLAGS= + fi +fi + +G77=`test $ac_compiler_gnu = yes && echo yes` +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +# Autoconf 2.13's AC_OBJEXT and AC_EXEEXT macros only works for C compilers! + +# find the maximum length of command line arguments +{ echo "$as_me:$LINENO: checking the maximum length of command line arguments" >&5 +echo $ECHO_N "checking the maximum length of command line arguments... $ECHO_C" >&6; } +if test "${lt_cv_sys_max_cmd_len+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + while (test "X"`$SHELL $0 --fallback-echo "X$teststring" 2>/dev/null` \ + = "XX$teststring") >/dev/null 2>&1 && + new_result=`expr "X$teststring" : ".*" 2>&1` && + lt_cv_sys_max_cmd_len=$new_result && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + teststring= + # Add a significant safety factor because C++ compilers can tack on massive + # amounts of additional arguments before passing them to the linker. + # It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + ;; + esac + +fi + +if test -n $lt_cv_sys_max_cmd_len ; then + { echo "$as_me:$LINENO: result: $lt_cv_sys_max_cmd_len" >&5 +echo "${ECHO_T}$lt_cv_sys_max_cmd_len" >&6; } +else + { echo "$as_me:$LINENO: result: none" >&5 +echo "${ECHO_T}none" >&6; } +fi + + + + +# Check for command to grab the raw symbol name followed by C symbol from nm. +{ echo "$as_me:$LINENO: checking command to parse $NM output from $compiler object" >&5 +echo $ECHO_N "checking command to parse $NM output from $compiler object... $ECHO_C" >&6; } +if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[BCDEGRST]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([_A-Za-z][_A-Za-z0-9]*\)' + +# Transform an extracted symbol line into a proper C declaration +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern int \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode \([^ ]*\) \([^ ]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[BCDT]' + ;; +cygwin* | mingw* | pw32*) + symcode='[ABCDGISTW]' + ;; +hpux*) # Its linker distinguishes data from code symbols + if test "$host_cpu" = ia64; then + symcode='[ABCDEGRST]' + fi + lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + ;; +linux*) + if test "$host_cpu" = ia64; then + symcode='[ABCDGIRSTW]' + lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + fi + ;; +irix* | nonstopux*) + symcode='[BCDEGRST]' + ;; +osf*) + symcode='[BCDEGQRST]' + ;; +solaris*) + symcode='[BDRT]' + ;; +sco3.2v5*) + symcode='[DT]' + ;; +sysv4.2uw2*) + symcode='[DT]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[ABDT]' + ;; +sysv4) + symcode='[DFNSTU]' + ;; +esac + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[ABCDGIRSTW]' ;; +esac + +# Try without a prefix undercore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Now try to grab the symbols. + nlist=conftest.nm + if { (eval echo "$as_me:$LINENO: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\"") >&5 + (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if grep ' nm_test_var$' "$nlist" >/dev/null; then + if grep ' nm_test_func$' "$nlist" >/dev/null; then + cat < conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | grep -v main >> conftest.$ac_ext' + + cat <> conftest.$ac_ext +#if defined (__STDC__) && __STDC__ +# define lt_ptr_t void * +#else +# define lt_ptr_t char * +# define const +#endif + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + lt_ptr_t address; +} +lt_preloaded_symbols[] = +{ +EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" | grep -v main >> conftest.$ac_ext + cat <<\EOF >> conftest.$ac_ext + {0, (lt_ptr_t) 0} +}; + +#ifdef __cplusplus +} +#endif +EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" + if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&5 + fi + else + echo "cannot find nm_test_var in $nlist" >&5 + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 + fi + else + echo "$progname: failed program was:" >&5 + cat conftest.$ac_ext >&5 + fi + rm -f conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done + +fi + +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + { echo "$as_me:$LINENO: result: failed" >&5 +echo "${ECHO_T}failed" >&6; } +else + { echo "$as_me:$LINENO: result: ok" >&5 +echo "${ECHO_T}ok" >&6; } +fi + +{ echo "$as_me:$LINENO: checking for objdir" >&5 +echo $ECHO_N "checking for objdir... $ECHO_C" >&6; } +if test "${lt_cv_objdir+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null +fi +{ echo "$as_me:$LINENO: result: $lt_cv_objdir" >&5 +echo "${ECHO_T}$lt_cv_objdir" >&6; } +objdir=$lt_cv_objdir + + + + + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='sed -e 1s/^X//' +sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Constants: +rm="rm -f" + +# Global variables: +default_ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a +ltmain="$ac_aux_dir/ltmain.sh" +ofile="$default_ofile" +with_gnu_ld="$lt_cv_prog_gnu_ld" + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args. +set dummy ${ac_tool_prefix}ar; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_AR+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_AR="${ac_tool_prefix}ar" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { echo "$as_me:$LINENO: result: $AR" >&5 +echo "${ECHO_T}$AR" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_AR"; then + ac_ct_AR=$AR + # Extract the first word of "ar", so it can be a program name with args. +set dummy ar; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_AR+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_AR="ar" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { echo "$as_me:$LINENO: result: $ac_ct_AR" >&5 +echo "${ECHO_T}$ac_ct_AR" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_AR" = x; then + AR="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +else + AR="$ac_cv_prog_AR" +fi + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { echo "$as_me:$LINENO: result: $RANLIB" >&5 +echo "${ECHO_T}$RANLIB" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5 +echo "${ECHO_T}$ac_ct_RANLIB" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_STRIP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { echo "$as_me:$LINENO: result: $STRIP" >&5 +echo "${ECHO_T}$STRIP" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_STRIP="strip" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { echo "$as_me:$LINENO: result: $ac_ct_STRIP" >&5 +echo "${ECHO_T}$ac_ct_STRIP" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru +test -z "$AS" && AS=as +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$DLLTOOL" && DLLTOOL=dlltool +test -z "$LD" && LD=ld +test -z "$LN_S" && LN_S="ln -s" +test -z "$MAGIC_CMD" && MAGIC_CMD=file +test -z "$NM" && NM=nm +test -z "$SED" && SED=sed +test -z "$OBJDUMP" && OBJDUMP=objdump +test -z "$RANLIB" && RANLIB=: +test -z "$STRIP" && STRIP=: +test -z "$ac_objext" && ac_objext=o + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi + +for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + +# Only perform the check for file, if the check method requires it +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + { echo "$as_me:$LINENO: checking for ${ac_tool_prefix}file" >&5 +echo $ECHO_N "checking for ${ac_tool_prefix}file... $ECHO_C" >&6; } +if test "${lt_cv_path_MAGIC_CMD+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/${ac_tool_prefix}file; then + lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac +fi + +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + { echo "$as_me:$LINENO: result: $MAGIC_CMD" >&5 +echo "${ECHO_T}$MAGIC_CMD" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + { echo "$as_me:$LINENO: checking for file" >&5 +echo $ECHO_N "checking for file... $ECHO_C" >&6; } +if test "${lt_cv_path_MAGIC_CMD+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/file; then + lt_cv_path_MAGIC_CMD="$ac_dir/file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac +fi + +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + { echo "$as_me:$LINENO: result: $MAGIC_CMD" >&5 +echo "${ECHO_T}$MAGIC_CMD" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + else + MAGIC_CMD=: + fi +fi + + fi + ;; +esac + +enable_dlopen=no +enable_win32_dll=no + +# Check whether --enable-libtool-lock was given. +if test "${enable_libtool_lock+set}" = set; then + enableval=$enable_libtool_lock; +fi + +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + + +# Check whether --with-pic was given. +if test "${with_pic+set}" = set; then + withval=$with_pic; pic_mode="$withval" +else + pic_mode=default +fi + +test -z "$pic_mode" && pic_mode=default + +# Use C for the default configuration in the libtool script +tagname= +lt_save_CC="$CC" +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +objext=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;\n" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}\n' + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +printf "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$rm conftest* + +ac_outfile=conftest.$ac_objext +printf "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$rm conftest* + + + +lt_prog_compiler_no_builtin_flag= + +if test "$GCC" = yes; then + lt_prog_compiler_no_builtin_flag=' -fno-builtin' + + +{ echo "$as_me:$LINENO: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +echo $ECHO_N "checking if $compiler supports -fno-rtti -fno-exceptions... $ECHO_C" >&6; } +if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_prog_compiler_rtti_exceptions=no + ac_outfile=conftest.$ac_objext + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="-fno-rtti -fno-exceptions" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:7154: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:7158: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_rtti_exceptions=yes + fi + fi + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +echo "${ECHO_T}$lt_cv_prog_compiler_rtti_exceptions" >&6; } + +if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then + lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" +else + : +fi + +fi + +lt_prog_compiler_wl= +lt_prog_compiler_pic= +lt_prog_compiler_static= + +{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5 +echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; } + + if test "$GCC" = yes; then + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_static='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + fi + ;; + + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' + ;; + + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + ;; + + interix3*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared=no + enable_shared=no + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic=-Kconform_pic + fi + ;; + + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + ;; + + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + else + lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' + fi + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + lt_prog_compiler_pic='-qnocommon' + lt_prog_compiler_wl='-Wl,' + ;; + esac + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static='-non_shared' + ;; + + newsos6) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + linux*) + case $cc_basename in + icc* | ecc*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + esac + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + lt_prog_compiler_wl='-Qoption ld ';; + *) + lt_prog_compiler_wl='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl='-Qoption ld ' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + lt_prog_compiler_pic='-Kconform_pic' + lt_prog_compiler_static='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_can_build_shared=no + ;; + + uts4*) + lt_prog_compiler_pic='-pic' + lt_prog_compiler_static='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared=no + ;; + esac + fi + +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic" >&6; } + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic"; then + +{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_pic_works+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_pic_works=no + ac_outfile=conftest.$ac_objext + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic -DPIC" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:7422: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:7426: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_pic_works=yes + fi + fi + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic_works" >&6; } + +if test x"$lt_prog_compiler_pic_works" = xyes; then + case $lt_prog_compiler_pic in + "" | " "*) ;; + *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; + esac +else + lt_prog_compiler_pic= + lt_prog_compiler_can_build_shared=no +fi + +fi +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic= + ;; + *) + lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC" + ;; +esac + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" +{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_static_works+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_static_works=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + printf "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_static_works=yes + fi + else + lt_prog_compiler_static_works=yes + fi + fi + $rm conftest* + LDFLAGS="$save_LDFLAGS" + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works" >&5 +echo "${ECHO_T}$lt_prog_compiler_static_works" >&6; } + +if test x"$lt_prog_compiler_static_works" = xyes; then + : +else + lt_prog_compiler_static= +fi + + +{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5 +echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; } +if test "${lt_cv_prog_compiler_c_o+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_prog_compiler_c_o=no + $rm -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:7526: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:7530: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $rm conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files + $rm out/* && rmdir out + cd .. + rmdir conftest + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o" >&5 +echo "${ECHO_T}$lt_cv_prog_compiler_c_o" >&6; } + + +hard_links="nottested" +if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5 +echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; } + hard_links=yes + $rm conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { echo "$as_me:$LINENO: result: $hard_links" >&5 +echo "${ECHO_T}$hard_links" >&6; } + if test "$hard_links" = no; then + { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5 +echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + +{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; } + + runpath_var= + allow_undefined_flag= + enable_shared_with_static_runtimes=no + archive_cmds= + archive_expsym_cmds= + old_archive_From_new_cmds= + old_archive_from_expsyms_cmds= + export_dynamic_flag_spec= + whole_archive_flag_spec= + thread_safe_flag_spec= + hardcode_libdir_flag_spec= + hardcode_libdir_flag_spec_ld= + hardcode_libdir_separator= + hardcode_direct=no + hardcode_minus_L=no + hardcode_shlibpath_var=unsupported + link_all_deplibs=unknown + hardcode_automatic=no + module_cmds= + module_expsym_cmds= + always_export_symbols=no + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + exclude_expsyms="_GLOBAL_OFFSET_TABLE_" + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + extract_expsyms_cmds= + # Just being paranoid about ensuring that cc_basename is set. + for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + case $host_os in + cygwin* | mingw* | pw32*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + esac + + ld_shlibs=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec='${wl}--rpath ${wl}$libdir' + export_dynamic_flag_spec='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + whole_archive_flag_spec= + fi + supports_anon_versioning=no + case `$LD -v 2>/dev/null` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix3* | aix4* | aix5*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + ld_shlibs=no + cat <&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +EOF + fi + ;; + + amigaos*) + archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + + # Samuel A. Falvo II reports + # that the semantics of dynamic libraries on AmigaOS, at least up + # to version 4, is to share data among multiple programs linked + # with the same dynamic library. Since this doesn't match the + # behavior of shared libraries on other platforms, we can't use + # them. + ld_shlibs=no + ;; + + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + ld_shlibs=no + fi + ;; + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + allow_undefined_flag=unsupported + always_export_symbols=no + enable_shared_with_static_runtimes=yes + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS] /s/.* \([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW] /s/.* //'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs=no + fi + ;; + + interix3*) + hardcode_direct=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + export_dynamic_flag_spec='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + linux*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + tmp_addflag= + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + esac + archive_cmds='$CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test $supports_anon_versioning = yes; then + archive_expsym_cmds='$echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + $echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + else + ld_shlibs=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + cat <&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +EOF + elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + + if test "$ld_shlibs" = no; then + runpath_var= + hardcode_libdir_flag_spec= + export_dynamic_flag_spec= + whole_archive_flag_spec= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag=unsupported + always_export_symbols=yes + archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[23]|aix4.[23].*|aix5*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds='' + hardcode_direct=yes + hardcode_libdir_separator=':' + link_all_deplibs=yes + + if test "$GCC" = yes; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + hardcode_direct=yes + else + # We have old collect2 + hardcode_direct=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag='-berok' + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' + allow_undefined_flag="-z nodefs" + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag=' ${wl}-bernotok' + allow_undefined_flag=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec='$convenience' + archive_cmds_need_lc=yes + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + # see comment about different semantics on the GNU ld section + ld_shlibs=no + ;; + + bsdi[45]*) + export_dynamic_flag_spec=-rdynamic + ;; + + cygwin* | mingw* | pw32*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_From_new_cmds='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds='lib /OUT:$oldlib$oldobjs$old_deplibs' + fix_srcfile_path='`cygpath -w "$srcfile"`' + enable_shared_with_static_runtimes=yes + ;; + + darwin* | rhapsody*) + case $host_os in + rhapsody* | darwin1.[012]) + allow_undefined_flag='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + allow_undefined_flag='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[012]) + allow_undefined_flag='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + allow_undefined_flag='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes + hardcode_shlibpath_var=unsupported + whole_archive_flag_spec='' + link_all_deplibs=yes + if test "$GCC" = yes ; then + output_verbose_link_cmd='echo' + archive_cmds='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + module_cmds='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + module_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + archive_cmds='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + module_cmds='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + module_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + ld_shlibs=no + ;; + esac + fi + ;; + + dgux*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + freebsd1*) + ld_shlibs=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | kfreebsd*-gnu | dragonfly*) + archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + hpux9*) + if test "$GCC" = yes; then + archive_cmds='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + archive_cmds='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + export_dynamic_flag_spec='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + + hardcode_direct=yes + export_dynamic_flag_spec='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_libdir_flag_spec_ld='+b $libdir' + hardcode_direct=no + hardcode_shlibpath_var=no + ;; + *) + hardcode_direct=yes + export_dynamic_flag_spec='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + hardcode_libdir_flag_spec_ld='-rpath $libdir' + fi + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + link_all_deplibs=yes + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + newsos6) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_shlibpath_var=no + ;; + + openbsd*) + hardcode_direct=yes + hardcode_shlibpath_var=no + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + export_dynamic_flag_spec='${wl}-E' + else + case $host_os in + openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-R$libdir' + ;; + *) + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + ;; + esac + fi + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + archive_cmds='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + fi + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~ + $LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + hardcode_libdir_separator=: + ;; + + solaris*) + no_undefined_flag=' -z text' + if test "$GCC" = yes; then + wlarc='${wl}' + archive_cmds='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp' + else + wlarc='' + archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp' + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_shlibpath_var=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine linker options so we + # cannot just pass the convience library names through + # without $wl, iff we do not link with $LD. + # Luckily, gcc supports the same syntax we need for Sun Studio. + # Supported since Solaris 2.6 (maybe 2.5.1?) + case $wlarc in + '') + whole_archive_flag_spec='-z allextract$convenience -z defaultextract' ;; + *) + whole_archive_flag_spec='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' ;; + esac ;; + esac + link_all_deplibs=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds='$CC -r -o $output$reload_objs' + hardcode_direct=no + ;; + motorola) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var=no + ;; + + sysv4.3*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + export_dynamic_flag_spec='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7*) + no_undefined_flag='${wl}-z,text' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag='${wl}-z,text' + allow_undefined_flag='${wl}-z,nodefs' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + hardcode_libdir_separator=':' + link_all_deplibs=yes + export_dynamic_flag_spec='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + *) + ld_shlibs=no + ;; + esac + fi + +{ echo "$as_me:$LINENO: result: $ld_shlibs" >&5 +echo "${ECHO_T}$ld_shlibs" >&6; } +test "$ld_shlibs" = no && can_build_shared=no + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $archive_cmds in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5 +echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; } + $rm conftest* + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl + pic_flag=$lt_prog_compiler_pic + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag + allow_undefined_flag= + if { (eval echo "$as_me:$LINENO: \"$archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5 + (eval $archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + then + archive_cmds_need_lc=no + else + archive_cmds_need_lc=yes + fi + allow_undefined_flag=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $rm conftest* + { echo "$as_me:$LINENO: result: $archive_cmds_need_lc" >&5 +echo "${ECHO_T}$archive_cmds_need_lc" >&6; } + ;; + esac + fi + ;; +esac + +{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5 +echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; } +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix4* | aix5*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $rm \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + # Apple's gcc prints 'gcc -print-search-dirs' doesn't operate the same. + if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | tr "\n" "$PATH_SEPARATOR" | sed -e 's/libraries:/@libraries:/' | tr "@" "\n" | grep "^libraries:" | sed -e "s/^libraries://" -e "s,=/,/,g" -e "s,$PATH_SEPARATOR, ,g" -e "s,.*,& /lib /usr/lib /usr/local/lib,g"` + else + sys_lib_search_path_spec='/lib /usr/lib /usr/local/lib' + fi + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +kfreebsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[123]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + freebsd*) # from 4.6 on + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix3*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # find out which ABI we are using + libsuff= + case "$host_cpu" in + x86_64*|s390x*|powerpc64*) + echo '#line 8991 "configure"' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + case `/usr/bin/file conftest.$ac_objext` in + *64-bit*) + libsuff=64 + sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" + ;; + esac + fi + rm -rf conftest* + ;; + esac + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/^ *//;s/#.*//;/^[^\/]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +knetbsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +nto-qnx*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[89] | openbsd2.[89].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + export_dynamic_flag_spec='${wl}-Blargedynsym' + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + shlibpath_overrides_runpath=no + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + shlibpath_overrides_runpath=yes + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5 +echo "${ECHO_T}$dynamic_linker" >&6; } +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5 +echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; } +hardcode_action= +if test -n "$hardcode_libdir_flag_spec" || \ + test -n "$runpath_var" || \ + test "X$hardcode_automatic" = "Xyes" ; then + + # We can hardcode non-existant directories. + if test "$hardcode_direct" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, )" != no && + test "$hardcode_minus_L" != no; then + # Linking always hardcodes the temporary library directory. + hardcode_action=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action=unsupported +fi +{ echo "$as_me:$LINENO: result: $hardcode_action" >&5 +echo "${ECHO_T}$hardcode_action" >&6; } + +if test "$hardcode_action" = relink; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi + +striplib= +old_striplib= +{ echo "$as_me:$LINENO: checking whether stripping libraries is possible" >&5 +echo $ECHO_N "checking whether stripping libraries is possible... $ECHO_C" >&6; } +if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + ;; + *) + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + ;; + esac +fi + +if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + { echo "$as_me:$LINENO: checking for dlopen in -ldl" >&5 +echo $ECHO_N "checking for dlopen in -ldl... $ECHO_C" >&6; } +if test "${ac_cv_lib_dl_dlopen+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_dl_dlopen=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_dl_dlopen=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5 +echo "${ECHO_T}$ac_cv_lib_dl_dlopen" >&6; } +if test $ac_cv_lib_dl_dlopen = yes; then + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" +else + + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + +fi + + ;; + + *) + { echo "$as_me:$LINENO: checking for shl_load" >&5 +echo $ECHO_N "checking for shl_load... $ECHO_C" >&6; } +if test "${ac_cv_func_shl_load+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define shl_load to an innocuous variant, in case declares shl_load. + For example, HP-UX 11i declares gettimeofday. */ +#define shl_load innocuous_shl_load + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char shl_load (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef shl_load + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_shl_load || defined __stub___shl_load +choke me +#endif + +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_func_shl_load=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_func_shl_load=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_func_shl_load" >&5 +echo "${ECHO_T}$ac_cv_func_shl_load" >&6; } +if test $ac_cv_func_shl_load = yes; then + lt_cv_dlopen="shl_load" +else + { echo "$as_me:$LINENO: checking for shl_load in -ldld" >&5 +echo $ECHO_N "checking for shl_load in -ldld... $ECHO_C" >&6; } +if test "${ac_cv_lib_dld_shl_load+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_dld_shl_load=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_dld_shl_load=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_dld_shl_load" >&5 +echo "${ECHO_T}$ac_cv_lib_dld_shl_load" >&6; } +if test $ac_cv_lib_dld_shl_load = yes; then + lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-dld" +else + { echo "$as_me:$LINENO: checking for dlopen" >&5 +echo $ECHO_N "checking for dlopen... $ECHO_C" >&6; } +if test "${ac_cv_func_dlopen+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define dlopen to an innocuous variant, in case declares dlopen. + For example, HP-UX 11i declares gettimeofday. */ +#define dlopen innocuous_dlopen + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char dlopen (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef dlopen + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_dlopen || defined __stub___dlopen +choke me +#endif + +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_func_dlopen=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_func_dlopen=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_func_dlopen" >&5 +echo "${ECHO_T}$ac_cv_func_dlopen" >&6; } +if test $ac_cv_func_dlopen = yes; then + lt_cv_dlopen="dlopen" +else + { echo "$as_me:$LINENO: checking for dlopen in -ldl" >&5 +echo $ECHO_N "checking for dlopen in -ldl... $ECHO_C" >&6; } +if test "${ac_cv_lib_dl_dlopen+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_dl_dlopen=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_dl_dlopen=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5 +echo "${ECHO_T}$ac_cv_lib_dl_dlopen" >&6; } +if test $ac_cv_lib_dl_dlopen = yes; then + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" +else + { echo "$as_me:$LINENO: checking for dlopen in -lsvld" >&5 +echo $ECHO_N "checking for dlopen in -lsvld... $ECHO_C" >&6; } +if test "${ac_cv_lib_svld_dlopen+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsvld $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_svld_dlopen=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_svld_dlopen=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_svld_dlopen" >&5 +echo "${ECHO_T}$ac_cv_lib_svld_dlopen" >&6; } +if test $ac_cv_lib_svld_dlopen = yes; then + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld" +else + { echo "$as_me:$LINENO: checking for dld_link in -ldld" >&5 +echo $ECHO_N "checking for dld_link in -ldld... $ECHO_C" >&6; } +if test "${ac_cv_lib_dld_dld_link+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dld_link (); +int +main () +{ +return dld_link (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_dld_dld_link=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_dld_dld_link=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_dld_dld_link" >&5 +echo "${ECHO_T}$ac_cv_lib_dld_dld_link" >&6; } +if test $ac_cv_lib_dld_dld_link = yes; then + lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-dld" +fi + + +fi + + +fi + + +fi + + +fi + + +fi + + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + { echo "$as_me:$LINENO: checking whether a program can dlopen itself" >&5 +echo $ECHO_N "checking whether a program can dlopen itself... $ECHO_C" >&6; } +if test "${lt_cv_dlopen_self+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$cross_compiling" = yes; then : + lt_cv_dlopen_self=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext < +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +#ifdef __cplusplus +extern "C" void exit (int); +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + exit (status); +} +EOF + if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self=no + fi +fi +rm -fr conftest* + + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_dlopen_self" >&5 +echo "${ECHO_T}$lt_cv_dlopen_self" >&6; } + + if test "x$lt_cv_dlopen_self" = xyes; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + { echo "$as_me:$LINENO: checking whether a statically linked program can dlopen itself" >&5 +echo $ECHO_N "checking whether a statically linked program can dlopen itself... $ECHO_C" >&6; } +if test "${lt_cv_dlopen_self_static+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$cross_compiling" = yes; then : + lt_cv_dlopen_self_static=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext < +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +#ifdef __cplusplus +extern "C" void exit (int); +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + exit (status); +} +EOF + if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self_static=no + fi +fi +rm -fr conftest* + + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_dlopen_self_static" >&5 +echo "${ECHO_T}$lt_cv_dlopen_self_static" >&6; } + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi + + +# Report which library types will actually be built +{ echo "$as_me:$LINENO: checking if libtool supports shared libraries" >&5 +echo $ECHO_N "checking if libtool supports shared libraries... $ECHO_C" >&6; } +{ echo "$as_me:$LINENO: result: $can_build_shared" >&5 +echo "${ECHO_T}$can_build_shared" >&6; } + +{ echo "$as_me:$LINENO: checking whether to build shared libraries" >&5 +echo $ECHO_N "checking whether to build shared libraries... $ECHO_C" >&6; } +test "$can_build_shared" = "no" && enable_shared=no + +# On AIX, shared libraries and static libraries use the same namespace, and +# are all built from PIC. +case $host_os in +aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + +aix4* | aix5*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; +esac +{ echo "$as_me:$LINENO: result: $enable_shared" >&5 +echo "${ECHO_T}$enable_shared" >&6; } + +{ echo "$as_me:$LINENO: checking whether to build static libraries" >&5 +echo $ECHO_N "checking whether to build static libraries... $ECHO_C" >&6; } +# Make sure either enable_shared or enable_static is yes. +test "$enable_shared" = yes || enable_static=yes +{ echo "$as_me:$LINENO: result: $enable_static" >&5 +echo "${ECHO_T}$enable_static" >&6; } + +# The else clause should only fire when bootstrapping the +# libtool distribution, otherwise you forgot to ship ltmain.sh +# with your package, and you will get complaints that there are +# no rules to generate ltmain.sh. +if test -f "$ltmain"; then + # See if we are running on zsh, and set the options which allow our commands through + # without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + # Now quote all the things that may contain metacharacters while being + # careful not to overquote the AC_SUBSTed values. We take copies of the + # variables and quote the copies for generation of the libtool script. + for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \ + SED SHELL STRIP \ + libname_spec library_names_spec soname_spec extract_expsyms_cmds \ + old_striplib striplib file_magic_cmd finish_cmds finish_eval \ + deplibs_check_method reload_flag reload_cmds need_locks \ + lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \ + lt_cv_sys_global_symbol_to_c_name_address \ + sys_lib_search_path_spec sys_lib_dlsearch_path_spec \ + old_postinstall_cmds old_postuninstall_cmds \ + compiler \ + CC \ + LD \ + lt_prog_compiler_wl \ + lt_prog_compiler_pic \ + lt_prog_compiler_static \ + lt_prog_compiler_no_builtin_flag \ + export_dynamic_flag_spec \ + thread_safe_flag_spec \ + whole_archive_flag_spec \ + enable_shared_with_static_runtimes \ + old_archive_cmds \ + old_archive_from_new_cmds \ + predep_objects \ + postdep_objects \ + predeps \ + postdeps \ + compiler_lib_search_path \ + archive_cmds \ + archive_expsym_cmds \ + postinstall_cmds \ + postuninstall_cmds \ + old_archive_from_expsyms_cmds \ + allow_undefined_flag \ + no_undefined_flag \ + export_symbols_cmds \ + hardcode_libdir_flag_spec \ + hardcode_libdir_flag_spec_ld \ + hardcode_libdir_separator \ + hardcode_automatic \ + module_cmds \ + module_expsym_cmds \ + lt_cv_prog_compiler_c_o \ + exclude_expsyms \ + include_expsyms; do + + case $var in + old_archive_cmds | \ + old_archive_from_new_cmds | \ + archive_cmds | \ + archive_expsym_cmds | \ + module_cmds | \ + module_expsym_cmds | \ + old_archive_from_expsyms_cmds | \ + export_symbols_cmds | \ + extract_expsyms_cmds | reload_cmds | finish_cmds | \ + postinstall_cmds | postuninstall_cmds | \ + old_postinstall_cmds | old_postuninstall_cmds | \ + sys_lib_search_path_spec | sys_lib_dlsearch_path_spec) + # Double-quote double-evaled strings. + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\"" + ;; + *) + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\"" + ;; + esac + done + + case $lt_echo in + *'\$0 --fallback-echo"') + lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'` + ;; + esac + +cfgfile="${ofile}T" + trap "$rm \"$cfgfile\"; exit 1" 1 2 15 + $rm -f "$cfgfile" + { echo "$as_me:$LINENO: creating $ofile" >&5 +echo "$as_me: creating $ofile" >&6;} + + cat <<__EOF__ >> "$cfgfile" +#! $SHELL + +# `$echo "$cfgfile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP) +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. +# +# This file is part of GNU Libtool: +# Originally by Gordon Matzigkeit , 1996 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="$SED -e 1s/^X//" + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# The names of the tagged configurations supported by this script. +available_tags= + +# ### BEGIN LIBTOOL CONFIG + +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc + +# Whether or not to disallow shared libs when runtime libs are static +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# An echo program that does not interpret backslashes. +echo=$lt_echo + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A C compiler. +LTCC=$lt_LTCC + +# LTCC compiler flags. +LTCFLAGS=$lt_LTCFLAGS + +# A language-specific compiler. +CC=$lt_compiler + +# Is the compiler the GNU C compiler? +with_gcc=$GCC + +# An ERE matcher. +EGREP=$lt_EGREP + +# The linker used to build libraries. +LD=$lt_LD + +# Whether we need hard or soft links. +LN_S=$lt_LN_S + +# A BSD-compatible nm program. +NM=$lt_NM + +# A symbol stripping program +STRIP=$lt_STRIP + +# Used to examine libraries when file_magic_cmd begins "file" +MAGIC_CMD=$MAGIC_CMD + +# Used on cygwin: DLL creation program. +DLLTOOL="$DLLTOOL" + +# Used on cygwin: object dumper. +OBJDUMP="$OBJDUMP" + +# Used on cygwin: assembler. +AS="$AS" + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl + +# Object file suffix (normally "o"). +objext="$ac_objext" + +# Old archive suffix (normally "a"). +libext="$libext" + +# Shared library suffix (normally ".so"). +shrext_cmds='$shrext_cmds' + +# Executable file suffix (normally ""). +exeext="$exeext" + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic +pic_mode=$pic_mode + +# What is the maximum length of a command? +max_cmd_len=$lt_cv_sys_max_cmd_len + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Do we need the lib prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec + +# Compiler flag to generate thread-safe objects. +thread_safe_flag_spec=$lt_thread_safe_flag_spec + +# Library versioning type. +version_type=$version_type + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME. +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Commands used to build and install an old-style archive. +RANLIB=$lt_RANLIB +old_archive_cmds=$lt_old_archive_cmds +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds + +# Commands used to build and install a shared archive. +archive_cmds=$lt_archive_cmds +archive_expsym_cmds=$lt_archive_expsym_cmds +postinstall_cmds=$lt_postinstall_cmds +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to build a loadable module (assumed same as above if empty) +module_cmds=$lt_module_cmds +module_expsym_cmds=$lt_module_expsym_cmds + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + +# Dependencies to place before the objects being linked to create a +# shared library. +predep_objects=$lt_predep_objects + +# Dependencies to place after the objects being linked to create a +# shared library. +postdep_objects=$lt_postdep_objects + +# Dependencies to place before the objects being linked to create a +# shared library. +predeps=$lt_predeps + +# Dependencies to place after the objects being linked to create a +# shared library. +postdeps=$lt_postdeps + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == file_magic. +file_magic_cmd=$lt_file_magic_cmd + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag + +# Flag that forces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# Same as above, but a single script fragment to be evaled but not shown. +finish_eval=$lt_finish_eval + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# This is the shared library runtime path variable. +runpath_var=$runpath_var + +# This is the shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec + +# If ld is used when linking, flag to hardcode \$libdir into +# a binary during linking. This must work even if \$libdir does +# not exist. +hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld + +# Whether we need a single -rpath flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator + +# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the +# resulting binary. +hardcode_direct=$hardcode_direct + +# Set to yes if using the -LDIR flag during linking hardcodes DIR into the +# resulting binary. +hardcode_minus_L=$hardcode_minus_L + +# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into +# the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var + +# Set to yes if building a shared library automatically hardcodes DIR into the library +# and all subsequent libraries and executables linked against it. +hardcode_automatic=$hardcode_automatic + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at relink time. +variables_saved_for_relink="$variables_saved_for_relink" + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs + +# Compile-time system search path for libraries +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path="$fix_srcfile_path" + +# Set to yes if exported symbols are required. +always_export_symbols=$always_export_symbols + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms + +# ### END LIBTOOL CONFIG + +__EOF__ + + + case $host_os in + aix3*) + cat <<\EOF >> "$cfgfile" + +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +EOF + ;; + esac + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || \ + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" + +else + # If there is no Makefile yet, we rely on a make rule to execute + # `config.status --recheck' to rerun these tests and create the + # libtool script then. + ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'` + if test -f "$ltmain_in"; then + test -f Makefile && make "$ltmain" + fi +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC="$lt_save_CC" + + +# Check whether --with-tags was given. +if test "${with_tags+set}" = set; then + withval=$with_tags; tagnames="$withval" +fi + + +if test -f "$ltmain" && test -n "$tagnames"; then + if test ! -f "${ofile}"; then + { echo "$as_me:$LINENO: WARNING: output file \`$ofile' does not exist" >&5 +echo "$as_me: WARNING: output file \`$ofile' does not exist" >&2;} + fi + + if test -z "$LTCC"; then + eval "`$SHELL ${ofile} --config | grep '^LTCC='`" + if test -z "$LTCC"; then + { echo "$as_me:$LINENO: WARNING: output file \`$ofile' does not look like a libtool script" >&5 +echo "$as_me: WARNING: output file \`$ofile' does not look like a libtool script" >&2;} + else + { echo "$as_me:$LINENO: WARNING: using \`LTCC=$LTCC', extracted from \`$ofile'" >&5 +echo "$as_me: WARNING: using \`LTCC=$LTCC', extracted from \`$ofile'" >&2;} + fi + fi + if test -z "$LTCFLAGS"; then + eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`" + fi + + # Extract list of available tagged configurations in $ofile. + # Note that this assumes the entire list is on one line. + available_tags=`grep "^available_tags=" "${ofile}" | $SED -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'` + + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for tagname in $tagnames; do + IFS="$lt_save_ifs" + # Check whether tagname contains only valid characters + case `$echo "X$tagname" | $Xsed -e 's:[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]::g'` in + "") ;; + *) { { echo "$as_me:$LINENO: error: invalid tag name: $tagname" >&5 +echo "$as_me: error: invalid tag name: $tagname" >&2;} + { (exit 1); exit 1; }; } + ;; + esac + + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "${ofile}" > /dev/null + then + { { echo "$as_me:$LINENO: error: tag name \"$tagname\" already exists" >&5 +echo "$as_me: error: tag name \"$tagname\" already exists" >&2;} + { (exit 1); exit 1; }; } + fi + + # Update the list of available tags. + if test -n "$tagname"; then + echo appending configuration tag \"$tagname\" to $ofile + + case $tagname in + CXX) + if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + + + +archive_cmds_need_lc_CXX=no +allow_undefined_flag_CXX= +always_export_symbols_CXX=no +archive_expsym_cmds_CXX= +export_dynamic_flag_spec_CXX= +hardcode_direct_CXX=no +hardcode_libdir_flag_spec_CXX= +hardcode_libdir_flag_spec_ld_CXX= +hardcode_libdir_separator_CXX= +hardcode_minus_L_CXX=no +hardcode_shlibpath_var_CXX=unsupported +hardcode_automatic_CXX=no +module_cmds_CXX= +module_expsym_cmds_CXX= +link_all_deplibs_CXX=unknown +old_archive_cmds_CXX=$old_archive_cmds +no_undefined_flag_CXX= +whole_archive_flag_spec_CXX= +enable_shared_with_static_runtimes_CXX=no + +# Dependencies to place before and after the object being linked: +predep_objects_CXX= +postdep_objects_CXX= +predeps_CXX= +postdeps_CXX= +compiler_lib_search_path_CXX= + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +objext_CXX=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;\n" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(int, char *[]) { return(0); }\n' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +printf "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$rm conftest* + +ac_outfile=conftest.$ac_objext +printf "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$rm conftest* + + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_LD=$LD +lt_save_GCC=$GCC +GCC=$GXX +lt_save_with_gnu_ld=$with_gnu_ld +lt_save_path_LD=$lt_cv_path_LD +if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx +else + $as_unset lt_cv_prog_gnu_ld +fi +if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX +else + $as_unset lt_cv_path_LD +fi +test -z "${LDCXX+set}" || LD=$LDCXX +CC=${CXX-"c++"} +compiler=$CC +compiler_CXX=$CC +for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + +# We don't want -fno-exception wen compiling C++ code, so set the +# no_builtin_flag separately +if test "$GXX" = yes; then + lt_prog_compiler_no_builtin_flag_CXX=' -fno-builtin' +else + lt_prog_compiler_no_builtin_flag_CXX= +fi + +if test "$GXX" = yes; then + # Set up default GNU C++ configuration + + +# Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then + withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + { echo "$as_me:$LINENO: checking for ld used by $CC" >&5 +echo $ECHO_N "checking for ld used by $CC... $ECHO_C" >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'` + while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + { echo "$as_me:$LINENO: checking for GNU ld" >&5 +echo $ECHO_N "checking for GNU ld... $ECHO_C" >&6; } +else + { echo "$as_me:$LINENO: checking for non-GNU ld" >&5 +echo $ECHO_N "checking for non-GNU ld... $ECHO_C" >&6; } +fi +if test "${lt_cv_path_LD+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +echo "${ECHO_T}$LD" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi +test -z "$LD" && { { echo "$as_me:$LINENO: error: no acceptable ld found in \$PATH" >&5 +echo "$as_me: error: no acceptable ld found in \$PATH" >&2;} + { (exit 1); exit 1; }; } +{ echo "$as_me:$LINENO: checking if the linker ($LD) is GNU ld" >&5 +echo $ECHO_N "checking if the linker ($LD) is GNU ld... $ECHO_C" >&6; } +if test "${lt_cv_prog_gnu_ld+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +echo "${ECHO_T}$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test "$with_gnu_ld" = yes; then + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + + hardcode_libdir_flag_spec_CXX='${wl}--rpath ${wl}$libdir' + export_dynamic_flag_spec_CXX='${wl}--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='${wl}' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | \ + grep 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec_CXX="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + whole_archive_flag_spec_CXX= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + +else + GXX=no + with_gnu_ld=no + wlarc= +fi + +# PORTME: fill in a description of your system's C++ link characteristics +{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; } +ld_shlibs_CXX=yes +case $host_os in + aix3*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[23]|aix4.[23].*|aix5*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds_CXX='' + hardcode_direct_CXX=yes + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + + if test "$GXX" = yes; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + hardcode_direct_CXX=yes + else + # We have old collect2 + hardcode_direct_CXX=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L_CXX=yes + hardcode_libdir_flag_spec_CXX='-L$libdir' + hardcode_libdir_separator_CXX= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols_CXX=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag_CXX='-berok' + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec_CXX='${wl}-blibpath:$libdir:'"$aix_libpath" + + archive_expsym_cmds_CXX="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + hardcode_libdir_flag_spec_CXX='${wl}-R $libdir:/usr/lib:/lib' + allow_undefined_flag_CXX="-z nodefs" + archive_expsym_cmds_CXX="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec_CXX='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag_CXX=' ${wl}-bernotok' + allow_undefined_flag_CXX=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec_CXX='$convenience' + archive_cmds_need_lc_CXX=yes + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds_CXX="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag_CXX=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds_CXX='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + ld_shlibs_CXX=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, CXX) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec_CXX='-L$libdir' + allow_undefined_flag_CXX=unsupported + always_export_symbols_CXX=no + enable_shared_with_static_runtimes_CXX=yes + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + archive_expsym_cmds_CXX='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs_CXX=no + fi + ;; + darwin* | rhapsody*) + case $host_os in + rhapsody* | darwin1.[012]) + allow_undefined_flag_CXX='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + allow_undefined_flag_CXX='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[012]) + allow_undefined_flag_CXX='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + allow_undefined_flag_CXX='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes + hardcode_shlibpath_var_CXX=unsupported + whole_archive_flag_spec_CXX='' + link_all_deplibs_CXX=yes + + if test "$GXX" = yes ; then + lt_int_apple_cc_single_mod=no + output_verbose_link_cmd='echo' + if $CC -dumpspecs 2>&1 | $EGREP 'single_module' >/dev/null ; then + lt_int_apple_cc_single_mod=yes + fi + if test "X$lt_int_apple_cc_single_mod" = Xyes ; then + archive_cmds_CXX='$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + else + archive_cmds_CXX='$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + fi + module_cmds_CXX='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + if test "X$lt_int_apple_cc_single_mod" = Xyes ; then + archive_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + archive_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + module_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + archive_cmds_CXX='$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + module_cmds_CXX='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + archive_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + module_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + ld_shlibs_CXX=no + ;; + esac + fi + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + freebsd[12]*) + # C++ shared libraries reported to be fairly broken before switch to ELF + ld_shlibs_CXX=no + ;; + freebsd-elf*) + archive_cmds_need_lc_CXX=no + ;; + freebsd* | kfreebsd*-gnu | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + ld_shlibs_CXX=yes + ;; + gnu*) + ;; + hpux9*) + hardcode_libdir_flag_spec_CXX='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_CXX=: + export_dynamic_flag_spec_CXX='${wl}-E' + hardcode_direct_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + archive_cmds_CXX='$rm $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "[-]L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes; then + archive_cmds_CXX='$rm $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + hpux10*|hpux11*) + if test $with_gnu_ld = no; then + hardcode_libdir_flag_spec_CXX='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_CXX=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_libdir_flag_spec_ld_CXX='+b $libdir' + ;; + *) + export_dynamic_flag_spec_CXX='${wl}-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + ;; + *) + hardcode_direct_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes; then + if test $with_gnu_ld = no; then + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + interix3*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir' + export_dynamic_flag_spec_CXX='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds_CXX='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds_CXX='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + archive_cmds_CXX='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test "$GXX" = yes; then + if test "$with_gnu_ld" = no; then + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` -o $lib' + fi + fi + link_all_deplibs_CXX=yes + ;; + esac + hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_CXX=: + ;; + linux*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + archive_expsym_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | grep "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + + hardcode_libdir_flag_spec_CXX='${wl}--rpath,$libdir' + export_dynamic_flag_spec_CXX='${wl}--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc*) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + archive_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + archive_cmds_need_lc_CXX=no + hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir' + export_dynamic_flag_spec_CXX='${wl}--export-dynamic' + whole_archive_flag_spec_CXX='${wl}--whole-archive$convenience ${wl}--no-whole-archive' + ;; + pgCC*) + # Portland Group C++ compiler + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + + hardcode_libdir_flag_spec_CXX='${wl}--rpath ${wl}$libdir' + export_dynamic_flag_spec_CXX='${wl}--export-dynamic' + whole_archive_flag_spec_CXX='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + ;; + cxx*) + # Compaq C++ + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + esac + ;; + lynxos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + m88k*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + archive_cmds_CXX='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + openbsd2*) + # C++ shared libraries are fairly broken + ld_shlibs_CXX=no + ;; + openbsd*) + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' + export_dynamic_flag_spec_CXX='${wl}-E' + whole_archive_flag_spec_CXX="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + fi + output_verbose_link_cmd='echo' + ;; + osf3*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir' + hardcode_libdir_separator_CXX=: + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' + + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + cxx*) + allow_undefined_flag_CXX=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds_CXX='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && echo ${wl}-set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + + hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + allow_undefined_flag_CXX=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds_CXX='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + + hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir' + hardcode_libdir_separator_CXX=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + old_archive_cmds_CXX='$CC -o $oldlib $oldobjs' + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + cxx*) + allow_undefined_flag_CXX=' -expect_unresolved \*' + archive_cmds_CXX='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + archive_expsym_cmds_CXX='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname -Wl,-input -Wl,$lib.exp `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~ + $rm $lib.exp' + + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + allow_undefined_flag_CXX=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds_CXX='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + + hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + psos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + archive_cmds_need_lc_CXX=yes + no_undefined_flag_CXX=' -zdefs' + archive_cmds_CXX='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + archive_expsym_cmds_CXX='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_shlibpath_var_CXX=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The C++ compiler is used as linker so we must use $wl + # flag to pass the commands to the underlying system + # linker. We must also pass each convience library through + # to the system linker between allextract/defaultextract. + # The C++ compiler will combine linker options so we + # cannot just pass the convience library names through + # without $wl. + # Supported since Solaris 2.6 (maybe 2.5.1?) + whole_archive_flag_spec_CXX='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' + ;; + esac + link_all_deplibs_CXX=yes + + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + old_archive_cmds_CXX='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + no_undefined_flag_CXX=' ${wl}-z ${wl}defs' + if $CC --version | grep -v '^2\.7' > /dev/null; then + archive_cmds_CXX='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\"" + else + # g++ 2.7 appears to require `-G' NOT `-shared' on this + # platform. + archive_cmds_CXX='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd="$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\"" + fi + + hardcode_libdir_flag_spec_CXX='${wl}-R $wl$libdir' + fi + ;; + esac + ;; + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag_CXX='${wl}-z,text' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + # So that behaviour is only enabled if SCOABSPATH is set to a + # non-empty value in the environment. Most likely only useful for + # creating official distributions of packages. + # This is a hack until libtool officially supports absolute path + # names for shared libraries. + no_undefined_flag_CXX='${wl}-z,text' + allow_undefined_flag_CXX='${wl}-z,nodefs' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + export_dynamic_flag_spec_CXX='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + vxworks*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; +esac +{ echo "$as_me:$LINENO: result: $ld_shlibs_CXX" >&5 +echo "${ECHO_T}$ld_shlibs_CXX" >&6; } +test "$ld_shlibs_CXX" = no && can_build_shared=no + +GCC_CXX="$GXX" +LD_CXX="$LD" + + +cat > conftest.$ac_ext <&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + # The `*' in the case matches for architectures that use `case' in + # $output_verbose_cmd can trigger glob expansion during the loop + # eval without this substitution. + output_verbose_link_cmd=`$echo "X$output_verbose_link_cmd" | $Xsed -e "$no_glob_subst"` + + for p in `eval $output_verbose_link_cmd`; do + case $p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test $p = "-L" \ + || test $p = "-R"; then + prev=$p + continue + else + prev= + fi + + if test "$pre_test_object_deps_done" = no; then + case $p in + -L* | -R*) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$compiler_lib_search_path_CXX"; then + compiler_lib_search_path_CXX="${prev}${p}" + else + compiler_lib_search_path_CXX="${compiler_lib_search_path_CXX} ${prev}${p}" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$postdeps_CXX"; then + postdeps_CXX="${prev}${p}" + else + postdeps_CXX="${postdeps_CXX} ${prev}${p}" + fi + fi + ;; + + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test "$pre_test_object_deps_done" = no; then + if test -z "$predep_objects_CXX"; then + predep_objects_CXX="$p" + else + predep_objects_CXX="$predep_objects_CXX $p" + fi + else + if test -z "$postdep_objects_CXX"; then + postdep_objects_CXX="$p" + else + postdep_objects_CXX="$postdep_objects_CXX $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling CXX test program" +fi + +$rm -f confest.$objext + +# PORTME: override above test on systems where it is broken +case $host_os in +interix3*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + predep_objects_CXX= + postdep_objects_CXX= + postdeps_CXX= + ;; + +solaris*) + case $cc_basename in + CC*) + # Adding this requires a known-good setup of shared libraries for + # Sun compiler versions before 5.6, else PIC objects from an old + # archive will be linked into the output, leading to subtle bugs. + postdeps_CXX='-lCstd -lCrun' + ;; + esac + ;; +esac + + +case " $postdeps_CXX " in +*" -lc "*) archive_cmds_need_lc_CXX=no ;; +esac + +lt_prog_compiler_wl_CXX= +lt_prog_compiler_pic_CXX= +lt_prog_compiler_static_CXX= + +{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5 +echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; } + + # C++ specific cases for pic, static, wl, etc. + if test "$GXX" = yes; then + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + fi + ;; + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + lt_prog_compiler_pic_CXX='-m68020 -resident32 -malways-restore-a4' + ;; + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | os2* | pw32*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_CXX='-DDLL_EXPORT' + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic_CXX='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + lt_prog_compiler_pic_CXX= + ;; + interix3*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic_CXX=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + else + case $host_os in + aix4* | aix5*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + else + lt_prog_compiler_static_CXX='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_AC_TAGVAR(lt_prog_compiler_static, CXX)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + lt_prog_compiler_pic_CXX='-qnocommon' + lt_prog_compiler_wl_CXX='-Wl,' + ;; + esac + ;; + dgux*) + case $cc_basename in + ec++*) + lt_prog_compiler_pic_CXX='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | kfreebsd*-gnu | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='${wl}-a ${wl}archive' + if test "$host_cpu" != ia64; then + lt_prog_compiler_pic_CXX='+Z' + fi + ;; + aCC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='${wl}-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_CXX='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + lt_prog_compiler_wl_CXX='--backend -Wl,' + lt_prog_compiler_pic_CXX='-fPIC' + ;; + icpc* | ecpc*) + # Intel C++ + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-static' + ;; + pgCC*) + # Portland Group C++ compiler. + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-fpic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + *) + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + lt_prog_compiler_pic_CXX='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + lt_prog_compiler_wl_CXX='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + lt_prog_compiler_pic_CXX='-pic' + ;; + cxx*) + # Digital/Compaq C++ + lt_prog_compiler_wl_CXX='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + lt_prog_compiler_wl_CXX='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + lt_prog_compiler_pic_CXX='-pic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + lcc*) + # Lucid + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + lt_prog_compiler_pic_CXX='-KPIC' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + esac + ;; + vxworks*) + ;; + *) + lt_prog_compiler_can_build_shared_CXX=no + ;; + esac + fi + +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_CXX" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic_CXX" >&6; } + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic_CXX"; then + +{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 +echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_pic_works_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_pic_works_CXX=no + ac_outfile=conftest.$ac_objext + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic_CXX -DPIC" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:12291: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:12295: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_pic_works_CXX=yes + fi + fi + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works_CXX" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic_works_CXX" >&6; } + +if test x"$lt_prog_compiler_pic_works_CXX" = xyes; then + case $lt_prog_compiler_pic_CXX in + "" | " "*) ;; + *) lt_prog_compiler_pic_CXX=" $lt_prog_compiler_pic_CXX" ;; + esac +else + lt_prog_compiler_pic_CXX= + lt_prog_compiler_can_build_shared_CXX=no +fi + +fi +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic_CXX= + ;; + *) + lt_prog_compiler_pic_CXX="$lt_prog_compiler_pic_CXX -DPIC" + ;; +esac + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl_CXX eval lt_tmp_static_flag=\"$lt_prog_compiler_static_CXX\" +{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_static_works_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_static_works_CXX=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + printf "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_static_works_CXX=yes + fi + else + lt_prog_compiler_static_works_CXX=yes + fi + fi + $rm conftest* + LDFLAGS="$save_LDFLAGS" + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works_CXX" >&5 +echo "${ECHO_T}$lt_prog_compiler_static_works_CXX" >&6; } + +if test x"$lt_prog_compiler_static_works_CXX" = xyes; then + : +else + lt_prog_compiler_static_CXX= +fi + + +{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5 +echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; } +if test "${lt_cv_prog_compiler_c_o_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_prog_compiler_c_o_CXX=no + $rm -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:12395: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:12399: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_CXX=yes + fi + fi + chmod u+w . 2>&5 + $rm conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files + $rm out/* && rmdir out + cd .. + rmdir conftest + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +echo "${ECHO_T}$lt_cv_prog_compiler_c_o_CXX" >&6; } + + +hard_links="nottested" +if test "$lt_cv_prog_compiler_c_o_CXX" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5 +echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; } + hard_links=yes + $rm conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { echo "$as_me:$LINENO: result: $hard_links" >&5 +echo "${ECHO_T}$hard_links" >&6; } + if test "$hard_links" = no; then + { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5 +echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + +{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; } + + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + case $host_os in + aix4* | aix5*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds_CXX='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + export_symbols_cmds_CXX="$ltdll_cmds" + ;; + cygwin* | mingw*) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS] /s/.* \([^ ]*\)/\1 DATA/;/^.* __nm__/s/^.* __nm__\([^ ]*\) [^ ]*/\1 DATA/;/^I /d;/^[AITW] /s/.* //'\'' | sort | uniq > $export_symbols' + ;; + *) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + +{ echo "$as_me:$LINENO: result: $ld_shlibs_CXX" >&5 +echo "${ECHO_T}$ld_shlibs_CXX" >&6; } +test "$ld_shlibs_CXX" = no && can_build_shared=no + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc_CXX" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc_CXX=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $archive_cmds_CXX in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5 +echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; } + $rm conftest* + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl_CXX + pic_flag=$lt_prog_compiler_pic_CXX + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag_CXX + allow_undefined_flag_CXX= + if { (eval echo "$as_me:$LINENO: \"$archive_cmds_CXX 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5 + (eval $archive_cmds_CXX 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + then + archive_cmds_need_lc_CXX=no + else + archive_cmds_need_lc_CXX=yes + fi + allow_undefined_flag_CXX=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $rm conftest* + { echo "$as_me:$LINENO: result: $archive_cmds_need_lc_CXX" >&5 +echo "${ECHO_T}$archive_cmds_need_lc_CXX" >&6; } + ;; + esac + fi + ;; +esac + +{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5 +echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; } +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix4* | aix5*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $rm \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + # Apple's gcc prints 'gcc -print-search-dirs' doesn't operate the same. + if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | tr "\n" "$PATH_SEPARATOR" | sed -e 's/libraries:/@libraries:/' | tr "@" "\n" | grep "^libraries:" | sed -e "s/^libraries://" -e "s,=/,/,g" -e "s,$PATH_SEPARATOR, ,g" -e "s,.*,& /lib /usr/lib /usr/local/lib,g"` + else + sys_lib_search_path_spec='/lib /usr/lib /usr/local/lib' + fi + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +kfreebsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[123]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + freebsd*) # from 4.6 on + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix3*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # find out which ABI we are using + libsuff= + case "$host_cpu" in + x86_64*|s390x*|powerpc64*) + echo '#line 12931 "configure"' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + case `/usr/bin/file conftest.$ac_objext` in + *64-bit*) + libsuff=64 + sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" + ;; + esac + fi + rm -rf conftest* + ;; + esac + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/^ *//;s/#.*//;/^[^\/]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +knetbsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +nto-qnx*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[89] | openbsd2.[89].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + export_dynamic_flag_spec='${wl}-Blargedynsym' + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + shlibpath_overrides_runpath=no + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + shlibpath_overrides_runpath=yes + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5 +echo "${ECHO_T}$dynamic_linker" >&6; } +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5 +echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; } +hardcode_action_CXX= +if test -n "$hardcode_libdir_flag_spec_CXX" || \ + test -n "$runpath_var_CXX" || \ + test "X$hardcode_automatic_CXX" = "Xyes" ; then + + # We can hardcode non-existant directories. + if test "$hardcode_direct_CXX" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, CXX)" != no && + test "$hardcode_minus_L_CXX" != no; then + # Linking always hardcodes the temporary library directory. + hardcode_action_CXX=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action_CXX=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action_CXX=unsupported +fi +{ echo "$as_me:$LINENO: result: $hardcode_action_CXX" >&5 +echo "${ECHO_T}$hardcode_action_CXX" >&6; } + +if test "$hardcode_action_CXX" = relink; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + +# The else clause should only fire when bootstrapping the +# libtool distribution, otherwise you forgot to ship ltmain.sh +# with your package, and you will get complaints that there are +# no rules to generate ltmain.sh. +if test -f "$ltmain"; then + # See if we are running on zsh, and set the options which allow our commands through + # without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + # Now quote all the things that may contain metacharacters while being + # careful not to overquote the AC_SUBSTed values. We take copies of the + # variables and quote the copies for generation of the libtool script. + for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \ + SED SHELL STRIP \ + libname_spec library_names_spec soname_spec extract_expsyms_cmds \ + old_striplib striplib file_magic_cmd finish_cmds finish_eval \ + deplibs_check_method reload_flag reload_cmds need_locks \ + lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \ + lt_cv_sys_global_symbol_to_c_name_address \ + sys_lib_search_path_spec sys_lib_dlsearch_path_spec \ + old_postinstall_cmds old_postuninstall_cmds \ + compiler_CXX \ + CC_CXX \ + LD_CXX \ + lt_prog_compiler_wl_CXX \ + lt_prog_compiler_pic_CXX \ + lt_prog_compiler_static_CXX \ + lt_prog_compiler_no_builtin_flag_CXX \ + export_dynamic_flag_spec_CXX \ + thread_safe_flag_spec_CXX \ + whole_archive_flag_spec_CXX \ + enable_shared_with_static_runtimes_CXX \ + old_archive_cmds_CXX \ + old_archive_from_new_cmds_CXX \ + predep_objects_CXX \ + postdep_objects_CXX \ + predeps_CXX \ + postdeps_CXX \ + compiler_lib_search_path_CXX \ + archive_cmds_CXX \ + archive_expsym_cmds_CXX \ + postinstall_cmds_CXX \ + postuninstall_cmds_CXX \ + old_archive_from_expsyms_cmds_CXX \ + allow_undefined_flag_CXX \ + no_undefined_flag_CXX \ + export_symbols_cmds_CXX \ + hardcode_libdir_flag_spec_CXX \ + hardcode_libdir_flag_spec_ld_CXX \ + hardcode_libdir_separator_CXX \ + hardcode_automatic_CXX \ + module_cmds_CXX \ + module_expsym_cmds_CXX \ + lt_cv_prog_compiler_c_o_CXX \ + exclude_expsyms_CXX \ + include_expsyms_CXX; do + + case $var in + old_archive_cmds_CXX | \ + old_archive_from_new_cmds_CXX | \ + archive_cmds_CXX | \ + archive_expsym_cmds_CXX | \ + module_cmds_CXX | \ + module_expsym_cmds_CXX | \ + old_archive_from_expsyms_cmds_CXX | \ + export_symbols_cmds_CXX | \ + extract_expsyms_cmds | reload_cmds | finish_cmds | \ + postinstall_cmds | postuninstall_cmds | \ + old_postinstall_cmds | old_postuninstall_cmds | \ + sys_lib_search_path_spec | sys_lib_dlsearch_path_spec) + # Double-quote double-evaled strings. + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\"" + ;; + *) + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\"" + ;; + esac + done + + case $lt_echo in + *'\$0 --fallback-echo"') + lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'` + ;; + esac + +cfgfile="$ofile" + + cat <<__EOF__ >> "$cfgfile" +# ### BEGIN LIBTOOL TAG CONFIG: $tagname + +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc_CXX + +# Whether or not to disallow shared libs when runtime libs are static +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_CXX + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# An echo program that does not interpret backslashes. +echo=$lt_echo + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A C compiler. +LTCC=$lt_LTCC + +# LTCC compiler flags. +LTCFLAGS=$lt_LTCFLAGS + +# A language-specific compiler. +CC=$lt_compiler_CXX + +# Is the compiler the GNU C compiler? +with_gcc=$GCC_CXX + +# An ERE matcher. +EGREP=$lt_EGREP + +# The linker used to build libraries. +LD=$lt_LD_CXX + +# Whether we need hard or soft links. +LN_S=$lt_LN_S + +# A BSD-compatible nm program. +NM=$lt_NM + +# A symbol stripping program +STRIP=$lt_STRIP + +# Used to examine libraries when file_magic_cmd begins "file" +MAGIC_CMD=$MAGIC_CMD + +# Used on cygwin: DLL creation program. +DLLTOOL="$DLLTOOL" + +# Used on cygwin: object dumper. +OBJDUMP="$OBJDUMP" + +# Used on cygwin: assembler. +AS="$AS" + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl_CXX + +# Object file suffix (normally "o"). +objext="$ac_objext" + +# Old archive suffix (normally "a"). +libext="$libext" + +# Shared library suffix (normally ".so"). +shrext_cmds='$shrext_cmds' + +# Executable file suffix (normally ""). +exeext="$exeext" + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic_CXX +pic_mode=$pic_mode + +# What is the maximum length of a command? +max_cmd_len=$lt_cv_sys_max_cmd_len + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o_CXX + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Do we need the lib prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static_CXX + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_CXX + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_CXX + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec_CXX + +# Compiler flag to generate thread-safe objects. +thread_safe_flag_spec=$lt_thread_safe_flag_spec_CXX + +# Library versioning type. +version_type=$version_type + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME. +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Commands used to build and install an old-style archive. +RANLIB=$lt_RANLIB +old_archive_cmds=$lt_old_archive_cmds_CXX +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_CXX + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_CXX + +# Commands used to build and install a shared archive. +archive_cmds=$lt_archive_cmds_CXX +archive_expsym_cmds=$lt_archive_expsym_cmds_CXX +postinstall_cmds=$lt_postinstall_cmds +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to build a loadable module (assumed same as above if empty) +module_cmds=$lt_module_cmds_CXX +module_expsym_cmds=$lt_module_expsym_cmds_CXX + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + +# Dependencies to place before the objects being linked to create a +# shared library. +predep_objects=$lt_predep_objects_CXX + +# Dependencies to place after the objects being linked to create a +# shared library. +postdep_objects=$lt_postdep_objects_CXX + +# Dependencies to place before the objects being linked to create a +# shared library. +predeps=$lt_predeps_CXX + +# Dependencies to place after the objects being linked to create a +# shared library. +postdeps=$lt_postdeps_CXX + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path_CXX + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == file_magic. +file_magic_cmd=$lt_file_magic_cmd + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag_CXX + +# Flag that forces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag_CXX + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# Same as above, but a single script fragment to be evaled but not shown. +finish_eval=$lt_finish_eval + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# This is the shared library runtime path variable. +runpath_var=$runpath_var + +# This is the shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action_CXX + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_CXX + +# If ld is used when linking, flag to hardcode \$libdir into +# a binary during linking. This must work even if \$libdir does +# not exist. +hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_CXX + +# Whether we need a single -rpath flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator_CXX + +# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the +# resulting binary. +hardcode_direct=$hardcode_direct_CXX + +# Set to yes if using the -LDIR flag during linking hardcodes DIR into the +# resulting binary. +hardcode_minus_L=$hardcode_minus_L_CXX + +# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into +# the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var_CXX + +# Set to yes if building a shared library automatically hardcodes DIR into the library +# and all subsequent libraries and executables linked against it. +hardcode_automatic=$hardcode_automatic_CXX + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at relink time. +variables_saved_for_relink="$variables_saved_for_relink" + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs_CXX + +# Compile-time system search path for libraries +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path="$fix_srcfile_path_CXX" + +# Set to yes if exported symbols are required. +always_export_symbols=$always_export_symbols_CXX + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds_CXX + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms_CXX + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms_CXX + +# ### END LIBTOOL TAG CONFIG: $tagname + +__EOF__ + + +else + # If there is no Makefile yet, we rely on a make rule to execute + # `config.status --recheck' to rerun these tests and create the + # libtool script then. + ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'` + if test -f "$ltmain_in"; then + test -f Makefile && make "$ltmain" + fi +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC=$lt_save_CC +LDCXX=$LD +LD=$lt_save_LD +GCC=$lt_save_GCC +with_gnu_ldcxx=$with_gnu_ld +with_gnu_ld=$lt_save_with_gnu_ld +lt_cv_path_LDCXX=$lt_cv_path_LD +lt_cv_path_LD=$lt_save_path_LD +lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld +lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld + + else + tagname="" + fi + ;; + + F77) + if test -n "$F77" && test "X$F77" != "Xno"; then + +ac_ext=f +ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5' +ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_f77_compiler_gnu + + +archive_cmds_need_lc_F77=no +allow_undefined_flag_F77= +always_export_symbols_F77=no +archive_expsym_cmds_F77= +export_dynamic_flag_spec_F77= +hardcode_direct_F77=no +hardcode_libdir_flag_spec_F77= +hardcode_libdir_flag_spec_ld_F77= +hardcode_libdir_separator_F77= +hardcode_minus_L_F77=no +hardcode_automatic_F77=no +module_cmds_F77= +module_expsym_cmds_F77= +link_all_deplibs_F77=unknown +old_archive_cmds_F77=$old_archive_cmds +no_undefined_flag_F77= +whole_archive_flag_spec_F77= +enable_shared_with_static_runtimes_F77=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +objext_F77=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code=" subroutine t\n return\n end\n" + +# Code to be used in simple link tests +lt_simple_link_test_code=" program t\n end\n" + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +printf "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$rm conftest* + +ac_outfile=conftest.$ac_objext +printf "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$rm conftest* + + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +CC=${F77-"f77"} +compiler=$CC +compiler_F77=$CC +for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + +{ echo "$as_me:$LINENO: checking if libtool supports shared libraries" >&5 +echo $ECHO_N "checking if libtool supports shared libraries... $ECHO_C" >&6; } +{ echo "$as_me:$LINENO: result: $can_build_shared" >&5 +echo "${ECHO_T}$can_build_shared" >&6; } + +{ echo "$as_me:$LINENO: checking whether to build shared libraries" >&5 +echo $ECHO_N "checking whether to build shared libraries... $ECHO_C" >&6; } +test "$can_build_shared" = "no" && enable_shared=no + +# On AIX, shared libraries and static libraries use the same namespace, and +# are all built from PIC. +case $host_os in +aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; +aix4* | aix5*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; +esac +{ echo "$as_me:$LINENO: result: $enable_shared" >&5 +echo "${ECHO_T}$enable_shared" >&6; } + +{ echo "$as_me:$LINENO: checking whether to build static libraries" >&5 +echo $ECHO_N "checking whether to build static libraries... $ECHO_C" >&6; } +# Make sure either enable_shared or enable_static is yes. +test "$enable_shared" = yes || enable_static=yes +{ echo "$as_me:$LINENO: result: $enable_static" >&5 +echo "${ECHO_T}$enable_static" >&6; } + +GCC_F77="$G77" +LD_F77="$LD" + +lt_prog_compiler_wl_F77= +lt_prog_compiler_pic_F77= +lt_prog_compiler_static_F77= + +{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5 +echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; } + + if test "$GCC" = yes; then + lt_prog_compiler_wl_F77='-Wl,' + lt_prog_compiler_static_F77='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_F77='-Bstatic' + fi + ;; + + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + lt_prog_compiler_pic_F77='-m68020 -resident32 -malways-restore-a4' + ;; + + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_F77='-DDLL_EXPORT' + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic_F77='-fno-common' + ;; + + interix3*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared_F77=no + enable_shared=no + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic_F77=-Kconform_pic + fi + ;; + + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_F77='-fPIC' + ;; + esac + ;; + + *) + lt_prog_compiler_pic_F77='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl_F77='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_F77='-Bstatic' + else + lt_prog_compiler_static_F77='-bnso -bI:/lib/syscalls.exp' + fi + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + lt_prog_compiler_pic_F77='-qnocommon' + lt_prog_compiler_wl_F77='-Wl,' + ;; + esac + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_F77='-DDLL_EXPORT' + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl_F77='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_F77='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static_F77='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl_F77='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static_F77='-non_shared' + ;; + + newsos6) + lt_prog_compiler_pic_F77='-KPIC' + lt_prog_compiler_static_F77='-Bstatic' + ;; + + linux*) + case $cc_basename in + icc* | ecc*) + lt_prog_compiler_wl_F77='-Wl,' + lt_prog_compiler_pic_F77='-KPIC' + lt_prog_compiler_static_F77='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl_F77='-Wl,' + lt_prog_compiler_pic_F77='-fpic' + lt_prog_compiler_static_F77='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl_F77='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static_F77='-non_shared' + ;; + esac + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl_F77='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static_F77='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic_F77='-KPIC' + lt_prog_compiler_static_F77='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + lt_prog_compiler_wl_F77='-Qoption ld ';; + *) + lt_prog_compiler_wl_F77='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl_F77='-Qoption ld ' + lt_prog_compiler_pic_F77='-PIC' + lt_prog_compiler_static_F77='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl_F77='-Wl,' + lt_prog_compiler_pic_F77='-KPIC' + lt_prog_compiler_static_F77='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + lt_prog_compiler_pic_F77='-Kconform_pic' + lt_prog_compiler_static_F77='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl_F77='-Wl,' + lt_prog_compiler_pic_F77='-KPIC' + lt_prog_compiler_static_F77='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl_F77='-Wl,' + lt_prog_compiler_can_build_shared_F77=no + ;; + + uts4*) + lt_prog_compiler_pic_F77='-pic' + lt_prog_compiler_static_F77='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared_F77=no + ;; + esac + fi + +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_F77" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic_F77" >&6; } + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic_F77"; then + +{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works" >&5 +echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_pic_works_F77+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_pic_works_F77=no + ac_outfile=conftest.$ac_objext + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic_F77" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:13986: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:13990: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_pic_works_F77=yes + fi + fi + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works_F77" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic_works_F77" >&6; } + +if test x"$lt_prog_compiler_pic_works_F77" = xyes; then + case $lt_prog_compiler_pic_F77 in + "" | " "*) ;; + *) lt_prog_compiler_pic_F77=" $lt_prog_compiler_pic_F77" ;; + esac +else + lt_prog_compiler_pic_F77= + lt_prog_compiler_can_build_shared_F77=no +fi + +fi +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic_F77= + ;; + *) + lt_prog_compiler_pic_F77="$lt_prog_compiler_pic_F77" + ;; +esac + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl_F77 eval lt_tmp_static_flag=\"$lt_prog_compiler_static_F77\" +{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_static_works_F77+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_static_works_F77=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + printf "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_static_works_F77=yes + fi + else + lt_prog_compiler_static_works_F77=yes + fi + fi + $rm conftest* + LDFLAGS="$save_LDFLAGS" + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works_F77" >&5 +echo "${ECHO_T}$lt_prog_compiler_static_works_F77" >&6; } + +if test x"$lt_prog_compiler_static_works_F77" = xyes; then + : +else + lt_prog_compiler_static_F77= +fi + + +{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5 +echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; } +if test "${lt_cv_prog_compiler_c_o_F77+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_prog_compiler_c_o_F77=no + $rm -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:14090: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:14094: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_F77=yes + fi + fi + chmod u+w . 2>&5 + $rm conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files + $rm out/* && rmdir out + cd .. + rmdir conftest + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o_F77" >&5 +echo "${ECHO_T}$lt_cv_prog_compiler_c_o_F77" >&6; } + + +hard_links="nottested" +if test "$lt_cv_prog_compiler_c_o_F77" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5 +echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; } + hard_links=yes + $rm conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { echo "$as_me:$LINENO: result: $hard_links" >&5 +echo "${ECHO_T}$hard_links" >&6; } + if test "$hard_links" = no; then + { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5 +echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + +{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; } + + runpath_var= + allow_undefined_flag_F77= + enable_shared_with_static_runtimes_F77=no + archive_cmds_F77= + archive_expsym_cmds_F77= + old_archive_From_new_cmds_F77= + old_archive_from_expsyms_cmds_F77= + export_dynamic_flag_spec_F77= + whole_archive_flag_spec_F77= + thread_safe_flag_spec_F77= + hardcode_libdir_flag_spec_F77= + hardcode_libdir_flag_spec_ld_F77= + hardcode_libdir_separator_F77= + hardcode_direct_F77=no + hardcode_minus_L_F77=no + hardcode_shlibpath_var_F77=unsupported + link_all_deplibs_F77=unknown + hardcode_automatic_F77=no + module_cmds_F77= + module_expsym_cmds_F77= + always_export_symbols_F77=no + export_symbols_cmds_F77='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms_F77= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + exclude_expsyms_F77="_GLOBAL_OFFSET_TABLE_" + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + extract_expsyms_cmds= + # Just being paranoid about ensuring that cc_basename is set. + for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + case $host_os in + cygwin* | mingw* | pw32*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + esac + + ld_shlibs_F77=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec_F77='${wl}--rpath ${wl}$libdir' + export_dynamic_flag_spec_F77='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec_F77="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + whole_archive_flag_spec_F77= + fi + supports_anon_versioning=no + case `$LD -v 2>/dev/null` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix3* | aix4* | aix5*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + ld_shlibs_F77=no + cat <&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +EOF + fi + ;; + + amigaos*) + archive_cmds_F77='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec_F77='-L$libdir' + hardcode_minus_L_F77=yes + + # Samuel A. Falvo II reports + # that the semantics of dynamic libraries on AmigaOS, at least up + # to version 4, is to share data among multiple programs linked + # with the same dynamic library. Since this doesn't match the + # behavior of shared libraries on other platforms, we can't use + # them. + ld_shlibs_F77=no + ;; + + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag_F77=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds_F77='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + ld_shlibs_F77=no + fi + ;; + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, F77) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec_F77='-L$libdir' + allow_undefined_flag_F77=unsupported + always_export_symbols_F77=no + enable_shared_with_static_runtimes_F77=yes + export_symbols_cmds_F77='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS] /s/.* \([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW] /s/.* //'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + archive_expsym_cmds_F77='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs_F77=no + fi + ;; + + interix3*) + hardcode_direct_F77=no + hardcode_shlibpath_var_F77=no + hardcode_libdir_flag_spec_F77='${wl}-rpath,$libdir' + export_dynamic_flag_spec_F77='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds_F77='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds_F77='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + linux*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + tmp_addflag= + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec_F77='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + whole_archive_flag_spec_F77='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + esac + archive_cmds_F77='$CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test $supports_anon_versioning = yes; then + archive_expsym_cmds_F77='$echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + $echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + else + ld_shlibs_F77=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + archive_cmds_F77='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then + ld_shlibs_F77=no + cat <&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +EOF + elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs_F77=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs_F77=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec_F77='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' + archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib' + archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib' + else + ld_shlibs_F77=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds_F77='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct_F77=yes + hardcode_shlibpath_var_F77=no + ;; + + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs_F77=no + fi + ;; + esac + + if test "$ld_shlibs_F77" = no; then + runpath_var= + hardcode_libdir_flag_spec_F77= + export_dynamic_flag_spec_F77= + whole_archive_flag_spec_F77= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag_F77=unsupported + always_export_symbols_F77=yes + archive_expsym_cmds_F77='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L_F77=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct_F77=unsupported + fi + ;; + + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + export_symbols_cmds_F77='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds_F77='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[23]|aix4.[23].*|aix5*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds_F77='' + hardcode_direct_F77=yes + hardcode_libdir_separator_F77=':' + link_all_deplibs_F77=yes + + if test "$GCC" = yes; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + hardcode_direct_F77=yes + else + # We have old collect2 + hardcode_direct_F77=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L_F77=yes + hardcode_libdir_flag_spec_F77='-L$libdir' + hardcode_libdir_separator_F77= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols_F77=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag_F77='-berok' + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF + program main + + end +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_f77_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec_F77='${wl}-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds_F77="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + hardcode_libdir_flag_spec_F77='${wl}-R $libdir:/usr/lib:/lib' + allow_undefined_flag_F77="-z nodefs" + archive_expsym_cmds_F77="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF + program main + + end +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_f77_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec_F77='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag_F77=' ${wl}-bernotok' + allow_undefined_flag_F77=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec_F77='$convenience' + archive_cmds_need_lc_F77=yes + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds_F77="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + archive_cmds_F77='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec_F77='-L$libdir' + hardcode_minus_L_F77=yes + # see comment about different semantics on the GNU ld section + ld_shlibs_F77=no + ;; + + bsdi[45]*) + export_dynamic_flag_spec_F77=-rdynamic + ;; + + cygwin* | mingw* | pw32*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec_F77=' ' + allow_undefined_flag_F77=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + archive_cmds_F77='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_From_new_cmds_F77='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds_F77='lib /OUT:$oldlib$oldobjs$old_deplibs' + fix_srcfile_path_F77='`cygpath -w "$srcfile"`' + enable_shared_with_static_runtimes_F77=yes + ;; + + darwin* | rhapsody*) + case $host_os in + rhapsody* | darwin1.[012]) + allow_undefined_flag_F77='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + allow_undefined_flag_F77='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[012]) + allow_undefined_flag_F77='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + allow_undefined_flag_F77='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + archive_cmds_need_lc_F77=no + hardcode_direct_F77=no + hardcode_automatic_F77=yes + hardcode_shlibpath_var_F77=unsupported + whole_archive_flag_spec_F77='' + link_all_deplibs_F77=yes + if test "$GCC" = yes ; then + output_verbose_link_cmd='echo' + archive_cmds_F77='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + module_cmds_F77='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + archive_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + module_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + archive_cmds_F77='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + module_cmds_F77='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + archive_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + module_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + ld_shlibs_F77=no + ;; + esac + fi + ;; + + dgux*) + archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec_F77='-L$libdir' + hardcode_shlibpath_var_F77=no + ;; + + freebsd1*) + ld_shlibs_F77=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec_F77='-R$libdir' + hardcode_direct_F77=yes + hardcode_shlibpath_var_F77=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_F77=yes + hardcode_minus_L_F77=yes + hardcode_shlibpath_var_F77=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | kfreebsd*-gnu | dragonfly*) + archive_cmds_F77='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec_F77='-R$libdir' + hardcode_direct_F77=yes + hardcode_shlibpath_var_F77=no + ;; + + hpux9*) + if test "$GCC" = yes; then + archive_cmds_F77='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + archive_cmds_F77='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec_F77='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_F77=: + hardcode_direct_F77=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L_F77=yes + export_dynamic_flag_spec_F77='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + archive_cmds_F77='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_F77='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec_F77='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_F77=: + + hardcode_direct_F77=yes + export_dynamic_flag_spec_F77='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L_F77=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + archive_cmds_F77='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds_F77='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_F77='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds_F77='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds_F77='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_F77='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec_F77='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_F77=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_libdir_flag_spec_ld_F77='+b $libdir' + hardcode_direct_F77=no + hardcode_shlibpath_var_F77=no + ;; + *) + hardcode_direct_F77=yes + export_dynamic_flag_spec_F77='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L_F77=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + archive_cmds_F77='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + hardcode_libdir_flag_spec_ld_F77='-rpath $libdir' + fi + hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_F77=: + link_all_deplibs_F77=yes + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds_F77='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec_F77='-R$libdir' + hardcode_direct_F77=yes + hardcode_shlibpath_var_F77=no + ;; + + newsos6) + archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_F77=yes + hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_F77=: + hardcode_shlibpath_var_F77=no + ;; + + openbsd*) + hardcode_direct_F77=yes + hardcode_shlibpath_var_F77=no + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + archive_cmds_F77='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_F77='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec_F77='${wl}-rpath,$libdir' + export_dynamic_flag_spec_F77='${wl}-E' + else + case $host_os in + openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) + archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec_F77='-R$libdir' + ;; + *) + archive_cmds_F77='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec_F77='${wl}-rpath,$libdir' + ;; + esac + fi + ;; + + os2*) + hardcode_libdir_flag_spec_F77='-L$libdir' + hardcode_minus_L_F77=yes + allow_undefined_flag_F77=unsupported + archive_cmds_F77='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + old_archive_From_new_cmds_F77='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + allow_undefined_flag_F77=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds_F77='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + allow_undefined_flag_F77=' -expect_unresolved \*' + archive_cmds_F77='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + fi + hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_F77=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + allow_undefined_flag_F77=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds_F77='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir' + else + allow_undefined_flag_F77=' -expect_unresolved \*' + archive_cmds_F77='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + archive_expsym_cmds_F77='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~ + $LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec_F77='-rpath $libdir' + fi + hardcode_libdir_separator_F77=: + ;; + + solaris*) + no_undefined_flag_F77=' -z text' + if test "$GCC" = yes; then + wlarc='${wl}' + archive_cmds_F77='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_F77='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp' + else + wlarc='' + archive_cmds_F77='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds_F77='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp' + fi + hardcode_libdir_flag_spec_F77='-R$libdir' + hardcode_shlibpath_var_F77=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine linker options so we + # cannot just pass the convience library names through + # without $wl, iff we do not link with $LD. + # Luckily, gcc supports the same syntax we need for Sun Studio. + # Supported since Solaris 2.6 (maybe 2.5.1?) + case $wlarc in + '') + whole_archive_flag_spec_F77='-z allextract$convenience -z defaultextract' ;; + *) + whole_archive_flag_spec_F77='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' ;; + esac ;; + esac + link_all_deplibs_F77=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds_F77='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_F77='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec_F77='-L$libdir' + hardcode_direct_F77=yes + hardcode_minus_L_F77=yes + hardcode_shlibpath_var_F77=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_F77=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds_F77='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds_F77='$CC -r -o $output$reload_objs' + hardcode_direct_F77=no + ;; + motorola) + archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_F77=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var_F77=no + ;; + + sysv4.3*) + archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var_F77=no + export_dynamic_flag_spec_F77='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var_F77=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs_F77=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7*) + no_undefined_flag_F77='${wl}-z,text' + archive_cmds_need_lc_F77=no + hardcode_shlibpath_var_F77=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds_F77='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_F77='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_F77='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_F77='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag_F77='${wl}-z,text' + allow_undefined_flag_F77='${wl}-z,nodefs' + archive_cmds_need_lc_F77=no + hardcode_shlibpath_var_F77=no + hardcode_libdir_flag_spec_F77='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + hardcode_libdir_separator_F77=':' + link_all_deplibs_F77=yes + export_dynamic_flag_spec_F77='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds_F77='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_F77='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_F77='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_F77='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec_F77='-L$libdir' + hardcode_shlibpath_var_F77=no + ;; + + *) + ld_shlibs_F77=no + ;; + esac + fi + +{ echo "$as_me:$LINENO: result: $ld_shlibs_F77" >&5 +echo "${ECHO_T}$ld_shlibs_F77" >&6; } +test "$ld_shlibs_F77" = no && can_build_shared=no + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc_F77" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc_F77=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $archive_cmds_F77 in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5 +echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; } + $rm conftest* + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl_F77 + pic_flag=$lt_prog_compiler_pic_F77 + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag_F77 + allow_undefined_flag_F77= + if { (eval echo "$as_me:$LINENO: \"$archive_cmds_F77 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5 + (eval $archive_cmds_F77 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + then + archive_cmds_need_lc_F77=no + else + archive_cmds_need_lc_F77=yes + fi + allow_undefined_flag_F77=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $rm conftest* + { echo "$as_me:$LINENO: result: $archive_cmds_need_lc_F77" >&5 +echo "${ECHO_T}$archive_cmds_need_lc_F77" >&6; } + ;; + esac + fi + ;; +esac + +{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5 +echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; } +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix4* | aix5*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $rm \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + # Apple's gcc prints 'gcc -print-search-dirs' doesn't operate the same. + if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | tr "\n" "$PATH_SEPARATOR" | sed -e 's/libraries:/@libraries:/' | tr "@" "\n" | grep "^libraries:" | sed -e "s/^libraries://" -e "s,=/,/,g" -e "s,$PATH_SEPARATOR, ,g" -e "s,.*,& /lib /usr/lib /usr/local/lib,g"` + else + sys_lib_search_path_spec='/lib /usr/lib /usr/local/lib' + fi + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +kfreebsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[123]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + freebsd*) # from 4.6 on + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix3*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # find out which ABI we are using + libsuff= + case "$host_cpu" in + x86_64*|s390x*|powerpc64*) + echo '#line 15535 "configure"' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + case `/usr/bin/file conftest.$ac_objext` in + *64-bit*) + libsuff=64 + sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" + ;; + esac + fi + rm -rf conftest* + ;; + esac + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/^ *//;s/#.*//;/^[^\/]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +knetbsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +nto-qnx*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[89] | openbsd2.[89].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + export_dynamic_flag_spec='${wl}-Blargedynsym' + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + shlibpath_overrides_runpath=no + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + shlibpath_overrides_runpath=yes + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5 +echo "${ECHO_T}$dynamic_linker" >&6; } +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5 +echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; } +hardcode_action_F77= +if test -n "$hardcode_libdir_flag_spec_F77" || \ + test -n "$runpath_var_F77" || \ + test "X$hardcode_automatic_F77" = "Xyes" ; then + + # We can hardcode non-existant directories. + if test "$hardcode_direct_F77" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, F77)" != no && + test "$hardcode_minus_L_F77" != no; then + # Linking always hardcodes the temporary library directory. + hardcode_action_F77=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action_F77=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action_F77=unsupported +fi +{ echo "$as_me:$LINENO: result: $hardcode_action_F77" >&5 +echo "${ECHO_T}$hardcode_action_F77" >&6; } + +if test "$hardcode_action_F77" = relink; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + +# The else clause should only fire when bootstrapping the +# libtool distribution, otherwise you forgot to ship ltmain.sh +# with your package, and you will get complaints that there are +# no rules to generate ltmain.sh. +if test -f "$ltmain"; then + # See if we are running on zsh, and set the options which allow our commands through + # without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + # Now quote all the things that may contain metacharacters while being + # careful not to overquote the AC_SUBSTed values. We take copies of the + # variables and quote the copies for generation of the libtool script. + for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \ + SED SHELL STRIP \ + libname_spec library_names_spec soname_spec extract_expsyms_cmds \ + old_striplib striplib file_magic_cmd finish_cmds finish_eval \ + deplibs_check_method reload_flag reload_cmds need_locks \ + lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \ + lt_cv_sys_global_symbol_to_c_name_address \ + sys_lib_search_path_spec sys_lib_dlsearch_path_spec \ + old_postinstall_cmds old_postuninstall_cmds \ + compiler_F77 \ + CC_F77 \ + LD_F77 \ + lt_prog_compiler_wl_F77 \ + lt_prog_compiler_pic_F77 \ + lt_prog_compiler_static_F77 \ + lt_prog_compiler_no_builtin_flag_F77 \ + export_dynamic_flag_spec_F77 \ + thread_safe_flag_spec_F77 \ + whole_archive_flag_spec_F77 \ + enable_shared_with_static_runtimes_F77 \ + old_archive_cmds_F77 \ + old_archive_from_new_cmds_F77 \ + predep_objects_F77 \ + postdep_objects_F77 \ + predeps_F77 \ + postdeps_F77 \ + compiler_lib_search_path_F77 \ + archive_cmds_F77 \ + archive_expsym_cmds_F77 \ + postinstall_cmds_F77 \ + postuninstall_cmds_F77 \ + old_archive_from_expsyms_cmds_F77 \ + allow_undefined_flag_F77 \ + no_undefined_flag_F77 \ + export_symbols_cmds_F77 \ + hardcode_libdir_flag_spec_F77 \ + hardcode_libdir_flag_spec_ld_F77 \ + hardcode_libdir_separator_F77 \ + hardcode_automatic_F77 \ + module_cmds_F77 \ + module_expsym_cmds_F77 \ + lt_cv_prog_compiler_c_o_F77 \ + exclude_expsyms_F77 \ + include_expsyms_F77; do + + case $var in + old_archive_cmds_F77 | \ + old_archive_from_new_cmds_F77 | \ + archive_cmds_F77 | \ + archive_expsym_cmds_F77 | \ + module_cmds_F77 | \ + module_expsym_cmds_F77 | \ + old_archive_from_expsyms_cmds_F77 | \ + export_symbols_cmds_F77 | \ + extract_expsyms_cmds | reload_cmds | finish_cmds | \ + postinstall_cmds | postuninstall_cmds | \ + old_postinstall_cmds | old_postuninstall_cmds | \ + sys_lib_search_path_spec | sys_lib_dlsearch_path_spec) + # Double-quote double-evaled strings. + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\"" + ;; + *) + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\"" + ;; + esac + done + + case $lt_echo in + *'\$0 --fallback-echo"') + lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'` + ;; + esac + +cfgfile="$ofile" + + cat <<__EOF__ >> "$cfgfile" +# ### BEGIN LIBTOOL TAG CONFIG: $tagname + +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc_F77 + +# Whether or not to disallow shared libs when runtime libs are static +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_F77 + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# An echo program that does not interpret backslashes. +echo=$lt_echo + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A C compiler. +LTCC=$lt_LTCC + +# LTCC compiler flags. +LTCFLAGS=$lt_LTCFLAGS + +# A language-specific compiler. +CC=$lt_compiler_F77 + +# Is the compiler the GNU C compiler? +with_gcc=$GCC_F77 + +# An ERE matcher. +EGREP=$lt_EGREP + +# The linker used to build libraries. +LD=$lt_LD_F77 + +# Whether we need hard or soft links. +LN_S=$lt_LN_S + +# A BSD-compatible nm program. +NM=$lt_NM + +# A symbol stripping program +STRIP=$lt_STRIP + +# Used to examine libraries when file_magic_cmd begins "file" +MAGIC_CMD=$MAGIC_CMD + +# Used on cygwin: DLL creation program. +DLLTOOL="$DLLTOOL" + +# Used on cygwin: object dumper. +OBJDUMP="$OBJDUMP" + +# Used on cygwin: assembler. +AS="$AS" + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl_F77 + +# Object file suffix (normally "o"). +objext="$ac_objext" + +# Old archive suffix (normally "a"). +libext="$libext" + +# Shared library suffix (normally ".so"). +shrext_cmds='$shrext_cmds' + +# Executable file suffix (normally ""). +exeext="$exeext" + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic_F77 +pic_mode=$pic_mode + +# What is the maximum length of a command? +max_cmd_len=$lt_cv_sys_max_cmd_len + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o_F77 + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Do we need the lib prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static_F77 + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_F77 + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_F77 + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec_F77 + +# Compiler flag to generate thread-safe objects. +thread_safe_flag_spec=$lt_thread_safe_flag_spec_F77 + +# Library versioning type. +version_type=$version_type + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME. +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Commands used to build and install an old-style archive. +RANLIB=$lt_RANLIB +old_archive_cmds=$lt_old_archive_cmds_F77 +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_F77 + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_F77 + +# Commands used to build and install a shared archive. +archive_cmds=$lt_archive_cmds_F77 +archive_expsym_cmds=$lt_archive_expsym_cmds_F77 +postinstall_cmds=$lt_postinstall_cmds +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to build a loadable module (assumed same as above if empty) +module_cmds=$lt_module_cmds_F77 +module_expsym_cmds=$lt_module_expsym_cmds_F77 + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + +# Dependencies to place before the objects being linked to create a +# shared library. +predep_objects=$lt_predep_objects_F77 + +# Dependencies to place after the objects being linked to create a +# shared library. +postdep_objects=$lt_postdep_objects_F77 + +# Dependencies to place before the objects being linked to create a +# shared library. +predeps=$lt_predeps_F77 + +# Dependencies to place after the objects being linked to create a +# shared library. +postdeps=$lt_postdeps_F77 + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path_F77 + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == file_magic. +file_magic_cmd=$lt_file_magic_cmd + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag_F77 + +# Flag that forces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag_F77 + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# Same as above, but a single script fragment to be evaled but not shown. +finish_eval=$lt_finish_eval + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# This is the shared library runtime path variable. +runpath_var=$runpath_var + +# This is the shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action_F77 + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_F77 + +# If ld is used when linking, flag to hardcode \$libdir into +# a binary during linking. This must work even if \$libdir does +# not exist. +hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_F77 + +# Whether we need a single -rpath flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator_F77 + +# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the +# resulting binary. +hardcode_direct=$hardcode_direct_F77 + +# Set to yes if using the -LDIR flag during linking hardcodes DIR into the +# resulting binary. +hardcode_minus_L=$hardcode_minus_L_F77 + +# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into +# the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var_F77 + +# Set to yes if building a shared library automatically hardcodes DIR into the library +# and all subsequent libraries and executables linked against it. +hardcode_automatic=$hardcode_automatic_F77 + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at relink time. +variables_saved_for_relink="$variables_saved_for_relink" + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs_F77 + +# Compile-time system search path for libraries +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path="$fix_srcfile_path_F77" + +# Set to yes if exported symbols are required. +always_export_symbols=$always_export_symbols_F77 + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds_F77 + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms_F77 + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms_F77 + +# ### END LIBTOOL TAG CONFIG: $tagname + +__EOF__ + + +else + # If there is no Makefile yet, we rely on a make rule to execute + # `config.status --recheck' to rerun these tests and create the + # libtool script then. + ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'` + if test -f "$ltmain_in"; then + test -f Makefile && make "$ltmain" + fi +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC="$lt_save_CC" + + else + tagname="" + fi + ;; + + GCJ) + if test -n "$GCJ" && test "X$GCJ" != "Xno"; then + + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +objext_GCJ=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}\n" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[] argv) {}; }\n' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +printf "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$rm conftest* + +ac_outfile=conftest.$ac_objext +printf "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$rm conftest* + + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +CC=${GCJ-"gcj"} +compiler=$CC +compiler_GCJ=$CC +for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +archive_cmds_need_lc_GCJ=no + +old_archive_cmds_GCJ=$old_archive_cmds + + +lt_prog_compiler_no_builtin_flag_GCJ= + +if test "$GCC" = yes; then + lt_prog_compiler_no_builtin_flag_GCJ=' -fno-builtin' + + +{ echo "$as_me:$LINENO: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +echo $ECHO_N "checking if $compiler supports -fno-rtti -fno-exceptions... $ECHO_C" >&6; } +if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_prog_compiler_rtti_exceptions=no + ac_outfile=conftest.$ac_objext + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="-fno-rtti -fno-exceptions" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:16309: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:16313: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_rtti_exceptions=yes + fi + fi + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +echo "${ECHO_T}$lt_cv_prog_compiler_rtti_exceptions" >&6; } + +if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then + lt_prog_compiler_no_builtin_flag_GCJ="$lt_prog_compiler_no_builtin_flag_GCJ -fno-rtti -fno-exceptions" +else + : +fi + +fi + +lt_prog_compiler_wl_GCJ= +lt_prog_compiler_pic_GCJ= +lt_prog_compiler_static_GCJ= + +{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5 +echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; } + + if test "$GCC" = yes; then + lt_prog_compiler_wl_GCJ='-Wl,' + lt_prog_compiler_static_GCJ='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_GCJ='-Bstatic' + fi + ;; + + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + lt_prog_compiler_pic_GCJ='-m68020 -resident32 -malways-restore-a4' + ;; + + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_GCJ='-DDLL_EXPORT' + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic_GCJ='-fno-common' + ;; + + interix3*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared_GCJ=no + enable_shared=no + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic_GCJ=-Kconform_pic + fi + ;; + + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_GCJ='-fPIC' + ;; + esac + ;; + + *) + lt_prog_compiler_pic_GCJ='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl_GCJ='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_GCJ='-Bstatic' + else + lt_prog_compiler_static_GCJ='-bnso -bI:/lib/syscalls.exp' + fi + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + lt_prog_compiler_pic_GCJ='-qnocommon' + lt_prog_compiler_wl_GCJ='-Wl,' + ;; + esac + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_GCJ='-DDLL_EXPORT' + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl_GCJ='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_GCJ='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static_GCJ='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl_GCJ='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static_GCJ='-non_shared' + ;; + + newsos6) + lt_prog_compiler_pic_GCJ='-KPIC' + lt_prog_compiler_static_GCJ='-Bstatic' + ;; + + linux*) + case $cc_basename in + icc* | ecc*) + lt_prog_compiler_wl_GCJ='-Wl,' + lt_prog_compiler_pic_GCJ='-KPIC' + lt_prog_compiler_static_GCJ='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl_GCJ='-Wl,' + lt_prog_compiler_pic_GCJ='-fpic' + lt_prog_compiler_static_GCJ='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl_GCJ='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static_GCJ='-non_shared' + ;; + esac + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl_GCJ='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static_GCJ='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic_GCJ='-KPIC' + lt_prog_compiler_static_GCJ='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + lt_prog_compiler_wl_GCJ='-Qoption ld ';; + *) + lt_prog_compiler_wl_GCJ='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl_GCJ='-Qoption ld ' + lt_prog_compiler_pic_GCJ='-PIC' + lt_prog_compiler_static_GCJ='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl_GCJ='-Wl,' + lt_prog_compiler_pic_GCJ='-KPIC' + lt_prog_compiler_static_GCJ='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + lt_prog_compiler_pic_GCJ='-Kconform_pic' + lt_prog_compiler_static_GCJ='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl_GCJ='-Wl,' + lt_prog_compiler_pic_GCJ='-KPIC' + lt_prog_compiler_static_GCJ='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl_GCJ='-Wl,' + lt_prog_compiler_can_build_shared_GCJ=no + ;; + + uts4*) + lt_prog_compiler_pic_GCJ='-pic' + lt_prog_compiler_static_GCJ='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared_GCJ=no + ;; + esac + fi + +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_GCJ" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic_GCJ" >&6; } + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic_GCJ"; then + +{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic_GCJ works" >&5 +echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic_GCJ works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_pic_works_GCJ+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_pic_works_GCJ=no + ac_outfile=conftest.$ac_objext + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic_GCJ" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:16577: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:16581: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_pic_works_GCJ=yes + fi + fi + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works_GCJ" >&5 +echo "${ECHO_T}$lt_prog_compiler_pic_works_GCJ" >&6; } + +if test x"$lt_prog_compiler_pic_works_GCJ" = xyes; then + case $lt_prog_compiler_pic_GCJ in + "" | " "*) ;; + *) lt_prog_compiler_pic_GCJ=" $lt_prog_compiler_pic_GCJ" ;; + esac +else + lt_prog_compiler_pic_GCJ= + lt_prog_compiler_can_build_shared_GCJ=no +fi + +fi +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic_GCJ= + ;; + *) + lt_prog_compiler_pic_GCJ="$lt_prog_compiler_pic_GCJ" + ;; +esac + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl_GCJ eval lt_tmp_static_flag=\"$lt_prog_compiler_static_GCJ\" +{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; } +if test "${lt_prog_compiler_static_works_GCJ+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_prog_compiler_static_works_GCJ=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + printf "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_prog_compiler_static_works_GCJ=yes + fi + else + lt_prog_compiler_static_works_GCJ=yes + fi + fi + $rm conftest* + LDFLAGS="$save_LDFLAGS" + +fi +{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works_GCJ" >&5 +echo "${ECHO_T}$lt_prog_compiler_static_works_GCJ" >&6; } + +if test x"$lt_prog_compiler_static_works_GCJ" = xyes; then + : +else + lt_prog_compiler_static_GCJ= +fi + + +{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5 +echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; } +if test "${lt_cv_prog_compiler_c_o_GCJ+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + lt_cv_prog_compiler_c_o_GCJ=no + $rm -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:16681: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:16685: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_GCJ=yes + fi + fi + chmod u+w . 2>&5 + $rm conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files + $rm out/* && rmdir out + cd .. + rmdir conftest + $rm conftest* + +fi +{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o_GCJ" >&5 +echo "${ECHO_T}$lt_cv_prog_compiler_c_o_GCJ" >&6; } + + +hard_links="nottested" +if test "$lt_cv_prog_compiler_c_o_GCJ" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5 +echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; } + hard_links=yes + $rm conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { echo "$as_me:$LINENO: result: $hard_links" >&5 +echo "${ECHO_T}$hard_links" >&6; } + if test "$hard_links" = no; then + { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5 +echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + +{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; } + + runpath_var= + allow_undefined_flag_GCJ= + enable_shared_with_static_runtimes_GCJ=no + archive_cmds_GCJ= + archive_expsym_cmds_GCJ= + old_archive_From_new_cmds_GCJ= + old_archive_from_expsyms_cmds_GCJ= + export_dynamic_flag_spec_GCJ= + whole_archive_flag_spec_GCJ= + thread_safe_flag_spec_GCJ= + hardcode_libdir_flag_spec_GCJ= + hardcode_libdir_flag_spec_ld_GCJ= + hardcode_libdir_separator_GCJ= + hardcode_direct_GCJ=no + hardcode_minus_L_GCJ=no + hardcode_shlibpath_var_GCJ=unsupported + link_all_deplibs_GCJ=unknown + hardcode_automatic_GCJ=no + module_cmds_GCJ= + module_expsym_cmds_GCJ= + always_export_symbols_GCJ=no + export_symbols_cmds_GCJ='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms_GCJ= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + exclude_expsyms_GCJ="_GLOBAL_OFFSET_TABLE_" + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + extract_expsyms_cmds= + # Just being paranoid about ensuring that cc_basename is set. + for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + case $host_os in + cygwin* | mingw* | pw32*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + esac + + ld_shlibs_GCJ=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec_GCJ='${wl}--rpath ${wl}$libdir' + export_dynamic_flag_spec_GCJ='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec_GCJ="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + whole_archive_flag_spec_GCJ= + fi + supports_anon_versioning=no + case `$LD -v 2>/dev/null` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix3* | aix4* | aix5*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + ld_shlibs_GCJ=no + cat <&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +EOF + fi + ;; + + amigaos*) + archive_cmds_GCJ='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec_GCJ='-L$libdir' + hardcode_minus_L_GCJ=yes + + # Samuel A. Falvo II reports + # that the semantics of dynamic libraries on AmigaOS, at least up + # to version 4, is to share data among multiple programs linked + # with the same dynamic library. Since this doesn't match the + # behavior of shared libraries on other platforms, we can't use + # them. + ld_shlibs_GCJ=no + ;; + + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag_GCJ=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds_GCJ='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + ld_shlibs_GCJ=no + fi + ;; + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, GCJ) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec_GCJ='-L$libdir' + allow_undefined_flag_GCJ=unsupported + always_export_symbols_GCJ=no + enable_shared_with_static_runtimes_GCJ=yes + export_symbols_cmds_GCJ='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS] /s/.* \([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW] /s/.* //'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + archive_expsym_cmds_GCJ='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs_GCJ=no + fi + ;; + + interix3*) + hardcode_direct_GCJ=no + hardcode_shlibpath_var_GCJ=no + hardcode_libdir_flag_spec_GCJ='${wl}-rpath,$libdir' + export_dynamic_flag_spec_GCJ='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds_GCJ='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds_GCJ='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + linux*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + tmp_addflag= + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec_GCJ='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + whole_archive_flag_spec_GCJ='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + esac + archive_cmds_GCJ='$CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test $supports_anon_versioning = yes; then + archive_expsym_cmds_GCJ='$echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + $echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + else + ld_shlibs_GCJ=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + archive_cmds_GCJ='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then + ld_shlibs_GCJ=no + cat <&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +EOF + elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs_GCJ=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs_GCJ=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec_GCJ='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' + archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib' + archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib' + else + ld_shlibs_GCJ=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds_GCJ='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct_GCJ=yes + hardcode_shlibpath_var_GCJ=no + ;; + + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs_GCJ=no + fi + ;; + esac + + if test "$ld_shlibs_GCJ" = no; then + runpath_var= + hardcode_libdir_flag_spec_GCJ= + export_dynamic_flag_spec_GCJ= + whole_archive_flag_spec_GCJ= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag_GCJ=unsupported + always_export_symbols_GCJ=yes + archive_expsym_cmds_GCJ='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L_GCJ=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct_GCJ=unsupported + fi + ;; + + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + export_symbols_cmds_GCJ='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds_GCJ='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[23]|aix4.[23].*|aix5*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds_GCJ='' + hardcode_direct_GCJ=yes + hardcode_libdir_separator_GCJ=':' + link_all_deplibs_GCJ=yes + + if test "$GCC" = yes; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + hardcode_direct_GCJ=yes + else + # We have old collect2 + hardcode_direct_GCJ=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L_GCJ=yes + hardcode_libdir_flag_spec_GCJ='-L$libdir' + hardcode_libdir_separator_GCJ= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols_GCJ=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag_GCJ='-berok' + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec_GCJ='${wl}-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds_GCJ="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + hardcode_libdir_flag_spec_GCJ='${wl}-R $libdir:/usr/lib:/lib' + allow_undefined_flag_GCJ="-z nodefs" + archive_expsym_cmds_GCJ="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec_GCJ='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag_GCJ=' ${wl}-bernotok' + allow_undefined_flag_GCJ=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec_GCJ='$convenience' + archive_cmds_need_lc_GCJ=yes + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds_GCJ="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + archive_cmds_GCJ='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec_GCJ='-L$libdir' + hardcode_minus_L_GCJ=yes + # see comment about different semantics on the GNU ld section + ld_shlibs_GCJ=no + ;; + + bsdi[45]*) + export_dynamic_flag_spec_GCJ=-rdynamic + ;; + + cygwin* | mingw* | pw32*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec_GCJ=' ' + allow_undefined_flag_GCJ=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + archive_cmds_GCJ='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_From_new_cmds_GCJ='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds_GCJ='lib /OUT:$oldlib$oldobjs$old_deplibs' + fix_srcfile_path_GCJ='`cygpath -w "$srcfile"`' + enable_shared_with_static_runtimes_GCJ=yes + ;; + + darwin* | rhapsody*) + case $host_os in + rhapsody* | darwin1.[012]) + allow_undefined_flag_GCJ='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + allow_undefined_flag_GCJ='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[012]) + allow_undefined_flag_GCJ='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + allow_undefined_flag_GCJ='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + archive_cmds_need_lc_GCJ=no + hardcode_direct_GCJ=no + hardcode_automatic_GCJ=yes + hardcode_shlibpath_var_GCJ=unsupported + whole_archive_flag_spec_GCJ='' + link_all_deplibs_GCJ=yes + if test "$GCC" = yes ; then + output_verbose_link_cmd='echo' + archive_cmds_GCJ='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + module_cmds_GCJ='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + archive_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + module_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + archive_cmds_GCJ='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + module_cmds_GCJ='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds + archive_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + module_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + ld_shlibs_GCJ=no + ;; + esac + fi + ;; + + dgux*) + archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec_GCJ='-L$libdir' + hardcode_shlibpath_var_GCJ=no + ;; + + freebsd1*) + ld_shlibs_GCJ=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec_GCJ='-R$libdir' + hardcode_direct_GCJ=yes + hardcode_shlibpath_var_GCJ=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_GCJ=yes + hardcode_minus_L_GCJ=yes + hardcode_shlibpath_var_GCJ=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | kfreebsd*-gnu | dragonfly*) + archive_cmds_GCJ='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec_GCJ='-R$libdir' + hardcode_direct_GCJ=yes + hardcode_shlibpath_var_GCJ=no + ;; + + hpux9*) + if test "$GCC" = yes; then + archive_cmds_GCJ='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + archive_cmds_GCJ='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec_GCJ='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_GCJ=: + hardcode_direct_GCJ=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L_GCJ=yes + export_dynamic_flag_spec_GCJ='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + archive_cmds_GCJ='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_GCJ='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec_GCJ='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_GCJ=: + + hardcode_direct_GCJ=yes + export_dynamic_flag_spec_GCJ='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L_GCJ=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + archive_cmds_GCJ='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds_GCJ='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_GCJ='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds_GCJ='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds_GCJ='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_GCJ='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec_GCJ='${wl}+b ${wl}$libdir' + hardcode_libdir_separator_GCJ=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_libdir_flag_spec_ld_GCJ='+b $libdir' + hardcode_direct_GCJ=no + hardcode_shlibpath_var_GCJ=no + ;; + *) + hardcode_direct_GCJ=yes + export_dynamic_flag_spec_GCJ='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L_GCJ=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + archive_cmds_GCJ='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + hardcode_libdir_flag_spec_ld_GCJ='-rpath $libdir' + fi + hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_GCJ=: + link_all_deplibs_GCJ=yes + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds_GCJ='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec_GCJ='-R$libdir' + hardcode_direct_GCJ=yes + hardcode_shlibpath_var_GCJ=no + ;; + + newsos6) + archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_GCJ=yes + hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_GCJ=: + hardcode_shlibpath_var_GCJ=no + ;; + + openbsd*) + hardcode_direct_GCJ=yes + hardcode_shlibpath_var_GCJ=no + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + archive_cmds_GCJ='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_GCJ='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec_GCJ='${wl}-rpath,$libdir' + export_dynamic_flag_spec_GCJ='${wl}-E' + else + case $host_os in + openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) + archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec_GCJ='-R$libdir' + ;; + *) + archive_cmds_GCJ='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec_GCJ='${wl}-rpath,$libdir' + ;; + esac + fi + ;; + + os2*) + hardcode_libdir_flag_spec_GCJ='-L$libdir' + hardcode_minus_L_GCJ=yes + allow_undefined_flag_GCJ=unsupported + archive_cmds_GCJ='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + old_archive_From_new_cmds_GCJ='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + allow_undefined_flag_GCJ=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds_GCJ='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + allow_undefined_flag_GCJ=' -expect_unresolved \*' + archive_cmds_GCJ='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + fi + hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator_GCJ=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + allow_undefined_flag_GCJ=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds_GCJ='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir' + else + allow_undefined_flag_GCJ=' -expect_unresolved \*' + archive_cmds_GCJ='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + archive_expsym_cmds_GCJ='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~ + $LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec_GCJ='-rpath $libdir' + fi + hardcode_libdir_separator_GCJ=: + ;; + + solaris*) + no_undefined_flag_GCJ=' -z text' + if test "$GCC" = yes; then + wlarc='${wl}' + archive_cmds_GCJ='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_GCJ='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp' + else + wlarc='' + archive_cmds_GCJ='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds_GCJ='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp' + fi + hardcode_libdir_flag_spec_GCJ='-R$libdir' + hardcode_shlibpath_var_GCJ=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine linker options so we + # cannot just pass the convience library names through + # without $wl, iff we do not link with $LD. + # Luckily, gcc supports the same syntax we need for Sun Studio. + # Supported since Solaris 2.6 (maybe 2.5.1?) + case $wlarc in + '') + whole_archive_flag_spec_GCJ='-z allextract$convenience -z defaultextract' ;; + *) + whole_archive_flag_spec_GCJ='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' ;; + esac ;; + esac + link_all_deplibs_GCJ=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds_GCJ='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_GCJ='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec_GCJ='-L$libdir' + hardcode_direct_GCJ=yes + hardcode_minus_L_GCJ=yes + hardcode_shlibpath_var_GCJ=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_GCJ=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds_GCJ='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds_GCJ='$CC -r -o $output$reload_objs' + hardcode_direct_GCJ=no + ;; + motorola) + archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct_GCJ=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var_GCJ=no + ;; + + sysv4.3*) + archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var_GCJ=no + export_dynamic_flag_spec_GCJ='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var_GCJ=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs_GCJ=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7*) + no_undefined_flag_GCJ='${wl}-z,text' + archive_cmds_need_lc_GCJ=no + hardcode_shlibpath_var_GCJ=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds_GCJ='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_GCJ='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_GCJ='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_GCJ='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag_GCJ='${wl}-z,text' + allow_undefined_flag_GCJ='${wl}-z,nodefs' + archive_cmds_need_lc_GCJ=no + hardcode_shlibpath_var_GCJ=no + hardcode_libdir_flag_spec_GCJ='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + hardcode_libdir_separator_GCJ=':' + link_all_deplibs_GCJ=yes + export_dynamic_flag_spec_GCJ='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds_GCJ='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_GCJ='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds_GCJ='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_GCJ='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec_GCJ='-L$libdir' + hardcode_shlibpath_var_GCJ=no + ;; + + *) + ld_shlibs_GCJ=no + ;; + esac + fi + +{ echo "$as_me:$LINENO: result: $ld_shlibs_GCJ" >&5 +echo "${ECHO_T}$ld_shlibs_GCJ" >&6; } +test "$ld_shlibs_GCJ" = no && can_build_shared=no + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc_GCJ" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc_GCJ=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $archive_cmds_GCJ in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5 +echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; } + $rm conftest* + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl_GCJ + pic_flag=$lt_prog_compiler_pic_GCJ + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag_GCJ + allow_undefined_flag_GCJ= + if { (eval echo "$as_me:$LINENO: \"$archive_cmds_GCJ 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5 + (eval $archive_cmds_GCJ 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + then + archive_cmds_need_lc_GCJ=no + else + archive_cmds_need_lc_GCJ=yes + fi + allow_undefined_flag_GCJ=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $rm conftest* + { echo "$as_me:$LINENO: result: $archive_cmds_need_lc_GCJ" >&5 +echo "${ECHO_T}$archive_cmds_need_lc_GCJ" >&6; } + ;; + esac + fi + ;; +esac + +{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5 +echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; } +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix4* | aix5*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $rm \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + # Apple's gcc prints 'gcc -print-search-dirs' doesn't operate the same. + if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | tr "\n" "$PATH_SEPARATOR" | sed -e 's/libraries:/@libraries:/' | tr "@" "\n" | grep "^libraries:" | sed -e "s/^libraries://" -e "s,=/,/,g" -e "s,$PATH_SEPARATOR, ,g" -e "s,.*,& /lib /usr/lib /usr/local/lib,g"` + else + sys_lib_search_path_spec='/lib /usr/lib /usr/local/lib' + fi + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +kfreebsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[123]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + freebsd*) # from 4.6 on + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix3*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # find out which ABI we are using + libsuff= + case "$host_cpu" in + x86_64*|s390x*|powerpc64*) + echo '#line 18146 "configure"' > conftest.$ac_ext + if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + case `/usr/bin/file conftest.$ac_objext` in + *64-bit*) + libsuff=64 + sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" + ;; + esac + fi + rm -rf conftest* + ;; + esac + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/^ *//;s/#.*//;/^[^\/]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +knetbsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +nto-qnx*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[89] | openbsd2.[89].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + export_dynamic_flag_spec='${wl}-Blargedynsym' + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + shlibpath_overrides_runpath=no + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + shlibpath_overrides_runpath=yes + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5 +echo "${ECHO_T}$dynamic_linker" >&6; } +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5 +echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; } +hardcode_action_GCJ= +if test -n "$hardcode_libdir_flag_spec_GCJ" || \ + test -n "$runpath_var_GCJ" || \ + test "X$hardcode_automatic_GCJ" = "Xyes" ; then + + # We can hardcode non-existant directories. + if test "$hardcode_direct_GCJ" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, GCJ)" != no && + test "$hardcode_minus_L_GCJ" != no; then + # Linking always hardcodes the temporary library directory. + hardcode_action_GCJ=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action_GCJ=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action_GCJ=unsupported +fi +{ echo "$as_me:$LINENO: result: $hardcode_action_GCJ" >&5 +echo "${ECHO_T}$hardcode_action_GCJ" >&6; } + +if test "$hardcode_action_GCJ" = relink; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + +# The else clause should only fire when bootstrapping the +# libtool distribution, otherwise you forgot to ship ltmain.sh +# with your package, and you will get complaints that there are +# no rules to generate ltmain.sh. +if test -f "$ltmain"; then + # See if we are running on zsh, and set the options which allow our commands through + # without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + # Now quote all the things that may contain metacharacters while being + # careful not to overquote the AC_SUBSTed values. We take copies of the + # variables and quote the copies for generation of the libtool script. + for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \ + SED SHELL STRIP \ + libname_spec library_names_spec soname_spec extract_expsyms_cmds \ + old_striplib striplib file_magic_cmd finish_cmds finish_eval \ + deplibs_check_method reload_flag reload_cmds need_locks \ + lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \ + lt_cv_sys_global_symbol_to_c_name_address \ + sys_lib_search_path_spec sys_lib_dlsearch_path_spec \ + old_postinstall_cmds old_postuninstall_cmds \ + compiler_GCJ \ + CC_GCJ \ + LD_GCJ \ + lt_prog_compiler_wl_GCJ \ + lt_prog_compiler_pic_GCJ \ + lt_prog_compiler_static_GCJ \ + lt_prog_compiler_no_builtin_flag_GCJ \ + export_dynamic_flag_spec_GCJ \ + thread_safe_flag_spec_GCJ \ + whole_archive_flag_spec_GCJ \ + enable_shared_with_static_runtimes_GCJ \ + old_archive_cmds_GCJ \ + old_archive_from_new_cmds_GCJ \ + predep_objects_GCJ \ + postdep_objects_GCJ \ + predeps_GCJ \ + postdeps_GCJ \ + compiler_lib_search_path_GCJ \ + archive_cmds_GCJ \ + archive_expsym_cmds_GCJ \ + postinstall_cmds_GCJ \ + postuninstall_cmds_GCJ \ + old_archive_from_expsyms_cmds_GCJ \ + allow_undefined_flag_GCJ \ + no_undefined_flag_GCJ \ + export_symbols_cmds_GCJ \ + hardcode_libdir_flag_spec_GCJ \ + hardcode_libdir_flag_spec_ld_GCJ \ + hardcode_libdir_separator_GCJ \ + hardcode_automatic_GCJ \ + module_cmds_GCJ \ + module_expsym_cmds_GCJ \ + lt_cv_prog_compiler_c_o_GCJ \ + exclude_expsyms_GCJ \ + include_expsyms_GCJ; do + + case $var in + old_archive_cmds_GCJ | \ + old_archive_from_new_cmds_GCJ | \ + archive_cmds_GCJ | \ + archive_expsym_cmds_GCJ | \ + module_cmds_GCJ | \ + module_expsym_cmds_GCJ | \ + old_archive_from_expsyms_cmds_GCJ | \ + export_symbols_cmds_GCJ | \ + extract_expsyms_cmds | reload_cmds | finish_cmds | \ + postinstall_cmds | postuninstall_cmds | \ + old_postinstall_cmds | old_postuninstall_cmds | \ + sys_lib_search_path_spec | sys_lib_dlsearch_path_spec) + # Double-quote double-evaled strings. + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\"" + ;; + *) + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\"" + ;; + esac + done + + case $lt_echo in + *'\$0 --fallback-echo"') + lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'` + ;; + esac + +cfgfile="$ofile" + + cat <<__EOF__ >> "$cfgfile" +# ### BEGIN LIBTOOL TAG CONFIG: $tagname + +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc_GCJ + +# Whether or not to disallow shared libs when runtime libs are static +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_GCJ + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# An echo program that does not interpret backslashes. +echo=$lt_echo + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A C compiler. +LTCC=$lt_LTCC + +# LTCC compiler flags. +LTCFLAGS=$lt_LTCFLAGS + +# A language-specific compiler. +CC=$lt_compiler_GCJ + +# Is the compiler the GNU C compiler? +with_gcc=$GCC_GCJ + +# An ERE matcher. +EGREP=$lt_EGREP + +# The linker used to build libraries. +LD=$lt_LD_GCJ + +# Whether we need hard or soft links. +LN_S=$lt_LN_S + +# A BSD-compatible nm program. +NM=$lt_NM + +# A symbol stripping program +STRIP=$lt_STRIP + +# Used to examine libraries when file_magic_cmd begins "file" +MAGIC_CMD=$MAGIC_CMD + +# Used on cygwin: DLL creation program. +DLLTOOL="$DLLTOOL" + +# Used on cygwin: object dumper. +OBJDUMP="$OBJDUMP" + +# Used on cygwin: assembler. +AS="$AS" + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl_GCJ + +# Object file suffix (normally "o"). +objext="$ac_objext" + +# Old archive suffix (normally "a"). +libext="$libext" + +# Shared library suffix (normally ".so"). +shrext_cmds='$shrext_cmds' + +# Executable file suffix (normally ""). +exeext="$exeext" + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic_GCJ +pic_mode=$pic_mode + +# What is the maximum length of a command? +max_cmd_len=$lt_cv_sys_max_cmd_len + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o_GCJ + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Do we need the lib prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static_GCJ + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_GCJ + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_GCJ + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec_GCJ + +# Compiler flag to generate thread-safe objects. +thread_safe_flag_spec=$lt_thread_safe_flag_spec_GCJ + +# Library versioning type. +version_type=$version_type + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME. +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Commands used to build and install an old-style archive. +RANLIB=$lt_RANLIB +old_archive_cmds=$lt_old_archive_cmds_GCJ +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_GCJ + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_GCJ + +# Commands used to build and install a shared archive. +archive_cmds=$lt_archive_cmds_GCJ +archive_expsym_cmds=$lt_archive_expsym_cmds_GCJ +postinstall_cmds=$lt_postinstall_cmds +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to build a loadable module (assumed same as above if empty) +module_cmds=$lt_module_cmds_GCJ +module_expsym_cmds=$lt_module_expsym_cmds_GCJ + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + +# Dependencies to place before the objects being linked to create a +# shared library. +predep_objects=$lt_predep_objects_GCJ + +# Dependencies to place after the objects being linked to create a +# shared library. +postdep_objects=$lt_postdep_objects_GCJ + +# Dependencies to place before the objects being linked to create a +# shared library. +predeps=$lt_predeps_GCJ + +# Dependencies to place after the objects being linked to create a +# shared library. +postdeps=$lt_postdeps_GCJ + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path_GCJ + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == file_magic. +file_magic_cmd=$lt_file_magic_cmd + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag_GCJ + +# Flag that forces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag_GCJ + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# Same as above, but a single script fragment to be evaled but not shown. +finish_eval=$lt_finish_eval + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# This is the shared library runtime path variable. +runpath_var=$runpath_var + +# This is the shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action_GCJ + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_GCJ + +# If ld is used when linking, flag to hardcode \$libdir into +# a binary during linking. This must work even if \$libdir does +# not exist. +hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_GCJ + +# Whether we need a single -rpath flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator_GCJ + +# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the +# resulting binary. +hardcode_direct=$hardcode_direct_GCJ + +# Set to yes if using the -LDIR flag during linking hardcodes DIR into the +# resulting binary. +hardcode_minus_L=$hardcode_minus_L_GCJ + +# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into +# the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var_GCJ + +# Set to yes if building a shared library automatically hardcodes DIR into the library +# and all subsequent libraries and executables linked against it. +hardcode_automatic=$hardcode_automatic_GCJ + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at relink time. +variables_saved_for_relink="$variables_saved_for_relink" + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs_GCJ + +# Compile-time system search path for libraries +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path="$fix_srcfile_path_GCJ" + +# Set to yes if exported symbols are required. +always_export_symbols=$always_export_symbols_GCJ + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds_GCJ + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms_GCJ + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms_GCJ + +# ### END LIBTOOL TAG CONFIG: $tagname + +__EOF__ + + +else + # If there is no Makefile yet, we rely on a make rule to execute + # `config.status --recheck' to rerun these tests and create the + # libtool script then. + ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'` + if test -f "$ltmain_in"; then + test -f Makefile && make "$ltmain" + fi +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC="$lt_save_CC" + + else + tagname="" + fi + ;; + + RC) + + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +objext_RC=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }\n' + +# Code to be used in simple link tests +lt_simple_link_test_code="$lt_simple_compile_test_code" + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +printf "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$rm conftest* + +ac_outfile=conftest.$ac_objext +printf "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$rm conftest* + + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +CC=${RC-"windres"} +compiler=$CC +compiler_RC=$CC +for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + +lt_cv_prog_compiler_c_o_RC=yes + +# The else clause should only fire when bootstrapping the +# libtool distribution, otherwise you forgot to ship ltmain.sh +# with your package, and you will get complaints that there are +# no rules to generate ltmain.sh. +if test -f "$ltmain"; then + # See if we are running on zsh, and set the options which allow our commands through + # without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + # Now quote all the things that may contain metacharacters while being + # careful not to overquote the AC_SUBSTed values. We take copies of the + # variables and quote the copies for generation of the libtool script. + for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \ + SED SHELL STRIP \ + libname_spec library_names_spec soname_spec extract_expsyms_cmds \ + old_striplib striplib file_magic_cmd finish_cmds finish_eval \ + deplibs_check_method reload_flag reload_cmds need_locks \ + lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \ + lt_cv_sys_global_symbol_to_c_name_address \ + sys_lib_search_path_spec sys_lib_dlsearch_path_spec \ + old_postinstall_cmds old_postuninstall_cmds \ + compiler_RC \ + CC_RC \ + LD_RC \ + lt_prog_compiler_wl_RC \ + lt_prog_compiler_pic_RC \ + lt_prog_compiler_static_RC \ + lt_prog_compiler_no_builtin_flag_RC \ + export_dynamic_flag_spec_RC \ + thread_safe_flag_spec_RC \ + whole_archive_flag_spec_RC \ + enable_shared_with_static_runtimes_RC \ + old_archive_cmds_RC \ + old_archive_from_new_cmds_RC \ + predep_objects_RC \ + postdep_objects_RC \ + predeps_RC \ + postdeps_RC \ + compiler_lib_search_path_RC \ + archive_cmds_RC \ + archive_expsym_cmds_RC \ + postinstall_cmds_RC \ + postuninstall_cmds_RC \ + old_archive_from_expsyms_cmds_RC \ + allow_undefined_flag_RC \ + no_undefined_flag_RC \ + export_symbols_cmds_RC \ + hardcode_libdir_flag_spec_RC \ + hardcode_libdir_flag_spec_ld_RC \ + hardcode_libdir_separator_RC \ + hardcode_automatic_RC \ + module_cmds_RC \ + module_expsym_cmds_RC \ + lt_cv_prog_compiler_c_o_RC \ + exclude_expsyms_RC \ + include_expsyms_RC; do + + case $var in + old_archive_cmds_RC | \ + old_archive_from_new_cmds_RC | \ + archive_cmds_RC | \ + archive_expsym_cmds_RC | \ + module_cmds_RC | \ + module_expsym_cmds_RC | \ + old_archive_from_expsyms_cmds_RC | \ + export_symbols_cmds_RC | \ + extract_expsyms_cmds | reload_cmds | finish_cmds | \ + postinstall_cmds | postuninstall_cmds | \ + old_postinstall_cmds | old_postuninstall_cmds | \ + sys_lib_search_path_spec | sys_lib_dlsearch_path_spec) + # Double-quote double-evaled strings. + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\"" + ;; + *) + eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\"" + ;; + esac + done + + case $lt_echo in + *'\$0 --fallback-echo"') + lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'` + ;; + esac + +cfgfile="$ofile" + + cat <<__EOF__ >> "$cfgfile" +# ### BEGIN LIBTOOL TAG CONFIG: $tagname + +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc_RC + +# Whether or not to disallow shared libs when runtime libs are static +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_RC + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# An echo program that does not interpret backslashes. +echo=$lt_echo + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A C compiler. +LTCC=$lt_LTCC + +# LTCC compiler flags. +LTCFLAGS=$lt_LTCFLAGS + +# A language-specific compiler. +CC=$lt_compiler_RC + +# Is the compiler the GNU C compiler? +with_gcc=$GCC_RC + +# An ERE matcher. +EGREP=$lt_EGREP + +# The linker used to build libraries. +LD=$lt_LD_RC + +# Whether we need hard or soft links. +LN_S=$lt_LN_S + +# A BSD-compatible nm program. +NM=$lt_NM + +# A symbol stripping program +STRIP=$lt_STRIP + +# Used to examine libraries when file_magic_cmd begins "file" +MAGIC_CMD=$MAGIC_CMD + +# Used on cygwin: DLL creation program. +DLLTOOL="$DLLTOOL" + +# Used on cygwin: object dumper. +OBJDUMP="$OBJDUMP" + +# Used on cygwin: assembler. +AS="$AS" + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl_RC + +# Object file suffix (normally "o"). +objext="$ac_objext" + +# Old archive suffix (normally "a"). +libext="$libext" + +# Shared library suffix (normally ".so"). +shrext_cmds='$shrext_cmds' + +# Executable file suffix (normally ""). +exeext="$exeext" + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic_RC +pic_mode=$pic_mode + +# What is the maximum length of a command? +max_cmd_len=$lt_cv_sys_max_cmd_len + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o_RC + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Do we need the lib prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static_RC + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_RC + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_RC + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec_RC + +# Compiler flag to generate thread-safe objects. +thread_safe_flag_spec=$lt_thread_safe_flag_spec_RC + +# Library versioning type. +version_type=$version_type + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME. +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Commands used to build and install an old-style archive. +RANLIB=$lt_RANLIB +old_archive_cmds=$lt_old_archive_cmds_RC +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_RC + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_RC + +# Commands used to build and install a shared archive. +archive_cmds=$lt_archive_cmds_RC +archive_expsym_cmds=$lt_archive_expsym_cmds_RC +postinstall_cmds=$lt_postinstall_cmds +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to build a loadable module (assumed same as above if empty) +module_cmds=$lt_module_cmds_RC +module_expsym_cmds=$lt_module_expsym_cmds_RC + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + +# Dependencies to place before the objects being linked to create a +# shared library. +predep_objects=$lt_predep_objects_RC + +# Dependencies to place after the objects being linked to create a +# shared library. +postdep_objects=$lt_postdep_objects_RC + +# Dependencies to place before the objects being linked to create a +# shared library. +predeps=$lt_predeps_RC + +# Dependencies to place after the objects being linked to create a +# shared library. +postdeps=$lt_postdeps_RC + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path_RC + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == file_magic. +file_magic_cmd=$lt_file_magic_cmd + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag_RC + +# Flag that forces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag_RC + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# Same as above, but a single script fragment to be evaled but not shown. +finish_eval=$lt_finish_eval + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# This is the shared library runtime path variable. +runpath_var=$runpath_var + +# This is the shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action_RC + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_RC + +# If ld is used when linking, flag to hardcode \$libdir into +# a binary during linking. This must work even if \$libdir does +# not exist. +hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_RC + +# Whether we need a single -rpath flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator_RC + +# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the +# resulting binary. +hardcode_direct=$hardcode_direct_RC + +# Set to yes if using the -LDIR flag during linking hardcodes DIR into the +# resulting binary. +hardcode_minus_L=$hardcode_minus_L_RC + +# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into +# the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var_RC + +# Set to yes if building a shared library automatically hardcodes DIR into the library +# and all subsequent libraries and executables linked against it. +hardcode_automatic=$hardcode_automatic_RC + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at relink time. +variables_saved_for_relink="$variables_saved_for_relink" + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs_RC + +# Compile-time system search path for libraries +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path="$fix_srcfile_path_RC" + +# Set to yes if exported symbols are required. +always_export_symbols=$always_export_symbols_RC + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds_RC + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms_RC + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms_RC + +# ### END LIBTOOL TAG CONFIG: $tagname + +__EOF__ + + +else + # If there is no Makefile yet, we rely on a make rule to execute + # `config.status --recheck' to rerun these tests and create the + # libtool script then. + ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'` + if test -f "$ltmain_in"; then + test -f Makefile && make "$ltmain" + fi +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC="$lt_save_CC" + + ;; + + *) + { { echo "$as_me:$LINENO: error: Unsupported tag name: $tagname" >&5 +echo "$as_me: error: Unsupported tag name: $tagname" >&2;} + { (exit 1); exit 1; }; } + ;; + esac + + # Append the new tag name to the list of available tags. + if test -n "$tagname" ; then + available_tags="$available_tags $tagname" + fi + fi + done + IFS="$lt_save_ifs" + + # Now substitute the updated list of available tags. + if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' \"$ofile\" > \"${ofile}T\""; then + mv "${ofile}T" "$ofile" + chmod +x "$ofile" + else + rm -f "${ofile}T" + { { echo "$as_me:$LINENO: error: unable to update list of available tagged configurations." >&5 +echo "$as_me: error: unable to update list of available tagged configurations." >&2;} + { (exit 1); exit 1; }; } + fi +fi + + + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS="$ac_aux_dir/ltmain.sh" + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' + +# Prevent multiple expansion + + + + + + + + + + + + + + + + + + + + +# Extract the first word of "math", so it can be a program name with args. +set dummy math; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_have_mathematica+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$have_mathematica"; then + ac_cv_prog_have_mathematica="$have_mathematica" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_have_mathematica="yes" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + + test -z "$ac_cv_prog_have_mathematica" && ac_cv_prog_have_mathematica="no" +fi +fi +have_mathematica=$ac_cv_prog_have_mathematica +if test -n "$have_mathematica"; then + { echo "$as_me:$LINENO: result: $have_mathematica" >&5 +echo "${ECHO_T}$have_mathematica" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +if test "x$have_mathematica" = "xyes" ; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_MATHEMATICA 1 +_ACEOF + +fi + +# Checks for libraries. +LIBM= +case $host in +*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + { echo "$as_me:$LINENO: checking for _mwvalidcheckl in -lmw" >&5 +echo $ECHO_N "checking for _mwvalidcheckl in -lmw... $ECHO_C" >&6; } +if test "${ac_cv_lib_mw__mwvalidcheckl+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lmw $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char _mwvalidcheckl (); +int +main () +{ +return _mwvalidcheckl (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_mw__mwvalidcheckl=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_mw__mwvalidcheckl=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_mw__mwvalidcheckl" >&5 +echo "${ECHO_T}$ac_cv_lib_mw__mwvalidcheckl" >&6; } +if test $ac_cv_lib_mw__mwvalidcheckl = yes; then + LIBM="-lmw" +fi + + { echo "$as_me:$LINENO: checking for cos in -lm" >&5 +echo $ECHO_N "checking for cos in -lm... $ECHO_C" >&6; } +if test "${ac_cv_lib_m_cos+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char cos (); +int +main () +{ +return cos (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_m_cos=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_m_cos=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_m_cos" >&5 +echo "${ECHO_T}$ac_cv_lib_m_cos" >&6; } +if test $ac_cv_lib_m_cos = yes; then + LIBM="$LIBM -lm" +fi + + ;; +*) + { echo "$as_me:$LINENO: checking for cos in -lm" >&5 +echo $ECHO_N "checking for cos in -lm... $ECHO_C" >&6; } +if test "${ac_cv_lib_m_cos+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char cos (); +int +main () +{ +return cos (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_m_cos=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_m_cos=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_m_cos" >&5 +echo "${ECHO_T}$ac_cv_lib_m_cos" >&6; } +if test $ac_cv_lib_m_cos = yes; then + LIBM="-lm" +fi + + ;; +esac + + +# Checks for header files. +{ echo "$as_me:$LINENO: checking for ANSI C header files" >&5 +echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; } +if test "${ac_cv_header_stdc+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_header_stdc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_header_stdc=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then + : +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + +fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 +echo "${ECHO_T}$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +cat >>confdefs.h <<\_ACEOF +#define STDC_HEADERS 1 +_ACEOF + +fi + + + + + + +for ac_header in sys/utsname.h unistd.h windows.h gmp.h stdint.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + { echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +else + # Is the header compilable? +{ echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_compiler=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6; } + +# Is the header present? +{ echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi + +rm -f conftest.err conftest.$ac_ext +{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + ( cat <<\_ASBOX +## --------------------------------------- ## +## Report this to lecuyer@iro.umontreal.ca ## +## --------------------------------------- ## +_ASBOX + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +{ echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +# Checks for typedefs, structures, and compiler characteristics. +{ echo "$as_me:$LINENO: checking for an ANSI C-conforming const" >&5 +echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6; } +if test "${ac_cv_c_const+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +/* FIXME: Include the comments suggested by Paul. */ +#ifndef __cplusplus + /* Ultrix mips cc rejects this. */ + typedef int charset[2]; + const charset cs; + /* SunOS 4.1.1 cc rejects this. */ + char const *const *pcpcc; + char **ppc; + /* NEC SVR4.0.2 mips cc rejects this. */ + struct point {int x, y;}; + static struct point const zero = {0,0}; + /* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in + an arm of an if-expression whose if-part is not a constant + expression */ + const char *g = "string"; + pcpcc = &g + (g ? g-g : 0); + /* HPUX 7.0 cc rejects these. */ + ++pcpcc; + ppc = (char**) pcpcc; + pcpcc = (char const *const *) ppc; + { /* SCO 3.2v4 cc rejects this. */ + char *t; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; + if (s) return 0; + } + { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; + } + { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; + } + { /* AIX XL C 1.02.0.0 rejects this saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; }; + struct s *b; b->j = 5; + } + { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; + if (!foo) return 0; + } + return !cs[0] && !zero.x; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_c_const=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_c_const=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_c_const" >&5 +echo "${ECHO_T}$ac_cv_c_const" >&6; } +if test $ac_cv_c_const = no; then + +cat >>confdefs.h <<\_ACEOF +#define const +_ACEOF + +fi + +{ echo "$as_me:$LINENO: checking for size_t" >&5 +echo $ECHO_N "checking for size_t... $ECHO_C" >&6; } +if test "${ac_cv_type_size_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef size_t ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_type_size_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_size_t=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5 +echo "${ECHO_T}$ac_cv_type_size_t" >&6; } +if test $ac_cv_type_size_t = yes; then + : +else + +cat >>confdefs.h <<_ACEOF +#define size_t unsigned int +_ACEOF + +fi + +{ echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5 +echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6; } +if test "${ac_cv_c_bigendian+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # See if sys/param.h defines the BYTE_ORDER macro. +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include + +int +main () +{ +#if ! (defined BYTE_ORDER && defined BIG_ENDIAN && defined LITTLE_ENDIAN \ + && BYTE_ORDER && BIG_ENDIAN && LITTLE_ENDIAN) + bogus endian macros +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + # It does; now see whether it defined to BIG_ENDIAN or not. +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include + +int +main () +{ +#if BYTE_ORDER != BIG_ENDIAN + not big endian +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_c_bigendian=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_c_bigendian=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # It does not; compile a test program. +if test "$cross_compiling" = yes; then + # try to guess the endianness by grepping values into an object file + ac_cv_c_bigendian=unknown + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; +short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; +void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; } +short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; +short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; +void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; } +int +main () +{ + _ascii (); _ebcdic (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then + ac_cv_c_bigendian=yes +fi +if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then + if test "$ac_cv_c_bigendian" = unknown; then + ac_cv_c_bigendian=no + else + # finding both strings is unlikely to happen, but who knows? + ac_cv_c_bigendian=unknown + fi +fi +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ + + /* Are we little or big endian? From Harbison&Steele. */ + union + { + long int l; + char c[sizeof (long int)]; + } u; + u.l = 1; + return u.c[sizeof (long int) - 1] == 1; + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_c_bigendian=no +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_c_bigendian=yes +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5 +echo "${ECHO_T}$ac_cv_c_bigendian" >&6; } +case $ac_cv_c_bigendian in + yes) + +cat >>confdefs.h <<\_ACEOF +#define WORDS_BIGENDIAN 1 +_ACEOF + ;; + no) + ;; + *) + { { echo "$as_me:$LINENO: error: unknown endianness +presetting ac_cv_c_bigendian=no (or yes) will help" >&5 +echo "$as_me: error: unknown endianness +presetting ac_cv_c_bigendian=no (or yes) will help" >&2;} + { (exit 1); exit 1; }; } ;; +esac + +{ echo "$as_me:$LINENO: checking for long long" >&5 +echo $ECHO_N "checking for long long... $ECHO_C" >&6; } +if test "${ac_cv_type_long_long+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef long long ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_type_long_long=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_long_long=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_long_long" >&5 +echo "${ECHO_T}$ac_cv_type_long_long" >&6; } +if test $ac_cv_type_long_long = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_LONG_LONG 1 +_ACEOF + + +fi +{ echo "$as_me:$LINENO: checking for uint32_t" >&5 +echo $ECHO_N "checking for uint32_t... $ECHO_C" >&6; } +if test "${ac_cv_type_uint32_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef uint32_t ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_type_uint32_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_uint32_t=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_uint32_t" >&5 +echo "${ECHO_T}$ac_cv_type_uint32_t" >&6; } +if test $ac_cv_type_uint32_t = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_UINT32_T 1 +_ACEOF + + +fi +{ echo "$as_me:$LINENO: checking for uint8_t" >&5 +echo $ECHO_N "checking for uint8_t... $ECHO_C" >&6; } +if test "${ac_cv_type_uint8_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef uint8_t ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_type_uint8_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_uint8_t=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_uint8_t" >&5 +echo "${ECHO_T}$ac_cv_type_uint8_t" >&6; } +if test $ac_cv_type_uint8_t = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_UINT8_T 1 +_ACEOF + + +fi + + +# Checks for library functions. +# AC_FUNC_MALLOC +# AC_FUNC_REALLOC +LIBS="$LIBM $LIBS" + + + + +for ac_func in random erf lgamma log1p +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; } +if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$ac_func || defined __stub___$ac_func +choke me +#endif + +int +main () +{ +return $ac_func (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_var=no" +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_var'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +ac_config_files="$ac_config_files Makefile include/Makefile mylib/Makefile probdist/Makefile testu01/Makefile examples/Makefile doc/Makefile param/Makefile" + + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { echo "$as_me:$LINENO: updating cache $cache_file" >&5 +echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file + else + { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5 +echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + +if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then + { { echo "$as_me:$LINENO: error: conditional \"AMDEP\" was never defined. +Usually this means the macro was only invoked conditionally." >&5 +echo "$as_me: error: conditional \"AMDEP\" was never defined. +Usually this means the macro was only invoked conditionally." >&2;} + { (exit 1); exit 1; }; } +fi +if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + { { echo "$as_me:$LINENO: error: conditional \"am__fastdepCC\" was never defined. +Usually this means the macro was only invoked conditionally." >&5 +echo "$as_me: error: conditional \"am__fastdepCC\" was never defined. +Usually this means the macro was only invoked conditionally." >&2;} + { (exit 1); exit 1; }; } +fi +if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then + { { echo "$as_me:$LINENO: error: conditional \"am__fastdepCXX\" was never defined. +Usually this means the macro was only invoked conditionally." >&5 +echo "$as_me: error: conditional \"am__fastdepCXX\" was never defined. +Usually this means the macro was only invoked conditionally." >&2;} + { (exit 1); exit 1; }; } +fi + +: ${CONFIG_STATUS=./config.status} +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 + +# Save the log message, to keep $[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by TestU01 $as_me 1.2.3, which was +generated by GNU Autoconf 2.61. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" +config_commands="$ac_config_commands" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Configuration commands: +$config_commands + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +TestU01 config.status 1.2.3 +configured by $0, generated by GNU Autoconf 2.61, + with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2006 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + echo "$ac_cs_version"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + { echo "$as_me: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; };; + --help | --hel | -h ) + echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) { echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + CONFIG_SHELL=$SHELL + export CONFIG_SHELL + exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +# +# INIT-COMMANDS +# +AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "include/config.h") CONFIG_HEADERS="$CONFIG_HEADERS include/config.h" ;; + "include/gdefconf.h") CONFIG_HEADERS="$CONFIG_HEADERS include/gdefconf.h" ;; + "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "include/Makefile") CONFIG_FILES="$CONFIG_FILES include/Makefile" ;; + "mylib/Makefile") CONFIG_FILES="$CONFIG_FILES mylib/Makefile" ;; + "probdist/Makefile") CONFIG_FILES="$CONFIG_FILES probdist/Makefile" ;; + "testu01/Makefile") CONFIG_FILES="$CONFIG_FILES testu01/Makefile" ;; + "examples/Makefile") CONFIG_FILES="$CONFIG_FILES examples/Makefile" ;; + "doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; + "param/Makefile") CONFIG_FILES="$CONFIG_FILES param/Makefile" ;; + + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} + +# +# Set up the sed scripts for CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "$CONFIG_FILES"; then + +_ACEOF + + + +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + cat >conf$$subs.sed <<_ACEOF +SHELL!$SHELL$ac_delim +PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim +PACKAGE_NAME!$PACKAGE_NAME$ac_delim +PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim +PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim +PACKAGE_STRING!$PACKAGE_STRING$ac_delim +PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim +exec_prefix!$exec_prefix$ac_delim +prefix!$prefix$ac_delim +program_transform_name!$program_transform_name$ac_delim +bindir!$bindir$ac_delim +sbindir!$sbindir$ac_delim +libexecdir!$libexecdir$ac_delim +datarootdir!$datarootdir$ac_delim +datadir!$datadir$ac_delim +sysconfdir!$sysconfdir$ac_delim +sharedstatedir!$sharedstatedir$ac_delim +localstatedir!$localstatedir$ac_delim +includedir!$includedir$ac_delim +oldincludedir!$oldincludedir$ac_delim +docdir!$docdir$ac_delim +infodir!$infodir$ac_delim +htmldir!$htmldir$ac_delim +dvidir!$dvidir$ac_delim +pdfdir!$pdfdir$ac_delim +psdir!$psdir$ac_delim +libdir!$libdir$ac_delim +localedir!$localedir$ac_delim +mandir!$mandir$ac_delim +DEFS!$DEFS$ac_delim +ECHO_C!$ECHO_C$ac_delim +ECHO_N!$ECHO_N$ac_delim +ECHO_T!$ECHO_T$ac_delim +LIBS!$LIBS$ac_delim +build_alias!$build_alias$ac_delim +host_alias!$host_alias$ac_delim +target_alias!$target_alias$ac_delim +INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim +INSTALL_SCRIPT!$INSTALL_SCRIPT$ac_delim +INSTALL_DATA!$INSTALL_DATA$ac_delim +am__isrc!$am__isrc$ac_delim +CYGPATH_W!$CYGPATH_W$ac_delim +PACKAGE!$PACKAGE$ac_delim +VERSION!$VERSION$ac_delim +ACLOCAL!$ACLOCAL$ac_delim +AUTOCONF!$AUTOCONF$ac_delim +AUTOMAKE!$AUTOMAKE$ac_delim +AUTOHEADER!$AUTOHEADER$ac_delim +MAKEINFO!$MAKEINFO$ac_delim +install_sh!$install_sh$ac_delim +STRIP!$STRIP$ac_delim +INSTALL_STRIP_PROGRAM!$INSTALL_STRIP_PROGRAM$ac_delim +mkdir_p!$mkdir_p$ac_delim +AWK!$AWK$ac_delim +SET_MAKE!$SET_MAKE$ac_delim +am__leading_dot!$am__leading_dot$ac_delim +AMTAR!$AMTAR$ac_delim +am__tar!$am__tar$ac_delim +am__untar!$am__untar$ac_delim +build!$build$ac_delim +build_cpu!$build_cpu$ac_delim +build_vendor!$build_vendor$ac_delim +build_os!$build_os$ac_delim +host!$host$ac_delim +host_cpu!$host_cpu$ac_delim +host_vendor!$host_vendor$ac_delim +host_os!$host_os$ac_delim +CC!$CC$ac_delim +CFLAGS!$CFLAGS$ac_delim +LDFLAGS!$LDFLAGS$ac_delim +CPPFLAGS!$CPPFLAGS$ac_delim +ac_ct_CC!$ac_ct_CC$ac_delim +EXEEXT!$EXEEXT$ac_delim +OBJEXT!$OBJEXT$ac_delim +DEPDIR!$DEPDIR$ac_delim +am__include!$am__include$ac_delim +am__quote!$am__quote$ac_delim +AMDEP_TRUE!$AMDEP_TRUE$ac_delim +AMDEP_FALSE!$AMDEP_FALSE$ac_delim +AMDEPBACKSLASH!$AMDEPBACKSLASH$ac_delim +CCDEPMODE!$CCDEPMODE$ac_delim +am__fastdepCC_TRUE!$am__fastdepCC_TRUE$ac_delim +am__fastdepCC_FALSE!$am__fastdepCC_FALSE$ac_delim +CPP!$CPP$ac_delim +LN_S!$LN_S$ac_delim +SED!$SED$ac_delim +GREP!$GREP$ac_delim +EGREP!$EGREP$ac_delim +ECHO!$ECHO$ac_delim +AR!$AR$ac_delim +RANLIB!$RANLIB$ac_delim +CXX!$CXX$ac_delim +CXXFLAGS!$CXXFLAGS$ac_delim +ac_ct_CXX!$ac_ct_CXX$ac_delim +CXXDEPMODE!$CXXDEPMODE$ac_delim +am__fastdepCXX_TRUE!$am__fastdepCXX_TRUE$ac_delim +am__fastdepCXX_FALSE!$am__fastdepCXX_FALSE$ac_delim +_ACEOF + + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then + break + elif $ac_last_try; then + { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 +echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} + { (exit 1); exit 1; }; } + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed` +if test -n "$ac_eof"; then + ac_eof=`echo "$ac_eof" | sort -nru | sed 1q` + ac_eof=`expr $ac_eof + 1` +fi + +cat >>$CONFIG_STATUS <<_ACEOF +cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +_ACEOF +sed ' +s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g +s/^/s,@/; s/!/@,|#_!!_#|/ +:n +t n +s/'"$ac_delim"'$/,g/; t +s/$/\\/; p +N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n +' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF +CEOF$ac_eof +_ACEOF + + +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + cat >conf$$subs.sed <<_ACEOF +CXXCPP!$CXXCPP$ac_delim +F77!$F77$ac_delim +FFLAGS!$FFLAGS$ac_delim +ac_ct_F77!$ac_ct_F77$ac_delim +LIBTOOL!$LIBTOOL$ac_delim +have_mathematica!$have_mathematica$ac_delim +LIBM!$LIBM$ac_delim +LIBOBJS!$LIBOBJS$ac_delim +LTLIBOBJS!$LTLIBOBJS$ac_delim +_ACEOF + + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 9; then + break + elif $ac_last_try; then + { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 +echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} + { (exit 1); exit 1; }; } + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed` +if test -n "$ac_eof"; then + ac_eof=`echo "$ac_eof" | sort -nru | sed 1q` + ac_eof=`expr $ac_eof + 1` +fi + +cat >>$CONFIG_STATUS <<_ACEOF +cat >"\$tmp/subs-2.sed" <<\CEOF$ac_eof +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end +_ACEOF +sed ' +s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g +s/^/s,@/; s/!/@,|#_!!_#|/ +:n +t n +s/'"$ac_delim"'$/,g/; t +s/$/\\/; p +N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n +' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF +:end +s/|#_!!_#|//g +CEOF$ac_eof +_ACEOF + + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF +fi # test -n "$CONFIG_FILES" + + +for ac_tag in :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5 +echo "$as_me: error: Invalid tag $ac_tag." >&2;} + { (exit 1); exit 1; }; };; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5 +echo "$as_me: error: cannot find input file: $ac_f" >&2;} + { (exit 1); exit 1; }; };; + esac + ac_file_inputs="$ac_file_inputs $ac_f" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input="Generated from "`IFS=: + echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure." + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + fi + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin";; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + { as_dir="$ac_dir" + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= + +case `sed -n '/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p +' $ac_file_inputs` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s&@configure_input@&$configure_input&;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t +$ac_datarootdir_hack +" $ac_file_inputs | sed -f "$tmp/subs-1.sed" | sed -f "$tmp/subs-2.sed" >$tmp/out + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out"; rm -f "$tmp/out";; + *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;; + esac + ;; + :H) + # + # CONFIG_HEADER + # +_ACEOF + +# Transform confdefs.h into a sed script `conftest.defines', that +# substitutes the proper values into config.h.in to produce config.h. +rm -f conftest.defines conftest.tail +# First, append a space to every undef/define line, to ease matching. +echo 's/$/ /' >conftest.defines +# Then, protect against being on the right side of a sed subst, or in +# an unquoted here document, in config.status. If some macros were +# called several times there might be several #defines for the same +# symbol, which is useless. But do not sort them, since the last +# AC_DEFINE must be honored. +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +# These sed commands are passed to sed as "A NAME B PARAMS C VALUE D", where +# NAME is the cpp macro being defined, VALUE is the value it is being given. +# PARAMS is the parameter list in the macro definition--in most cases, it's +# just an empty string. +ac_dA='s,^\\([ #]*\\)[^ ]*\\([ ]*' +ac_dB='\\)[ (].*,\\1define\\2' +ac_dC=' ' +ac_dD=' ,' + +uniq confdefs.h | + sed -n ' + t rset + :rset + s/^[ ]*#[ ]*define[ ][ ]*// + t ok + d + :ok + s/[\\&,]/\\&/g + s/^\('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/ '"$ac_dA"'\1'"$ac_dB"'\2'"${ac_dC}"'\3'"$ac_dD"'/p + s/^\('"$ac_word_re"'\)[ ]*\(.*\)/'"$ac_dA"'\1'"$ac_dB$ac_dC"'\2'"$ac_dD"'/p + ' >>conftest.defines + +# Remove the space that was appended to ease matching. +# Then replace #undef with comments. This is necessary, for +# example, in the case of _POSIX_SOURCE, which is predefined and required +# on some systems where configure will not decide to define it. +# (The regexp can be short, since the line contains either #define or #undef.) +echo 's/ $// +s,^[ #]*u.*,/* & */,' >>conftest.defines + +# Break up conftest.defines: +ac_max_sed_lines=50 + +# First sed command is: sed -f defines.sed $ac_file_inputs >"$tmp/out1" +# Second one is: sed -f defines.sed "$tmp/out1" >"$tmp/out2" +# Third one will be: sed -f defines.sed "$tmp/out2" >"$tmp/out1" +# et cetera. +ac_in='$ac_file_inputs' +ac_out='"$tmp/out1"' +ac_nxt='"$tmp/out2"' + +while : +do + # Write a here document: + cat >>$CONFIG_STATUS <<_ACEOF + # First, check the format of the line: + cat >"\$tmp/defines.sed" <<\\CEOF +/^[ ]*#[ ]*undef[ ][ ]*$ac_word_re[ ]*\$/b def +/^[ ]*#[ ]*define[ ][ ]*$ac_word_re[( ]/b def +b +:def +_ACEOF + sed ${ac_max_sed_lines}q conftest.defines >>$CONFIG_STATUS + echo 'CEOF + sed -f "$tmp/defines.sed"' "$ac_in >$ac_out" >>$CONFIG_STATUS + ac_in=$ac_out; ac_out=$ac_nxt; ac_nxt=$ac_in + sed 1,${ac_max_sed_lines}d conftest.defines >conftest.tail + grep . conftest.tail >/dev/null || break + rm -f conftest.defines + mv conftest.tail conftest.defines +done +rm -f conftest.defines conftest.tail + +echo "ac_result=$ac_in" >>$CONFIG_STATUS +cat >>$CONFIG_STATUS <<\_ACEOF + if test x"$ac_file" != x-; then + echo "/* $configure_input */" >"$tmp/config.h" + cat "$ac_result" >>"$tmp/config.h" + if diff $ac_file "$tmp/config.h" >/dev/null 2>&1; then + { echo "$as_me:$LINENO: $ac_file is unchanged" >&5 +echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f $ac_file + mv "$tmp/config.h" $ac_file + fi + else + echo "/* $configure_input */" + cat "$ac_result" + fi + rm -f "$tmp/out12" +# Compute $ac_file's index in $config_headers. +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $ac_file | $ac_file:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $ac_file" >`$as_dirname -- $ac_file || +$as_expr X$ac_file : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X$ac_file : 'X\(//\)[^/]' \| \ + X$ac_file : 'X\(//\)$' \| \ + X$ac_file : 'X\(/\)' \| . 2>/dev/null || +echo X$ac_file | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'`/stamp-h$_am_stamp_count + ;; + + :C) { echo "$as_me:$LINENO: executing $ac_file commands" >&5 +echo "$as_me: executing $ac_file commands" >&6;} + ;; + esac + + + case $ac_file$ac_mode in + "depfiles":C) test x"$AMDEP_TRUE" != x"" || for mf in $CONFIG_FILES; do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named `Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed 10q "$mf" | grep '^#.*generated by automake' > /dev/null 2>&1; then + dirpart=`$as_dirname -- "$mf" || +$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$mf" : 'X\(//\)[^/]' \| \ + X"$mf" : 'X\(//\)$' \| \ + X"$mf" : 'X\(/\)' \| . 2>/dev/null || +echo X"$mf" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running `make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`$as_dirname -- "$file" || +$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$file" : 'X\(//\)[^/]' \| \ + X"$file" : 'X\(//\)$' \| \ + X"$file" : 'X\(/\)' \| . 2>/dev/null || +echo X"$file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + { as_dir=$dirpart/$fdir + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done +done + ;; + + esac +done # for ac_tag + + +{ (exit 0); exit 0; } +_ACEOF +chmod +x $CONFIG_STATUS +ac_clean_files=$ac_clean_files_save + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi + diff --git a/TESTU01/TestU01-1.2.3/configure.ac b/TESTU01/TestU01-1.2.3/configure.ac new file mode 100644 index 0000000..9cd8a44 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/configure.ac @@ -0,0 +1,48 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +# AC_PREREQ(2.57) +AC_INIT(TestU01, 1.2.3, lecuyer@iro.umontreal.ca) +AC_CONFIG_SRCDIR([mylib/num.c]) +AM_INIT_AUTOMAKE +AC_CONFIG_HEADER([include/config.h]) +AC_CONFIG_HEADER([include/gdefconf.h]) + +AC_CANONICAL_HOST + +# Checks for programs. +AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AC_PROG_LIBTOOL +AC_CHECK_PROG(have_mathematica,math, yes, no) +if test "x$have_mathematica" = "xyes" ; then + AC_DEFINE([HAVE_MATHEMATICA], 1, [Define when Mathematica is installed]) +fi + +# Checks for libraries. +AC_CHECK_LIBM + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([sys/utsname.h unistd.h windows.h gmp.h stdint.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_SIZE_T +AC_C_BIGENDIAN +AC_CHECK_TYPES([long long, uint32_t, uint8_t]) + +# Checks for library functions. +# AC_FUNC_MALLOC +# AC_FUNC_REALLOC +LIBS="$LIBM $LIBS" +AC_CHECK_FUNCS([random erf lgamma log1p]) + +AC_CONFIG_FILES([Makefile + include/Makefile mylib/Makefile probdist/Makefile + testu01/Makefile examples/Makefile doc/Makefile param/Makefile]) +AC_SUBST([LIBM]) +AC_OUTPUT diff --git a/TESTU01/TestU01-1.2.3/depcomp b/TESTU01/TestU01-1.2.3/depcomp new file mode 100755 index 0000000..807b991 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/depcomp @@ -0,0 +1,423 @@ +#! /bin/sh + +# depcomp - compile a program generating dependencies as side-effects +# Copyright 1999, 2000 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Alexandre Oliva . + +if test -z "$depmode" || test -z "$source" || test -z "$object"; then + echo "depcomp: Variables source, object and depmode must be set" 1>&2 + exit 1 +fi +# `libtool' can also be set to `yes' or `no'. + +if test -z "$depfile"; then + base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'` + dir=`echo "$object" | sed 's,/.*$,/,'` + if test "$dir" = "$object"; then + dir= + fi + # FIXME: should be _deps on DOS. + depfile="$dir.deps/$base" +fi + +tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} + +rm -f "$tmpdepfile" + +# Some modes work just like other modes, but use different flags. We +# parameterize here, but still list the modes in the big case below, +# to make depend.m4 easier to write. Note that we *cannot* use a case +# here, because this file can only contain one case statement. +if test "$depmode" = hp; then + # HP compiler uses -M and no extra arg. + gccflag=-M + depmode=gcc +fi + +if test "$depmode" = dashXmstdout; then + # This is just like dashmstdout with a different argument. + dashmflag=-xM + depmode=dashmstdout +fi + +case "$depmode" in +gcc3) +## gcc 3 implements dependency tracking that does exactly what +## we want. Yay! Note: for some reason libtool 1.4 doesn't like +## it if -MD -MP comes after the -MF stuff. Hmm. + "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + mv "$tmpdepfile" "$depfile" + ;; + +gcc) +## There are various ways to get dependency output from gcc. Here's +## why we pick this rather obscure method: +## - Don't want to use -MD because we'd like the dependencies to end +## up in a subdir. Having to rename by hand is ugly. +## (We might end up doing this anyway to support other compilers.) +## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like +## -MM, not -M (despite what the docs say). +## - Using -M directly means running the compiler twice (even worse +## than renaming). + if test -z "$gccflag"; then + gccflag=-MD, + fi + "$@" -Wp,"$gccflag$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +## The second -e expression handles DOS-style file names with drive letters. + sed -e 's/^[^:]*: / /' \ + -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" +## This next piece of magic avoids the `deleted header file' problem. +## The problem is that when a header file which appears in a .P file +## is deleted, the dependency causes make to die (because there is +## typically no way to rebuild the header). We avoid this by adding +## dummy dependencies for each header file. Too bad gcc doesn't do +## this for us directly. + tr ' ' ' +' < "$tmpdepfile" | +## Some versions of gcc put a space before the `:'. On the theory +## that the space means something, we add a space to the output as +## well. +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +sgi) + if test "$libtool" = yes; then + "$@" "-Wp,-MDupdate,$tmpdepfile" + else + "$@" -MDupdate "$tmpdepfile" + fi + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + + if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files + echo "$object : \\" > "$depfile" + + # Clip off the initial element (the dependent). Don't try to be + # clever and replace this with sed code, as IRIX sed won't handle + # lines with more than a fixed number of characters (4096 in + # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; + # the IRIX cc adds comments like `#:fec' to the end of the + # dependency line. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ + tr ' +' ' ' >> $depfile + echo >> $depfile + + # The second pass generates a dummy entry for each header file. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ + >> $depfile + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +aix) + # The C for AIX Compiler uses -M and outputs the dependencies + # in a .u file. This file always lives in the current directory. + # Also, the AIX compiler puts `$object:' at the start of each line; + # $object doesn't have directory information. + stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` + tmpdepfile="$stripped.u" + outname="$stripped.o" + if test "$libtool" = yes; then + "$@" -Wc,-M + else + "$@" -M + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + + if test -f "$tmpdepfile"; then + # Each line is of the form `foo.o: dependent.h'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" + sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +tru64) + # The Tru64 compiler uses -MD to generate dependencies as a side + # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. + # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put + # dependencies in `foo.d' instead, so we check for that too. + # Subdirectories are respected. + dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` + test "x$dir" = "x$object" && dir= + base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` + + if test "$libtool" = yes; then + tmpdepfile1="$dir.libs/$base.lo.d" + tmpdepfile2="$dir.libs/$base.d" + "$@" -Wc,-MD + else + tmpdepfile1="$dir$base.o.d" + tmpdepfile2="$dir$base.d" + "$@" -MD + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile1" "$tmpdepfile2" + exit $stat + fi + + if test -f "$tmpdepfile1"; then + tmpdepfile="$tmpdepfile1" + else + tmpdepfile="$tmpdepfile2" + fi + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" + # That's a space and a tab in the []. + sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" + else + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +#nosideeffect) + # This comment above is used by automake to tell side-effect + # dependency tracking mechanisms from slower ones. + +dashmstdout) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test $1 != '--mode=compile'; do + shift + done + shift + fi + + # Remove `-o $object'. We will use -o /dev/null later, + # however we can't do the remplacement now because + # `-o $object' might simply not be used + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + test -z "$dashmflag" && dashmflag=-M + "$@" -o /dev/null $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + tr ' ' ' +' < "$tmpdepfile" | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +dashXmstdout) + # This case only exists to satisfy depend.m4. It is never actually + # run, as this mode is specially recognized in the preamble. + exit 1 + ;; + +makedepend) + "$@" || exit $? + # X makedepend + shift + cleared=no + for arg in "$@"; do + case $cleared in + no) + set ""; shift + cleared=yes ;; + esac + case "$arg" in + -D*|-I*) + set fnord "$@" "$arg"; shift ;; + -*) + ;; + *) + set fnord "$@" "$arg"; shift ;; + esac + done + obj_suffix="`echo $object | sed 's/^.*\././'`" + touch "$tmpdepfile" + ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + sed '1,2d' "$tmpdepfile" | tr ' ' ' +' | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" "$tmpdepfile".bak + ;; + +cpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test $1 != '--mode=compile'; do + shift + done + shift + fi + + # Remove `-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + "$@" -E | + sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | + sed '$ s: \\$::' > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + cat < "$tmpdepfile" >> "$depfile" + sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvisualcpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + "$@" || exit $? + IFS=" " + for arg + do + case "$arg" in + "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") + set fnord "$@" + shift + shift + ;; + *) + set fnord "$@" "$arg" + shift + shift + ;; + esac + done + "$@" -E | + sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" + echo " " >> "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +none) + exec "$@" + ;; + +*) + echo "Unknown depmode $depmode" 1>&2 + exit 1 + ;; +esac + +exit 0 diff --git a/TESTU01/TestU01-1.2.3/doc/Makefile.am b/TESTU01/TestU01-1.2.3/doc/Makefile.am new file mode 100644 index 0000000..a7d78b1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/doc/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = lmac.tex myarticle.sty diff --git a/TESTU01/TestU01-1.2.3/doc/Makefile.in b/TESTU01/TestU01-1.2.3/doc/Makefile.in new file mode 100644 index 0000000..72ba5d0 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/doc/Makefile.in @@ -0,0 +1,324 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = doc +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h \ + $(top_builddir)/include/gdefconf.h +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +EXTRA_DIST = lmac.tex myarticle.sty +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu doc/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu doc/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-exec-am: + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + distclean distclean-generic distclean-libtool distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/doc/lmac.tex b/TESTU01/TestU01-1.2.3/doc/lmac.tex new file mode 100644 index 0000000..33c5c98 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/doc/lmac.tex @@ -0,0 +1,187 @@ +% Macros pour usage avec LATEX. (Pierre L'Ecuyer). + +\def\?{\discretionary{}{}{}} % Same as \- but does not print the - sign + % (useful to hyphenate in math mode). +\def\From {From } +\def\mod{{\rm\ mod\ }} % Modulo. +\def\MOD{{\rm\ MOD\ }} +\def\div{{\rm\ div\ }} % Division entiere. +\def\DIV{{\rm\ DIV\ }} +\def\var{{\rm var }} % Variance. +\def\Var{{\rm Var }} +\def\Cov{{\rm Cov }} +\def\MSE{{\rm MSE }} +\def\arg{{\rm\ arg}} % Argument. +\def\Re{{\rm I\kern-0.2em R}} % Ensemble des nombres reels. +\def\R{\Re} +\def\d{{\rm d}} % Pour les derivees (parfois). +\def\B{{\rm I\kern-0.2em B}} +\def\F{{\rm I\kern-0.2em F}} +\def\FF{{\rm I\kern-0.1em F}} +\def\N{{\rm I\kern-0.2em N}} % Ensemble des nombres naturels. +\def\Z{{\sf Z\kern-0.4em Z}} % Ensemble des nombres entiers. +\def\Fbar{\overline F} % F avec une barre au dessus. +\def\square{\vrule height6pt width5pt depth1pt} + % Petit rectangle noir pour terminer une preuve de theoreme, etc. +\def\eqdef {\buildrel \rm def \over =} % Egal par definition. +\def\eqas {\buildrel \rm a.s. \over =} % Egal a.s. +\def\eqps {\buildrel \rm p.s. \over =} % Egal p.s. +\def\toas {\buildrel \rm a.s. \over \to} % ---> a.s. +\def\tops {\buildrel \rm p.s. \over \to} % ---> p.s. +\def\_{{\tt\char'137}} % Signe _ ("souligne"). +\def\bs{{\tt\char'134}} % Signe \ +\def\tttilde{{\tt\char'176}} % Signe ~ +\def\<{$\langle$} % Signe < +\def\>{$\rangle$} % Signe > +\def\q{$\kern1.4em$} % Space for indentation in slides and programs. + +\def\version {\begin{flushright} \it Draft Version: \today \end{flushright}} +\def\workingpaper {\begin{flushright} \it WORKING PAPER. \end{flushright}} +\def\submitted#1 {\begin{flushright} \it SUBMITTED TO: #1.\end{flushright}} + +\def\adrmaison {\begin {verse} + Pierre L'Ecuyer\\ + 45 Hampton Gardens\\ Pointe Claire (Qu\'e.) \\ H9S 5B8\\ CANADA \\ + T\'el.: (514) 426-4029 \end {verse}} +\def\adrum {\begin {verse} + Professeur Pierre L'Ecuyer\\ + D\'epartement d'I.R.O., Universit\'e de Montr\'eal\\ + C.P.\ 6128, Succ.\ Centre-Ville, Montr\'eal, H3C 3J7\\ CANADA \\ + T\'el. : (514) 343-2143 \hspace{1in} + FAX : (514) 343-5834\\ + e-mail : {\tt lecuyer@IRO.UMontreal.ca}\\ + url : {\tt www.iro.umontreal.ca/$\sim$lecuyer} \end {verse}} +% +\def\adrsalzburg {\begin {verse} + Professor Pierre L'Ecuyer\\ + Institut f\"ur Mathematik\\ Universit\"at Salzburg\\ + Hellbrunnerstrasse 34, A-5020 Salzburg, AUSTRIA \end {verse}} +\def\adrncsu {\begin {verse} + Professor Pierre L'Ecuyer\\ + Department of Industrial Engineering\\ + North Carolina State University\\ Box 7906\\ + Raleigh, North Carolina 27695-7906, U.S.A. \\ + e-mail : {\tt lecuyer@IRO.UMontreal.ca}\\ + url : {\tt www.iro.umontreal.ca/$\sim$lecuyer} \end {verse}} +% +\def\adrum0 {\begin {verse} + Professeur Pierre L'Ecuyer\\ + D\'epartement d'I.R.O.\\ Universit\'e de Montr\'eal\\ + C.P.\ 6128, Succ.\ Centre-Ville\\ Montr\'eal, H3C 3J7\\ CANADA + \end {verse}} + +% Redefinition du macro pour les ``footnotes''. +\catcode`\@=11 +\def\ninepoint{\def\rm{\fam0\ninerm} + \textfont0=\ninerm\normalbaselineskip=11pt + \setbox\strutbox=\hbox{\vrule height8pt depth 3pt width0pt}% + \normalbaselines\rm} +\def\vfootnote#1{\insert\footins\bgroup\ninepoint + \interlinepenalty 100 + \leftskip=0pt \rightskip=0pt \spaceskip=0pt \xspaceskip=0pt + \splittopskip=\ht\strutbox \floatingpenalty = 20000 + \splitmaxdepth=\dp\strutbox + \item{#1}\footstrut\futurelet\next\fo@t} + +% Macros pour inserer des bouts de code (programmes). +% Faire \code ... \endcode +{\obeyspaces\gdef {\ }} +\def\setverbatim{\def\par{\leavevmode\endgraf} + \parskip=0pt\parindent=0pt\obeylines\obeyspaces } +\chardef\other=12 +\def\ttverbatim{\setverbatim\tt + \catcode`\{=\other \catcode`\}=\other \catcode`\_=\other + \catcode`\^=\other \catcode`\$=\other \catcode`\%=\other + \catcode`\#=\other \catcode`\&=\other \baselineskip=11pt + } + % Reproduit tel quel ce qui est ecrit, en caracteres \tt. + % On doit faire \begingroup\ttverbatim .... \endgroup +\def\smallttverbatim{\ttverbatim\small\tt} +\def\code {\vfil\vfilneg\vbox\bgroup\ttverbatim} +\def\longcode {\vfil\vfilneg\bgroup\ttverbatim} +\def\smallc {\small\tt\baselineskip=9.5pt} +\def\footc {\footnotesize\tt\baselineskip=9.0pt} +\def\smallcode {\code\smallc} +\let\endcode=\egroup +\let\vcode=\code +\let\endvcode=\egroup + +% Definition d'un module ou d'une classe. +\def\ps@nomark {\def\leftmark{} \def\rightmark{}} +\def\defmodule#1 {\addcontentsline{toc}{subsection}{#1} \markboth{#1}{#1} + \centerline {\LARGE\bf #1}\bigskip \thispagestyle{nomark}} +\def\defclass#1 {\addcontentsline{toc}{subsection}{#1} \markboth{#1}{#1} + \centerline {\LARGE\bf #1}\bigskip \thispagestyle{nomark}} +% Lorsqu'on veut cacher certaines choses a l'usager, faire \hide ... \endhide +\newif\iffull\fullfalse +\def\hide{\iffull} +\let\endhide=\fi + +\def\parup{\nobreak\vskip -2pt\nobreak} + +\def\tab{\small\dimen9=\parindent\parindent=0pt% + \advance\leftskip by 1.5em\parup} +\def\tabb{\small\dimen9=\parindent\parindent=0pt% + \advance\leftskip by 3.0em\parup} +\def\tabbb{\small\dimen9=\parindent\parindent=0pt% + \advance\leftskip by 4.5em\parup} +\def\endtab{\vskip 0.01pt\advance\leftskip by -1.5em\normalsize% + \parindent=\dimen9} +\def\endtabb{\vskip 0.01pt\advance\leftskip by -3.0em\normalsize% + \parindent=\dimen9} +\def\endtabbb{\vskip 0.01pt\advance\leftskip by -4.5em\normalsize% + \parindent=\dimen9} + +% Pour mettre quelque chose dans une boite double. +\def\boxit#1{\vbox{\hrule height1pt + \hbox{\vrule width1pt\kern3pt + \vbox{\kern3pt#1\kern3pt + }\kern3pt\vrule width1pt + }\hrule height1pt }} +\def\boxr#1{\hfil\vbox{\hrule height1pt + \hbox{\vrule width1pt\kern3pt + \vbox{#1}\hfil + \kern3pt\vrule width1pt + }\hrule height1pt }} + +% Synonymes plus courts pour \begin{equation}, \begin{eqnarray}, etc. +\def\eq{\equation} \def\endeq{\endequation} +\def\eqs{\eqnarray} \def\endeqs{\endeqnarray} +\def\eqsn{\begin {eqnarray*}} \def\endeqsn{\end{eqnarray*}} + +% Proof avec boite alignee a droite a la fin. +\newenvironment{myproof}{{\em Proof.}}{\hspace*{\fill}$\Box$} +% \newenvironment{proof}{{\em Proof.}}{\hspace*{\fill}$\Box$} + +% Macros (avec switch) pour faire apparaitre les noms des labels dans les eqs. +% Utiliser \eqlabel au lieu de \label. Doit laisser un espace apres le } +% Pour que les etiquettes apparaissent, faire \seeeqlabelstrue au debut. +\newif\ifseeeqlabels\seeeqlabelsfalse +\newbox\eqlab \setbox\eqlab=\hbox {} +\def\eqlabel#1 {\global\setbox\eqlab=\hbox + {\ifseeeqlabels {\rm (#1)} \else {} \fi } \label{#1} } +\def\@eqnnum {{\rm \box\eqlab \setbox\eqlab=\hbox {} (\theequation)}} + +% Comme ci-haut pour \eqlabel, mais pour les noms des autres labels +% (Theoremes, Propositions, etc.). +% Utiliser \vislabel au lieu de \label. +% Pour que les etiquettes apparaissent, faire \seevislabelstrue au debut. +\newif\ifseevislabels\seevislabelsfalse +\def\vislabel#1 {\ifseevislabels {\ \em (#1).\ } \else {} \fi \label{#1} } + +% Pour mettre des remarques temporaires. +\newif\ifREM\REMfalse +\def\REM#1 {\ifREM \begin{quote} \small\em #1 \end{quote} \else {\null} \fi } + +% Pour avoir "running head" et no. de page en haut de page, faire \mytwoheads +% Si on veut la date en haut de chaque page, on fait aussi \dateheadtrue +\newif\ifdatehead\dateheadfalse +\def\mytwoheads {\pagestyle{headings} + \topmargin=-0.4in\headheight=0.2in\headsep=0.4in + \oddsidemargin=0.2in\evensidemargin=0in + \def\@evenhead {{\large\bf\thepage}\quad\leftmark\hfil + \ifdatehead\small\it\today\fi}% Left heading + \def\@oddhead {\ifdatehead{\small\it\kern-1em\today}\fi\hfil + \rightmark\quad\large\bf\thepage}}% Right heading + +\catcode`\@=12 diff --git a/TESTU01/TestU01-1.2.3/doc/myarticle.sty b/TESTU01/TestU01-1.2.3/doc/myarticle.sty new file mode 100644 index 0000000..2213395 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/doc/myarticle.sty @@ -0,0 +1,44 @@ +% LATEX ARTICLE DOCUMENT STYLE +% Modifications et ajout de macros. Pierre L'Ecuyer. + +\topmargin=-0.5in\oddsidemargin=0pt\topskip=\baselineskip +\headsep=0pt\headheight=0.5in +\renewcommand{\topfraction}{.90} +\renewcommand{\bottomfraction}{.80} +\renewcommand{\textfraction}{.10} +\textwidth=6.5 true in\textheight=8.9 true in +\tolerance=500 \parskip=.1in plus .1in minus .04in + +\catcode`\@=11 +%\def\thesection {\arabic{section}.} +%\def\thesubsection {\thesection\arabic{subsection}.} +%\def\thesubsubsection {\thesubsection\arabic{subsubsection}.} +%\def\theparagraph {\thesubsubsection\arabic{paragraph}.} +%\def\thesubparagraph {\theparagraph\arabic{subparagraph}.} +%\def\@thmcounter#1{\noexpand\arabic{#1}.} + +\def\fps@figure {hbtp} +\def\fps@table {hbtp} + +\def\thebibliography#1{\section*{References\markboth + {REFERENCES}{REFERENCES}}\list + {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}\leftmargin\labelwidth + \advance\leftmargin\labelsep\usecounter{enumi}}} +\def\@citex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi + \def\@citea{}\@cite{\@for\@citeb:=#2\do + {\@citea\def\@citea{, }\@ifundefined + {b@\@citeb}{{\bf ?}\@warning + {Citation `\@citeb' on page \thepage \space undefined}}% + \hbox{\csname b@\@citeb\endcsname}}}{#1}} + +\def\abstract{\if@twocolumn \section*{Abstract} + \else \small + \begin{center}{\bf ABSTRACT\vspace{-.5em}\vspace{0pt}}\end{center} + \quotation\fi} + +\def\inc#1{\@partswtrue\edef\@partlist{#1}} +\catcode`\@=12 + +\input ../doc/lmac.tex + + diff --git a/TESTU01/TestU01-1.2.3/examples/Makefile.am b/TESTU01/TestU01-1.2.3/examples/Makefile.am new file mode 100644 index 0000000..d50d8ed --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/Makefile.am @@ -0,0 +1,6 @@ +exdir = ${prefix}/share/TestU01/examples + +ex_DATA = bat1.res bat2.res birth1.res ex3.res excel.dat vax.bin my16807.h \ + bat1.c bat2.c bat3.c birth1.c birth2.c ex1.c ex3.c ex4.c ex7.c \ + fcoll.c fbirth.c scat.c scat2.c my16807.c mrg32k3a.c xorshift.c \ + fbirth.res1.tex fbirth.res2.tex fcoll.res1.tex fcoll.res2.tex diff --git a/TESTU01/TestU01-1.2.3/examples/Makefile.in b/TESTU01/TestU01-1.2.3/examples/Makefile.in new file mode 100644 index 0000000..49c4228 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/Makefile.in @@ -0,0 +1,360 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = examples +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h \ + $(top_builddir)/include/gdefconf.h +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(exdir)" +exDATA_INSTALL = $(INSTALL_DATA) +DATA = $(ex_DATA) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +exdir = ${prefix}/share/TestU01/examples +ex_DATA = bat1.res bat2.res birth1.res ex3.res excel.dat vax.bin my16807.h \ + bat1.c bat2.c bat3.c birth1.c birth2.c ex1.c ex3.c ex4.c ex7.c \ + fcoll.c fbirth.c scat.c scat2.c my16807.c mrg32k3a.c xorshift.c \ + fbirth.res1.tex fbirth.res2.tex fcoll.res1.tex fcoll.res2.tex + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu examples/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-exDATA: $(ex_DATA) + @$(NORMAL_INSTALL) + test -z "$(exdir)" || $(MKDIR_P) "$(DESTDIR)$(exdir)" + @list='$(ex_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(exDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(exdir)/$$f'"; \ + $(exDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(exdir)/$$f"; \ + done + +uninstall-exDATA: + @$(NORMAL_UNINSTALL) + @list='$(ex_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(exdir)/$$f'"; \ + rm -f "$(DESTDIR)$(exdir)/$$f"; \ + done +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(DATA) +installdirs: + for dir in "$(DESTDIR)$(exdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-exDATA + +install-dvi: install-dvi-am + +install-exec-am: + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-exDATA + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + distclean distclean-generic distclean-libtool distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exDATA install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + uninstall uninstall-am uninstall-exDATA + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/examples/bat1.c b/TESTU01/TestU01-1.2.3/examples/bat1.c new file mode 100644 index 0000000..db3c345 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/bat1.c @@ -0,0 +1,12 @@ +#include "ulcg.h" +#include "unif01.h" +#include "bbattery.h" + +int main (void) +{ + unif01_Gen *gen; + gen = ulcg_CreateLCG (2147483647, 16807, 0, 12345); + bbattery_SmallCrush (gen); + ulcg_DeleteGen (gen); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/bat1.res b/TESTU01/TestU01-1.2.3/examples/bat1.res new file mode 100644 index 0000000..9c4bcec --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/bat1.res @@ -0,0 +1,17 @@ +========= Summary results of SmallCrush ========= + + Version: TestU01 1.2.3 + Generator: ulcg_CreateLCG + Number of statistics: 15 + Total CPU time: 00:00:19.35 + The following tests gave p-values outside [0.001, 0.9990]: + (eps means a value < 1.0e-300): + (eps1 means a value < 1.0e-15): + + Test p-value + ---------------------------------------------- + 1 BirthdaySpacings eps + 2 Collision eps + 6 MaxOft eps + ---------------------------------------------- + All other tests were passed diff --git a/TESTU01/TestU01-1.2.3/examples/bat2.c b/TESTU01/TestU01-1.2.3/examples/bat2.c new file mode 100644 index 0000000..20f6219 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/bat2.c @@ -0,0 +1,10 @@ +#include "gdef.h" +#include "swrite.h" +#include "bbattery.h" + +int main (void) +{ + swrite_Basic = FALSE; + bbattery_RabbitFile ("vax.bin", 1048576); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/bat2.res b/TESTU01/TestU01-1.2.3/examples/bat2.res new file mode 100644 index 0000000..4f10ff2 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/bat2.res @@ -0,0 +1,23 @@ +========= Summary results of Rabbit ========= + + Version: TestU01 1.2.3 + File: vax.bin + Number of bits: 1048576 + Number of statistics: 38 + Total CPU time: 00:00:01.75 + The following tests gave p-values outside [0.001, 0.9990]: + (eps means a value < 1.0e-300): + (eps1 means a value < 1.0e-15): + + Test p-value + ---------------------------------------------- + 4 AppearanceSpacings 1.1e-4 + 7 Fourier1 eps + 8 Fourier3 3.2e-213 + 13 HammingCorr, L = 64 1 - eps1 + 16 HammingIndep, L = 32 eps + 17 HammingIndep, L = 64 eps + 24 RandomWalk1 M eps + 24 RandomWalk1 J eps + ---------------------------------------------- + All other tests were passed diff --git a/TESTU01/TestU01-1.2.3/examples/bat3.c b/TESTU01/TestU01-1.2.3/examples/bat3.c new file mode 100644 index 0000000..c8c6c4d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/bat3.c @@ -0,0 +1,18 @@ +#include "usoft.h" +#include "unif01.h" +#include "bbattery.h" + +int main (void) +{ + unif01_Gen *gen; + int n = 1024*1024; + + /* Test the first n bits of binary file vax.bin */ + bbattery_AlphabitFile ("vax.bin", n); + + /* Test the Java random number generator */ + gen = usoft_CreateJava48 (1234567, 1); + bbattery_Alphabit (gen, n, 0, 32); + + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/birth1.c b/TESTU01/TestU01-1.2.3/examples/birth1.c new file mode 100644 index 0000000..fd73aed --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/birth1.c @@ -0,0 +1,15 @@ + +#include "unif01.h" +#include "ulcg.h" +#include "smarsa.h" +#include + +int main (void) +{ + unif01_Gen *gen; + gen = ulcg_CreateLCG (2147483647, 397204094, 0, 12345); + smarsa_BirthdaySpacings (gen, NULL, 1, 1000, 0, 10000, 2, 1); + smarsa_BirthdaySpacings (gen, NULL, 1, 10000, 0, 1000000, 2, 1); + ulcg_DeleteGen (gen); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/birth1.res b/TESTU01/TestU01-1.2.3/examples/birth1.res new file mode 100644 index 0000000..fa3044e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/birth1.res @@ -0,0 +1,56 @@ +*********************************************************** +HOST = + +ulcg_CreateLCG: m = 2147483647, a = 397204094, c = 0, s = 12345 + + +smarsa_BirthdaySpacings test: +----------------------------------------------- + N = 1, n = 1000, r = 0, d = 10000, t = 2, p = 1 + + + Number of cells = d^t = 100000000 + Lambda = Poisson mean = 2.5000 + + +---------------------------------------------------- +Total expected number = N*Lambda : 2.50 +Total observed number : 6 +p-value of test : 0.04 + + +----------------------------------------------- +CPU time used : 00:00:00.00 + +Generator state: + s = 1858647048 + + + + +*********************************************************** +HOST = + +ulcg_CreateLCG: m = 2147483647, a = 397204094, c = 0, s = 12345 + + +smarsa_BirthdaySpacings test: +----------------------------------------------- + N = 1, n = 10000, r = 0, d = 1000000, t = 2, p = 1 + + + Number of cells = d^t = 1000000000000 + Lambda = Poisson mean = 0.2500 + + +---------------------------------------------------- +Total expected number = N*Lambda : 0.25 +Total observed number : 44 +p-value of test : 9.5e-82 ***** + + +----------------------------------------------- +CPU time used : 00:00:00.00 + +Generator state: + s = 731506484 diff --git a/TESTU01/TestU01-1.2.3/examples/birth2.c b/TESTU01/TestU01-1.2.3/examples/birth2.c new file mode 100644 index 0000000..b6eeeca --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/birth2.c @@ -0,0 +1,26 @@ + +#include "unif01.h" +#include "ulcg.h" +#include "sres.h" +#include "swrite.h" +#include "smarsa.h" + +int main (void) +{ + unif01_Gen *gen; + sres_Poisson *res; + swrite_Basic = FALSE; + + gen = ulcg_CreateLCG (2147483647, 397204094, 0, 12345); + res = sres_CreatePoisson (); + + smarsa_BirthdaySpacings (gen, res, 1, 1000, 0, 10000, 2, 1); + /* .... Examine or postprocess res */ + + smarsa_BirthdaySpacings (gen, res, 1, 10000, 0, 1000000, 2, 1); + /* .... Examine or postprocess res */ + + sres_DeletePoisson (res); + ulcg_DeleteGen (gen); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/ex1.c b/TESTU01/TestU01-1.2.3/examples/ex1.c new file mode 100644 index 0000000..fdfd070 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/ex1.c @@ -0,0 +1,30 @@ + +#include "unif01.h" +#include "ulcg.h" +#include "ulec.h" +#include + +int main (void) +{ + int i; + double x; + unsigned long z; + unif01_Gen *gen; + + gen = ulcg_CreateLCG (2147483647, 16807, 0, 12345); + x = 0.0; + for (i = 0; i < 50; i++) + x += gen->GetU01(gen->param, gen->state); + for (i = 0; i < 50; i++) + x += unif01_StripD (gen, 0); + printf ("Sum = %14.10f\n\n", x); + ulcg_DeleteGen (gen); + + gen = ulec_Createlfsr113 (12345, 12345, 12345, 12345); + for (i = 0; i < 5; i++) { + z = unif01_StripB (gen, 4, 10); + printf ("%10lu\n", z); + } + ulec_DeleteGen (gen); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/ex3.c b/TESTU01/TestU01-1.2.3/examples/ex3.c new file mode 100644 index 0000000..2e0090b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/ex3.c @@ -0,0 +1,34 @@ + +#include "unif01.h" +#include "ulcg.h" +#include "ulec.h" +#include "my16807.h" +#include + +int main (void) +{ + unif01_Gen *gen; + double x = 0.0; + int i; + + gen = ulcg_CreateLCGFloat (2147483647, 16807, 0, 12345); + unif01_TimerSumGenWr (gen, 10000000, TRUE); + ulcg_DeleteGen (gen); + + gen = CreateMy16807 (12345); + unif01_TimerSumGenWr (gen, 10000000, TRUE); + DeleteMy16807 (gen); + + gen = ulec_CreateMRG32k3a (123., 123., 123., 123., 123., 123.); + unif01_TimerSumGenWr (gen, 10000000, TRUE); + ulec_DeleteGen (gen); + + gen = ulec_Createlfsr113 (12345, 12345, 12345, 12345); + unif01_TimerSumGenWr (gen, 10000000, TRUE); + for (i = 0; i < 100; i++) + x += unif01_StripD (gen, 0); + printf ("Sum = %14.10f\n", x); + ulec_DeleteGen (gen); + + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/ex3.res b/TESTU01/TestU01-1.2.3/examples/ex3.res new file mode 100644 index 0000000..65f6b4c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/ex3.res @@ -0,0 +1,41 @@ + +------------- Results of speed test --------------- + + Host: + Generator: ulcg_CreateLCGFloat + Method: GetU01 + Mean = 0.499974546727091 + Number of calls: 10000000 + Total CPU time: 0.28 sec + + +------------- Results of speed test --------------- + + Host: + Generator: My LCG implementation for a = 16807 + Method: GetU01 + Mean = 0.499974546727091 + Number of calls: 10000000 + Total CPU time: 0.28 sec + + +------------- Results of speed test --------------- + + Host: + Generator: ulec_CreateMRG32k3a + Method: GetU01 + Mean = 0.500045268775809 + Number of calls: 10000000 + Total CPU time: 0.50 sec + + +------------- Results of speed test --------------- + + Host: + Generator: ulec_Createlfsr113 + Method: GetU01 + Mean = 0.500154672454091 + Number of calls: 10000000 + Total CPU time: 0.10 sec + +Sum = 50.6276649707 diff --git a/TESTU01/TestU01-1.2.3/examples/ex4.c b/TESTU01/TestU01-1.2.3/examples/ex4.c new file mode 100644 index 0000000..fdb4e2e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/ex4.c @@ -0,0 +1,38 @@ + +#include "unif01.h" +#include "utaus.h" +#include + +int main (void) +{ + unif01_Gen *gen1, *gen2, *gen3; + long I[3] = { 3, 7, 9 }; + int i, n = 20; + double x; + + gen1 = utaus_CreateTaus (31, 3, 12, 12345); + for (i = 0; i < n; i++) + printf ("%f\n", unif01_StripD (gen1, 0)); + utaus_DeleteGen (gen1); + printf ("\n"); + + gen1 = utaus_CreateTaus (31, 3, 12, 12345); + gen2 = unif01_CreateLacGen (gen1, 3, I); + for (i = 0; i < n; i++) + printf ("%f\n", unif01_StripD (gen2, 0)); + + gen3 = unif01_CreateDoubleGen (gen2, 24); + for (i = 0; i < n; i++) + x = unif01_StripD (gen3, 0); + unif01_DeleteDoubleGen (gen3); + unif01_DeleteLacGen (gen2); + + gen2 = utaus_CreateTaus (28, 7, 14, 12345); + gen3 = unif01_CreateCombXor2 (gen1, gen2, "A Combined Tausworthe Gener."); + for (i = 0; i < n; i++) + x = unif01_StripD (gen3, 0); + unif01_DeleteCombGen (gen3); + utaus_DeleteGen (gen2); + utaus_DeleteGen (gen1); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/ex7.c b/TESTU01/TestU01-1.2.3/examples/ex7.c new file mode 100644 index 0000000..b5a3f2f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/ex7.c @@ -0,0 +1,21 @@ + +#include "unif01.h" +#include "bbattery.h" + +unsigned int xorshift (void); +double MRG32k3a (void); + +int main (void) +{ + unif01_Gen *gen; + + gen = unif01_CreateExternGen01 ("MRG32k3a", MRG32k3a); + bbattery_SmallCrush (gen); + unif01_DeleteExternGen01 (gen); + + gen = unif01_CreateExternGenBits ("xorshift", xorshift); + bbattery_SmallCrush (gen); + unif01_DeleteExternGenBits (gen); + + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/excel.dat b/TESTU01/TestU01-1.2.3/examples/excel.dat new file mode 100644 index 0000000..bfb62d7 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/excel.dat @@ -0,0 +1,12 @@ +1500000 Number of points +2 Dimension = t +TRUE Overlapping +1 2 Components shown +1 0.0 0.0005 Component and bounds on x1 +2 0.0 1.0 Component and bounds on xt +13.0 13.0 Size of plot in centimeters +latex Output format: latex, gnu_term or gnu_ps +8 Precision +FALSE Lacunary +1 Lacunary indices +3 diff --git a/TESTU01/TestU01-1.2.3/examples/fbirth.c b/TESTU01/TestU01-1.2.3/examples/fbirth.c new file mode 100644 index 0000000..ac23a65 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/fbirth.c @@ -0,0 +1,23 @@ +#include "fcong.h" +#include "ffam.h" +#include "fcho.h" +#include "fmarsa.h" + +int main (void) +{ + ffam_Fam *fam; + fcho_Cho *chon; + fcho_Cho *chod; + fcho_Cho2 *cho; + + fam = fcong_CreateLCGPow2 (NULL, 10, 30, 1); + chon = fcho_CreateSampleSize (1.0/3.0, 1, 0, NULL, "n"); + chod = fmarsa_CreateBirthEC (1, 2, 1.0); + cho = fcho_CreateCho2 (chon, chod); + fmarsa_BirthdayS1 (fam, NULL, cho, 1, 0, 2, 1, 21, 1, 5, 1); + fcho_DeleteCho2 (cho); + fmarsa_DeleteBirthEC (chod); + fcho_DeleteSampleSize (chon); + fcong_DeleteLCGPow2 (fam); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/fbirth.res1.tex b/TESTU01/TestU01-1.2.3/examples/fbirth.res1.tex new file mode 100644 index 0000000..d117e88 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/fbirth.res1.tex @@ -0,0 +1,37 @@ +\begin {table} +\centering +\caption {Birthday spacings test: Expected and + observed number of collisions for each $i$ and $j$.} +\label {tab:birth.res1} +\smallskip +%%%%%%%%%%%%%%%%%%%%% +\begin {tabular}{|c|@{\extracolsep{10pt}}rr|rr|rr|rr|rr|} +\hline + LSize& \multicolumn{2}{c|}{$ j=1 $} & \multicolumn{2}{c|}{$ j=2 $} & \multicolumn{2}{c|}{$ j=3 $} & \multicolumn{2}{c|}{$ j=4 $} & \multicolumn{2}{c|}{$ j=5 $} \\ +\hline + 10 & --- & --- & 1.01 & 5 & 1.00 & 48 & 1.00 & 131 & --- & --- \\ + 11 & --- & --- & 1.01 & 8 & 1.00 & 52 & 1.00 & 147 & 1.00 & 377 \\ + 12 & 1.01 & 0 & 1.00 & 10 & 1.00 & 44 & 1.00 & 204 & 1.00 & 447 \\ + 13 & 1.01 & 0 & 1.00 & 11 & 1.00 & 50 & 1.00 & 196 & 1.00 & 579 \\ + 14 & 1.01 & 0 & 1.00 & 10 & 1.00 & 56 & 1.00 & 247 & 1.00 & 662 \\ + 15 & 1.00 & 2 & 1.00 & 9 & 1.00 & 55 & 1.00 & 258 & 1.00 & 911 \\ + 16 & 1.00 & 1 & 1.00 & 5 & 1.00 & 61 & 1.00 & 316 & 1.00 & 958 \\ + 17 & 1.00 & 0 & 1.00 & 7 & 1.00 & 70 & 1.00 & 365 & 1.00 & 1172 \\ + 18 & 1.00 & 1 & 1.00 & 10 & 1.00 & 73 & 1.00 & 385 & 1.00 & 1374 \\ + 19 & 1.00 & 4 & 1.00 & 13 & 1.00 & 79 & 1.00 & 414 & 1.00 & 1600 \\ + 20 & 1.00 & 0 & 1.00 & 7 & 1.00 & 72 & 1.00 & 449 & 1.00 & 1895 \\ + 21 & 1.00 & 1 & 1.00 & 5 & 1.00 & 73 & 1.00 & 509 & 1.00 & 2176 \\ + 22 & 1.00 & 4 & 1.00 & 8 & 1.00 & 78 & 1.00 & 505 & 1.00 & 2472 \\ + 23 & 1.00 & 3 & 1.00 & 13 & 1.00 & 79 & 1.00 & 522 & 1.00 & 2797 \\ + 24 & 1.00 & 1 & 1.00 & 16 & 1.00 & 59 & 1.00 & 580 & 1.00 & 3092 \\ + 25 & 1.00 & 2 & 1.00 & 9 & 1.00 & 102 & 1.00 & 588 & 1.00 & 3392 \\ + 26 & 1.00 & 0 & 1.00 & 10 & 1.00 & 79 & 1.00 & 629 & 1.00 & 3709 \\ + 27 & 1.00 & 2 & 1.00 & 11 & 1.00 & 89 & 1.00 & 636 & 1.00 & 3915 \\ + 28 & 1.00 & 1 & 1.00 & 8 & 1.00 & 83 & 1.00 & 691 & 1.00 & 4097 \\ + 29 & 1.00 & 2 & 1.00 & 12 & 1.00 & 89 & 1.00 & 650 & 1.00 & 4500 \\ + 30 & 1.00 & 3 & 1.00 & 16 & 1.00 & 80 & 1.00 & 649 & 1.00 & 4551 \\ +\hline +\end {tabular} \\ +\medskip + +\end {table} diff --git a/TESTU01/TestU01-1.2.3/examples/fbirth.res2.tex b/TESTU01/TestU01-1.2.3/examples/fbirth.res2.tex new file mode 100644 index 0000000..6bc09e4 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/fbirth.res2.tex @@ -0,0 +1,38 @@ + +\begin {table} +\centering +\caption {The right $p$-values $P[Y \ge y]$ of the BirthdaySpacings test + for the LCGPow2s.} +\label {tab:birth.res2} +\smallskip +Total CPU time: 00:00:00.07\\[4pt] + +\begin {tabular}{|c|@{\extracolsep{10pt}}ccccc|} +\hline +LSize & $ j= 1 $ & $ j= 2 $ & $ j= 3 $ & $ j= 4 $ & $ j= 5$ \\ +\hline + 10 & --- & 3.8e--3\phantom{0} & 3.7e--62\phantom{0} & 4.9e--223 & --- \\ + 11 & --- & 1.1e--5\phantom{0} & 5.2e--69\phantom{0} & 2.2e--257 & \eps \\ + 12 & & 1.1e--7\phantom{0} & 1.4e--55\phantom{0} & \eps & \eps \\ + 13 & & 1.0e--8\phantom{0} & 1.3e--65\phantom{0} & \eps & \eps \\ + 14 & & 1.1e--7\phantom{0} & 5.3e--76\phantom{0} & \eps & \eps \\ + 15 & & 1.1e--6\phantom{0} & 3.0e--74\phantom{0} & \eps & \eps \\ + 16 & & 3.7e--3\phantom{0} & 7.4e--85\phantom{0} & \eps & \eps \\ + 17 & & 8.3e--5\phantom{0} & 3.2e--101 & \eps & \eps \\ + 18 & & 1.1e--7\phantom{0} & 8.5e--107 & \eps & \eps \\ + 19 & & 6.4e--11 & 4.2e--118 & \eps & \eps \\ + 20 & & 8.3e--5\phantom{0} & 6.1e--105 & \eps & \eps \\ + 21 & & 3.7e--3\phantom{0} & 8.3e--107 & \eps & \eps \\ + 22 & & 1.0e--5\phantom{0} & 3.3e--116 & \eps & \eps \\ + 23 & & 6.4e--11 & 4.2e--118 & \eps & \eps \\ + 24 & & 1.9e--14 & 2.7e--81\phantom{0} & \eps & \eps \\ + 25 & & 1.1e--6\phantom{0} & 3.9e--163 & \eps & \eps \\ + 26 & & 1.1e--7\phantom{0} & 4.2e--118 & \eps & \eps \\ + 27 & & 1.0e--8\phantom{0} & 2.3e--137 & \eps & \eps \\ + 28 & & 1.0e--5\phantom{0} & 9.4e--126 & \eps & \eps \\ + 29 & & 8.3e--10 & 2.3e--137 & \eps & \eps \\ + 30 & & 1.9e--14 & 5.2e--120 & \eps & \eps \\ +\hline +\end {tabular} \\ +\medskip +\end {table} diff --git a/TESTU01/TestU01-1.2.3/examples/fcoll.c b/TESTU01/TestU01-1.2.3/examples/fcoll.c new file mode 100644 index 0000000..a43c74b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/fcoll.c @@ -0,0 +1,35 @@ +#include "fcong.h" +#include "ffam.h" +#include "fcho.h" +#include "fmultin.h" +#include "smultin.h" + +int main (void) +{ + int NbDelta = 1; + double ValDelta[] = { -1 }; + int t = 2; + ffam_Fam *fam; + smultin_Param *par; + fmultin_Res *res; + fcho_Cho *chon; + fcho_Cho *chod; + fcho_Cho2 *cho; + + fam = fcong_CreateLCG ("LCGGood.par", 10, 30, 1); + par = smultin_CreateParam (NbDelta, ValDelta, smultin_GenerCellSerial, 2); + res = fmultin_CreateRes (par); + chon = fcho_CreateSampleSize (0.5, 1, 0, NULL, "n"); + chod = fmultin_CreatePer_DT (t, 1); + cho = fcho_CreateCho2 (chon, chod); + + fmultin_Serial1 (fam, par, res, cho, 1, 0, t, TRUE, 21, 1, 5, 1); + + fcho_DeleteCho2 (cho); + fmultin_DeletePer (chod); + fcho_DeleteSampleSize (chon); + fmultin_DeleteRes (res); + smultin_DeleteParam (par); + fcong_DeleteLCG (fam); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/fcoll.res1.tex b/TESTU01/TestU01-1.2.3/examples/fcoll.res1.tex new file mode 100644 index 0000000..8fa588b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/fcoll.res1.tex @@ -0,0 +1,40 @@ + + +\begin {table} +\centering +\caption {Expected number of + collisions and observed number of collisions.} +\label {tab:coll1} +\smallskip + +%%%%%%%%%%%%%%%%%%%%% +\begin {tabular}{|c|@{\extracolsep{10pt}}rr|rr|rr|rr|rr|} +%% \multicolumn{11}{l}{\makebox[0pt][l]{fmultin\_Serial1: Collision test, Expected numbers---fmultin\_Serial1: Collision test, Observed numbers}}\\ +\hline + LSize& \multicolumn{2}{c|}{$ j=1 $} & \multicolumn{2}{c|}{$ j=2 $} & \multicolumn{2}{c|}{$ j=3 $} & \multicolumn{2}{c|}{$ j=4 $} & \multicolumn{2}{c|}{$ j=5 $} \\ +\hline + 10 & 1.93 & 2 & 7.62 & 2 & 29.39 & 11 & 108.94 & 58 & 376.52 & 570 \\ + 11 & 1.95 & 1 & 7.81 & 0 & 30.44 & 6 & 115.16 & 17 & 413.38 & 474 \\ + 12 & 1.96 & 0 & 7.81 & 2 & 30.65 & 13 & 117.87 & 44 & 436.20 & 216 \\ + 13 & 2.00 & 0 & 7.95 & 2 & 31.37 & 13 & 121.97 & 55 & 461.02 & 211 \\ + 14 & 1.98 & 1 & 7.90 & 5 & 31.31 & 11 & 122.77 & 52 & 471.77 & 191 \\ + 15 & 1.99 & 1 & 7.93 & 1 & 31.51 & 7 & 124.27 & 41 & 483.04 & 132 \\ + 16 & 1.99 & 1 & 7.95 & 0 & 31.65 & 5 & 125.35 & 20 & 491.26 & 75 \\ + 17 & 1.99 & 0 & 7.97 & 1 & 31.75 & 11 & 126.11 & 23 & 497.29 & 101 \\ + 18 & 2.00 & 0 & 7.98 & 4 & 31.83 & 15 & 126.66 & 45 & 501.47 & 214 \\ + 19 & 2.00 & 0 & 7.98 & 1 & 31.88 & 3 & 127.07 & 19 & 504.60 & 61 \\ + 20 & 2.00 & 0 & 7.99 & 0 & 31.91 & 4 & 127.33 & 14 & 506.69 & 74 \\ + 21 & 2.00 & 0 & 7.99 & 1 & 31.94 & 12 & 127.55 & 48 & 508.33 & 178 \\ + 22 & 2.00 & 0 & 7.99 & 3 & 31.96 & 14 & 127.66 & 59 & 509.34 & 220 \\ + 23 & 2.00 & 0 & 8.00 & 0 & 31.97 & 5 & 127.78 & 16 & 510.21 & 45 \\ + 24 & 2.00 & 0 & 8.00 & 0 & 31.98 & 1 & 127.83 & 15 & 510.67 & 37 \\ + 25 & 2.00 & 1 & 8.00 & 4 & 31.99 & 8 & 127.91 & 44 & 511.16 & 142 \\ + 26 & 2.00 & 2 & 8.00 & 1 & 31.99 & 7 & 127.92 & 24 & 511.33 & 71 \\ + 27 & 2.00 & 1 & 8.00 & 1 & 31.99 & 7 & 127.94 & 38 & 511.55 & 152 \\ + 28 & 2.00 & 0 & 8.00 & 3 & 31.99 & 17 & 127.96 & 41 & 511.67 & 193 \\ + 29 & 2.00 & 1 & 8.00 & 0 & 32.00 & 0 & 127.98 & 8 & 511.78 & 25 \\ + 30 & 2.00 & 0 & 8.00 & 3 & 32.00 & 10 & 127.98 & 29 & 511.83 & 189 \\ +\hline +\end {tabular} \\ +\medskip +\end {table} diff --git a/TESTU01/TestU01-1.2.3/examples/fcoll.res2.tex b/TESTU01/TestU01-1.2.3/examples/fcoll.res2.tex new file mode 100644 index 0000000..88af9f8 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/fcoll.res2.tex @@ -0,0 +1,41 @@ + + +\begin {table} +\centering +\caption {The $p$-values of the collision test for the good LCGs, + for $t=2$ and $k\approx 2^i$.} +\label {tab:coll11} +\smallskip +Total CPU time: 00:00:06.69\\[4pt] + +\begin {tabular}{|c|@{\extracolsep{10pt}}ccccc|} +% \multicolumn{6}{l}{\makebox[0pt][l]{fmultin\_Serial1: Collision test, p-value for discrete statistic}}\\ +\hline +LSize & $ j= 1 $ & $ j= 2 $ & $ j= 3 $ & $ j= 4 $ & $ j= 5$ \\ +\hline + 10 & & & --1.0e--5\phantom{0} & --1.1e--12 & \eps \\ + 11 & & --2.5e--4 & --6.3e--9\phantom{0} & \epsm & 1.1e--6 \\ + 12 & & & --1.1e--4\phantom{0} & \epsm & \epsm \\ + 13 & & & --9.0e--5\phantom{0} & --6.0e--14 & \epsm \\ + 14 & & & --1.5e--5\phantom{0} & --9.4e--15 & \epsm \\ + 15 & & --2.9e--3 & --9.0e--8\phantom{0} & \epsm & \epsm \\ + 16 & & --3.2e--4 & --3.5e--9\phantom{0} & \epsm & \epsm \\ + 17 & & --3.0e--3 & --1.6e--5\phantom{0} & \epsm & \epsm \\ + 18 & & & --6.6e--4\phantom{0} & \epsm & \epsm \\ + 19 & & --3.0e--3 & --7.0e--11 & \epsm & \epsm \\ + 20 & & --3.3e--4 & --6.0e--10 & \epsm & \epsm \\ + 21 & & --3.0e--3 & --4.7e--5\phantom{0} & \epsm & \epsm \\ + 22 & & & --2.9e--4\phantom{0} & --7.1e--12 & \epsm \\ + 23 & & --3.3e--4 & --4.1e--9\phantom{0} & \epsm & \epsm \\ + 24 & & --3.3e--4 & --4.1e--13 & \epsm & \epsm \\ + 25 & & & --4.5e--7\phantom{0} & \epsm & \epsm \\ + 26 & & --3.0e--3 & --1.1e--7\phantom{0} & \epsm & \epsm \\ + 27 & & --3.0e--3 & --1.1e--7\phantom{0} & \epsm & \epsm \\ + 28 & & & --2.8e--3\phantom{0} & \epsm & \epsm \\ + 29 & & --3.4e--4 & --1.3e--14 & \epsm & \epsm \\ + 30 & & & --5.6e--6\phantom{0} & \epsm & \epsm \\ +\hline +\end {tabular} \\ +\medskip + +\end {table} diff --git a/TESTU01/TestU01-1.2.3/examples/mrg32k3a.c b/TESTU01/TestU01-1.2.3/examples/mrg32k3a.c new file mode 100644 index 0000000..46a91c9 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/mrg32k3a.c @@ -0,0 +1,30 @@ + + #define norm 2.328306549295728e-10 + #define m1 4294967087.0 + #define m2 4294944443.0 + #define a12 1403580.0 + #define a13n 810728.0 + #define a21 527612.0 + #define a23n 1370589.0 + + static double s10 = 12345, s11 = 12345, s12 = 123, + s20 = 12345, s21 = 12345, s22 = 123; + + double MRG32k3a (void) + { + long k; + double p1, p2; + /* Component 1 */ + p1 = a12 * s11 - a13n * s10; + k = p1 / m1; p1 -= k * m1; if (p1 < 0.0) p1 += m1; + s10 = s11; s11 = s12; s12 = p1; + + /* Component 2 */ + p2 = a21 * s22 - a23n * s20; + k = p2 / m2; p2 -= k * m2; if (p2 < 0.0) p2 += m2; + s20 = s21; s21 = s22; s22 = p2; + + /* Combination */ + if (p1 <= p2) return ((p1 - p2 + m1) * norm); + else return ((p1 - p2) * norm); + } diff --git a/TESTU01/TestU01-1.2.3/examples/my16807.c b/TESTU01/TestU01-1.2.3/examples/my16807.c new file mode 100644 index 0000000..28ce2ab --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/my16807.c @@ -0,0 +1,58 @@ +#include "my16807.h" +#include "unif01.h" +#include "util.h" +#include "addstr.h" +#include + +typedef struct { double S; } My16807_state; + +static double My16807_U01 (void *par, void *sta) +{ + My16807_state *state = sta; + long k; + state->S *= 16807.0; + k = state->S / 2147483647.0; + state->S -= k * 2147483647.0; + return (state->S * 4.656612875245797E-10); +} + +static unsigned long My16807_Bits (void *par, void *sta) +{ + return (unsigned long) (My16807_U01 (par, sta) * 4294967296.0); +} + +static void WrMy16807 (void *sta) +{ + My16807_state *state = sta; + printf (" S = %.0f\n", state->S); +} + +unif01_Gen *CreateMy16807 (int s) +{ + unif01_Gen *gen; + My16807_state *state; + size_t leng; + char name[60]; + + gen = util_Malloc (sizeof (unif01_Gen)); + gen->state = state = util_Malloc (sizeof (My16807_state)); + state->S = s; + gen->param = NULL; + gen->Write = WrMy16807; + gen->GetU01 = My16807_U01; + gen->GetBits = My16807_Bits; + + strcpy (name, "My LCG implementation for a = 16807:"); + addstr_Int (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + return gen; +} + +void DeleteMy16807 (unif01_Gen * gen) +{ + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} diff --git a/TESTU01/TestU01-1.2.3/examples/my16807.h b/TESTU01/TestU01-1.2.3/examples/my16807.h new file mode 100644 index 0000000..eef35b5 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/my16807.h @@ -0,0 +1,5 @@ +#include "unif01.h" + +unif01_Gen *CreateMy16807 (int s); + +void DeleteMy16807 (unif01_Gen * gen); diff --git a/TESTU01/TestU01-1.2.3/examples/scat.c b/TESTU01/TestU01-1.2.3/examples/scat.c new file mode 100644 index 0000000..36b0750 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/scat.c @@ -0,0 +1,12 @@ +#include "unif01.h" +#include "ufile.h" +#include "scatter.h" + +int main (void) +{ + unif01_Gen *gen; + gen = ufile_CreateReadText ("excel.pts", 100000); + scatter_PlotUnif (gen, "excel"); + ufile_DeleteReadText (gen); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/scat2.c b/TESTU01/TestU01-1.2.3/examples/scat2.c new file mode 100644 index 0000000..6dd48ec --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/scat2.c @@ -0,0 +1,19 @@ +#include "unif01.h" +#include "usoft.h" +#include "scatter.h" + +int Proj[] = { 1, 3 }; +long LacI[] = { 1, 2, 6}; +double Lower[] = { 0.0, 0.0, 0.0 }; +double Upper[] = { 0.0001, 0.5, 1.0 }; + +int main (void) +{ + unif01_Gen *gen; + + gen = usoft_CreateVisualBasic (12345); + scatter_PlotUnif1 (gen, 10000000, 3, FALSE, Proj, Lower, Upper, + scatter_latex, 8, TRUE, LacI, "bone"); + usoft_DeleteGen (gen); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/examples/vax.bin b/TESTU01/TestU01-1.2.3/examples/vax.bin new file mode 100644 index 0000000..546bd49 Binary files /dev/null and b/TESTU01/TestU01-1.2.3/examples/vax.bin differ diff --git a/TESTU01/TestU01-1.2.3/examples/xorshift.c b/TESTU01/TestU01-1.2.3/examples/xorshift.c new file mode 100644 index 0000000..8956b22 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/examples/xorshift.c @@ -0,0 +1,8 @@ +static unsigned int y = 2463534242U; + +unsigned int xorshift (void) +{ + y ^= (y << 13); + y ^= (y >> 17); + return y ^= (y << 5); +} diff --git a/TESTU01/TestU01-1.2.3/include/Makefile.am b/TESTU01/TestU01-1.2.3/include/Makefile.am new file mode 100644 index 0000000..04f7838 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/include/Makefile.am @@ -0,0 +1,18 @@ +%.h: ${MYLIB}/%.tex + ${top_srcdir}/tcode $< $@ + +%.h: ${PROBDIST}/%.tex + ${top_srcdir}/tcode $< $@ + +%.h: ${TESTU01}/%.tex + ${top_srcdir}/tcode $< $@ + +include Makefile.def + +include_HEADERS = $(MYLIBHEADERS) $(PROBDISTHEADERS) $(TESTU01HEADERS) gdefconf.h + +noinst_HEADERS = $(MYLIBTEX) $(PROBDISTTEX) $(TESTU01TEX) +noinst_SCRIPTS = makedef + +CLEANFILES = $(MYLIBHEADERS) $(PROBDISTHEADERS) $(TESTU01HEADERS) gdefconf.h +MAINTAINERCLEANFILES = Makefile.in Makefile.def diff --git a/TESTU01/TestU01-1.2.3/include/Makefile.def b/TESTU01/TestU01-1.2.3/include/Makefile.def new file mode 100644 index 0000000..4bd0d7e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/include/Makefile.def @@ -0,0 +1,17 @@ +docdir = ${prefix}/share/TestU01/doc +MYLIB = ${top_srcdir}/mylib +PROBDIST = ${top_srcdir}/probdist +TESTU01 = ${top_srcdir}/testu01 + +MYLIBHEADERS = gdef.h addstr.h bitset.h chrono.h mystr.h num.h num2.h tables.h util.h +MYLIBSOURCES = gdef.c addstr.c bitset.c chrono.c mystr.c num.c num2.c tables.c util.c +MYLIBTEX = $(MYLIB)/gdef.tex $(MYLIB)/addstr.tex $(MYLIB)/bitset.tex $(MYLIB)/chrono.tex $(MYLIB)/mystr.tex $(MYLIB)/num.tex $(MYLIB)/num2.tex $(MYLIB)/tables.tex $(MYLIB)/util.tex + +PROBDISTHEADERS = fmass.h fdist.h fbar.h finv.h gofs.h gofw.h statcoll.h wdist.h +PROBDISTSOURCES = fmass.c fdist.c fbar.c finv.c gofs.c gofw.c statcoll.c wdist.c +PROBDISTTEX = $(PROBDIST)/fmass.tex $(PROBDIST)/fdist.tex $(PROBDIST)/fbar.tex $(PROBDIST)/finv.tex $(PROBDIST)/gofs.tex $(PROBDIST)/gofw.tex $(PROBDIST)/statcoll.tex $(PROBDIST)/wdist.tex + +TESTU01HEADERS = unif01.h ulcg.h umrg.h ucarry.h utaus.h ugfsr.h uinv.h uquad.h ucubic.h ulec.h utezuka.h umarsa.h uweyl.h uknuth.h uwu.h unumrec.h uvaria.h usoft.h ugranger.h ucrypto.h ufile.h udeng.h utouzin.h uautomata.h uxorshift.h ubrent.h rijndael-alg-fst.h tu01_sha1.h scatter.h swrite.h sres.h smultin.h sknuth.h smarsa.h sstring.h svaria.h snpair.h swalk.h sentrop.h sspectral.h scomp.h sspacings.h vectorsF2.h bbattery.h ffam.h fcong.h ffsr.h ftab.h fres.h fcho.h fmultin.h fmarsa.h fknuth.h fwalk.h fstring.h fspectral.h fvaria.h fnpair.h +TESTU01SOURCES = unif01.c ulcg.c umrg.c ucarry.c utaus.c ugfsr.c uinv.c uquad.c ucubic.c ulec.c utezuka.c umarsa.c uweyl.c uknuth.c uwu.c unumrec.c uvaria.c usoft.c ugranger.c ucrypto.c ufile.c udeng.c utouzin.c uautomata.c uxorshift.c ubrent.c rijndael-alg-fst.c tu01_sha1.c scatter.c swrite.c sres.c smultin.c sknuth.c smarsa.c sstring.c svaria.c snpair.c swalk.c sentrop.c sspectral.c scomp.c sspacings.c vectorsF2.c bbattery.c ffam.c fcong.c ffsr.c ftab.c fres.c fcho.c fmultin.c fmarsa.c fknuth.c fwalk.c fstring.c fspectral.c fvaria.c fnpair.c +TESTU01TEX = $(TESTU01)/unif01.tex $(TESTU01)/ulcg.tex $(TESTU01)/umrg.tex $(TESTU01)/ucarry.tex $(TESTU01)/utaus.tex $(TESTU01)/ugfsr.tex $(TESTU01)/uinv.tex $(TESTU01)/uquad.tex $(TESTU01)/ucubic.tex $(TESTU01)/ulec.tex $(TESTU01)/utezuka.tex $(TESTU01)/umarsa.tex $(TESTU01)/uweyl.tex $(TESTU01)/uknuth.tex $(TESTU01)/uwu.tex $(TESTU01)/unumrec.tex $(TESTU01)/uvaria.tex $(TESTU01)/usoft.tex $(TESTU01)/ugranger.tex $(TESTU01)/ucrypto.tex $(TESTU01)/ufile.tex $(TESTU01)/udeng.tex $(TESTU01)/utouzin.tex $(TESTU01)/uautomata.tex $(TESTU01)/uxorshift.tex $(TESTU01)/ubrent.tex $(TESTU01)/rijndael-alg-fst.tex $(TESTU01)/tu01_sha1.tex $(TESTU01)/scatter.tex $(TESTU01)/swrite.tex $(TESTU01)/sres.tex $(TESTU01)/smultin.tex $(TESTU01)/sknuth.tex $(TESTU01)/smarsa.tex $(TESTU01)/sstring.tex $(TESTU01)/svaria.tex $(TESTU01)/snpair.tex $(TESTU01)/swalk.tex $(TESTU01)/sentrop.tex $(TESTU01)/sspectral.tex $(TESTU01)/scomp.tex $(TESTU01)/sspacings.tex $(TESTU01)/vectorsF2.tex $(TESTU01)/bbattery.tex $(TESTU01)/ffam.tex $(TESTU01)/fcong.tex $(TESTU01)/ffsr.tex $(TESTU01)/ftab.tex $(TESTU01)/fres.tex $(TESTU01)/fcho.tex $(TESTU01)/fmultin.tex $(TESTU01)/fmarsa.tex $(TESTU01)/fknuth.tex $(TESTU01)/fwalk.tex $(TESTU01)/fstring.tex $(TESTU01)/fspectral.tex $(TESTU01)/fvaria.tex $(TESTU01)/fnpair.tex + diff --git a/TESTU01/TestU01-1.2.3/include/Makefile.in b/TESTU01/TestU01-1.2.3/include/Makefile.in new file mode 100644 index 0000000..db818dd --- /dev/null +++ b/TESTU01/TestU01-1.2.3/include/Makefile.in @@ -0,0 +1,484 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +DIST_COMMON = $(include_HEADERS) $(noinst_HEADERS) \ + $(srcdir)/Makefile.am $(srcdir)/Makefile.def \ + $(srcdir)/Makefile.in $(srcdir)/config.h.in \ + $(srcdir)/gdefconf.h.in +subdir = include +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = config.h gdefconf.h +CONFIG_CLEAN_FILES = +SCRIPTS = $(noinst_SCRIPTS) +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(includedir)" +includeHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(include_HEADERS) $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = ${prefix}/share/TestU01/doc +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +MYLIB = ${top_srcdir}/mylib +PROBDIST = ${top_srcdir}/probdist +TESTU01 = ${top_srcdir}/testu01 +MYLIBHEADERS = gdef.h addstr.h bitset.h chrono.h mystr.h num.h num2.h tables.h util.h +MYLIBSOURCES = gdef.c addstr.c bitset.c chrono.c mystr.c num.c num2.c tables.c util.c +MYLIBTEX = $(MYLIB)/gdef.tex $(MYLIB)/addstr.tex $(MYLIB)/bitset.tex $(MYLIB)/chrono.tex $(MYLIB)/mystr.tex $(MYLIB)/num.tex $(MYLIB)/num2.tex $(MYLIB)/tables.tex $(MYLIB)/util.tex +PROBDISTHEADERS = fmass.h fdist.h fbar.h finv.h gofs.h gofw.h statcoll.h wdist.h +PROBDISTSOURCES = fmass.c fdist.c fbar.c finv.c gofs.c gofw.c statcoll.c wdist.c +PROBDISTTEX = $(PROBDIST)/fmass.tex $(PROBDIST)/fdist.tex $(PROBDIST)/fbar.tex $(PROBDIST)/finv.tex $(PROBDIST)/gofs.tex $(PROBDIST)/gofw.tex $(PROBDIST)/statcoll.tex $(PROBDIST)/wdist.tex +TESTU01HEADERS = unif01.h ulcg.h umrg.h ucarry.h utaus.h ugfsr.h uinv.h uquad.h ucubic.h ulec.h utezuka.h umarsa.h uweyl.h uknuth.h uwu.h unumrec.h uvaria.h usoft.h ugranger.h ucrypto.h ufile.h udeng.h utouzin.h uautomata.h uxorshift.h ubrent.h rijndael-alg-fst.h tu01_sha1.h scatter.h swrite.h sres.h smultin.h sknuth.h smarsa.h sstring.h svaria.h snpair.h swalk.h sentrop.h sspectral.h scomp.h sspacings.h vectorsF2.h bbattery.h ffam.h fcong.h ffsr.h ftab.h fres.h fcho.h fmultin.h fmarsa.h fknuth.h fwalk.h fstring.h fspectral.h fvaria.h fnpair.h +TESTU01SOURCES = unif01.c ulcg.c umrg.c ucarry.c utaus.c ugfsr.c uinv.c uquad.c ucubic.c ulec.c utezuka.c umarsa.c uweyl.c uknuth.c uwu.c unumrec.c uvaria.c usoft.c ugranger.c ucrypto.c ufile.c udeng.c utouzin.c uautomata.c uxorshift.c ubrent.c rijndael-alg-fst.c tu01_sha1.c scatter.c swrite.c sres.c smultin.c sknuth.c smarsa.c sstring.c svaria.c snpair.c swalk.c sentrop.c sspectral.c scomp.c sspacings.c vectorsF2.c bbattery.c ffam.c fcong.c ffsr.c ftab.c fres.c fcho.c fmultin.c fmarsa.c fknuth.c fwalk.c fstring.c fspectral.c fvaria.c fnpair.c +TESTU01TEX = $(TESTU01)/unif01.tex $(TESTU01)/ulcg.tex \ + $(TESTU01)/umrg.tex $(TESTU01)/ucarry.tex $(TESTU01)/utaus.tex \ + $(TESTU01)/ugfsr.tex $(TESTU01)/uinv.tex $(TESTU01)/uquad.tex \ + $(TESTU01)/ucubic.tex $(TESTU01)/ulec.tex \ + $(TESTU01)/utezuka.tex $(TESTU01)/umarsa.tex \ + $(TESTU01)/uweyl.tex $(TESTU01)/uknuth.tex $(TESTU01)/uwu.tex \ + $(TESTU01)/unumrec.tex $(TESTU01)/uvaria.tex \ + $(TESTU01)/usoft.tex $(TESTU01)/ugranger.tex \ + $(TESTU01)/ucrypto.tex $(TESTU01)/ufile.tex \ + $(TESTU01)/udeng.tex $(TESTU01)/utouzin.tex \ + $(TESTU01)/uautomata.tex $(TESTU01)/uxorshift.tex \ + $(TESTU01)/ubrent.tex $(TESTU01)/rijndael-alg-fst.tex \ + $(TESTU01)/tu01_sha1.tex $(TESTU01)/scatter.tex \ + $(TESTU01)/swrite.tex $(TESTU01)/sres.tex \ + $(TESTU01)/smultin.tex $(TESTU01)/sknuth.tex \ + $(TESTU01)/smarsa.tex $(TESTU01)/sstring.tex \ + $(TESTU01)/svaria.tex $(TESTU01)/snpair.tex \ + $(TESTU01)/swalk.tex $(TESTU01)/sentrop.tex \ + $(TESTU01)/sspectral.tex $(TESTU01)/scomp.tex \ + $(TESTU01)/sspacings.tex $(TESTU01)/vectorsF2.tex \ + $(TESTU01)/bbattery.tex $(TESTU01)/ffam.tex \ + $(TESTU01)/fcong.tex $(TESTU01)/ffsr.tex $(TESTU01)/ftab.tex \ + $(TESTU01)/fres.tex $(TESTU01)/fcho.tex $(TESTU01)/fmultin.tex \ + $(TESTU01)/fmarsa.tex $(TESTU01)/fknuth.tex \ + $(TESTU01)/fwalk.tex $(TESTU01)/fstring.tex \ + $(TESTU01)/fspectral.tex $(TESTU01)/fvaria.tex \ + $(TESTU01)/fnpair.tex +include_HEADERS = $(MYLIBHEADERS) $(PROBDISTHEADERS) $(TESTU01HEADERS) gdefconf.h +noinst_HEADERS = $(MYLIBTEX) $(PROBDISTTEX) $(TESTU01TEX) +noinst_SCRIPTS = makedef +CLEANFILES = $(MYLIBHEADERS) $(PROBDISTHEADERS) $(TESTU01HEADERS) gdefconf.h +MAINTAINERCLEANFILES = Makefile.in Makefile.def +all: config.h gdefconf.h + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/Makefile.def $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu include/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +config.h: stamp-h1 + @if test ! -f $@; then \ + rm -f stamp-h1; \ + $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \ + else :; fi + +stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status include/config.h +$(srcdir)/config.h.in: $(am__configure_deps) + cd $(top_srcdir) && $(AUTOHEADER) + rm -f stamp-h1 + touch $@ + +gdefconf.h: stamp-h2 + @if test ! -f $@; then \ + rm -f stamp-h2; \ + $(MAKE) $(AM_MAKEFLAGS) stamp-h2; \ + else :; fi + +stamp-h2: $(srcdir)/gdefconf.h.in $(top_builddir)/config.status + @rm -f stamp-h2 + cd $(top_builddir) && $(SHELL) ./config.status include/gdefconf.h + +distclean-hdr: + -rm -f config.h stamp-h1 gdefconf.h stamp-h2 + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-includeHEADERS: $(include_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)" + @list='$(include_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \ + $(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \ + done + +uninstall-includeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(include_HEADERS)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \ + rm -f "$(DESTDIR)$(includedir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) config.h.in gdefconf.h.in $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) config.h.in gdefconf.h.in $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) config.h.in gdefconf.h.in $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) config.h.in gdefconf.h.in $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(SCRIPTS) $(HEADERS) config.h gdefconf.h +installdirs: + for dir in "$(DESTDIR)$(includedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-hdr distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-includeHEADERS + +install-dvi: install-dvi-am + +install-exec-am: + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-includeHEADERS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool ctags distclean distclean-generic distclean-hdr \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am \ + install-includeHEADERS install-info install-info-am \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ + ps ps-am tags uninstall uninstall-am uninstall-includeHEADERS + +%.h: ${MYLIB}/%.tex + ${top_srcdir}/tcode $< $@ + +%.h: ${PROBDIST}/%.tex + ${top_srcdir}/tcode $< $@ + +%.h: ${TESTU01}/%.tex + ${top_srcdir}/tcode $< $@ +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/include/config.h.in b/TESTU01/TestU01-1.2.3/include/config.h.in new file mode 100644 index 0000000..816da57 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/include/config.h.in @@ -0,0 +1,98 @@ +/* include/config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the `erf' function. */ +#undef HAVE_ERF + +/* Define to 1 if you have the header file. */ +#undef HAVE_GMP_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `lgamma' function. */ +#undef HAVE_LGAMMA + +/* Define to 1 if you have the `log1p' function. */ +#undef HAVE_LOG1P + +/* Define to 1 if the system has the type `long long'. */ +#undef HAVE_LONG_LONG + +/* Define when Mathematica is installed */ +#undef HAVE_MATHEMATICA + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `random' function. */ +#undef HAVE_RANDOM + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UTSNAME_H + +/* Define to 1 if the system has the type `uint32_t'. */ +#undef HAVE_UINT32_T + +/* Define to 1 if the system has the type `uint8_t'. */ +#undef HAVE_UINT8_T + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINDOWS_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +#undef WORDS_BIGENDIAN + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `unsigned int' if does not define. */ +#undef size_t diff --git a/TESTU01/TestU01-1.2.3/include/gdefconf.h.in b/TESTU01/TestU01-1.2.3/include/gdefconf.h.in new file mode 100644 index 0000000..327f933 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/include/gdefconf.h.in @@ -0,0 +1,29 @@ +/* gdef.h for ANSI C */ +#ifndef GDEFCONF_H +#define GDEFCONF_H + +#undef HAVE_LEBOOL + +#undef HAVE_LONG_LONG + +#undef HAVE_ERF + +#undef HAVE_RANDOM + +#undef HAVE_LGAMMA + +#undef HAVE_GMP_H + +#undef HAVE_MATHEMATICA + +#undef HAVE_SYS_UTSNAME_H + +#undef HAVE_UNISTD_H + +#undef HAVE_STDINT_H + +#undef HAVE_UINT32_T + +#undef HAVE_UINT8_T + +#endif diff --git a/TESTU01/TestU01-1.2.3/include/makedef b/TESTU01/TestU01-1.2.3/include/makedef new file mode 100755 index 0000000..2180753 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/include/makedef @@ -0,0 +1,52 @@ +#!/bin/sh + +rm -f Makefile.def + +echo 'docdir = ${prefix}/share/TestU01/doc' >> Makefile.def +echo 'MYLIB = ${top_srcdir}/mylib' >> Makefile.def +echo 'PROBDIST = ${top_srcdir}/probdist' >> Makefile.def +echo 'TESTU01 = ${top_srcdir}/testu01' >> Makefile.def +echo '' >> Makefile.def + +MYLIBMODULES='gdef addstr bitset chrono mystr num num2 tables util' + +PROBDISTMODULES='fmass fdist fbar finv gofs gofw statcoll wdist' + +TESTU01MODULES='unif01 ulcg umrg ucarry utaus ugfsr + uinv uquad ucubic ulec utezuka umarsa + uweyl uknuth uwu unumrec uvaria usoft + ugranger ucrypto ufile udeng utouzin uautomata + uxorshift ubrent rijndael-alg-fst tu01_sha1 + scatter swrite sres smultin sknuth smarsa + sstring svaria snpair swalk sentrop sspectral + scomp sspacings vectorsF2 bbattery + ffam fcong ffsr ftab fres fcho + fmultin fmarsa fknuth fwalk fstring fspectral + fvaria fnpair' + +function writevar() { + HEADERS="" + TEX="" + SOURCES="" + for mod in $1; do + HEADERS="$HEADERS ${mod}.h" + SOURCES="$SOURCES ${mod}.c" + TEX="$TEX \$($2)/${mod}.tex" + done + echo "$2HEADERS =$HEADERS" >> Makefile.def + echo "$2SOURCES =$SOURCES" >> Makefile.def + echo "$2TEX =$TEX" >> Makefile.def + echo '' >> Makefile.def + unset HEADERS + unset TEX + unset SOURCES +} + +writevar "$MYLIBMODULES" 'MYLIB' +writevar "$PROBDISTMODULES" "PROBDIST" +writevar "$TESTU01MODULES" "TESTU01" + +unset writevar +unset MYLIBMODULES +unset PROBDISTMODULES +unset TESTU01MODULES diff --git a/TESTU01/TestU01-1.2.3/install-sh b/TESTU01/TestU01-1.2.3/install-sh new file mode 100755 index 0000000..11870f1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + : +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=$mkdirprog + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f "$src" ] || [ -d "$src" ] + then + : + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + : + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + : + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' + ' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + : + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + : + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/TESTU01/TestU01-1.2.3/ltmain.sh b/TESTU01/TestU01-1.2.3/ltmain.sh new file mode 100644 index 0000000..d70dc75 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/ltmain.sh @@ -0,0 +1,6909 @@ +# ltmain.sh - Provide generalized library-building support services. +# NOTE: Changing this file will not affect anything until you rerun configure. +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# Originally by Gordon Matzigkeit , 1996 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +basename="s,^.*/,,g" + +# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh +# is ksh but when the shell is invoked as "sh" and the current value of +# the _XPG environment variable is not equal to 1 (one), the special +# positional parameter $0, within a function call, is the name of the +# function. +progpath="$0" + +# The name of this program: +progname=`echo "$progpath" | $SED $basename` +modename="$progname" + +# Global variables: +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +PROGRAM=ltmain.sh +PACKAGE=libtool +VERSION=1.5.22 +TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)" + +# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi + +# Check that we have a working $echo. +if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X$1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then + # Yippee, $echo works! + : +else + # Restart under the correct shell, and then maybe $echo will work. + exec $SHELL "$progpath" --no-reexec ${1+"$@"} +fi + +if test "X$1" = X--fallback-echo; then + # used as fallback echo + shift + cat <&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE +fi + +# Global variables. +mode=$default_mode +nonopt= +prev= +prevopt= +run= +show="$echo" +show_help= +execute_dlfiles= +duplicate_deps=no +preserve_args= +lo2o="s/\\.lo\$/.${objext}/" +o2lo="s/\\.${objext}\$/.lo/" +extracted_archives= +extracted_serial=0 + +##################################### +# Shell function definitions: +# This seems to be the best place for them + +# func_mktempdir [string] +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible. If +# given, STRING is the basename for that directory. +func_mktempdir () +{ + my_template="${TMPDIR-/tmp}/${1-$progname}" + + if test "$run" = ":"; then + # Return a directory name, but don't create it in dry-run mode + my_tmpdir="${my_template}-$$" + else + + # If mktemp works, use that first and foremost + my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` + + if test ! -d "$my_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + my_tmpdir="${my_template}-${RANDOM-0}$$" + + save_mktempdir_umask=`umask` + umask 0077 + $mkdir "$my_tmpdir" + umask $save_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$my_tmpdir" || { + $echo "cannot create temporary directory \`$my_tmpdir'" 1>&2 + exit $EXIT_FAILURE + } + fi + + $echo "X$my_tmpdir" | $Xsed +} + + +# func_win32_libid arg +# return the library type of file 'arg' +# +# Need a lot of goo to handle *both* DLLs and import libs +# Has to be a shell function in order to 'eat' the argument +# that is supplied when $file_magic_command is called. +func_win32_libid () +{ + win32_libid_type="unknown" + win32_fileres=`file -L $1 2>/dev/null` + case $win32_fileres in + *ar\ archive\ import\ library*) # definitely import + win32_libid_type="x86 archive import" + ;; + *ar\ archive*) # could be an import, or static + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ + $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then + win32_nmres=`eval $NM -f posix -A $1 | \ + $SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'` + case $win32_nmres in + import*) win32_libid_type="x86 archive import";; + *) win32_libid_type="x86 archive static";; + esac + fi + ;; + *DLL*) + win32_libid_type="x86 DLL" + ;; + *executable*) # but shell scripts are "executable" too... + case $win32_fileres in + *MS\ Windows\ PE\ Intel*) + win32_libid_type="x86 DLL" + ;; + esac + ;; + esac + $echo $win32_libid_type +} + + +# func_infer_tag arg +# Infer tagged configuration to use if any are available and +# if one wasn't chosen via the "--tag" command line option. +# Only attempt this if the compiler in the base compile +# command doesn't match the default compiler. +# arg is usually of the form 'gcc ...' +func_infer_tag () +{ + if test -n "$available_tags" && test -z "$tagname"; then + CC_quoted= + for arg in $CC; do + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + CC_quoted="$CC_quoted $arg" + done + case $@ in + # Blanks in the command may have been stripped by the calling shell, + # but not from the CC environment variable when configure was run. + " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;; + # Blanks at the start of $base_compile will cause this to fail + # if we don't check for them as well. + *) + for z in $available_tags; do + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then + # Evaluate the configuration. + eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" + CC_quoted= + for arg in $CC; do + # Double-quote args containing other shell metacharacters. + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + CC_quoted="$CC_quoted $arg" + done + case "$@ " in + " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) + # The compiler in the base compile command matches + # the one in the tagged configuration. + # Assume this is the tagged configuration we want. + tagname=$z + break + ;; + esac + fi + done + # If $tagname still isn't set, then no tagged configuration + # was found and let the user know that the "--tag" command + # line option must be used. + if test -z "$tagname"; then + $echo "$modename: unable to infer tagged configuration" + $echo "$modename: specify a tag with \`--tag'" 1>&2 + exit $EXIT_FAILURE +# else +# $echo "$modename: using $tagname tagged configuration" + fi + ;; + esac + fi +} + + +# func_extract_an_archive dir oldlib +func_extract_an_archive () +{ + f_ex_an_ar_dir="$1"; shift + f_ex_an_ar_oldlib="$1" + + $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)" + $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $? + if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then + : + else + $echo "$modename: ERROR: object name conflicts: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" 1>&2 + exit $EXIT_FAILURE + fi +} + +# func_extract_archives gentop oldlib ... +func_extract_archives () +{ + my_gentop="$1"; shift + my_oldlibs=${1+"$@"} + my_oldobjs="" + my_xlib="" + my_xabs="" + my_xdir="" + my_status="" + + $show "${rm}r $my_gentop" + $run ${rm}r "$my_gentop" + $show "$mkdir $my_gentop" + $run $mkdir "$my_gentop" + my_status=$? + if test "$my_status" -ne 0 && test ! -d "$my_gentop"; then + exit $my_status + fi + + for my_xlib in $my_oldlibs; do + # Extract the objects. + case $my_xlib in + [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; + *) my_xabs=`pwd`"/$my_xlib" ;; + esac + my_xlib=`$echo "X$my_xlib" | $Xsed -e 's%^.*/%%'` + my_xlib_u=$my_xlib + while :; do + case " $extracted_archives " in + *" $my_xlib_u "*) + extracted_serial=`expr $extracted_serial + 1` + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac + done + extracted_archives="$extracted_archives $my_xlib_u" + my_xdir="$my_gentop/$my_xlib_u" + + $show "${rm}r $my_xdir" + $run ${rm}r "$my_xdir" + $show "$mkdir $my_xdir" + $run $mkdir "$my_xdir" + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$my_xdir"; then + exit $exit_status + fi + case $host in + *-darwin*) + $show "Extracting $my_xabs" + # Do not bother doing anything if just a dry run + if test -z "$run"; then + darwin_orig_dir=`pwd` + cd $my_xdir || exit $? + darwin_archive=$my_xabs + darwin_curdir=`pwd` + darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'` + darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null` + if test -n "$darwin_arches"; then + darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'` + darwin_arch= + $show "$darwin_base_archive has multiple architectures $darwin_arches" + for darwin_arch in $darwin_arches ; do + mkdir -p "unfat-$$/${darwin_base_archive}-${darwin_arch}" + lipo -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" + cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" + func_extract_an_archive "`pwd`" "${darwin_base_archive}" + cd "$darwin_curdir" + $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" + done # $darwin_arches + ## Okay now we have a bunch of thin objects, gotta fatten them up :) + darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print| xargs basename | sort -u | $NL2SP` + darwin_file= + darwin_files= + for darwin_file in $darwin_filelist; do + darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP` + lipo -create -output "$darwin_file" $darwin_files + done # $darwin_filelist + ${rm}r unfat-$$ + cd "$darwin_orig_dir" + else + cd "$darwin_orig_dir" + func_extract_an_archive "$my_xdir" "$my_xabs" + fi # $darwin_arches + fi # $run + ;; + *) + func_extract_an_archive "$my_xdir" "$my_xabs" + ;; + esac + my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` + done + func_extract_archives_result="$my_oldobjs" +} +# End of Shell function definitions +##################################### + +# Darwin sucks +eval std_shrext=\"$shrext_cmds\" + +disable_libs=no + +# Parse our command line options once, thoroughly. +while test "$#" -gt 0 +do + arg="$1" + shift + + case $arg in + -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + execute_dlfiles) + execute_dlfiles="$execute_dlfiles $arg" + ;; + tag) + tagname="$arg" + preserve_args="${preserve_args}=$arg" + + # Check whether tagname contains only valid characters + case $tagname in + *[!-_A-Za-z0-9,/]*) + $echo "$progname: invalid tag name: $tagname" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $tagname in + CC) + # Don't test for the "default" C tag, as we know, it's there, but + # not specially marked. + ;; + *) + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$progpath" > /dev/null; then + taglist="$taglist $tagname" + # Evaluate the configuration. + eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $progpath`" + else + $echo "$progname: ignoring unknown tag $tagname" 1>&2 + fi + ;; + esac + ;; + *) + eval "$prev=\$arg" + ;; + esac + + prev= + prevopt= + continue + fi + + # Have we seen a non-optional argument yet? + case $arg in + --help) + show_help=yes + ;; + + --version) + $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP" + $echo + $echo "Copyright (C) 2005 Free Software Foundation, Inc." + $echo "This is free software; see the source for copying conditions. There is NO" + $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + exit $? + ;; + + --config) + ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $progpath + # Now print the configurations for the tags. + for tagname in $taglist; do + ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$progpath" + done + exit $? + ;; + + --debug) + $echo "$progname: enabling shell trace mode" + set -x + preserve_args="$preserve_args $arg" + ;; + + --dry-run | -n) + run=: + ;; + + --features) + $echo "host: $host" + if test "$build_libtool_libs" = yes; then + $echo "enable shared libraries" + else + $echo "disable shared libraries" + fi + if test "$build_old_libs" = yes; then + $echo "enable static libraries" + else + $echo "disable static libraries" + fi + exit $? + ;; + + --finish) mode="finish" ;; + + --mode) prevopt="--mode" prev=mode ;; + --mode=*) mode="$optarg" ;; + + --preserve-dup-deps) duplicate_deps="yes" ;; + + --quiet | --silent) + show=: + preserve_args="$preserve_args $arg" + ;; + + --tag) + prevopt="--tag" + prev=tag + preserve_args="$preserve_args --tag" + ;; + --tag=*) + set tag "$optarg" ${1+"$@"} + shift + prev=tag + preserve_args="$preserve_args --tag" + ;; + + -dlopen) + prevopt="-dlopen" + prev=execute_dlfiles + ;; + + -*) + $echo "$modename: unrecognized option \`$arg'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + + *) + nonopt="$arg" + break + ;; + esac +done + +if test -n "$prevopt"; then + $echo "$modename: option \`$prevopt' requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE +fi + +case $disable_libs in +no) + ;; +shared) + build_libtool_libs=no + build_old_libs=yes + ;; +static) + build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` + ;; +esac + +# If this variable is set in any of the actions, the command in it +# will be execed at the end. This prevents here-documents from being +# left over by shells. +exec_cmd= + +if test -z "$show_help"; then + + # Infer the operation mode. + if test -z "$mode"; then + $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2 + $echo "*** Future versions of Libtool will require --mode=MODE be specified." 1>&2 + case $nonopt in + *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*) + mode=link + for arg + do + case $arg in + -c) + mode=compile + break + ;; + esac + done + ;; + *db | *dbx | *strace | *truss) + mode=execute + ;; + *install*|cp|mv) + mode=install + ;; + *rm) + mode=uninstall + ;; + *) + # If we have no mode, but dlfiles were specified, then do execute mode. + test -n "$execute_dlfiles" && mode=execute + + # Just use the default operation mode. + if test -z "$mode"; then + if test -n "$nonopt"; then + $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2 + else + $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2 + fi + fi + ;; + esac + fi + + # Only execute mode is allowed to have -dlopen flags. + if test -n "$execute_dlfiles" && test "$mode" != execute; then + $echo "$modename: unrecognized option \`-dlopen'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Change the help message to a mode-specific one. + generic_help="$help" + help="Try \`$modename --help --mode=$mode' for more information." + + # These modes are in order of execution frequency so that they run quickly. + case $mode in + # libtool compile mode + compile) + modename="$modename: compile" + # Get the compilation command and the source file. + base_compile= + srcfile="$nonopt" # always keep a non-empty value in "srcfile" + suppress_opt=yes + suppress_output= + arg_mode=normal + libobj= + later= + + for arg + do + case $arg_mode in + arg ) + # do not "continue". Instead, add this to base_compile + lastarg="$arg" + arg_mode=normal + ;; + + target ) + libobj="$arg" + arg_mode=normal + continue + ;; + + normal ) + # Accept any command-line options. + case $arg in + -o) + if test -n "$libobj" ; then + $echo "$modename: you cannot specify \`-o' more than once" 1>&2 + exit $EXIT_FAILURE + fi + arg_mode=target + continue + ;; + + -static | -prefer-pic | -prefer-non-pic) + later="$later $arg" + continue + ;; + + -no-suppress) + suppress_opt=no + continue + ;; + + -Xcompiler) + arg_mode=arg # the next one goes into the "base_compile" arg list + continue # The current "srcfile" will either be retained or + ;; # replaced later. I would guess that would be a bug. + + -Wc,*) + args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"` + lastarg= + save_ifs="$IFS"; IFS=',' + for arg in $args; do + IFS="$save_ifs" + + # Double-quote args containing other shell metacharacters. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + lastarg="$lastarg $arg" + done + IFS="$save_ifs" + lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"` + + # Add the arguments to base_compile. + base_compile="$base_compile $lastarg" + continue + ;; + + * ) + # Accept the current argument as the source file. + # The previous "srcfile" becomes the current argument. + # + lastarg="$srcfile" + srcfile="$arg" + ;; + esac # case $arg + ;; + esac # case $arg_mode + + # Aesthetically quote the previous argument. + lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"` + + case $lastarg in + # Double-quote args containing other shell metacharacters. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, and some SunOS ksh mistreat backslash-escaping + # in scan sets (worked around with variable expansion), + # and furthermore cannot handle '|' '&' '(' ')' in scan sets + # at all, so we specify them separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + lastarg="\"$lastarg\"" + ;; + esac + + base_compile="$base_compile $lastarg" + done # for arg + + case $arg_mode in + arg) + $echo "$modename: you must specify an argument for -Xcompile" + exit $EXIT_FAILURE + ;; + target) + $echo "$modename: you must specify a target with \`-o'" 1>&2 + exit $EXIT_FAILURE + ;; + *) + # Get the name of the library object. + [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'` + ;; + esac + + # Recognize several different file suffixes. + # If the user specifies -o file.o, it is replaced with file.lo + xform='[cCFSifmso]' + case $libobj in + *.ada) xform=ada ;; + *.adb) xform=adb ;; + *.ads) xform=ads ;; + *.asm) xform=asm ;; + *.c++) xform=c++ ;; + *.cc) xform=cc ;; + *.ii) xform=ii ;; + *.class) xform=class ;; + *.cpp) xform=cpp ;; + *.cxx) xform=cxx ;; + *.f90) xform=f90 ;; + *.for) xform=for ;; + *.java) xform=java ;; + *.obj) xform=obj ;; + esac + + libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` + + case $libobj in + *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;; + *) + $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + func_infer_tag $base_compile + + for arg in $later; do + case $arg in + -static) + build_old_libs=yes + continue + ;; + + -prefer-pic) + pic_mode=yes + continue + ;; + + -prefer-non-pic) + pic_mode=no + continue + ;; + esac + done + + qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"` + case $qlibobj in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qlibobj="\"$qlibobj\"" ;; + esac + test "X$libobj" != "X$qlibobj" \ + && $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' &()|`$[]' \ + && $echo "$modename: libobj name \`$libobj' may not contain shell special characters." + objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` + xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$obj"; then + xdir= + else + xdir=$xdir/ + fi + lobj=${xdir}$objdir/$objname + + if test -z "$base_compile"; then + $echo "$modename: you must specify a compilation command" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Delete any leftover library objects. + if test "$build_old_libs" = yes; then + removelist="$obj $lobj $libobj ${libobj}T" + else + removelist="$lobj $libobj ${libobj}T" + fi + + $run $rm $removelist + trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 + + # On Cygwin there's no "real" PIC flag so we must build both object types + case $host_os in + cygwin* | mingw* | pw32* | os2*) + pic_mode=default + ;; + esac + if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then + # non-PIC code in shared libraries is not supported + pic_mode=default + fi + + # Calculate the filename of the output object if compiler does + # not support -o with -c + if test "$compiler_c_o" = no; then + output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} + lockfile="$output_obj.lock" + removelist="$removelist $output_obj $lockfile" + trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 + else + output_obj= + need_locks=no + lockfile= + fi + + # Lock this critical section if it is needed + # We use this script file to make the link, it avoids creating a new file + if test "$need_locks" = yes; then + until $run ln "$progpath" "$lockfile" 2>/dev/null; do + $show "Waiting for $lockfile to be removed" + sleep 2 + done + elif test "$need_locks" = warn; then + if test -f "$lockfile"; then + $echo "\ +*** ERROR, $lockfile exists and contains: +`cat $lockfile 2>/dev/null` + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + $echo "$srcfile" > "$lockfile" + fi + + if test -n "$fix_srcfile_path"; then + eval srcfile=\"$fix_srcfile_path\" + fi + qsrcfile=`$echo "X$srcfile" | $Xsed -e "$sed_quote_subst"` + case $qsrcfile in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qsrcfile="\"$qsrcfile\"" ;; + esac + + $run $rm "$libobj" "${libobj}T" + + # Create a libtool object file (analogous to a ".la" file), + # but don't create it if we're doing a dry run. + test -z "$run" && cat > ${libobj}T </dev/null`" != "X$srcfile"; then + $echo "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed, then go on to compile the next one + if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then + $show "$mv $output_obj $lobj" + if $run $mv $output_obj $lobj; then : + else + error=$? + $run $rm $removelist + exit $error + fi + fi + + # Append the name of the PIC object to the libtool object file. + test -z "$run" && cat >> ${libobj}T <> ${libobj}T </dev/null`" != "X$srcfile"; then + $echo "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed + if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then + $show "$mv $output_obj $obj" + if $run $mv $output_obj $obj; then : + else + error=$? + $run $rm $removelist + exit $error + fi + fi + + # Append the name of the non-PIC object the libtool object file. + # Only append if the libtool object file exists. + test -z "$run" && cat >> ${libobj}T <> ${libobj}T <&2 + fi + if test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + -static) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=built + ;; + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac + build_libtool_libs=no + build_old_libs=yes + break + ;; + esac + done + + # See if our shared archives depend on static archives. + test -n "$old_archive_from_new_cmds" && build_old_libs=yes + + # Go through the arguments, transforming them on the way. + while test "$#" -gt 0; do + arg="$1" + shift + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qarg=\"`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`\" ### testsuite: skip nested quoting test + ;; + *) qarg=$arg ;; + esac + libtool_args="$libtool_args $qarg" + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + output) + compile_command="$compile_command @OUTPUT@" + finalize_command="$finalize_command @OUTPUT@" + ;; + esac + + case $prev in + dlfiles|dlprefiles) + if test "$preload" = no; then + # Add the symbol object into the linking commands. + compile_command="$compile_command @SYMFILE@" + finalize_command="$finalize_command @SYMFILE@" + preload=yes + fi + case $arg in + *.la | *.lo) ;; # We handle these cases below. + force) + if test "$dlself" = no; then + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + self) + if test "$prev" = dlprefiles; then + dlself=yes + elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then + dlself=yes + else + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + *) + if test "$prev" = dlfiles; then + dlfiles="$dlfiles $arg" + else + dlprefiles="$dlprefiles $arg" + fi + prev= + continue + ;; + esac + ;; + expsyms) + export_symbols="$arg" + if test ! -f "$arg"; then + $echo "$modename: symbol file \`$arg' does not exist" + exit $EXIT_FAILURE + fi + prev= + continue + ;; + expsyms_regex) + export_symbols_regex="$arg" + prev= + continue + ;; + inst_prefix) + inst_prefix_dir="$arg" + prev= + continue + ;; + precious_regex) + precious_files_regex="$arg" + prev= + continue + ;; + release) + release="-$arg" + prev= + continue + ;; + objectlist) + if test -f "$arg"; then + save_arg=$arg + moreargs= + for fil in `cat $save_arg` + do +# moreargs="$moreargs $fil" + arg=$fil + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + pic_object= + non_pic_object= + + # Read the .lo file + # If there is no directory component, then add one. + case $arg in + */* | *\\*) . $arg ;; + *) . ./$arg ;; + esac + + if test -z "$pic_object" || \ + test -z "$non_pic_object" || + test "$pic_object" = none && \ + test "$non_pic_object" = none; then + $echo "$modename: cannot find name of object for \`$arg'" 1>&2 + exit $EXIT_FAILURE + fi + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + libobjs="$libobjs $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + non_pic_objects="$non_pic_objects $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if test -z "$run"; then + $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 + exit $EXIT_FAILURE + else + # Dry-run case. + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` + non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` + libobjs="$libobjs $pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + fi + done + else + $echo "$modename: link input file \`$save_arg' does not exist" + exit $EXIT_FAILURE + fi + arg=$save_arg + prev= + continue + ;; + rpath | xrpath) + # We need an absolute path. + case $arg in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + $echo "$modename: only absolute run-paths are allowed" 1>&2 + exit $EXIT_FAILURE + ;; + esac + if test "$prev" = rpath; then + case "$rpath " in + *" $arg "*) ;; + *) rpath="$rpath $arg" ;; + esac + else + case "$xrpath " in + *" $arg "*) ;; + *) xrpath="$xrpath $arg" ;; + esac + fi + prev= + continue + ;; + xcompiler) + compiler_flags="$compiler_flags $qarg" + prev= + compile_command="$compile_command $qarg" + finalize_command="$finalize_command $qarg" + continue + ;; + xlinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $wl$qarg" + prev= + compile_command="$compile_command $wl$qarg" + finalize_command="$finalize_command $wl$qarg" + continue + ;; + xcclinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $qarg" + prev= + compile_command="$compile_command $qarg" + finalize_command="$finalize_command $qarg" + continue + ;; + shrext) + shrext_cmds="$arg" + prev= + continue + ;; + darwin_framework|darwin_framework_skip) + test "$prev" = "darwin_framework" && compiler_flags="$compiler_flags $arg" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + prev= + continue + ;; + *) + eval "$prev=\"\$arg\"" + prev= + continue + ;; + esac + fi # test -n "$prev" + + prevarg="$arg" + + case $arg in + -all-static) + if test -n "$link_static_flag"; then + compile_command="$compile_command $link_static_flag" + finalize_command="$finalize_command $link_static_flag" + fi + continue + ;; + + -allow-undefined) + # FIXME: remove this flag sometime in the future. + $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2 + continue + ;; + + -avoid-version) + avoid_version=yes + continue + ;; + + -dlopen) + prev=dlfiles + continue + ;; + + -dlpreopen) + prev=dlprefiles + continue + ;; + + -export-dynamic) + export_dynamic=yes + continue + ;; + + -export-symbols | -export-symbols-regex) + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + $echo "$modename: more than one -exported-symbols argument is not allowed" + exit $EXIT_FAILURE + fi + if test "X$arg" = "X-export-symbols"; then + prev=expsyms + else + prev=expsyms_regex + fi + continue + ;; + + -framework|-arch|-isysroot) + case " $CC " in + *" ${arg} ${1} "* | *" ${arg} ${1} "*) + prev=darwin_framework_skip ;; + *) compiler_flags="$compiler_flags $arg" + prev=darwin_framework ;; + esac + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + continue + ;; + + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* + # so, if we see these flags be careful not to treat them like -L + -L[A-Z][A-Z]*:*) + case $with_gcc/$host in + no/*-*-irix* | /*-*-irix*) + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + ;; + esac + continue + ;; + + -L*) + dir=`$echo "X$arg" | $Xsed -e 's/^-L//'` + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2 + absdir="$dir" + notinst_path="$notinst_path $dir" + fi + dir="$absdir" + ;; + esac + case "$deplibs " in + *" -L$dir "*) ;; + *) + deplibs="$deplibs -L$dir" + lib_search_path="$lib_search_path $dir" + ;; + esac + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + testbindir=`$echo "X$dir" | $Xsed -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$dir:"*) ;; + *) dllsearchpath="$dllsearchpath:$dir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + continue + ;; + + -l*) + if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos*) + # These systems don't actually have a C or math library (as such) + continue + ;; + *-*-os2*) + # These systems don't actually have a C library (as such) + test "X$arg" = "X-lc" && continue + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + test "X$arg" = "X-lc" && continue + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C and math libraries are in the System framework + deplibs="$deplibs -framework System" + continue + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + test "X$arg" = "X-lc" && continue + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + test "X$arg" = "X-lc" && continue + ;; + esac + elif test "X$arg" = "X-lc_r"; then + case $host in + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc_r directly, use -pthread flag. + continue + ;; + esac + fi + deplibs="$deplibs $arg" + continue + ;; + + # Tru64 UNIX uses -model [arg] to determine the layout of C++ + # classes, name mangling, and exception handling. + -model) + compile_command="$compile_command $arg" + compiler_flags="$compiler_flags $arg" + finalize_command="$finalize_command $arg" + prev=xcompiler + continue + ;; + + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) + compiler_flags="$compiler_flags $arg" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + continue + ;; + + -module) + module=yes + continue + ;; + + # -64, -mips[0-9] enable 64-bit mode on the SGI compiler + # -r[0-9][0-9]* specifies the processor on the SGI compiler + # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler + # +DA*, +DD* enable 64-bit mode on the HP compiler + # -q* pass through compiler args for the IBM compiler + # -m* pass through architecture-specific compiler args for GCC + # -m*, -t[45]*, -txscale* pass through architecture-specific + # compiler args for GCC + # -pg pass through profiling flag for GCC + # @file GCC response files + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \ + -t[45]*|-txscale*|@*) + + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + compiler_flags="$compiler_flags $arg" + continue + ;; + + -shrext) + prev=shrext + continue + ;; + + -no-fast-install) + fast_install=no + continue + ;; + + -no-install) + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + # The PATH hackery in wrapper scripts is required on Windows + # in order for the loader to find any dlls it needs. + $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 + $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 + fast_install=no + ;; + *) no_install=yes ;; + esac + continue + ;; + + -no-undefined) + allow_undefined=no + continue + ;; + + -objectlist) + prev=objectlist + continue + ;; + + -o) prev=output ;; + + -precious-files-regex) + prev=precious_regex + continue + ;; + + -release) + prev=release + continue + ;; + + -rpath) + prev=rpath + continue + ;; + + -R) + prev=xrpath + continue + ;; + + -R*) + dir=`$echo "X$arg" | $Xsed -e 's/^-R//'` + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + $echo "$modename: only absolute run-paths are allowed" 1>&2 + exit $EXIT_FAILURE + ;; + esac + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + continue + ;; + + -static | -static-libtool-libs) + # The effects of -static are defined in a previous loop. + # We used to do the same as -all-static on platforms that + # didn't have a PIC flag, but the assumption that the effects + # would be equivalent was wrong. It would break on at least + # Digital Unix and AIX. + continue + ;; + + -thread-safe) + thread_safe=yes + continue + ;; + + -version-info) + prev=vinfo + continue + ;; + -version-number) + prev=vinfo + vinfo_number=yes + continue + ;; + + -Wc,*) + args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'` + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + case $flag in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + flag="\"$flag\"" + ;; + esac + arg="$arg $wl$flag" + compiler_flags="$compiler_flags $flag" + done + IFS="$save_ifs" + arg=`$echo "X$arg" | $Xsed -e "s/^ //"` + ;; + + -Wl,*) + args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'` + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + case $flag in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + flag="\"$flag\"" + ;; + esac + arg="$arg $wl$flag" + compiler_flags="$compiler_flags $wl$flag" + linker_flags="$linker_flags $flag" + done + IFS="$save_ifs" + arg=`$echo "X$arg" | $Xsed -e "s/^ //"` + ;; + + -Xcompiler) + prev=xcompiler + continue + ;; + + -Xlinker) + prev=xlinker + continue + ;; + + -XCClinker) + prev=xcclinker + continue + ;; + + # Some other compiler flag. + -* | +*) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + ;; + + *.$objext) + # A standard object. + objs="$objs $arg" + ;; + + *.lo) + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + pic_object= + non_pic_object= + + # Read the .lo file + # If there is no directory component, then add one. + case $arg in + */* | *\\*) . $arg ;; + *) . ./$arg ;; + esac + + if test -z "$pic_object" || \ + test -z "$non_pic_object" || + test "$pic_object" = none && \ + test "$non_pic_object" = none; then + $echo "$modename: cannot find name of object for \`$arg'" 1>&2 + exit $EXIT_FAILURE + fi + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + libobjs="$libobjs $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + non_pic_objects="$non_pic_objects $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if test -z "$run"; then + $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 + exit $EXIT_FAILURE + else + # Dry-run case. + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` + non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` + libobjs="$libobjs $pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + fi + ;; + + *.$libext) + # An archive. + deplibs="$deplibs $arg" + old_deplibs="$old_deplibs $arg" + continue + ;; + + *.la) + # A libtool-controlled library. + + if test "$prev" = dlfiles; then + # This library was specified with -dlopen. + dlfiles="$dlfiles $arg" + prev= + elif test "$prev" = dlprefiles; then + # The library was specified with -dlpreopen. + dlprefiles="$dlprefiles $arg" + prev= + else + deplibs="$deplibs $arg" + fi + continue + ;; + + # Some other compiler argument. + *) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + ;; + esac # arg + + # Now actually substitute the argument into the commands. + if test -n "$arg"; then + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + fi + done # argument parsing loop + + if test -n "$prev"; then + $echo "$modename: the \`$prevarg' option requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then + eval arg=\"$export_dynamic_flag_spec\" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + fi + + oldlibs= + # calculate the name of the file, without its directory + outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'` + libobjs_save="$libobjs" + + if test -n "$shlibpath_var"; then + # get the directories listed in $shlibpath_var + eval shlib_search_path=\`\$echo \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` + else + shlib_search_path= + fi + eval sys_lib_search_path=\"$sys_lib_search_path_spec\" + eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" + + output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'` + if test "X$output_objdir" = "X$output"; then + output_objdir="$objdir" + else + output_objdir="$output_objdir/$objdir" + fi + # Create the object directory. + if test ! -d "$output_objdir"; then + $show "$mkdir $output_objdir" + $run $mkdir $output_objdir + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$output_objdir"; then + exit $exit_status + fi + fi + + # Determine the type of output + case $output in + "") + $echo "$modename: you must specify an output file" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + *.$libext) linkmode=oldlib ;; + *.lo | *.$objext) linkmode=obj ;; + *.la) linkmode=lib ;; + *) linkmode=prog ;; # Anything else should be a program. + esac + + case $host in + *cygwin* | *mingw* | *pw32*) + # don't eliminate duplications in $postdeps and $predeps + duplicate_compiler_generated_deps=yes + ;; + *) + duplicate_compiler_generated_deps=$duplicate_deps + ;; + esac + specialdeplibs= + + libs= + # Find all interdependent deplibs by searching for libraries + # that are linked more than once (e.g. -la -lb -la) + for deplib in $deplibs; do + if test "X$duplicate_deps" = "Xyes" ; then + case "$libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + libs="$libs $deplib" + done + + if test "$linkmode" = lib; then + libs="$predeps $libs $compiler_lib_search_path $postdeps" + + # Compute libraries that are listed more than once in $predeps + # $postdeps and mark them as special (i.e., whose duplicates are + # not to be eliminated). + pre_post_deps= + if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then + for pre_post_dep in $predeps $postdeps; do + case "$pre_post_deps " in + *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; + esac + pre_post_deps="$pre_post_deps $pre_post_dep" + done + fi + pre_post_deps= + fi + + deplibs= + newdependency_libs= + newlib_search_path= + need_relink=no # whether we're linking any uninstalled libtool libraries + notinst_deplibs= # not-installed libtool libraries + case $linkmode in + lib) + passes="conv link" + for file in $dlfiles $dlprefiles; do + case $file in + *.la) ;; + *) + $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2 + exit $EXIT_FAILURE + ;; + esac + done + ;; + prog) + compile_deplibs= + finalize_deplibs= + alldeplibs=no + newdlfiles= + newdlprefiles= + passes="conv scan dlopen dlpreopen link" + ;; + *) passes="conv" + ;; + esac + for pass in $passes; do + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan"; then + libs="$deplibs" + deplibs= + fi + if test "$linkmode" = prog; then + case $pass in + dlopen) libs="$dlfiles" ;; + dlpreopen) libs="$dlprefiles" ;; + link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + esac + fi + if test "$pass" = dlopen; then + # Collect dlpreopened libraries + save_deplibs="$deplibs" + deplibs= + fi + for deplib in $libs; do + lib= + found=no + case $deplib in + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + compiler_flags="$compiler_flags $deplib" + fi + continue + ;; + -l*) + if test "$linkmode" != lib && test "$linkmode" != prog; then + $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2 + continue + fi + name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` + for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do + for search_ext in .la $std_shrext .so .a; do + # Search the libtool library + lib="$searchdir/lib${name}${search_ext}" + if test -f "$lib"; then + if test "$search_ext" = ".la"; then + found=yes + else + found=no + fi + break 2 + fi + done + done + if test "$found" != yes; then + # deplib doesn't seem to be a libtool library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + else # deplib is a libtool library + # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, + # We need to do some special things here, and not later. + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $deplib "*) + if (${SED} -e '2q' $lib | + grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + library_names= + old_library= + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + for l in $old_library $library_names; do + ll="$l" + done + if test "X$ll" = "X$old_library" ; then # only static version available + found=no + ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` + test "X$ladir" = "X$lib" && ladir="." + lib=$ladir/$old_library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + fi + ;; + *) ;; + esac + fi + fi + ;; # -l + -L*) + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test "$pass" = conv && continue + newdependency_libs="$deplib $newdependency_libs" + newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` + ;; + prog) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + if test "$pass" = scan; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` + ;; + *) + $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2 + ;; + esac # linkmode + continue + ;; # -L + -R*) + if test "$pass" = link; then + dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'` + # Make sure the xrpath contains only unique directories. + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + fi + deplibs="$deplib $deplibs" + continue + ;; + *.la) lib="$deplib" ;; + *.$libext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + case $linkmode in + lib) + valid_a_lib=no + case $deplibs_check_method in + match_pattern*) + set dummy $deplibs_check_method + match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` + if eval $echo \"$deplib\" 2>/dev/null \ + | $SED 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + valid_a_lib=yes + fi + ;; + pass_all) + valid_a_lib=yes + ;; + esac + if test "$valid_a_lib" != yes; then + $echo + $echo "*** Warning: Trying to link with static lib archive $deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because the file extensions .$libext of this argument makes me believe" + $echo "*** that it is just a static archive that I should not used here." + else + $echo + $echo "*** Warning: Linking the shared library $output against the" + $echo "*** static library $deplib is not portable!" + deplibs="$deplib $deplibs" + fi + continue + ;; + prog) + if test "$pass" != link; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + continue + ;; + esac # linkmode + ;; # *.$libext + *.lo | *.$objext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + elif test "$linkmode" = prog; then + if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then + # If there is no dlopen support or we're linking statically, + # we need to preload. + newdlprefiles="$newdlprefiles $deplib" + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + newdlfiles="$newdlfiles $deplib" + fi + fi + continue + ;; + %DEPLIBS%) + alldeplibs=yes + continue + ;; + esac # case $deplib + if test "$found" = yes || test -f "$lib"; then : + else + $echo "$modename: cannot find the library \`$lib' or unhandled argument \`$deplib'" 1>&2 + exit $EXIT_FAILURE + fi + + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + + ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` + test "X$ladir" = "X$lib" && ladir="." + + dlname= + dlopen= + dlpreopen= + libdir= + library_names= + old_library= + # If the library was installed with an old release of libtool, + # it will not redefine variables installed, or shouldnotlink + installed=yes + shouldnotlink=no + avoidtemprpath= + + + # Read the .la file + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan" || + { test "$linkmode" != prog && test "$linkmode" != lib; }; then + test -n "$dlopen" && dlfiles="$dlfiles $dlopen" + test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" + fi + + if test "$pass" = conv; then + # Only check for convenience libraries + deplibs="$lib $deplibs" + if test -z "$libdir"; then + if test -z "$old_library"; then + $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + # It is a libtool convenience library, so add in its objects. + convenience="$convenience $ladir/$objdir/$old_library" + old_convenience="$old_convenience $ladir/$objdir/$old_library" + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + elif test "$linkmode" != prog && test "$linkmode" != lib; then + $echo "$modename: \`$lib' is not a convenience library" 1>&2 + exit $EXIT_FAILURE + fi + continue + fi # $pass = conv + + + # Get the name of the library we link against. + linklib= + for l in $old_library $library_names; do + linklib="$l" + done + if test -z "$linklib"; then + $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + + # This library was specified with -dlopen. + if test "$pass" = dlopen; then + if test -z "$libdir"; then + $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + if test -z "$dlname" || + test "$dlopen_support" != yes || + test "$build_libtool_libs" = no; then + # If there is no dlname, no dlopen support or we're linking + # statically, we need to preload. We also need to preload any + # dependent libraries so libltdl's deplib preloader doesn't + # bomb out in the load deplibs phase. + dlprefiles="$dlprefiles $lib $dependency_libs" + else + newdlfiles="$newdlfiles $lib" + fi + continue + fi # $pass = dlopen + + # We need an absolute path. + case $ladir in + [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; + *) + abs_ladir=`cd "$ladir" && pwd` + if test -z "$abs_ladir"; then + $echo "$modename: warning: cannot determine absolute directory name of \`$ladir'" 1>&2 + $echo "$modename: passing it literally to the linker, although it might fail" 1>&2 + abs_ladir="$ladir" + fi + ;; + esac + laname=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + + # Find the relevant object directory and library name. + if test "X$installed" = Xyes; then + if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then + $echo "$modename: warning: library \`$lib' was moved." 1>&2 + dir="$ladir" + absdir="$abs_ladir" + libdir="$abs_ladir" + else + dir="$libdir" + absdir="$libdir" + fi + test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes + else + if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then + dir="$ladir" + absdir="$abs_ladir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + else + dir="$ladir/$objdir" + absdir="$abs_ladir/$objdir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + fi + fi # $installed = yes + name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` + + # This library was specified with -dlpreopen. + if test "$pass" = dlpreopen; then + if test -z "$libdir"; then + $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + # Prefer using a static library (so that no silly _DYNAMIC symbols + # are required to link). + if test -n "$old_library"; then + newdlprefiles="$newdlprefiles $dir/$old_library" + # Otherwise, use the dlname, so that lt_dlopen finds it. + elif test -n "$dlname"; then + newdlprefiles="$newdlprefiles $dir/$dlname" + else + newdlprefiles="$newdlprefiles $dir/$linklib" + fi + fi # $pass = dlpreopen + + if test -z "$libdir"; then + # Link the convenience library + if test "$linkmode" = lib; then + deplibs="$dir/$old_library $deplibs" + elif test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$dir/$old_library $compile_deplibs" + finalize_deplibs="$dir/$old_library $finalize_deplibs" + else + deplibs="$lib $deplibs" # used for prog,scan pass + fi + continue + fi + + + if test "$linkmode" = prog && test "$pass" != link; then + newlib_search_path="$newlib_search_path $ladir" + deplibs="$lib $deplibs" + + linkalldeplibs=no + if test "$link_all_deplibs" != no || test -z "$library_names" || + test "$build_libtool_libs" = no; then + linkalldeplibs=yes + fi + + tmp_libs= + for deplib in $dependency_libs; do + case $deplib in + -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test + esac + # Need to link against all dependency_libs? + if test "$linkalldeplibs" = yes; then + deplibs="$deplib $deplibs" + else + # Need to hardcode shared library paths + # or/and link against static libraries + newdependency_libs="$deplib $newdependency_libs" + fi + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done # for deplib + continue + fi # $linkmode = prog... + + if test "$linkmode,$pass" = "prog,link"; then + if test -n "$library_names" && + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then + # We need to hardcode the library path + if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then + # Make sure the rpath contains only unique directories. + case "$temp_rpath " in + *" $dir "*) ;; + *" $absdir "*) ;; + *) temp_rpath="$temp_rpath $absdir" ;; + esac + fi + + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi # $linkmode,$pass = prog,link... + + if test "$alldeplibs" = yes && + { test "$deplibs_check_method" = pass_all || + { test "$build_libtool_libs" = yes && + test -n "$library_names"; }; }; then + # We only need to search for static libraries + continue + fi + fi + + link_static=no # Whether the deplib will be linked statically + use_static_libs=$prefer_static_libs + if test "$use_static_libs" = built && test "$installed" = yes ; then + use_static_libs=no + fi + if test -n "$library_names" && + { test "$use_static_libs" = no || test -z "$old_library"; }; then + if test "$installed" = no; then + notinst_deplibs="$notinst_deplibs $lib" + need_relink=yes + fi + # This is a shared library + + # Warn about portability, can't link against -module's on + # some systems (darwin) + if test "$shouldnotlink" = yes && test "$pass" = link ; then + $echo + if test "$linkmode" = prog; then + $echo "*** Warning: Linking the executable $output against the loadable module" + else + $echo "*** Warning: Linking the shared library $output against the loadable module" + fi + $echo "*** $linklib is not portable!" + fi + if test "$linkmode" = lib && + test "$hardcode_into_libs" = yes; then + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi + + if test -n "$old_archive_from_expsyms_cmds"; then + # figure out the soname + set dummy $library_names + realname="$2" + shift; shift + libname=`eval \\$echo \"$libname_spec\"` + # use dlname if we got it. it's perfectly good, no? + if test -n "$dlname"; then + soname="$dlname" + elif test -n "$soname_spec"; then + # bleh windows + case $host in + *cygwin* | mingw*) + major=`expr $current - $age` + versuffix="-$major" + ;; + esac + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + + # Make a new name for the extract_expsyms_cmds to use + soroot="$soname" + soname=`$echo $soroot | ${SED} -e 's/^.*\///'` + newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a" + + # If the library has no export list, then create one now + if test -f "$output_objdir/$soname-def"; then : + else + $show "extracting exported symbol list from \`$soname'" + save_ifs="$IFS"; IFS='~' + cmds=$extract_expsyms_cmds + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + + # Create $newlib + if test -f "$output_objdir/$newlib"; then :; else + $show "generating import library for \`$soname'" + save_ifs="$IFS"; IFS='~' + cmds=$old_archive_from_expsyms_cmds + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + # make sure the library variables are pointing to the new library + dir=$output_objdir + linklib=$newlib + fi # test -n "$old_archive_from_expsyms_cmds" + + if test "$linkmode" = prog || test "$mode" != relink; then + add_shlibpath= + add_dir= + add= + lib_linked=yes + case $hardcode_action in + immediate | unsupported) + if test "$hardcode_direct" = no; then + add="$dir/$linklib" + case $host in + *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; + *-*-sysv4*uw2*) add_dir="-L$dir" ;; + *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ + *-*-unixware7*) add_dir="-L$dir" ;; + *-*-darwin* ) + # if the lib is a module then we can not link against + # it, someone is ignoring the new warnings I added + if /usr/bin/file -L $add 2> /dev/null | + $EGREP ": [^:]* bundle" >/dev/null ; then + $echo "** Warning, lib $linklib is a module, not a shared library" + if test -z "$old_library" ; then + $echo + $echo "** And there doesn't seem to be a static archive available" + $echo "** The link will probably fail, sorry" + else + add="$dir/$old_library" + fi + fi + esac + elif test "$hardcode_minus_L" = no; then + case $host in + *-*-sunos*) add_shlibpath="$dir" ;; + esac + add_dir="-L$dir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = no; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + relink) + if test "$hardcode_direct" = yes; then + add="$dir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$dir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + *) lib_linked=no ;; + esac + + if test "$lib_linked" != yes; then + $echo "$modename: configuration error: unsupported hardcode properties" + exit $EXIT_FAILURE + fi + + if test -n "$add_shlibpath"; then + case :$compile_shlibpath: in + *":$add_shlibpath:"*) ;; + *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; + esac + fi + if test "$linkmode" = prog; then + test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" + test -n "$add" && compile_deplibs="$add $compile_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + if test "$hardcode_direct" != yes && \ + test "$hardcode_minus_L" != yes && \ + test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + fi + fi + fi + + if test "$linkmode" = prog || test "$mode" = relink; then + add_shlibpath= + add_dir= + add= + # Finalize command for both is simple: just hardcode it. + if test "$hardcode_direct" = yes; then + add="$libdir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$libdir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + add="-l$name" + elif test "$hardcode_automatic" = yes; then + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib" ; then + add="$inst_prefix_dir$libdir/$linklib" + else + add="$libdir/$linklib" + fi + else + # We cannot seem to hardcode it, guess we'll fake it. + add_dir="-L$libdir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + fi + + if test "$linkmode" = prog; then + test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" + test -n "$add" && finalize_deplibs="$add $finalize_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + fi + fi + elif test "$linkmode" = prog; then + # Here we assume that one of hardcode_direct or hardcode_minus_L + # is not unsupported. This is valid on all known static and + # shared platforms. + if test "$hardcode_direct" != unsupported; then + test -n "$old_library" && linklib="$old_library" + compile_deplibs="$dir/$linklib $compile_deplibs" + finalize_deplibs="$dir/$linklib $finalize_deplibs" + else + compile_deplibs="-l$name -L$dir $compile_deplibs" + finalize_deplibs="-l$name -L$dir $finalize_deplibs" + fi + elif test "$build_libtool_libs" = yes; then + # Not a shared library + if test "$deplibs_check_method" != pass_all; then + # We're trying link a shared library against a static one + # but the system doesn't support it. + + # Just print a warning and add the library to dependency_libs so + # that the program can be linked against the static library. + $echo + $echo "*** Warning: This system can not link to static lib archive $lib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have." + if test "$module" = yes; then + $echo "*** But as you try to build a module library, libtool will still create " + $echo "*** a static module, that should work as long as the dlopening application" + $echo "*** is linked with the -dlopen flag to resolve symbols at runtime." + if test -z "$global_symbol_pipe"; then + $echo + $echo "*** However, this would only work if libtool was able to extract symbol" + $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" + $echo "*** not find such a program. So, this module is probably useless." + $echo "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + else + deplibs="$dir/$old_library $deplibs" + link_static=yes + fi + fi # link shared/static library? + + if test "$linkmode" = lib; then + if test -n "$dependency_libs" && + { test "$hardcode_into_libs" != yes || + test "$build_old_libs" = yes || + test "$link_static" = yes; }; then + # Extract -R from dependency_libs + temp_deplibs= + for libdir in $dependency_libs; do + case $libdir in + -R*) temp_xrpath=`$echo "X$libdir" | $Xsed -e 's/^-R//'` + case " $xrpath " in + *" $temp_xrpath "*) ;; + *) xrpath="$xrpath $temp_xrpath";; + esac;; + *) temp_deplibs="$temp_deplibs $libdir";; + esac + done + dependency_libs="$temp_deplibs" + fi + + newlib_search_path="$newlib_search_path $absdir" + # Link against this library + test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" + # ... and its dependency_libs + tmp_libs= + for deplib in $dependency_libs; do + newdependency_libs="$deplib $newdependency_libs" + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + + if test "$link_all_deplibs" != no; then + # Add the search paths of all dependency libraries + for deplib in $dependency_libs; do + case $deplib in + -L*) path="$deplib" ;; + *.la) + dir=`$echo "X$deplib" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$deplib" && dir="." + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2 + absdir="$dir" + fi + ;; + esac + if grep "^installed=no" $deplib > /dev/null; then + path="$absdir/$objdir" + else + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + if test -z "$libdir"; then + $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + if test "$absdir" != "$libdir"; then + $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2 + fi + path="$absdir" + fi + depdepl= + case $host in + *-*-darwin*) + # we do not want to link against static libs, + # but need to link against shared + eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + if test -n "$deplibrary_names" ; then + for tmp in $deplibrary_names ; do + depdepl=$tmp + done + if test -f "$path/$depdepl" ; then + depdepl="$path/$depdepl" + fi + # do not add paths which are already there + case " $newlib_search_path " in + *" $path "*) ;; + *) newlib_search_path="$newlib_search_path $path";; + esac + fi + path="" + ;; + *) + path="-L$path" + ;; + esac + ;; + -l*) + case $host in + *-*-darwin*) + # Again, we only want to link against shared libraries + eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"` + for tmp in $newlib_search_path ; do + if test -f "$tmp/lib$tmp_libs.dylib" ; then + eval depdepl="$tmp/lib$tmp_libs.dylib" + break + fi + done + path="" + ;; + *) continue ;; + esac + ;; + *) continue ;; + esac + case " $deplibs " in + *" $path "*) ;; + *) deplibs="$path $deplibs" ;; + esac + case " $deplibs " in + *" $depdepl "*) ;; + *) deplibs="$depdepl $deplibs" ;; + esac + done + fi # link_all_deplibs != no + fi # linkmode = lib + done # for deplib in $libs + dependency_libs="$newdependency_libs" + if test "$pass" = dlpreopen; then + # Link the dlpreopened libraries before other libraries + for deplib in $save_deplibs; do + deplibs="$deplib $deplibs" + done + fi + if test "$pass" != dlopen; then + if test "$pass" != conv; then + # Make sure lib_search_path contains only unique directories. + lib_search_path= + for dir in $newlib_search_path; do + case "$lib_search_path " in + *" $dir "*) ;; + *) lib_search_path="$lib_search_path $dir" ;; + esac + done + newlib_search_path= + fi + + if test "$linkmode,$pass" != "prog,link"; then + vars="deplibs" + else + vars="compile_deplibs finalize_deplibs" + fi + for var in $vars dependency_libs; do + # Add libraries to $var in reverse order + eval tmp_libs=\"\$$var\" + new_libs= + for deplib in $tmp_libs; do + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: + #new_libs="$deplib $new_libs" + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; + *) + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; + esac + done + tmp_libs= + for deplib in $new_libs; do + case $deplib in + -L*) + case " $tmp_libs " in + *" $deplib "*) ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + done + eval $var=\"$tmp_libs\" + done # for var + fi + # Last step: remove runtime libs from dependency_libs + # (they stay in deplibs) + tmp_libs= + for i in $dependency_libs ; do + case " $predeps $postdeps $compiler_lib_search_path " in + *" $i "*) + i="" + ;; + esac + if test -n "$i" ; then + tmp_libs="$tmp_libs $i" + fi + done + dependency_libs=$tmp_libs + done # for pass + if test "$linkmode" = prog; then + dlfiles="$newdlfiles" + dlprefiles="$newdlprefiles" + fi + + case $linkmode in + oldlib) + if test -n "$deplibs"; then + $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 + fi + + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 + fi + + if test -n "$rpath"; then + $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2 + fi + + if test -n "$xrpath"; then + $echo "$modename: warning: \`-R' is ignored for archives" 1>&2 + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for archives" 1>&2 + fi + + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2 + fi + + # Now set the variables for building old libraries. + build_libtool_libs=no + oldlibs="$output" + objs="$objs$old_deplibs" + ;; + + lib) + # Make sure we only generate libraries of the form `libNAME.la'. + case $outputname in + lib*) + name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + ;; + *) + if test "$module" = no; then + $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + if test "$need_lib_prefix" != no; then + # Add the "lib" prefix for modules if required + name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + else + libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` + fi + ;; + esac + + if test -n "$objs"; then + if test "$deplibs_check_method" != pass_all; then + $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1 + exit $EXIT_FAILURE + else + $echo + $echo "*** Warning: Linking the shared library $output against the non-libtool" + $echo "*** objects $objs is not portable!" + libobjs="$libobjs $objs" + fi + fi + + if test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen self' is ignored for libtool libraries" 1>&2 + fi + + set dummy $rpath + if test "$#" -gt 2; then + $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2 + fi + install_libdir="$2" + + oldlibs= + if test -z "$rpath"; then + if test "$build_libtool_libs" = yes; then + # Building a libtool convenience library. + # Some compilers have problems with a `.al' extension so + # convenience libraries should have the same extension an + # archive normally would. + oldlibs="$output_objdir/$libname.$libext $oldlibs" + build_libtool_libs=convenience + build_old_libs=yes + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2 + fi + else + + # Parse the version information argument. + save_ifs="$IFS"; IFS=':' + set dummy $vinfo 0 0 0 + IFS="$save_ifs" + + if test -n "$8"; then + $echo "$modename: too many parameters to \`-version-info'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # convert absolute version numbers to libtool ages + # this retains compatibility with .la files and attempts + # to make the code below a bit more comprehensible + + case $vinfo_number in + yes) + number_major="$2" + number_minor="$3" + number_revision="$4" + # + # There are really only two kinds -- those that + # use the current revision as the major version + # and those that subtract age and use age as + # a minor version. But, then there is irix + # which has an extra 1 added just for fun + # + case $version_type in + darwin|linux|osf|windows|none) + current=`expr $number_major + $number_minor` + age="$number_minor" + revision="$number_revision" + ;; + freebsd-aout|freebsd-elf|sunos) + current="$number_major" + revision="$number_minor" + age="0" + ;; + irix|nonstopux) + current=`expr $number_major + $number_minor - 1` + age="$number_minor" + revision="$number_minor" + ;; + esac + ;; + no) + current="$2" + revision="$3" + age="$4" + ;; + esac + + # Check that each of the things are valid numbers. + case $current in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: CURRENT \`$current' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $revision in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: REVISION \`$revision' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $age in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: AGE \`$age' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + if test "$age" -gt "$current"; then + $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + fi + + # Calculate the version variables. + major= + versuffix= + verstring= + case $version_type in + none) ;; + + darwin) + # Like Linux, but with the current version available in + # verstring for coding it into the library header + major=.`expr $current - $age` + versuffix="$major.$age.$revision" + # Darwin ld doesn't like 0 for these options... + minor_current=`expr $current + 1` + verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + ;; + + freebsd-aout) + major=".$current" + versuffix=".$current.$revision"; + ;; + + freebsd-elf) + major=".$current" + versuffix=".$current"; + ;; + + irix | nonstopux) + major=`expr $current - $age + 1` + + case $version_type in + nonstopux) verstring_prefix=nonstopux ;; + *) verstring_prefix=sgi ;; + esac + verstring="$verstring_prefix$major.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$revision + while test "$loop" -ne 0; do + iface=`expr $revision - $loop` + loop=`expr $loop - 1` + verstring="$verstring_prefix$major.$iface:$verstring" + done + + # Before this point, $major must not contain `.'. + major=.$major + versuffix="$major.$revision" + ;; + + linux) + major=.`expr $current - $age` + versuffix="$major.$age.$revision" + ;; + + osf) + major=.`expr $current - $age` + versuffix=".$current.$age.$revision" + verstring="$current.$age.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$age + while test "$loop" -ne 0; do + iface=`expr $current - $loop` + loop=`expr $loop - 1` + verstring="$verstring:${iface}.0" + done + + # Make executables depend on our current version. + verstring="$verstring:${current}.0" + ;; + + sunos) + major=".$current" + versuffix=".$current.$revision" + ;; + + windows) + # Use '-' rather than '.', since we only want one + # extension on DOS 8.3 filesystems. + major=`expr $current - $age` + versuffix="-$major" + ;; + + *) + $echo "$modename: unknown library version type \`$version_type'" 1>&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE + ;; + esac + + # Clear the version info if we defaulted, and they specified a release. + if test -z "$vinfo" && test -n "$release"; then + major= + case $version_type in + darwin) + # we can't check for "0.0" in archive_cmds due to quoting + # problems, so we reset it completely + verstring= + ;; + *) + verstring="0.0" + ;; + esac + if test "$need_version" = no; then + versuffix= + else + versuffix=".0.0" + fi + fi + + # Remove version info from name if versioning should be avoided + if test "$avoid_version" = yes && test "$need_version" = no; then + major= + versuffix= + verstring="" + fi + + # Check to see if the archive will have undefined symbols. + if test "$allow_undefined" = yes; then + if test "$allow_undefined_flag" = unsupported; then + $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2 + build_libtool_libs=no + build_old_libs=yes + fi + else + # Don't allow undefined symbols. + allow_undefined_flag="$no_undefined_flag" + fi + fi + + if test "$mode" != relink; then + # Remove our outputs, but don't remove object files since they + # may have been created when compiling PIC objects. + removelist= + tempremovelist=`$echo "$output_objdir/*"` + for p in $tempremovelist; do + case $p in + *.$objext) + ;; + $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) + if test "X$precious_files_regex" != "X"; then + if echo $p | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 + then + continue + fi + fi + removelist="$removelist $p" + ;; + *) ;; + esac + done + if test -n "$removelist"; then + $show "${rm}r $removelist" + $run ${rm}r $removelist + fi + fi + + # Now set the variables for building old libraries. + if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then + oldlibs="$oldlibs $output_objdir/$libname.$libext" + + # Transform .lo files to .o files. + oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` + fi + + # Eliminate all temporary directories. +# for path in $notinst_path; do +# lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` +# deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` +# dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` +# done + + if test -n "$xrpath"; then + # If the user specified any rpath flags, then add them. + temp_xrpath= + for libdir in $xrpath; do + temp_xrpath="$temp_xrpath -R$libdir" + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then + dependency_libs="$temp_xrpath $dependency_libs" + fi + fi + + # Make sure dlfiles contains only unique files that won't be dlpreopened + old_dlfiles="$dlfiles" + dlfiles= + for lib in $old_dlfiles; do + case " $dlprefiles $dlfiles " in + *" $lib "*) ;; + *) dlfiles="$dlfiles $lib" ;; + esac + done + + # Make sure dlprefiles contains only unique files + old_dlprefiles="$dlprefiles" + dlprefiles= + for lib in $old_dlprefiles; do + case "$dlprefiles " in + *" $lib "*) ;; + *) dlprefiles="$dlprefiles $lib" ;; + esac + done + + if test "$build_libtool_libs" = yes; then + if test -n "$rpath"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos*) + # these systems don't actually have a c library (as such)! + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C library is in the System framework + deplibs="$deplibs -framework System" + ;; + *-*-netbsd*) + # Don't link with libc until the a.out ld.so is fixed. + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + ;; + *) + # Add libc to deplibs on all other systems if necessary. + if test "$build_libtool_need_lc" = "yes"; then + deplibs="$deplibs -lc" + fi + ;; + esac + fi + + # Transform deplibs into only deplibs that can be linked in shared. + name_save=$name + libname_save=$libname + release_save=$release + versuffix_save=$versuffix + major_save=$major + # I'm not sure if I'm treating the release correctly. I think + # release should show up in the -l (ie -lgmp5) so we don't want to + # add it in twice. Is that correct? + release="" + versuffix="" + major="" + newdeplibs= + droppeddeps=no + case $deplibs_check_method in + pass_all) + # Don't check for shared/static. Everything works. + # This might be a little naive. We might want to check + # whether the library exists or not. But this is on + # osf3 & osf4 and I'm not really sure... Just + # implementing what was already the behavior. + newdeplibs=$deplibs + ;; + test_compile) + # This code stresses the "libraries are programs" paradigm to its + # limits. Maybe even breaks it. We compile a program, linking it + # against the deplibs as a proxy for the library. Then we can check + # whether they linked in statically or dynamically with ldd. + $rm conftest.c + cat > conftest.c </dev/null` + for potent_lib in $potential_libs; do + # Follow soft links. + if ls -lLd "$potent_lib" 2>/dev/null \ + | grep " -> " >/dev/null; then + continue + fi + # The statement above tries to avoid entering an + # endless loop below, in case of cyclic links. + # We might still enter an endless loop, since a link + # loop can be closed while we follow links, + # but so what? + potlib="$potent_lib" + while test -h "$potlib" 2>/dev/null; do + potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` + case $potliblink in + [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; + *) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; + esac + done + if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \ + | ${SED} 10q \ + | $EGREP "$file_magic_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $echo + $echo "*** Warning: linker path does not have real file for library $a_deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $echo "*** with $libname but no candidates were found. (...for file magic test)" + else + $echo "*** with $libname and none of the candidates passed a file format test" + $echo "*** using a file magic. Last file checked: $potlib" + fi + fi + else + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + fi + done # Gone through all deplibs. + ;; + match_pattern*) + set dummy $deplibs_check_method + match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` + for a_deplib in $deplibs; do + name=`expr $a_deplib : '-l\(.*\)'` + # If $name is empty we are operating on a -L argument. + if test -n "$name" && test "$name" != "0"; then + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $a_deplib "*) + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + ;; + esac + fi + if test -n "$a_deplib" ; then + libname=`eval \\$echo \"$libname_spec\"` + for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do + potential_libs=`ls $i/$libname[.-]* 2>/dev/null` + for potent_lib in $potential_libs; do + potlib="$potent_lib" # see symlink-check above in file_magic test + if eval $echo \"$potent_lib\" 2>/dev/null \ + | ${SED} 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $echo + $echo "*** Warning: linker path does not have real file for library $a_deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $echo "*** with $libname but no candidates were found. (...for regex pattern test)" + else + $echo "*** with $libname and none of the candidates passed a file format test" + $echo "*** using a regex pattern. Last file checked: $potlib" + fi + fi + else + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + fi + done # Gone through all deplibs. + ;; + none | unknown | *) + newdeplibs="" + tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \ + -e 's/ -[LR][^ ]*//g'` + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + for i in $predeps $postdeps ; do + # can't use Xsed below, because $i might contain '/' + tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"` + done + fi + if $echo "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' \ + | grep . >/dev/null; then + $echo + if test "X$deplibs_check_method" = "Xnone"; then + $echo "*** Warning: inter-library dependencies are not supported in this platform." + else + $echo "*** Warning: inter-library dependencies are not known to be supported." + fi + $echo "*** All declared inter-library dependencies are being dropped." + droppeddeps=yes + fi + ;; + esac + versuffix=$versuffix_save + major=$major_save + release=$release_save + libname=$libname_save + name=$name_save + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + newdeplibs=`$echo "X $newdeplibs" | $Xsed -e 's/ -lc / -framework System /'` + ;; + esac + + if test "$droppeddeps" = yes; then + if test "$module" = yes; then + $echo + $echo "*** Warning: libtool could not satisfy all declared inter-library" + $echo "*** dependencies of module $libname. Therefore, libtool will create" + $echo "*** a static module, that should work as long as the dlopening" + $echo "*** application is linked with the -dlopen flag." + if test -z "$global_symbol_pipe"; then + $echo + $echo "*** However, this would only work if libtool was able to extract symbol" + $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" + $echo "*** not find such a program. So, this module is probably useless." + $echo "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + else + $echo "*** The inter-library dependencies that have been dropped here will be" + $echo "*** automatically added whenever a program is linked with this library" + $echo "*** or is declared to -dlopen it." + + if test "$allow_undefined" = no; then + $echo + $echo "*** Since this library must not contain undefined symbols," + $echo "*** because either the platform does not support them or" + $echo "*** it was explicitly requested with -no-undefined," + $echo "*** libtool will only create a static version of it." + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + fi + fi + # Done checking deplibs! + deplibs=$newdeplibs + fi + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + deplibs="$new_libs" + + + # All the library-specific variables (install_libdir is set above). + library_names= + old_library= + dlname= + + # Test again, we may have decided not to build it any more + if test "$build_libtool_libs" = yes; then + if test "$hardcode_into_libs" = yes; then + # Hardcode the library paths + hardcode_libdirs= + dep_rpath= + rpath="$finalize_rpath" + test "$mode" != relink && rpath="$compile_rpath$rpath" + for libdir in $rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + dep_rpath="$dep_rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + if test -n "$hardcode_libdir_flag_spec_ld"; then + eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" + else + eval dep_rpath=\"$hardcode_libdir_flag_spec\" + fi + fi + if test -n "$runpath_var" && test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" + fi + test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" + fi + + shlibpath="$finalize_shlibpath" + test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" + if test -n "$shlibpath"; then + eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" + fi + + # Get the real and link names of the library. + eval shared_ext=\"$shrext_cmds\" + eval library_names=\"$library_names_spec\" + set dummy $library_names + realname="$2" + shift; shift + + if test -n "$soname_spec"; then + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + if test -z "$dlname"; then + dlname=$soname + fi + + lib="$output_objdir/$realname" + linknames= + for link + do + linknames="$linknames $link" + done + + # Use standard objects if they are pic + test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then + $show "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $run $rm $export_symbols + cmds=$export_symbols_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + if len=`expr "X$cmd" : ".*"` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + $show "$cmd" + $run eval "$cmd" || exit $? + skipped_export=false + else + # The command line is too long to execute in one step. + $show "using reloadable object file for export list..." + skipped_export=: + # Break out early, otherwise skipped_export may be + # set to false by a later but shorter cmd. + break + fi + done + IFS="$save_ifs" + if test -n "$export_symbols_regex"; then + $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"" + $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + $show "$mv \"${export_symbols}T\" \"$export_symbols\"" + $run eval '$mv "${export_symbols}T" "$export_symbols"' + fi + fi + fi + + if test -n "$export_symbols" && test -n "$include_expsyms"; then + $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"' + fi + + tmp_deplibs= + for test_deplib in $deplibs; do + case " $convenience " in + *" $test_deplib "*) ;; + *) + tmp_deplibs="$tmp_deplibs $test_deplib" + ;; + esac + done + deplibs="$tmp_deplibs" + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + else + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + libobjs="$libobjs $func_extract_archives_result" + fi + fi + + if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then + eval flag=\"$thread_safe_flag_spec\" + linker_flags="$linker_flags $flag" + fi + + # Make a backup of the uninstalled library when relinking + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}U && $mv $realname ${realname}U)' || exit $? + fi + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + eval test_cmds=\"$module_expsym_cmds\" + cmds=$module_expsym_cmds + else + eval test_cmds=\"$module_cmds\" + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + eval test_cmds=\"$archive_expsym_cmds\" + cmds=$archive_expsym_cmds + else + eval test_cmds=\"$archive_cmds\" + cmds=$archive_cmds + fi + fi + + if test "X$skipped_export" != "X:" && + len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + : + else + # The command line is too long to link in one step, link piecewise. + $echo "creating reloadable object files..." + + # Save the value of $output and $libobjs because we want to + # use them later. If we have whole_archive_flag_spec, we + # want to use save_libobjs as it was before + # whole_archive_flag_spec was expanded, because we can't + # assume the linker understands whole_archive_flag_spec. + # This may have to be revisited, in case too many + # convenience libraries get linked in and end up exceeding + # the spec. + if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + fi + save_output=$output + output_la=`$echo "X$output" | $Xsed -e "$basename"` + + # Clear the reloadable object creation command queue and + # initialize k to one. + test_cmds= + concat_cmds= + objlist= + delfiles= + last_robj= + k=1 + output=$output_objdir/$output_la-${k}.$objext + # Loop over the list of objects to be linked. + for obj in $save_libobjs + do + eval test_cmds=\"$reload_cmds $objlist $last_robj\" + if test "X$objlist" = X || + { len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len"; }; then + objlist="$objlist $obj" + else + # The command $test_cmds is almost too long, add a + # command to the queue. + if test "$k" -eq 1 ; then + # The first file doesn't have a previous command to add. + eval concat_cmds=\"$reload_cmds $objlist $last_robj\" + else + # All subsequent reloadable object files will link in + # the last one created. + eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\" + fi + last_robj=$output_objdir/$output_la-${k}.$objext + k=`expr $k + 1` + output=$output_objdir/$output_la-${k}.$objext + objlist=$obj + len=1 + fi + done + # Handle the remaining objects by creating one last + # reloadable object file. All subsequent reloadable object + # files will link in the last one created. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" + + if ${skipped_export-false}; then + $show "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $run $rm $export_symbols + libobjs=$output + # Append the command to create the export file. + eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\" + fi + + # Set up a command to remove the reloadable object files + # after they are used. + i=0 + while test "$i" -lt "$k" + do + i=`expr $i + 1` + delfiles="$delfiles $output_objdir/$output_la-${i}.$objext" + done + + $echo "creating a temporary reloadable object file: $output" + + # Loop through the commands generated above and execute them. + save_ifs="$IFS"; IFS='~' + for cmd in $concat_cmds; do + IFS="$save_ifs" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + + libobjs=$output + # Restore the value of output. + output=$save_output + + if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + fi + # Expand the library linking commands again to reset the + # value of $libobjs for piecewise linking. + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + cmds=$module_expsym_cmds + else + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + cmds=$archive_expsym_cmds + else + cmds=$archive_cmds + fi + fi + + # Append the command to remove the reloadable object files + # to the just-reset $cmds. + eval cmds=\"\$cmds~\$rm $delfiles\" + fi + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $? + + if test -n "$convenience"; then + if test -z "$whole_archive_flag_spec"; then + $show "${rm}r $gentop" + $run ${rm}r "$gentop" + fi + fi + + exit $EXIT_SUCCESS + fi + + # Create links to the real library. + for linkname in $linknames; do + if test "$realname" != "$linkname"; then + $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)" + $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $? + fi + done + + # If -module or -export-dynamic was specified, set the dlname. + if test "$module" = yes || test "$export_dynamic" = yes; then + # On all known operating systems, these are identical. + dlname="$soname" + fi + fi + ;; + + obj) + if test -n "$deplibs"; then + $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 + fi + + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 + fi + + if test -n "$rpath"; then + $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2 + fi + + if test -n "$xrpath"; then + $echo "$modename: warning: \`-R' is ignored for objects" 1>&2 + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for objects" 1>&2 + fi + + case $output in + *.lo) + if test -n "$objs$old_deplibs"; then + $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2 + exit $EXIT_FAILURE + fi + libobj="$output" + obj=`$echo "X$output" | $Xsed -e "$lo2o"` + ;; + *) + libobj= + obj="$output" + ;; + esac + + # Delete the old objects. + $run $rm $obj $libobj + + # Objects from convenience libraries. This assumes + # single-version convenience libraries. Whenever we create + # different ones for PIC/non-PIC, this we'll have to duplicate + # the extraction. + reload_conv_objs= + gentop= + # reload_cmds runs $LD directly, so let us get rid of + # -Wl from whole_archive_flag_spec and hope we can get by with + # turning comma into space.. + wl= + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" + reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + else + gentop="$output_objdir/${obj}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + reload_conv_objs="$reload_objs $func_extract_archives_result" + fi + fi + + # Create the old-style object. + reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test + + output="$obj" + cmds=$reload_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + + # Exit if we aren't doing a library object file. + if test -z "$libobj"; then + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + exit $EXIT_SUCCESS + fi + + if test "$build_libtool_libs" != yes; then + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + # Create an invalid libtool object if no PIC, so that we don't + # accidentally link it into a program. + # $show "echo timestamp > $libobj" + # $run eval "echo timestamp > $libobj" || exit $? + exit $EXIT_SUCCESS + fi + + if test -n "$pic_flag" || test "$pic_mode" != default; then + # Only do commands if we really have different PIC objects. + reload_objs="$libobjs $reload_conv_objs" + output="$libobj" + cmds=$reload_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + exit $EXIT_SUCCESS + ;; + + prog) + case $host in + *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;; + esac + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for programs" 1>&2 + fi + + if test "$preload" = yes; then + if test "$dlopen_support" = unknown && test "$dlopen_self" = unknown && + test "$dlopen_self_static" = unknown; then + $echo "$modename: warning: \`AC_LIBTOOL_DLOPEN' not used. Assuming no dlopen support." + fi + fi + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + compile_deplibs=`$echo "X $compile_deplibs" | $Xsed -e 's/ -lc / -framework System /'` + finalize_deplibs=`$echo "X $finalize_deplibs" | $Xsed -e 's/ -lc / -framework System /'` + ;; + esac + + case $host in + *darwin*) + # Don't allow lazy linking, it breaks C++ global constructors + if test "$tagname" = CXX ; then + compile_command="$compile_command ${wl}-bind_at_load" + finalize_command="$finalize_command ${wl}-bind_at_load" + fi + ;; + esac + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $compile_deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $compile_deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + compile_deplibs="$new_libs" + + + compile_command="$compile_command $compile_deplibs" + finalize_command="$finalize_command $finalize_deplibs" + + if test -n "$rpath$xrpath"; then + # If the user specified any rpath flags, then add them. + for libdir in $rpath $xrpath; do + # This is the magic to use -rpath. + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + fi + + # Now hardcode the library paths + rpath= + hardcode_libdirs= + for libdir in $compile_rpath $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + testbindir=`$echo "X$libdir" | $Xsed -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$libdir:"*) ;; + *) dllsearchpath="$dllsearchpath:$libdir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + compile_rpath="$rpath" + + rpath= + hardcode_libdirs= + for libdir in $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$finalize_perm_rpath " in + *" $libdir "*) ;; + *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + finalize_rpath="$rpath" + + if test -n "$libobjs" && test "$build_old_libs" = yes; then + # Transform all the library objects into standard objects. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + fi + + dlsyms= + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + dlsyms="${outputname}S.c" + else + $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 + fi + fi + + if test -n "$dlsyms"; then + case $dlsyms in + "") ;; + *.c) + # Discover the nlist of each of the dlfiles. + nlist="$output_objdir/${outputname}.nm" + + $show "$rm $nlist ${nlist}S ${nlist}T" + $run $rm "$nlist" "${nlist}S" "${nlist}T" + + # Parse the name list into a source file. + $show "creating $output_objdir/$dlsyms" + + test -z "$run" && $echo > "$output_objdir/$dlsyms" "\ +/* $dlsyms - symbol resolution table for \`$outputname' dlsym emulation. */ +/* Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP */ + +#ifdef __cplusplus +extern \"C\" { +#endif + +/* Prevent the only kind of declaration conflicts we can make. */ +#define lt_preloaded_symbols some_other_symbol + +/* External symbol declarations for the compiler. */\ +" + + if test "$dlself" = yes; then + $show "generating symbol list for \`$output'" + + test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist" + + # Add our own program objects to the symbol list. + progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + for arg in $progfiles; do + $show "extracting global C symbols from \`$arg'" + $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + + if test -n "$exclude_expsyms"; then + $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' + $run eval '$mv "$nlist"T "$nlist"' + fi + + if test -n "$export_symbols_regex"; then + $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' + $run eval '$mv "$nlist"T "$nlist"' + fi + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + export_symbols="$output_objdir/$outputname.exp" + $run $rm $export_symbols + $run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' + case $host in + *cygwin* | *mingw* ) + $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + $run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' + ;; + esac + else + $run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' + $run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' + $run eval 'mv "$nlist"T "$nlist"' + case $host in + *cygwin* | *mingw* ) + $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + $run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' + ;; + esac + fi + fi + + for arg in $dlprefiles; do + $show "extracting global C symbols from \`$arg'" + name=`$echo "$arg" | ${SED} -e 's%^.*/%%'` + $run eval '$echo ": $name " >> "$nlist"' + $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + + if test -z "$run"; then + # Make sure we have at least an empty file. + test -f "$nlist" || : > "$nlist" + + if test -n "$exclude_expsyms"; then + $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T + $mv "$nlist"T "$nlist" + fi + + # Try sorting and uniquifying the output. + if grep -v "^: " < "$nlist" | + if sort -k 3 /dev/null 2>&1; then + sort -k 3 + else + sort +2 + fi | + uniq > "$nlist"S; then + : + else + grep -v "^: " < "$nlist" > "$nlist"S + fi + + if test -f "$nlist"S; then + eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"' + else + $echo '/* NONE */' >> "$output_objdir/$dlsyms" + fi + + $echo >> "$output_objdir/$dlsyms" "\ + +#undef lt_preloaded_symbols + +#if defined (__STDC__) && __STDC__ +# define lt_ptr void * +#else +# define lt_ptr char * +# define const +#endif + +/* The mapping between symbol names and symbols. */ +" + + case $host in + *cygwin* | *mingw* ) + $echo >> "$output_objdir/$dlsyms" "\ +/* DATA imports from DLLs on WIN32 can't be const, because + runtime relocations are performed -- see ld's documentation + on pseudo-relocs */ +struct { +" + ;; + * ) + $echo >> "$output_objdir/$dlsyms" "\ +const struct { +" + ;; + esac + + + $echo >> "$output_objdir/$dlsyms" "\ + const char *name; + lt_ptr address; +} +lt_preloaded_symbols[] = +{\ +" + + eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms" + + $echo >> "$output_objdir/$dlsyms" "\ + {0, (lt_ptr) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif\ +" + fi + + pic_flag_for_symtable= + case $host in + # compiling the symbol table file with pic_flag works around + # a FreeBSD bug that causes programs to crash when -lm is + # linked before any other PIC object. But we must not use + # pic_flag when linking with -static. The problem exists in + # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. + *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + case "$compile_command " in + *" -static "*) ;; + *) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND";; + esac;; + *-*-hpux*) + case "$compile_command " in + *" -static "*) ;; + *) pic_flag_for_symtable=" $pic_flag";; + esac + esac + + # Now compile the dynamic symbol file. + $show "(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")" + $run eval '(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $? + + # Clean up the generated files. + $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T" + $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T" + + # Transform the symbol file into the correct name. + case $host in + *cygwin* | *mingw* ) + if test -f "$output_objdir/${outputname}.def" ; then + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` + else + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + fi + ;; + * ) + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + ;; + esac + ;; + *) + $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 + exit $EXIT_FAILURE + ;; + esac + else + # We keep going just in case the user didn't refer to + # lt_preloaded_symbols. The linker will fail if global_symbol_pipe + # really was required. + + # Nullify the symbol file. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` + fi + + if test "$need_relink" = no || test "$build_libtool_libs" != yes; then + # Replace the output file specification. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$output"'%g' | $NL2SP` + link_command="$compile_command$compile_rpath" + + # We have no uninstalled library dependencies, so finalize right now. + $show "$link_command" + $run eval "$link_command" + exit_status=$? + + # Delete the generated files. + if test -n "$dlsyms"; then + $show "$rm $output_objdir/${outputname}S.${objext}" + $run $rm "$output_objdir/${outputname}S.${objext}" + fi + + exit $exit_status + fi + + if test -n "$shlibpath_var"; then + # We should set the shlibpath_var + rpath= + for dir in $temp_rpath; do + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) + # Absolute path. + rpath="$rpath$dir:" + ;; + *) + # Relative path: add a thisdir entry. + rpath="$rpath\$thisdir/$dir:" + ;; + esac + done + temp_rpath="$rpath" + fi + + if test -n "$compile_shlibpath$finalize_shlibpath"; then + compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" + fi + if test -n "$finalize_shlibpath"; then + finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" + fi + + compile_var= + finalize_var= + if test -n "$runpath_var"; then + if test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + compile_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + if test -n "$finalize_perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $finalize_perm_rpath; do + rpath="$rpath$dir:" + done + finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + fi + + if test "$no_install" = yes; then + # We don't need to create a wrapper script. + link_command="$compile_var$compile_command$compile_rpath" + # Replace the output file specification. + link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` + # Delete the old output file. + $run $rm $output + # Link the executable and exit + $show "$link_command" + $run eval "$link_command" || exit $? + exit $EXIT_SUCCESS + fi + + if test "$hardcode_action" = relink; then + # Fast installation is not supported + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + + $echo "$modename: warning: this platform does not like uninstalled shared libraries" 1>&2 + $echo "$modename: \`$output' will be relinked during installation" 1>&2 + else + if test "$fast_install" != no; then + link_command="$finalize_var$compile_command$finalize_rpath" + if test "$fast_install" = yes; then + relink_command=`$echo "X$compile_var$compile_command$compile_rpath" | $SP2NL | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g' | $NL2SP` + else + # fast_install is set to needless + relink_command= + fi + else + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + fi + fi + + # Replace the output file specification. + link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` + + # Delete the old output files. + $run $rm $output $output_objdir/$outputname $output_objdir/lt-$outputname + + $show "$link_command" + $run eval "$link_command" || exit $? + + # Now create the wrapper script. + $show "creating $output" + + # Quote the relink command for shipping. + if test -n "$relink_command"; then + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` + relink_command="$var=\"$var_value\"; export $var; $relink_command" + fi + done + relink_command="(cd `pwd`; $relink_command)" + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` + fi + + # Quote $echo for shipping. + if test "X$echo" = "X$SHELL $progpath --fallback-echo"; then + case $progpath in + [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";; + *) qecho="$SHELL `pwd`/$progpath --fallback-echo";; + esac + qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"` + else + qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"` + fi + + # Only actually do things if our run command is non-null. + if test -z "$run"; then + # win32 will think the script is a binary if it has + # a .exe suffix, so we strip it off here. + case $output in + *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;; + esac + # test for cygwin because mv fails w/o .exe extensions + case $host in + *cygwin*) + exeext=.exe + outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;; + *) exeext= ;; + esac + case $host in + *cygwin* | *mingw* ) + output_name=`basename $output` + output_path=`dirname $output` + cwrappersource="$output_path/$objdir/lt-$output_name.c" + cwrapper="$output_path/$output_name.exe" + $rm $cwrappersource $cwrapper + trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 + + cat > $cwrappersource <> $cwrappersource<<"EOF" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(PATH_MAX) +# define LT_PATHMAX PATH_MAX +#elif defined(MAXPATHLEN) +# define LT_PATHMAX MAXPATHLEN +#else +# define LT_PATHMAX 1024 +#endif + +#ifndef DIR_SEPARATOR +# define DIR_SEPARATOR '/' +# define PATH_SEPARATOR ':' +#endif + +#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ + defined (__OS2__) +# define HAVE_DOS_BASED_FILE_SYSTEM +# ifndef DIR_SEPARATOR_2 +# define DIR_SEPARATOR_2 '\\' +# endif +# ifndef PATH_SEPARATOR_2 +# define PATH_SEPARATOR_2 ';' +# endif +#endif + +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + +#ifndef PATH_SEPARATOR_2 +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) +#else /* PATH_SEPARATOR_2 */ +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) +#endif /* PATH_SEPARATOR_2 */ + +#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) +#define XFREE(stale) do { \ + if (stale) { free ((void *) stale); stale = 0; } \ +} while (0) + +/* -DDEBUG is fairly common in CFLAGS. */ +#undef DEBUG +#if defined DEBUGWRAPPER +# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__) +#else +# define DEBUG(format, ...) +#endif + +const char *program_name = NULL; + +void * xmalloc (size_t num); +char * xstrdup (const char *string); +const char * base_name (const char *name); +char * find_executable(const char *wrapper); +int check_executable(const char *path); +char * strendzap(char *str, const char *pat); +void lt_fatal (const char *message, ...); + +int +main (int argc, char *argv[]) +{ + char **newargz; + int i; + + program_name = (char *) xstrdup (base_name (argv[0])); + DEBUG("(main) argv[0] : %s\n",argv[0]); + DEBUG("(main) program_name : %s\n",program_name); + newargz = XMALLOC(char *, argc+2); +EOF + + cat >> $cwrappersource <> $cwrappersource <<"EOF" + newargz[1] = find_executable(argv[0]); + if (newargz[1] == NULL) + lt_fatal("Couldn't find %s", argv[0]); + DEBUG("(main) found exe at : %s\n",newargz[1]); + /* we know the script has the same name, without the .exe */ + /* so make sure newargz[1] doesn't end in .exe */ + strendzap(newargz[1],".exe"); + for (i = 1; i < argc; i++) + newargz[i+1] = xstrdup(argv[i]); + newargz[argc+1] = NULL; + + for (i=0; i> $cwrappersource <> $cwrappersource <> $cwrappersource <<"EOF" + return 127; +} + +void * +xmalloc (size_t num) +{ + void * p = (void *) malloc (num); + if (!p) + lt_fatal ("Memory exhausted"); + + return p; +} + +char * +xstrdup (const char *string) +{ + return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL +; +} + +const char * +base_name (const char *name) +{ + const char *base; + +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + /* Skip over the disk name in MSDOS pathnames. */ + if (isalpha ((unsigned char)name[0]) && name[1] == ':') + name += 2; +#endif + + for (base = name; *name; name++) + if (IS_DIR_SEPARATOR (*name)) + base = name + 1; + return base; +} + +int +check_executable(const char * path) +{ + struct stat st; + + DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!"); + if ((!path) || (!*path)) + return 0; + + if ((stat (path, &st) >= 0) && + ( + /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */ +#if defined (S_IXOTH) + ((st.st_mode & S_IXOTH) == S_IXOTH) || +#endif +#if defined (S_IXGRP) + ((st.st_mode & S_IXGRP) == S_IXGRP) || +#endif + ((st.st_mode & S_IXUSR) == S_IXUSR)) + ) + return 1; + else + return 0; +} + +/* Searches for the full path of the wrapper. Returns + newly allocated full path name if found, NULL otherwise */ +char * +find_executable (const char* wrapper) +{ + int has_slash = 0; + const char* p; + const char* p_next; + /* static buffer for getcwd */ + char tmp[LT_PATHMAX + 1]; + int tmp_len; + char* concat_name; + + DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"); + + if ((wrapper == NULL) || (*wrapper == '\0')) + return NULL; + + /* Absolute path? */ +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':') + { + concat_name = xstrdup (wrapper); + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } + else + { +#endif + if (IS_DIR_SEPARATOR (wrapper[0])) + { + concat_name = xstrdup (wrapper); + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + } +#endif + + for (p = wrapper; *p; p++) + if (*p == '/') + { + has_slash = 1; + break; + } + if (!has_slash) + { + /* no slashes; search PATH */ + const char* path = getenv ("PATH"); + if (path != NULL) + { + for (p = path; *p; p = p_next) + { + const char* q; + size_t p_len; + for (q = p; *q; q++) + if (IS_PATH_SEPARATOR(*q)) + break; + p_len = q - p; + p_next = (*q == '\0' ? q : q + 1); + if (p_len == 0) + { + /* empty path: current directory */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen(tmp); + concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + } + else + { + concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, wrapper); + } + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } + } + /* not found in PATH; assume curdir */ + } + /* Relative path | not found in path: prepend cwd */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen(tmp); + concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + return NULL; +} + +char * +strendzap(char *str, const char *pat) +{ + size_t len, patlen; + + assert(str != NULL); + assert(pat != NULL); + + len = strlen(str); + patlen = strlen(pat); + + if (patlen <= len) + { + str += len - patlen; + if (strcmp(str, pat) == 0) + *str = '\0'; + } + return str; +} + +static void +lt_error_core (int exit_status, const char * mode, + const char * message, va_list ap) +{ + fprintf (stderr, "%s: %s: ", program_name, mode); + vfprintf (stderr, message, ap); + fprintf (stderr, ".\n"); + + if (exit_status >= 0) + exit (exit_status); +} + +void +lt_fatal (const char *message, ...) +{ + va_list ap; + va_start (ap, message); + lt_error_core (EXIT_FAILURE, "FATAL", message, ap); + va_end (ap); +} +EOF + # we should really use a build-platform specific compiler + # here, but OTOH, the wrappers (shell script and this C one) + # are only useful if you want to execute the "real" binary. + # Since the "real" binary is built for $host, then this + # wrapper might as well be built for $host, too. + $run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource + ;; + esac + $rm $output + trap "$rm $output; exit $EXIT_FAILURE" 1 2 15 + + $echo > $output "\ +#! $SHELL + +# $output - temporary wrapper script for $objdir/$outputname +# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP +# +# The $output program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='${SED} -e 1s/^X//' +sed_quote_subst='$sed_quote_subst' + +# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). +if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac +fi + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command=\"$relink_command\" + +# This environment variable determines our operation mode. +if test \"\$libtool_install_magic\" = \"$magic\"; then + # install mode needs the following variable: + notinst_deplibs='$notinst_deplibs' +else + # When we are sourced in execute mode, \$file and \$echo are already set. + if test \"\$libtool_execute_magic\" != \"$magic\"; then + echo=\"$qecho\" + file=\"\$0\" + # Make sure echo works. + if test \"X\$1\" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then + # Yippee, \$echo works! + : + else + # Restart under the correct shell, and then maybe \$echo will work. + exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} + fi + fi\ +" + $echo >> $output "\ + + # Find the directory that this script lives in. + thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` + test \"x\$thisdir\" = \"x\$file\" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` + while test -n \"\$file\"; do + destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` + + # If there was a directory component, then change thisdir. + if test \"x\$destdir\" != \"x\$file\"; then + case \"\$destdir\" in + [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; + *) thisdir=\"\$thisdir/\$destdir\" ;; + esac + fi + + file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\` + file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` + done + + # Try to get the absolute directory name. + absdir=\`cd \"\$thisdir\" && pwd\` + test -n \"\$absdir\" && thisdir=\"\$absdir\" +" + + if test "$fast_install" = yes; then + $echo >> $output "\ + program=lt-'$outputname'$exeext + progdir=\"\$thisdir/$objdir\" + + if test ! -f \"\$progdir/\$program\" || \\ + { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ + test \"X\$file\" != \"X\$progdir/\$program\"; }; then + + file=\"\$\$-\$program\" + + if test ! -d \"\$progdir\"; then + $mkdir \"\$progdir\" + else + $rm \"\$progdir/\$file\" + fi" + + $echo >> $output "\ + + # relink executable if necessary + if test -n \"\$relink_command\"; then + if relink_command_output=\`eval \$relink_command 2>&1\`; then : + else + $echo \"\$relink_command_output\" >&2 + $rm \"\$progdir/\$file\" + exit $EXIT_FAILURE + fi + fi + + $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || + { $rm \"\$progdir/\$program\"; + $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; } + $rm \"\$progdir/\$file\" + fi" + else + $echo >> $output "\ + program='$outputname' + progdir=\"\$thisdir/$objdir\" +" + fi + + $echo >> $output "\ + + if test -f \"\$progdir/\$program\"; then" + + # Export our shlibpath_var if we have one. + if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then + $echo >> $output "\ + # Add our own library path to $shlibpath_var + $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" + + # Some systems cannot cope with colon-terminated $shlibpath_var + # The second colon is a workaround for a bug in BeOS R4 sed + $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` + + export $shlibpath_var +" + fi + + # fixup the dll searchpath if we need to. + if test -n "$dllsearchpath"; then + $echo >> $output "\ + # Add the dll search path components to the executable PATH + PATH=$dllsearchpath:\$PATH +" + fi + + $echo >> $output "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then + # Run the actual program with our arguments. +" + case $host in + # Backslashes separate directories on plain windows + *-*-mingw | *-*-os2*) + $echo >> $output "\ + exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} +" + ;; + + *) + $echo >> $output "\ + exec \"\$progdir/\$program\" \${1+\"\$@\"} +" + ;; + esac + $echo >> $output "\ + \$echo \"\$0: cannot exec \$program \$*\" + exit $EXIT_FAILURE + fi + else + # The program doesn't exist. + \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 + \$echo \"This script is just a wrapper for \$program.\" 1>&2 + $echo \"See the $PACKAGE documentation for more information.\" 1>&2 + exit $EXIT_FAILURE + fi +fi\ +" + chmod +x $output + fi + exit $EXIT_SUCCESS + ;; + esac + + # See if we need to build an old-fashioned archive. + for oldlib in $oldlibs; do + + if test "$build_libtool_libs" = convenience; then + oldobjs="$libobjs_save" + addlibs="$convenience" + build_libtool_libs=no + else + if test "$build_libtool_libs" = module; then + oldobjs="$libobjs_save" + build_libtool_libs=no + else + oldobjs="$old_deplibs $non_pic_objects" + fi + addlibs="$old_convenience" + fi + + if test -n "$addlibs"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $addlibs + oldobjs="$oldobjs $func_extract_archives_result" + fi + + # Do each command in the archive commands. + if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then + cmds=$old_archive_from_new_cmds + else + # POSIX demands no paths to be encoded in archives. We have + # to avoid creating archives with duplicate basenames if we + # might have to extract them afterwards, e.g., when creating a + # static archive out of a convenience library, or when linking + # the entirety of a libtool archive into another (currently + # not supported by libtool). + if (for obj in $oldobjs + do + $echo "X$obj" | $Xsed -e 's%^.*/%%' + done | sort | sort -uc >/dev/null 2>&1); then + : + else + $echo "copying selected object files to avoid basename conflicts..." + + if test -z "$gentop"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + $show "${rm}r $gentop" + $run ${rm}r "$gentop" + $show "$mkdir $gentop" + $run $mkdir "$gentop" + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$gentop"; then + exit $exit_status + fi + fi + + save_oldobjs=$oldobjs + oldobjs= + counter=1 + for obj in $save_oldobjs + do + objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` + case " $oldobjs " in + " ") oldobjs=$obj ;; + *[\ /]"$objbase "*) + while :; do + # Make sure we don't pick an alternate name that also + # overlaps. + newobj=lt$counter-$objbase + counter=`expr $counter + 1` + case " $oldobjs " in + *[\ /]"$newobj "*) ;; + *) if test ! -f "$gentop/$newobj"; then break; fi ;; + esac + done + $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" + $run ln "$obj" "$gentop/$newobj" || + $run cp "$obj" "$gentop/$newobj" + oldobjs="$oldobjs $gentop/$newobj" + ;; + *) oldobjs="$oldobjs $obj" ;; + esac + done + fi + + eval cmds=\"$old_archive_cmds\" + + if len=`expr "X$cmds" : ".*"` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + cmds=$old_archive_cmds + else + # the command line is too long to link in one step, link in parts + $echo "using piecewise archive linking..." + save_RANLIB=$RANLIB + RANLIB=: + objlist= + concat_cmds= + save_oldobjs=$oldobjs + + # Is there a better way of finding the last object in the list? + for obj in $save_oldobjs + do + last_oldobj=$obj + done + for obj in $save_oldobjs + do + oldobjs="$objlist $obj" + objlist="$objlist $obj" + eval test_cmds=\"$old_archive_cmds\" + if len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len"; then + : + else + # the above command should be used before it gets too long + oldobjs=$objlist + if test "$obj" = "$last_oldobj" ; then + RANLIB=$save_RANLIB + fi + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" + objlist= + fi + done + RANLIB=$save_RANLIB + oldobjs=$objlist + if test "X$oldobjs" = "X" ; then + eval cmds=\"\$concat_cmds\" + else + eval cmds=\"\$concat_cmds~\$old_archive_cmds\" + fi + fi + fi + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + eval cmd=\"$cmd\" + IFS="$save_ifs" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + done + + if test -n "$generated"; then + $show "${rm}r$generated" + $run ${rm}r$generated + fi + + # Now create the libtool archive. + case $output in + *.la) + old_library= + test "$build_old_libs" = yes && old_library="$libname.$libext" + $show "creating $output" + + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` + relink_command="$var=\"$var_value\"; export $var; $relink_command" + fi + done + # Quote the link command for shipping. + relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` + if test "$hardcode_automatic" = yes ; then + relink_command= + fi + + + # Only create the output if not a dry run. + if test -z "$run"; then + for installed in no yes; do + if test "$installed" = yes; then + if test -z "$install_libdir"; then + break + fi + output="$output_objdir/$outputname"i + # Replace all uninstalled libtool libraries with the installed ones + newdependency_libs= + for deplib in $dependency_libs; do + case $deplib in + *.la) + name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + if test -z "$libdir"; then + $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdependency_libs="$newdependency_libs $libdir/$name" + ;; + *) newdependency_libs="$newdependency_libs $deplib" ;; + esac + done + dependency_libs="$newdependency_libs" + newdlfiles= + for lib in $dlfiles; do + name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + if test -z "$libdir"; then + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdlfiles="$newdlfiles $libdir/$name" + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + if test -z "$libdir"; then + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdlprefiles="$newdlprefiles $libdir/$name" + done + dlprefiles="$newdlprefiles" + else + newdlfiles= + for lib in $dlfiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlfiles="$newdlfiles $abs" + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlprefiles="$newdlprefiles $abs" + done + dlprefiles="$newdlprefiles" + fi + $rm $output + # place dlname in correct position for cygwin + tdlname=$dlname + case $host,$output,$installed,$module,$dlname in + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; + esac + $echo > $output "\ +# $outputname - a libtool library file +# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='$tdlname' + +# Names of this library. +library_names='$library_names' + +# The name of the static archive. +old_library='$old_library' + +# Libraries that this one depends upon. +dependency_libs='$dependency_libs' + +# Version information for $libname. +current=$current +age=$age +revision=$revision + +# Is this an already installed library? +installed=$installed + +# Should we warn about portability when linking against -modules? +shouldnotlink=$module + +# Files to dlopen/dlpreopen +dlopen='$dlfiles' +dlpreopen='$dlprefiles' + +# Directory that this library needs to be installed in: +libdir='$install_libdir'" + if test "$installed" = no && test "$need_relink" = yes; then + $echo >> $output "\ +relink_command=\"$relink_command\"" + fi + done + fi + + # Do a symbolic link so that the libtool archive can be found in + # LD_LIBRARY_PATH before the program is installed. + $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)" + $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $? + ;; + esac + exit $EXIT_SUCCESS + ;; + + # libtool install mode + install) + modename="$modename: install" + + # There may be an optional sh(1) argument at the beginning of + # install_prog (especially on Windows NT). + if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || + # Allow the use of GNU shtool's install command. + $echo "X$nonopt" | grep shtool > /dev/null; then + # Aesthetically quote it. + arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$arg " + arg="$1" + shift + else + install_prog= + arg=$nonopt + fi + + # The real first argument should be the name of the installation program. + # Aesthetically quote it. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$install_prog$arg" + + # We need to accept at least all the BSD install flags. + dest= + files= + opts= + prev= + install_type= + isdir=no + stripme= + for arg + do + if test -n "$dest"; then + files="$files $dest" + dest=$arg + continue + fi + + case $arg in + -d) isdir=yes ;; + -f) + case " $install_prog " in + *[\\\ /]cp\ *) ;; + *) prev=$arg ;; + esac + ;; + -g | -m | -o) prev=$arg ;; + -s) + stripme=" -s" + continue + ;; + -*) + ;; + *) + # If the previous option needed an argument, then skip it. + if test -n "$prev"; then + prev= + else + dest=$arg + continue + fi + ;; + esac + + # Aesthetically quote the argument. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$install_prog $arg" + done + + if test -z "$install_prog"; then + $echo "$modename: you must specify an install program" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test -n "$prev"; then + $echo "$modename: the \`$prev' option requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test -z "$files"; then + if test -z "$dest"; then + $echo "$modename: no file or destination specified" 1>&2 + else + $echo "$modename: you must specify a destination" 1>&2 + fi + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Strip any trailing slash from the destination. + dest=`$echo "X$dest" | $Xsed -e 's%/$%%'` + + # Check to see that the destination is a directory. + test -d "$dest" && isdir=yes + if test "$isdir" = yes; then + destdir="$dest" + destname= + else + destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'` + test "X$destdir" = "X$dest" && destdir=. + destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'` + + # Not a directory, so check to see that there is only one file specified. + set dummy $files + if test "$#" -gt 2; then + $echo "$modename: \`$dest' is not a directory" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + fi + case $destdir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + for file in $files; do + case $file in + *.lo) ;; + *) + $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + done + ;; + esac + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + staticlibs= + future_libdirs= + current_libdirs= + for file in $files; do + + # Do each installation. + case $file in + *.$libext) + # Do the static libraries later. + staticlibs="$staticlibs $file" + ;; + + *.la) + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$file' is not a valid libtool archive" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + library_names= + old_library= + relink_command= + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Add the libdir to current_libdirs if it is the destination. + if test "X$destdir" = "X$libdir"; then + case "$current_libdirs " in + *" $libdir "*) ;; + *) current_libdirs="$current_libdirs $libdir" ;; + esac + else + # Note the libdir as a future libdir. + case "$future_libdirs " in + *" $libdir "*) ;; + *) future_libdirs="$future_libdirs $libdir" ;; + esac + fi + + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/ + test "X$dir" = "X$file/" && dir= + dir="$dir$objdir" + + if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + # At present, this check doesn't affect windows .dll's that + # are installed into $libdir/../bin (currently, that works fine) + # but it's something to keep an eye on. + if test "$inst_prefix_dir" = "$destdir"; then + $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2 + exit $EXIT_FAILURE + fi + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%" | $NL2SP` + else + relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%%" | $NL2SP` + fi + + $echo "$modename: warning: relinking \`$file'" 1>&2 + $show "$relink_command" + if $run eval "$relink_command"; then : + else + $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 + exit $EXIT_FAILURE + fi + fi + + # See the names of the shared library. + set dummy $library_names + if test -n "$2"; then + realname="$2" + shift + shift + + srcname="$realname" + test -n "$relink_command" && srcname="$realname"T + + # Install the shared library and build the symlinks. + $show "$install_prog $dir/$srcname $destdir/$realname" + $run eval "$install_prog $dir/$srcname $destdir/$realname" || exit $? + if test -n "$stripme" && test -n "$striplib"; then + $show "$striplib $destdir/$realname" + $run eval "$striplib $destdir/$realname" || exit $? + fi + + if test "$#" -gt 0; then + # Delete the old symlinks, and create new ones. + # Try `ln -sf' first, because the `ln' binary might depend on + # the symlink we replace! Solaris /bin/ln does not understand -f, + # so we also need to try rm && ln -s. + for linkname + do + if test "$linkname" != "$realname"; then + $show "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" + $run eval "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" + fi + done + fi + + # Do each command in the postinstall commands. + lib="$destdir/$realname" + cmds=$postinstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + fi + + # Install the pseudo-library for information purposes. + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + instname="$dir/$name"i + $show "$install_prog $instname $destdir/$name" + $run eval "$install_prog $instname $destdir/$name" || exit $? + + # Maybe install the static library, too. + test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" + ;; + + *.lo) + # Install (i.e. copy) a libtool object. + + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + destfile="$destdir/$destfile" + fi + + # Deduce the name of the destination old-style object file. + case $destfile in + *.lo) + staticdest=`$echo "X$destfile" | $Xsed -e "$lo2o"` + ;; + *.$objext) + staticdest="$destfile" + destfile= + ;; + *) + $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + # Install the libtool object if requested. + if test -n "$destfile"; then + $show "$install_prog $file $destfile" + $run eval "$install_prog $file $destfile" || exit $? + fi + + # Install the old object if enabled. + if test "$build_old_libs" = yes; then + # Deduce the name of the old-style object file. + staticobj=`$echo "X$file" | $Xsed -e "$lo2o"` + + $show "$install_prog $staticobj $staticdest" + $run eval "$install_prog \$staticobj \$staticdest" || exit $? + fi + exit $EXIT_SUCCESS + ;; + + *) + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + destfile="$destdir/$destfile" + fi + + # If the file is missing, and there is a .exe on the end, strip it + # because it is most likely a libtool script we actually want to + # install + stripped_ext="" + case $file in + *.exe) + if test ! -f "$file"; then + file=`$echo $file|${SED} 's,.exe$,,'` + stripped_ext=".exe" + fi + ;; + esac + + # Do a test to see if this is really a libtool program. + case $host in + *cygwin*|*mingw*) + wrapper=`$echo $file | ${SED} -e 's,.exe$,,'` + ;; + *) + wrapper=$file + ;; + esac + if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then + notinst_deplibs= + relink_command= + + # Note that it is not necessary on cygwin/mingw to append a dot to + # foo even if both foo and FILE.exe exist: automatic-append-.exe + # behavior happens only for exec(3), not for open(2)! Also, sourcing + # `FILE.' does not work on cygwin managed mounts. + # + # If there is no directory component, then add one. + case $wrapper in + */* | *\\*) . ${wrapper} ;; + *) . ./${wrapper} ;; + esac + + # Check the variables that should have been set. + if test -z "$notinst_deplibs"; then + $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2 + exit $EXIT_FAILURE + fi + + finalize=yes + for lib in $notinst_deplibs; do + # Check to see that each library is installed. + libdir= + if test -f "$lib"; then + # If there is no directory component, then add one. + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + fi + libfile="$libdir/"`$echo "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test + if test -n "$libdir" && test ! -f "$libfile"; then + $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2 + finalize=no + fi + done + + relink_command= + # Note that it is not necessary on cygwin/mingw to append a dot to + # foo even if both foo and FILE.exe exist: automatic-append-.exe + # behavior happens only for exec(3), not for open(2)! Also, sourcing + # `FILE.' does not work on cygwin managed mounts. + # + # If there is no directory component, then add one. + case $wrapper in + */* | *\\*) . ${wrapper} ;; + *) . ./${wrapper} ;; + esac + + outputname= + if test "$fast_install" = no && test -n "$relink_command"; then + if test "$finalize" = yes && test -z "$run"; then + tmpdir=`func_mktempdir` + file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'` + outputname="$tmpdir/$file" + # Replace the output file specification. + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g' | $NL2SP` + + $show "$relink_command" + if $run eval "$relink_command"; then : + else + $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 + ${rm}r "$tmpdir" + continue + fi + file="$outputname" + else + $echo "$modename: warning: cannot relink \`$file'" 1>&2 + fi + else + # Install the binary that we compiled earlier. + file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` + fi + fi + + # remove .exe since cygwin /usr/bin/install will append another + # one anyway + case $install_prog,$host in + */usr/bin/install*,*cygwin*) + case $file:$destfile in + *.exe:*.exe) + # this is ok + ;; + *.exe:*) + destfile=$destfile.exe + ;; + *:*.exe) + destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'` + ;; + esac + ;; + esac + $show "$install_prog$stripme $file $destfile" + $run eval "$install_prog\$stripme \$file \$destfile" || exit $? + test -n "$outputname" && ${rm}r "$tmpdir" + ;; + esac + done + + for file in $staticlibs; do + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + + # Set up the ranlib parameters. + oldlib="$destdir/$name" + + $show "$install_prog $file $oldlib" + $run eval "$install_prog \$file \$oldlib" || exit $? + + if test -n "$stripme" && test -n "$old_striplib"; then + $show "$old_striplib $oldlib" + $run eval "$old_striplib $oldlib" || exit $? + fi + + # Do each command in the postinstall commands. + cmds=$old_postinstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + done + + if test -n "$future_libdirs"; then + $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2 + fi + + if test -n "$current_libdirs"; then + # Maybe just do a dry run. + test -n "$run" && current_libdirs=" -n$current_libdirs" + exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' + else + exit $EXIT_SUCCESS + fi + ;; + + # libtool finish mode + finish) + modename="$modename: finish" + libdirs="$nonopt" + admincmds= + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + for dir + do + libdirs="$libdirs $dir" + done + + for libdir in $libdirs; do + if test -n "$finish_cmds"; then + # Do each command in the finish commands. + cmds=$finish_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || admincmds="$admincmds + $cmd" + done + IFS="$save_ifs" + fi + if test -n "$finish_eval"; then + # Do the single finish_eval. + eval cmds=\"$finish_eval\" + $run eval "$cmds" || admincmds="$admincmds + $cmds" + fi + done + fi + + # Exit here if they wanted silent mode. + test "$show" = : && exit $EXIT_SUCCESS + + $echo "X----------------------------------------------------------------------" | $Xsed + $echo "Libraries have been installed in:" + for libdir in $libdirs; do + $echo " $libdir" + done + $echo + $echo "If you ever happen to want to link against installed libraries" + $echo "in a given directory, LIBDIR, you must either use libtool, and" + $echo "specify the full pathname of the library, or use the \`-LLIBDIR'" + $echo "flag during linking and do at least one of the following:" + if test -n "$shlibpath_var"; then + $echo " - add LIBDIR to the \`$shlibpath_var' environment variable" + $echo " during execution" + fi + if test -n "$runpath_var"; then + $echo " - add LIBDIR to the \`$runpath_var' environment variable" + $echo " during linking" + fi + if test -n "$hardcode_libdir_flag_spec"; then + libdir=LIBDIR + eval flag=\"$hardcode_libdir_flag_spec\" + + $echo " - use the \`$flag' linker flag" + fi + if test -n "$admincmds"; then + $echo " - have your system administrator run these commands:$admincmds" + fi + if test -f /etc/ld.so.conf; then + $echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" + fi + $echo + $echo "See any operating system documentation about shared libraries for" + $echo "more information, such as the ld(1) and ld.so(8) manual pages." + $echo "X----------------------------------------------------------------------" | $Xsed + exit $EXIT_SUCCESS + ;; + + # libtool execute mode + execute) + modename="$modename: execute" + + # The first argument is the command name. + cmd="$nonopt" + if test -z "$cmd"; then + $echo "$modename: you must specify a COMMAND" 1>&2 + $echo "$help" + exit $EXIT_FAILURE + fi + + # Handle -dlopen flags immediately. + for file in $execute_dlfiles; do + if test ! -f "$file"; then + $echo "$modename: \`$file' is not a file" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + dir= + case $file in + *.la) + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Read the libtool library. + dlname= + library_names= + + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Skip this library if it cannot be dlopened. + if test -z "$dlname"; then + # Warn if it was a shared library. + test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'" + continue + fi + + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$file" && dir=. + + if test -f "$dir/$objdir/$dlname"; then + dir="$dir/$objdir" + else + $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 + exit $EXIT_FAILURE + fi + ;; + + *.lo) + # Just add the directory containing the .lo file. + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$file" && dir=. + ;; + + *) + $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2 + continue + ;; + esac + + # Get the absolute pathname. + absdir=`cd "$dir" && pwd` + test -n "$absdir" && dir="$absdir" + + # Now add the directory to shlibpath_var. + if eval "test -z \"\$$shlibpath_var\""; then + eval "$shlibpath_var=\"\$dir\"" + else + eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" + fi + done + + # This variable tells wrapper scripts just to set shlibpath_var + # rather than running their programs. + libtool_execute_magic="$magic" + + # Check if any of the arguments is a wrapper script. + args= + for file + do + case $file in + -*) ;; + *) + # Do a test to see if this is really a libtool program. + if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Transform arg to wrapped name. + file="$progdir/$program" + fi + ;; + esac + # Quote arguments (to preserve shell metacharacters). + file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"` + args="$args \"$file\"" + done + + if test -z "$run"; then + if test -n "$shlibpath_var"; then + # Export the shlibpath_var. + eval "export $shlibpath_var" + fi + + # Restore saved environment variables + for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + do + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + fi" + done + + + # Now prepare to actually exec the command. + exec_cmd="\$cmd$args" + else + # Display what would be done. + if test -n "$shlibpath_var"; then + eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\"" + $echo "export $shlibpath_var" + fi + $echo "$cmd$args" + exit $EXIT_SUCCESS + fi + ;; + + # libtool clean and uninstall mode + clean | uninstall) + modename="$modename: $mode" + rm="$nonopt" + files= + rmforce= + exit_status=0 + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + for arg + do + case $arg in + -f) rm="$rm $arg"; rmforce=yes ;; + -*) rm="$rm $arg" ;; + *) files="$files $arg" ;; + esac + done + + if test -z "$rm"; then + $echo "$modename: you must specify an RM program" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + rmdirs= + + origobjdir="$objdir" + for file in $files; do + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + if test "X$dir" = "X$file"; then + dir=. + objdir="$origobjdir" + else + objdir="$dir/$origobjdir" + fi + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + test "$mode" = uninstall && objdir="$dir" + + # Remember objdir for removal later, being careful to avoid duplicates + if test "$mode" = clean; then + case " $rmdirs " in + *" $objdir "*) ;; + *) rmdirs="$rmdirs $objdir" ;; + esac + fi + + # Don't error if the file doesn't exist and rm -f was used. + if (test -L "$file") >/dev/null 2>&1 \ + || (test -h "$file") >/dev/null 2>&1 \ + || test -f "$file"; then + : + elif test -d "$file"; then + exit_status=1 + continue + elif test "$rmforce" = yes; then + continue + fi + + rmfiles="$file" + + case $name in + *.la) + # Possibly a libtool archive, so verify it. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + . $dir/$name + + # Delete the libtool libraries and symlinks. + for n in $library_names; do + rmfiles="$rmfiles $objdir/$n" + done + test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" + + case "$mode" in + clean) + case " $library_names " in + # " " in the beginning catches empty $dlname + *" $dlname "*) ;; + *) rmfiles="$rmfiles $objdir/$dlname" ;; + esac + test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" + ;; + uninstall) + if test -n "$library_names"; then + # Do each command in the postuninstall commands. + cmds=$postuninstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" + if test "$?" -ne 0 && test "$rmforce" != yes; then + exit_status=1 + fi + done + IFS="$save_ifs" + fi + + if test -n "$old_library"; then + # Do each command in the old_postuninstall commands. + cmds=$old_postuninstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" + if test "$?" -ne 0 && test "$rmforce" != yes; then + exit_status=1 + fi + done + IFS="$save_ifs" + fi + # FIXME: should reinstall the best remaining shared library. + ;; + esac + fi + ;; + + *.lo) + # Possibly a libtool object, so verify it. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + + # Read the .lo file + . $dir/$name + + # Add PIC object to the list of files to remove. + if test -n "$pic_object" \ + && test "$pic_object" != none; then + rmfiles="$rmfiles $dir/$pic_object" + fi + + # Add non-PIC object to the list of files to remove. + if test -n "$non_pic_object" \ + && test "$non_pic_object" != none; then + rmfiles="$rmfiles $dir/$non_pic_object" + fi + fi + ;; + + *) + if test "$mode" = clean ; then + noexename=$name + case $file in + *.exe) + file=`$echo $file|${SED} 's,.exe$,,'` + noexename=`$echo $name|${SED} 's,.exe$,,'` + # $file with .exe has already been added to rmfiles, + # add $file without .exe + rmfiles="$rmfiles $file" + ;; + esac + # Do a test to see if this is a libtool program. + if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + relink_command= + . $dir/$noexename + + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" + if test "$fast_install" = yes && test -n "$relink_command"; then + rmfiles="$rmfiles $objdir/lt-$name" + fi + if test "X$noexename" != "X$name" ; then + rmfiles="$rmfiles $objdir/lt-${noexename}.c" + fi + fi + fi + ;; + esac + $show "$rm $rmfiles" + $run $rm $rmfiles || exit_status=1 + done + objdir="$origobjdir" + + # Try to remove the ${objdir}s in the directories where we deleted files + for dir in $rmdirs; do + if test -d "$dir"; then + $show "rmdir $dir" + $run rmdir $dir >/dev/null 2>&1 + fi + done + + exit $exit_status + ;; + + "") + $echo "$modename: you must specify a MODE" 1>&2 + $echo "$generic_help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + if test -z "$exec_cmd"; then + $echo "$modename: invalid operation mode \`$mode'" 1>&2 + $echo "$generic_help" 1>&2 + exit $EXIT_FAILURE + fi +fi # test -z "$show_help" + +if test -n "$exec_cmd"; then + eval exec $exec_cmd + exit $EXIT_FAILURE +fi + +# We need to display help for each of the modes. +case $mode in +"") $echo \ +"Usage: $modename [OPTION]... [MODE-ARG]... + +Provide generalized library-building support services. + + --config show all configuration variables + --debug enable verbose shell tracing +-n, --dry-run display commands without modifying any files + --features display basic configuration information and exit + --finish same as \`--mode=finish' + --help display this help message and exit + --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS] + --quiet same as \`--silent' + --silent don't print informational messages + --tag=TAG use configuration variables from tag TAG + --version print version information + +MODE must be one of the following: + + clean remove files from the build directory + compile compile a source file into a libtool object + execute automatically set library path, then run a program + finish complete the installation of libtool libraries + install install libraries or executables + link create a library or an executable + uninstall remove libraries from an installed directory + +MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for +a more detailed description of MODE. + +Report bugs to ." + exit $EXIT_SUCCESS + ;; + +clean) + $echo \ +"Usage: $modename [OPTION]... --mode=clean RM [RM-OPTION]... FILE... + +Remove files from the build directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, object or program, all the files associated +with it are deleted. Otherwise, only FILE itself is deleted using RM." + ;; + +compile) + $echo \ +"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE + +Compile a source file into a libtool library object. + +This mode accepts the following additional options: + + -o OUTPUT-FILE set the output file name to OUTPUT-FILE + -prefer-pic try to building PIC objects only + -prefer-non-pic try to building non-PIC objects only + -static always build a \`.o' file suitable for static linking + +COMPILE-COMMAND is a command to be used in creating a \`standard' object file +from the given SOURCEFILE. + +The output file name is determined by removing the directory component from +SOURCEFILE, then substituting the C source code suffix \`.c' with the +library object suffix, \`.lo'." + ;; + +execute) + $echo \ +"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]... + +Automatically set library path, then run a program. + +This mode accepts the following additional options: + + -dlopen FILE add the directory containing FILE to the library path + +This mode sets the library path environment variable according to \`-dlopen' +flags. + +If any of the ARGS are libtool executable wrappers, then they are translated +into their corresponding uninstalled binary, and any of their required library +directories are added to the library path. + +Then, COMMAND is executed, with ARGS as arguments." + ;; + +finish) + $echo \ +"Usage: $modename [OPTION]... --mode=finish [LIBDIR]... + +Complete the installation of libtool libraries. + +Each LIBDIR is a directory that contains libtool libraries. + +The commands that this mode executes may require superuser privileges. Use +the \`--dry-run' option if you just want to see what would be executed." + ;; + +install) + $echo \ +"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND... + +Install executables or libraries. + +INSTALL-COMMAND is the installation command. The first component should be +either the \`install' or \`cp' program. + +The rest of the components are interpreted as arguments to that command (only +BSD-compatible install options are recognized)." + ;; + +link) + $echo \ +"Usage: $modename [OPTION]... --mode=link LINK-COMMAND... + +Link object files or libraries together to form another library, or to +create an executable program. + +LINK-COMMAND is a command using the C compiler that you would use to create +a program from several object files. + +The following components of LINK-COMMAND are treated specially: + + -all-static do not do any dynamic linking at all + -avoid-version do not add a version suffix if possible + -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime + -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols + -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) + -export-symbols SYMFILE + try to export only the symbols listed in SYMFILE + -export-symbols-regex REGEX + try to export only the symbols matching REGEX + -LLIBDIR search LIBDIR for required installed libraries + -lNAME OUTPUT-FILE requires the installed library libNAME + -module build a library that can dlopened + -no-fast-install disable the fast-install mode + -no-install link a not-installable executable + -no-undefined declare that a library does not refer to external symbols + -o OUTPUT-FILE create OUTPUT-FILE from the specified objects + -objectlist FILE Use a list of object files found in FILE to specify objects + -precious-files-regex REGEX + don't remove output files matching REGEX + -release RELEASE specify package release information + -rpath LIBDIR the created library will eventually be installed in LIBDIR + -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries + -static do not do any dynamic linking of uninstalled libtool libraries + -static-libtool-libs + do not do any dynamic linking of libtool libraries + -version-info CURRENT[:REVISION[:AGE]] + specify library version info [each variable defaults to 0] + +All other options (arguments beginning with \`-') are ignored. + +Every other argument is treated as a filename. Files ending in \`.la' are +treated as uninstalled libtool libraries, other files are standard or library +object files. + +If the OUTPUT-FILE ends in \`.la', then a libtool library is created, +only library objects (\`.lo' files) may be specified, and \`-rpath' is +required, except when creating a convenience library. + +If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created +using \`ar' and \`ranlib', or on Windows using \`lib'. + +If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file +is created, otherwise an executable program is created." + ;; + +uninstall) + $echo \ +"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... + +Remove libraries from an installation directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, all the files associated with it are deleted. +Otherwise, only FILE itself is deleted using RM." + ;; + +*) + $echo "$modename: invalid operation mode \`$mode'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; +esac + +$echo +$echo "Try \`$modename --help' for more information about other modes." + +exit $? + +# The TAGs below are defined such that we never get into a situation +# in which we disable both kinds of libraries. Given conflicting +# choices, we go for a static library, that is the most portable, +# since we can't tell whether shared libraries were disabled because +# the user asked for that or because the platform doesn't support +# them. This is particularly important on AIX, because we don't +# support having both static and shared libraries enabled at the same +# time on that platform, so we default to a shared-only configuration. +# If a disable-shared tag is given, we'll fallback to a static-only +# configuration. But we'll never go from static-only to shared-only. + +# ### BEGIN LIBTOOL TAG CONFIG: disable-shared +disable_libs=shared +# ### END LIBTOOL TAG CONFIG: disable-shared + +# ### BEGIN LIBTOOL TAG CONFIG: disable-static +disable_libs=static +# ### END LIBTOOL TAG CONFIG: disable-static + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: diff --git a/TESTU01/TestU01-1.2.3/missing b/TESTU01/TestU01-1.2.3/missing new file mode 100755 index 0000000..6a37006 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/missing @@ -0,0 +1,336 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. +# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. +# Originally by Fran,cois Pinard , 1996. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch]" + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing 0.4 - GNU automake" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. + You can get \`$1Help2man' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` + test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then + # We have makeinfo, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar "$@" && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar "$@" && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequirements for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 diff --git a/TESTU01/TestU01-1.2.3/mkinstalldirs b/TESTU01/TestU01-1.2.3/mkinstalldirs new file mode 100755 index 0000000..8ab885e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mkinstalldirs @@ -0,0 +1,99 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman +# Created: 1993-05-16 +# Public domain + +errstatus=0 +dirmode="" + +usage="\ +Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." + +# process command line arguments +while test $# -gt 0 ; do + case "${1}" in + -h | --help | --h* ) # -h for help + echo "${usage}" 1>&2; exit 0 ;; + -m ) # -m PERM arg + shift + test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; } + dirmode="${1}" + shift ;; + -- ) shift; break ;; # stop option processing + -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option + * ) break ;; # first non-opt arg + esac +done + +for file +do + if test -d "$file"; then + shift + else + break + fi +done + +case $# in +0) exit 0 ;; +esac + +case $dirmode in +'') + if mkdir -p -- . 2>/dev/null; then + echo "mkdir -p -- $*" + exec mkdir -p -- "$@" + fi ;; +*) + if mkdir -m "$dirmode" -p -- . 2>/dev/null; then + echo "mkdir -m $dirmode -p -- $*" + exec mkdir -m "$dirmode" -p -- "$@" + fi ;; +esac + +for file +do + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` + shift + + pathcomp= + for d + do + pathcomp="$pathcomp$d" + case "$pathcomp" in + -* ) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + else + if test ! -z "$dirmode"; then + echo "chmod $dirmode $pathcomp" + + lasterr="" + chmod "$dirmode" "$pathcomp" || lasterr=$? + + if test ! -z "$lasterr"; then + errstatus=$lasterr + fi + fi + fi + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# Local Variables: +# mode: shell-script +# sh-indentation: 3 +# End: +# mkinstalldirs ends here diff --git a/TESTU01/TestU01-1.2.3/mylib/Makefile.am b/TESTU01/TestU01-1.2.3/mylib/Makefile.am new file mode 100644 index 0000000..3f543ec --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/include/Makefile.def + +lib_LTLIBRARIES = libmylib.la +libmylib_la_SOURCES = $(MYLIBSOURCES) +libmylib_la_LIBADD = @LIBM@ +libmylib_la_LDFLAGS = -no-undefined -version-info 0:1:0 + +EXTRA_DIST = guidemylib.tex tcode.tex titre.tex guidemylib.bbl + +doc_DATA = guidemylib.pdf diff --git a/TESTU01/TestU01-1.2.3/mylib/Makefile.in b/TESTU01/TestU01-1.2.3/mylib/Makefile.in new file mode 100644 index 0000000..cbdad7d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/Makefile.in @@ -0,0 +1,541 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(top_srcdir)/include/Makefile.def +subdir = mylib +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h \ + $(top_builddir)/include/gdefconf.h +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +libmylib_la_DEPENDENCIES = +am__objects_1 = gdef.lo addstr.lo bitset.lo chrono.lo mystr.lo num.lo \ + num2.lo tables.lo util.lo +am_libmylib_la_OBJECTS = $(am__objects_1) +libmylib_la_OBJECTS = $(am_libmylib_la_OBJECTS) +libmylib_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libmylib_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I. -I$(top_builddir)/include@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libmylib_la_SOURCES) +DIST_SOURCES = $(libmylib_la_SOURCES) +docDATA_INSTALL = $(INSTALL_DATA) +DATA = $(doc_DATA) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = ${prefix}/share/TestU01/doc +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +MYLIB = ${top_srcdir}/mylib +PROBDIST = ${top_srcdir}/probdist +TESTU01 = ${top_srcdir}/testu01 +MYLIBHEADERS = gdef.h addstr.h bitset.h chrono.h mystr.h num.h num2.h tables.h util.h +MYLIBSOURCES = gdef.c addstr.c bitset.c chrono.c mystr.c num.c num2.c tables.c util.c +MYLIBTEX = $(MYLIB)/gdef.tex $(MYLIB)/addstr.tex $(MYLIB)/bitset.tex $(MYLIB)/chrono.tex $(MYLIB)/mystr.tex $(MYLIB)/num.tex $(MYLIB)/num2.tex $(MYLIB)/tables.tex $(MYLIB)/util.tex +PROBDISTHEADERS = fmass.h fdist.h fbar.h finv.h gofs.h gofw.h statcoll.h wdist.h +PROBDISTSOURCES = fmass.c fdist.c fbar.c finv.c gofs.c gofw.c statcoll.c wdist.c +PROBDISTTEX = $(PROBDIST)/fmass.tex $(PROBDIST)/fdist.tex $(PROBDIST)/fbar.tex $(PROBDIST)/finv.tex $(PROBDIST)/gofs.tex $(PROBDIST)/gofw.tex $(PROBDIST)/statcoll.tex $(PROBDIST)/wdist.tex +TESTU01HEADERS = unif01.h ulcg.h umrg.h ucarry.h utaus.h ugfsr.h uinv.h uquad.h ucubic.h ulec.h utezuka.h umarsa.h uweyl.h uknuth.h uwu.h unumrec.h uvaria.h usoft.h ugranger.h ucrypto.h ufile.h udeng.h utouzin.h uautomata.h uxorshift.h ubrent.h rijndael-alg-fst.h tu01_sha1.h scatter.h swrite.h sres.h smultin.h sknuth.h smarsa.h sstring.h svaria.h snpair.h swalk.h sentrop.h sspectral.h scomp.h sspacings.h vectorsF2.h bbattery.h ffam.h fcong.h ffsr.h ftab.h fres.h fcho.h fmultin.h fmarsa.h fknuth.h fwalk.h fstring.h fspectral.h fvaria.h fnpair.h +TESTU01SOURCES = unif01.c ulcg.c umrg.c ucarry.c utaus.c ugfsr.c uinv.c uquad.c ucubic.c ulec.c utezuka.c umarsa.c uweyl.c uknuth.c uwu.c unumrec.c uvaria.c usoft.c ugranger.c ucrypto.c ufile.c udeng.c utouzin.c uautomata.c uxorshift.c ubrent.c rijndael-alg-fst.c tu01_sha1.c scatter.c swrite.c sres.c smultin.c sknuth.c smarsa.c sstring.c svaria.c snpair.c swalk.c sentrop.c sspectral.c scomp.c sspacings.c vectorsF2.c bbattery.c ffam.c fcong.c ffsr.c ftab.c fres.c fcho.c fmultin.c fmarsa.c fknuth.c fwalk.c fstring.c fspectral.c fvaria.c fnpair.c +TESTU01TEX = $(TESTU01)/unif01.tex $(TESTU01)/ulcg.tex \ + $(TESTU01)/umrg.tex $(TESTU01)/ucarry.tex $(TESTU01)/utaus.tex \ + $(TESTU01)/ugfsr.tex $(TESTU01)/uinv.tex $(TESTU01)/uquad.tex \ + $(TESTU01)/ucubic.tex $(TESTU01)/ulec.tex \ + $(TESTU01)/utezuka.tex $(TESTU01)/umarsa.tex \ + $(TESTU01)/uweyl.tex $(TESTU01)/uknuth.tex $(TESTU01)/uwu.tex \ + $(TESTU01)/unumrec.tex $(TESTU01)/uvaria.tex \ + $(TESTU01)/usoft.tex $(TESTU01)/ugranger.tex \ + $(TESTU01)/ucrypto.tex $(TESTU01)/ufile.tex \ + $(TESTU01)/udeng.tex $(TESTU01)/utouzin.tex \ + $(TESTU01)/uautomata.tex $(TESTU01)/uxorshift.tex \ + $(TESTU01)/ubrent.tex $(TESTU01)/rijndael-alg-fst.tex \ + $(TESTU01)/tu01_sha1.tex $(TESTU01)/scatter.tex \ + $(TESTU01)/swrite.tex $(TESTU01)/sres.tex \ + $(TESTU01)/smultin.tex $(TESTU01)/sknuth.tex \ + $(TESTU01)/smarsa.tex $(TESTU01)/sstring.tex \ + $(TESTU01)/svaria.tex $(TESTU01)/snpair.tex \ + $(TESTU01)/swalk.tex $(TESTU01)/sentrop.tex \ + $(TESTU01)/sspectral.tex $(TESTU01)/scomp.tex \ + $(TESTU01)/sspacings.tex $(TESTU01)/vectorsF2.tex \ + $(TESTU01)/bbattery.tex $(TESTU01)/ffam.tex \ + $(TESTU01)/fcong.tex $(TESTU01)/ffsr.tex $(TESTU01)/ftab.tex \ + $(TESTU01)/fres.tex $(TESTU01)/fcho.tex $(TESTU01)/fmultin.tex \ + $(TESTU01)/fmarsa.tex $(TESTU01)/fknuth.tex \ + $(TESTU01)/fwalk.tex $(TESTU01)/fstring.tex \ + $(TESTU01)/fspectral.tex $(TESTU01)/fvaria.tex \ + $(TESTU01)/fnpair.tex +lib_LTLIBRARIES = libmylib.la +libmylib_la_SOURCES = $(MYLIBSOURCES) +libmylib_la_LIBADD = @LIBM@ +libmylib_la_LDFLAGS = -no-undefined -version-info 0:1:0 +EXTRA_DIST = guidemylib.tex tcode.tex titre.tex guidemylib.bbl +doc_DATA = guidemylib.pdf +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/include/Makefile.def $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu mylib/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu mylib/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libmylib.la: $(libmylib_la_OBJECTS) $(libmylib_la_DEPENDENCIES) + $(libmylib_la_LINK) -rpath $(libdir) $(libmylib_la_OBJECTS) $(libmylib_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/addstr.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitset.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chrono.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdef.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mystr.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/num.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/num2.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tables.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-docDATA: $(doc_DATA) + @$(NORMAL_INSTALL) + test -z "$(docdir)" || $(MKDIR_P) "$(DESTDIR)$(docdir)" + @list='$(doc_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(docDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(docdir)/$$f'"; \ + $(docDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(docdir)/$$f"; \ + done + +uninstall-docDATA: + @$(NORMAL_UNINSTALL) + @list='$(doc_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(docdir)/$$f'"; \ + rm -f "$(DESTDIR)$(docdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(DATA) +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-docDATA + +install-dvi: install-dvi-am + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-docDATA uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am \ + install-docDATA install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-libLTLIBRARIES install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-docDATA \ + uninstall-libLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/mylib/addstr.c b/TESTU01/TestU01-1.2.3/mylib/addstr.c new file mode 100644 index 0000000..6443f0e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/addstr.c @@ -0,0 +1,184 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: addstr.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "addstr.h" + +#include +#include + + +#define LEN1 63 + + + +/* ========================== functions ================================= */ + +void addstr_Long (char *to, const char *add, long n) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%1ld", n); + strcat (to, str); +} + +void addstr_Uint (char *to, const char *add, unsigned int n) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%1u", n); + strcat (to, str); +} + +void addstr_Int (char *to, const char *add, int n) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%1d", n); + strcat (to, str); +} + +void addstr_Ulong (char *to, const char *add, unsigned long n) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%1lu", n); + strcat (to, str); +} + +#ifdef USE_LONGLONG +void addstr_LONG (char *to, const char *add, longlong n) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%1" PRIdLEAST64, n); + strcat (to, str); +} + +void addstr_ULONG (char *to, const char *add, ulonglong n) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%1" PRIuLEAST64, n); + strcat (to, str); +} +#endif + +void addstr_Char (char *to, const char *add, char c) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%c", c); + strcat (to, str); +} + +void addstr_Double (char *to, const char *add, double x) +{ + char str[LEN1 + 1]; + strcat (to, add); + sprintf (str, "%.16G", x); + strcat (to, str); +} + +void addstr_Bool (char *to, const char *add, int b) +{ + strcat (to, add); + if (b) + strcat (to, "TRUE"); + else + strcat (to, "FALSE"); +} + +void addstr_ArrayLong (char *to, const char *add, int high, long val[]) +{ + int j; + strcat (to, add); + addstr_Long (to, "(", val[0]); + for (j = 1; (j < high) && (j < 5); j++) + addstr_Long (to, ", ", val[j]); + if (high > 5) + strcat (to, ", ... )"); + else + strcat (to, ")"); +} + +void addstr_ArrayUlong (char *to, const char *add, + int high, unsigned long val[]) +{ + int j; + strcat (to, add); + addstr_Ulong (to, "(", val[0]); + for (j = 1; (j < high) && (j < 5); j++) + addstr_Ulong (to, ", ", val[j]); + if (high > 5) + strcat (to, ", ... )"); + else + strcat (to, ")"); +} + +void addstr_ArrayUint (char *to, const char *add, int high, + unsigned int val[]) +{ + int j; + strcat (to, add); + addstr_Uint (to, "(", val[0]); + for (j = 1; (j < high) && (j < 5); j++) + addstr_Uint (to, ", ", val[j]); + if (high > 5) + strcat (to, ", ... )"); + else + strcat (to, ")"); +} + +void addstr_ArrayInt (char *to, const char *add, int high, int val[]) +{ + int j; + strcat (to, add); + addstr_Int (to, "(", val[0]); + for (j = 1; (j < high) && (j < 5); j++) + addstr_Int (to, ", ", val[j]); + if (high > 5) + strcat (to, ", ... )"); + else + strcat (to, ")"); +} + +void addstr_ArrayDouble (char *to, const char *add, + int high, double val[]) +{ + int j; + strcat (to, add); + addstr_Double (to, "(", val[0]); + for (j = 1; (j < high) && (j < 5); j++) + addstr_Double (to, ", ", val[j]); + if (high > 5) + strcat (to, ", ... )"); + else + strcat (to, ")"); +} diff --git a/TESTU01/TestU01-1.2.3/mylib/addstr.tex b/TESTU01/TestU01-1.2.3/mylib/addstr.tex new file mode 100644 index 0000000..7f1d268 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/addstr.tex @@ -0,0 +1,86 @@ +\defmodule {addstr} + +The functions described here are convenient tools for constructing +character strings that contain a series of numeric parameters, +with their values. +For example, suppose one wishes to put +``{\tt LCG with m = 101, a = 12, s = 1}'' in the string {\tt str}, +where the actual +numbers 101, 12, and 1 must be taken as the values of {\tt long} +integer variables {\tt m}, {\tt a}, and {\tt s}. +This can be achieved by the instructions: +\vcode + + strcpy (str, "LCG with "); + addstr\_Long (str, " m = ", m); + addstr\_Long (str, ", a = ", m); + addstr\_Long (str, ", s = ", s); +\endvcode + +Each function {\tt addstr\_... (char *to, const char *add, ...)} +first appends the string {\tt add} to the string {\tt to}, then +appends to it a character string representation of the number +(or array of numbers) specified by its last parameter. +In the case of an array of numbers (e.g., {\tt addstr\_ArrayLong}), +the parameter {\tt high} specifies the size of the array, and the +elements {\tt [0..high-1]} are added to {\tt str}. +The {\tt ...LONG} versions are for 64-bit integers. +In all cases, the string {\tt to} should be large enough to accomodate +what is appended to it. + + +%%%%%%%%%%%%% +\bigskip\hrule +\code\hide +/* addstr.h for ANSI C */ +#ifndef ADDSTR_H +#define ADDSTR_H +\endhide +#include "gdef.h" +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Prototypes} +\code + +void addstr_Int (char *to, const char *add, int n); + +void addstr_Uint (char *to, const char *add, unsigned int n); + +void addstr_Long (char *to, const char *add, long n); + +void addstr_Ulong (char *to, const char *add, unsigned long n); + +void addstr_Double (char *to, const char *add, double x); + +void addstr_Char (char *to, const char *add, char c); + +void addstr_Bool (char *to, const char *add, int b); +\endcode +\code + +#ifdef USE_LONGLONG +void addstr_LONG (char *to, const char *add, longlong n); + +void addstr_ULONG (char *to, const char *add, ulonglong n); +#endif +\endcode +\code + +void addstr_ArrayInt (char *to, const char *add, int high, int []); + +void addstr_ArrayUint (char *to, const char *add, int high, + unsigned int []); + +void addstr_ArrayLong (char *to, const char *add, int high, long []); + +void addstr_ArrayUlong (char *to, const char *add, int high, + unsigned long []); + +void addstr_ArrayDouble (char *to, const char *add, int high, double []); + +\hide +#endif +\endhide +\endcode + diff --git a/TESTU01/TestU01-1.2.3/mylib/annexea.tex b/TESTU01/TestU01-1.2.3/mylib/annexea.tex new file mode 100644 index 0000000..f67b80f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/annexea.tex @@ -0,0 +1,184 @@ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\section{Obsolete identifiers} + +The following identifiers from older versions of {\tt MyLib} +have been eliminated or replaced. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\subsection{util} + +\begin{itemize} + +\item {\tt util\_Free} + +the prototype has changed. + +\end{itemize} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\subsection{num} + +\begin{itemize} + +\item {\tt num\_MaxLongInt} + +use {\tt INT\_MAX} from $<${\tt limits.h}$>$ + +\item {\tt num\_MaxLongIntLR} + +use {\tt INT\_MAX from} $<${\tt limits.h}$>$ + +\item {\tt num\_LgMaxLongInt1} + +Eliminated. + +\item {\tt num\_InvLn2} + +Eliminated. + +\item {\tt num\_MaxIntLongReal} + +is now called {\tt num\_MaxIntDouble}. + +\item {\tt num\_MaxLongReal} + +use {\tt DBL\_MAX} from $<${\tt float.h}$>$ + +\item {\tt num\_MantDig} + +use {\tt DBL\_MANT\_DIG} from $<${\tt float.h}$>$ + +\item {\tt num\_hLR} + +use {\tt DBL\_EPSILON/2} from $<${\tt float.h}$>$ + +\item {\tt num\_chLR} + +use {\tt 1 - DBL\_EPSILON/2} from $<${\tt float.h}$>$ + +\item {\tt num\_jLR} + +use {\tt 0.75*DBL\_EPSILON} from $<${\tt float.h}$>$ + + +\item {\tt num\_SCeilLR (x)} + +use {\tt nextafter (x, 1.0)} from $<${\tt math.h}$>$ + +\item {\tt num\_Lg} + +use {\tt log2} from $<${\tt math.h}$>$ + +\item {\tt num\_ModLR} + +use {\tt fmod} from $<${\tt math.h}$>$ + +\item {\tt num\_TruncLR} + +use {\tt modf} from $<${\tt math.h}$>$ + +\item {\tt num\_RoundLR (x)} + +use {\tt floor (x + 0.5)} from $<${\tt math.h}$>$ + +\item {\tt num\_WriteLR} + +is now called {\tt num\_WriteD}. + +\item {\tt num\_MultModLI} + +is now called {\tt num\_MultModL} + +\item {\tt num\_MultModLR} + +is now called {\tt num\_MultModD} + +\end{itemize} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\subsection{num2} + +\begin{itemize} + +\item {\tt num2\_Combinaison (s, n)} + +replaced by {\tt num2\_Combination (n, s)}. +\end{itemize} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\subsection{tables} + +\begin{itemize} + +\item {\tt tables\_TabLI} + +use {\tt long *} + +\item {\tt tables\_TabLR} + +use {\tt double *} + +\item {\tt tables\_TabUL, tables\_TabBit} + +use {\tt unsigned long *} + + +\item {\tt tables\_MatLI} + +use {\tt long **} + +\item {\tt tables\_MatLR} + +use {\tt double **} + +\item {\tt tables\_MatUL, tables\_MatBit} + +use {\tt unsigned long **} + +\item {\tt tables\_CreateTab} + +use {\tt util\_Calloc} + +\item {\tt tables\_DeleteTab} + +use {\tt util\_Free} + +\item {\tt tables\_ResizeTab} + +use {\tt util\_Realloc} + +\item {\tt tables\_WriteTabLI} + +use {\tt tables\_WriteTabL} + +\item {\tt tables\_WriteTabLR } + +use {\tt tables\_WriteTabD} + +\item {\tt tables\_WriteMatrixLI} + +use {\tt tables\_WriteMatrixL} + +\item {\tt tables\_WriteMatrixLR} + +use {\tt tables\_WriteMatrixD} + +\item {\tt tables\_HachageMod} + +use {\tt tables\_HashPrime} + +\end{itemize} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/TESTU01/TestU01-1.2.3/mylib/bitset.c b/TESTU01/TestU01-1.2.3/mylib/bitset.c new file mode 100644 index 0000000..1e58c3a --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/bitset.c @@ -0,0 +1,222 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: bitset.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "bitset.h" +#include "util.h" +#include +#include +#include + + +unsigned long bitset_maskUL[] = { + 1, + 2, + 4, + 8, + 16, + 32, + 64, + 128, + 256, + 512, + 1024, + 2048, + 4096, + 8192, + 16384, + 32768, + 65536, + 131072, + 262144, + 524288, + 1048576, + 2097152, + 4194304, + 8388608, + 16777216, + 33554432, + 67108864, + 134217728, + 268435456, + 536870912, + 1073741824, + 2147483648UL +#if ULONG_MAX > 4294967295UL + , + 4294967296, + 8589934592, + 17179869184, + 34359738368, + 68719476736, + 137438953472, + 274877906944, + 549755813888, + 1099511627776, + 2199023255552, + 4398046511104, + 8796093022208, + 17592186044416, + 35184372088832, + 70368744177664, + 140737488355328, + 281474976710656, + 562949953421312, + 1125899906842624, + 2251799813685248, + 4503599627370496, + 9007199254740992, + 18014398509481984, + 36028797018963968, + 72057594037927936, + 144115188075855872, + 288230376151711744, + 576460752303423488, + 1152921504606846976, + 2305843009213693952, + 4611686018427387904, + 9223372036854775808UL +#endif + }; + + +/*--------------------------------------------------------------------------*/ + +unsigned long bitset_MASK[] = { + 0, + 1, + 3, + 7, + 15, + 31, + 63, + 127, + 255, + 511, + 1023, + 2047, + 4095, + 8191, + 16383, + 32767, + 65535, + 131071, + 262143, + 524287, + 1048575, + 2097151, + 4194303, + 8388607, + 16777215, + 33554431, + 67108863, + 134217727, + 268435455, + 536870911, + 1073741823, + 2147483647, + 4294967295UL +#if ULONG_MAX > 4294967295UL + , + 8589934591, + 17179869183, + 34359738367, + 68719476735, + 137438953471, + 274877906943, + 549755813887, + 1099511627775, + 2199023255551, + 4398046511103, + 8796093022207, + 17592186044415, + 35184372088831, + 70368744177663, + 140737488355327, + 281474976710655, + 562949953421311, + 1125899906842623, + 2251799813685247, + 4503599627370495, + 9007199254740991, + 18014398509481983, + 36028797018963967, + 72057594037927935, + 144115188075855871, + 288230376151711743, + 576460752303423487, + 1152921504606846975, + 2305843009213693951, + 4611686018427387903, + 9223372036854775807, + 18446744073709551615UL +#endif + }; + +/*--------------------------------------------------------------------------*/ + + +void bitset_WriteSet (char *desc, bitset_BitSet S, int n) +{ + int i; + bitset_BitSet mask; + + util_Assert (n > 0, "bitset_WriteSet: s <= 0"); + if ((unsigned) n > CHAR_BIT * sizeof (bitset_BitSet)) { + n = CHAR_BIT * sizeof (bitset_BitSet); + printf ("********** bitset_WriteSet: only %d bits in a BitSet\n\n", n); + } + if (desc != NULL && strlen (desc) > 0) + printf ("%s", desc); + mask = (bitset_BitSet) 1 << (n - 1); + for (i = 0; i < n; i++) { + if (S & mask) + printf ("1"); + else + printf ("0"); + mask >>= 1; + } +} + + +/*--------------------------------------------------------------------------*/ + +bitset_BitSet bitset_Reverse (bitset_BitSet Z, int s) +{ + unsigned long res = 0; + int i; + + for (i = 0; i < s; i++) { + res = (res << 1) | (Z & 1); + Z >>= 1; + } + return res; +} + diff --git a/TESTU01/TestU01-1.2.3/mylib/bitset.tex b/TESTU01/TestU01-1.2.3/mylib/bitset.tex new file mode 100644 index 0000000..ed09ba9 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/bitset.tex @@ -0,0 +1,152 @@ +\defmodule {bitset} + +This module defines sets of bits and useful operations for such sets. +Some of these operations are implemented as macros. + +\code\hide +/* bitset.h for ANSI C */ +#ifndef BITSET_H +#define BITSET_H +#include "gdef.h" +\endhide\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Constants} +\code + +extern unsigned long bitset_maskUL[]; +\endcode + \tab {\tt bitset\_maskUL[j]} has bit $j$ set to 1 and all other bits set to + 0. Bit 0 is the least significant bit. + \endtab +\code + + +extern unsigned long bitset_MASK[]; +\endcode + \tab {\tt bitset\_MASK[j]} has all the first $j$ bits set to 1 and all other + bits set to 0. Bit 0 is the least significant bit. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Types} +\code + +typedef unsigned long bitset_BitSet; +\endcode + \tab Set of bits. Bits are numbered starting from 0 for the least + significant bit. If bit $s$ is 1, then element $s$ is a member of + the set, otherwise not. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Macros} + +\noindent +{\tt bitset\_SetBit (S, b)}; + + \tab Sets bit {\tt b} in set {\tt S} to 1. + \endtab +\code +\hide +#define bitset_SetBit(S, b) ((S) |= (bitset_maskUL[b])) +\endhide +\endcode + +\noindent +{\tt bitset\_ClearBit (S, b)}; + + \tab Sets bit {\tt b} in set {\tt S} to 0. + \endtab +\code +\hide +#define bitset_ClearBit(S, b) ((S) &= ~(bitset_maskUL[b])) +\endhide +\endcode + +\noindent +{\tt bitset\_FlipBit (S, b)}; + + \tab Flips bit {\tt b} in set {\tt S}; thus, + $0 \rightarrow 1$ and $1 \rightarrow 0$. + \endtab +\code +\hide +#define bitset_FlipBit(S, b) ((S) ^= (bitset_maskUL[b])) +\endhide +\endcode + +\noindent +{\tt bitset\_TestBit (S, b)}; + + \tab Returns the value of bit {\tt b} in set {\tt S}. + \endtab +\code +\hide +#define bitset_TestBit(S, b) ((S) & (bitset_maskUL[b]) ? 1 : 0) +\endhide +\endcode + +\noindent +{\tt bitset\_RotateLeft (S, t, r)}; + + \tab Rotates the {\tt t} bits of set {\tt S} by {\tt r} bits to the left. + {\tt S} is considered as a {\tt t}-bit number kept + in the least significant bits of the equivalent number {\tt S}. + \endtab +\code +\hide +#define bitset_RotateLeft(S, t, r) do { \ + unsigned long v853 = (S) >> ((t) - (r)); \ + (S) <<= (r); (S) |= v853; (S) &= bitset_MASK[t]; \ + } while (0) +\endhide +\endcode + +\noindent +{\tt bitset\_RotateRight (S, t, r)}; + + \tab Rotates the {\tt t} bits of set {\tt S} by {\tt r} bits to the right. + {\tt S} is considered as a {\tt t}-bit number kept + in the least significant bits of the equivalent number {\tt S}. + \endtab +\code +\hide +#define bitset_RotateRight(S, t, r) do { \ + unsigned long v972 = (S) >> (r); \ + (S) <<= ((t) - (r)); (S) |= v972; (S) &= bitset_MASK[t]; \ + } while (0) +\endhide +\endcode + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Prototypes} +\code + +bitset_BitSet bitset_Reverse (bitset_BitSet Z, int s); +\endcode +\tab Reverses the {\tt s} least significant bits of {\tt Z} considered as a +number. Thus, if {\tt s}${}=4$ and {\tt Z}${}=0011$, the returned value is $1100$. + \endtab +\code + + +void bitset_WriteSet (char *desc, bitset_BitSet Z, int s); +\endcode + \tab + Prints the string {\tt desc} (which may be empty), then writes the {\tt + s} least significant bits of {\tt Z} considered as an unsigned binary number. + This corresponds to the {\tt s} first elements of {\tt Z}. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/mylib/chrono.c b/TESTU01/TestU01-1.2.3/mylib/chrono.c new file mode 100644 index 0000000..8ce8af1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/chrono.c @@ -0,0 +1,226 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: chrono.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "chrono.h" +#include "gdef.h" +#include "util.h" +#include "num.h" + +#include +#include +#include + +#ifdef HAVE_WINDOWS_H + +#include + +static HANDLE currentProcess = NULL; + +/* + * A helper function for converting FILETIME to a LONGLONG [safe from memory + * alignment point of view]. + */ +static ULONGLONG +fileTimeToInt64 (const FILETIME * time) +{ + ULARGE_INTEGER _time; + _time.LowPart = time->dwLowDateTime; + _time.HighPart = time->dwHighDateTime; + return _time.QuadPart; +} + +static void Heure (unsigned long *tsec, unsigned long *tusec) { + if (currentProcess == NULL) + currentProcess = GetCurrentProcess(); + FILETIME creationTime, exitTime, kernelTime, userTime; + /* Strongly inspired from + * http://www.javaworld.com/javaworld/javaqa/2002-11/01-qa-1108-cpu.html */ + GetProcessTimes (currentProcess, &creationTime, &exitTime, + &kernelTime, &userTime); + ULONGLONG rawTime = fileTimeToInt64 (&kernelTime) + + fileTimeToInt64 (&userTime); + /* We have to divide by 10000 to get milliseconds out of + * the computed time */ + *tsec = (unsigned long)(rawTime / 10000000); + *tusec = (unsigned long)((rawTime % 10000000) / 10); +} + + +#elif defined(USE_ANSI_CLOCK) +/* ANSI C timer */ + +static void Heure ( + unsigned long *tsec, /* Seconds */ + unsigned long *tmicrosec /* Micro-seconds */ + ) +/* + * Function returning the CPU time used by a program since it was + * started. This function is ANSI C compliant. + */ +{ + clock_t t; + double y; + + t = clock (); + y = ((double) t) / CLOCKS_PER_SEC; + *tsec = y; + *tmicrosec = (y - *tsec) * 1000000; +} + + +#else +/* POSIX timer */ + +#include +#include + +static void Heure (unsigned long *tsec, unsigned long *tusec) +/* + * Function returning the CPU time used by a program since it was + * started. This function is NOT ANSI C compliant. + */ +{ + struct tms us; + long TICKS, z; + + TICKS = sysconf(_SC_CLK_TCK); + if (TICKS == -1) { + fprintf (stdout, "chrono.c: 'sysconf(_SC_CLK_TCK)' failed\n"); + } + z = times (&us); + if (z == -1) { + fprintf (stdout, "chrono.c: timer times failed\n"); + } + + /* CPU time = user time + system time */ + *tusec = us.tms_utime + us.tms_stime; + + *tsec = *tusec / TICKS; + *tusec = (*tusec % TICKS) * 1000000 / TICKS; +} + +#endif + + +/*------------------------------------------------------------------------*/ + +void chrono_Init (chrono_Chrono *C) +{ + Heure (&C->second, &C->microsec); +} + + +chrono_Chrono * chrono_Create (void) +{ + chrono_Chrono *C; + C = (chrono_Chrono *) util_Malloc (sizeof (chrono_Chrono)); + Heure (&C->second, &C->microsec); + return C; +} + + +void chrono_Delete (chrono_Chrono *C) +{ + util_Free (C); +} + + +double chrono_Val (chrono_Chrono *C, chrono_TimeFormat Unit) +{ + double temps; /* Time elapsed, in seconds */ + chrono_Chrono now; + Heure (&now.second, &now.microsec); + temps = (((double) now.microsec - (double) C->microsec) / 1.E+6 + + (double) now.second) - (double) C->second; + + switch (Unit) { + case chrono_sec: + return temps; + case chrono_min: + return temps * 1.666666667E-2; + case chrono_hours: + return temps * 2.777777778E-4; + case chrono_days: + return temps * 1.157407407E-5; + case chrono_hms: + util_Error ("chrono_Val : hms is a wrong arg for chrono_TimeUnit"); + } + return 0.0; +} + +void chrono_Write (chrono_Chrono * C, chrono_TimeFormat Form) +{ + long centieme; + long minute; + long heure; + long seconde; + double temps; + if (Form != chrono_hms) + temps = chrono_Val (C, Form); + else + temps = 0.0; + switch (Form) { + case chrono_sec: + num_WriteD (temps, 10, 2, 1); + printf (" seconds"); + break; + case chrono_min: + num_WriteD (temps, 10, 2, 1); + printf (" minutes"); + break; + case chrono_hours: + num_WriteD (temps, 10, 2, 1); + printf (" hours"); + break; + case chrono_days: + num_WriteD (temps, 10, 2, 1); + printf (" days"); + break; + case chrono_hms: + temps = chrono_Val (C, chrono_sec); + heure = (long) (temps * 2.777777778E-4); + if (heure > 0) + temps -= (double) (heure) * 3600.0; + minute = (long) (temps * 1.666666667E-2); + if (minute > 0) + temps -= (double) (minute) * 60.0; + seconde = (long) (temps); + centieme = (long) (100.0 * (temps - (double) (seconde))); + printf ("%02ld:", heure); + printf ("%02ld:", minute); + printf ("%02ld.", seconde); + printf ("%02ld", centieme); + break; + } +} diff --git a/TESTU01/TestU01-1.2.3/mylib/chrono.tex b/TESTU01/TestU01-1.2.3/mylib/chrono.tex new file mode 100644 index 0000000..8ef38c3 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/chrono.tex @@ -0,0 +1,155 @@ +\defmodule{chrono} + +This module acts as an interface to the system clock to compute the +CPU time used by parts of a program. + Even though the ANSI/ISO macro {\tt CLOCKS\_PER\_SEC = 1000000} + is the number of clock ticks per second for the value + returned by the {\tt clock} function (so this function returns the + number of microseconds), on some systems where the 32-bit type {\tt long} + is used to measure time, the value returned by {\tt clock} + wraps around to negative values after about 36 minutes. + On some other systems where time is measured using the 32-bit type + {\tt unsigned long}, the clock may wrap around to 0 after about + 72 minutes. + When the macro {\tt USE\_ANSI\_CLOCK} in module {\tt gdef} is undefined, + a non-ANSI-C clock is used. + On Linux-Unix systems, it calls the POSIX + function {\tt times} to get the CPU time used by a program. +\hpierre{Is this true for both Linux and Windows?} +\hrichard{Je ne crois pas que MicroMou respecte le standard POSIX, qui est + sp\'ecifique aux syst\`emes Unix ou Linux.} + On a Windows platform (when the macro \texttt{HAVE\_WINDOWS\_H} is defined), + the Windows function \texttt{GetProcessTimes} will be used to measure + the CPU time used by programs. + + +Every variable of type {\tt chrono\_Chrono} acts as an independent +{\em stopwatch}. Several such stopwatchs can run at any given time. +An object of type {\tt chrono\_Chrono} must be declared +for each of them. +The function {\tt chrono\_Init} resets the stopwatch to zero, +{\tt chrono\_Val\/} returns its current reading, +and {\tt chrono\_Write\/} writes this reading to the current output. +The returned value includes part of the execution time of the functions +from module {\tt chrono\/}. +The {\tt chrono\_TimeFormat} allows one to choose the kind of +time units that are used. +% When no longer needed, +% the stopwatch can be deleted via {\tt chrono\_Delete}. + +Below is an example of how the functions may be used. +A stopwatch named {\tt mytimer} is declared and created. +After 2.1 seconds of CPU time have been consumed, the stopwatch is read and +reset. Then, after an additional 330 seconds (or 5.5 minutes) of CPU time +the stopwatch is read again, printed to the output and deleted. +% + \begin{verse}{\tt + double t; \\ + chrono\_Chrono *mytimer = chrono\_Create (); \\ +\hskip 1.0cm \vdots +\hskip 1.0cm ({\em suppose 2.1 CPU seconds are used here}.)\\[6pt] + t = chrono\_Val (mytimer, chrono\_sec); \qquad /* Here, t = 2.1 */ \\ + chrono\_Init (mytimer); \\ +\hskip 1.0cm \vdots +\hskip 1.0cm ({\em suppose 330 CPU seconds are used here}.) \\[10pt] + t = chrono\_Val (mytimer, chrono\_min); \qquad /* Here, t = 5.5 */\\ + chrono\_Write (mytimer, chrono\_hms); \qquad /* Prints: 00:05:30.00 */\\ + chrono\_Delete (mytimer); + }\end{verse} + +\code +\iffalse +/* chrono.h for ANSI C */ + +#ifndef CHRONO_H +#define CHRONO_H +#include "gdef.h" +\fi +\endcode + +\newpage +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Types} +\code + +typedef struct { + unsigned long microsec; + unsigned long second; + } chrono_Chrono; +\endcode + \tab + For every stopwatch needed, the user must declare a variable of + this type and initialize it by calling {\tt chrono\_Create}. + \endtab +\code + + +typedef enum { + chrono_sec, + chrono_min, + chrono_hours, + chrono_days, + chrono_hms + } chrono_TimeFormat; +\endcode + \tab + Types of units in which the time on a {\tt chrono\_Chrono} can be + read or printed: + in seconds ({\tt sec})), minutes ({\tt min}), hours ({\tt hour}), days + ({\tt days}), or in the {\tt HH:MM:SS.xx} format, with hours, + minutes, seconds and hundreths of a second ({\tt hms}). + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Timing functions} +\code + +chrono_Chrono * chrono_Create (void); +\endcode + \tab + Creates and returns a stopwatch, after initializing it to zero. This + function must be called for each new {\tt chrono\_Chrono} used. + One may reinitializes it later by calling {\tt chrono\_Init}. + \endtab +\code + + +void chrono_Delete (chrono_Chrono * C); +\endcode + \tab + Deletes the stopwatch {\tt C}. + \endtab +\code + + +void chrono_Init (chrono_Chrono * C); +\endcode + \tab + Initializes the stopwatch {\tt C} to zero. + \endtab +\code + + +double chrono_Val (chrono_Chrono * C, chrono_TimeFormat Unit); +\endcode + \tab + Returns the time used by the program since the last call to + {\tt chrono\_Init(C)}. The parameter {\tt Unit} specifies the time unit. + Restriction: {\tt Unit = chrono\_hms} is not allowed here; + it will cause an error. + \endtab +\code + + +void chrono_Write (chrono_Chrono * C, chrono_TimeFormat Unit); +\endcode + \tab + Prints the CPU time used by the program since its last + call to {\tt chrono\_Init(C)}. + The parameter {\tt Unit} specifies the time unit. + \endtab +\code +\iffalse +#endif +\fi\endcode diff --git a/TESTU01/TestU01-1.2.3/mylib/gdef.c b/TESTU01/TestU01-1.2.3/mylib/gdef.c new file mode 100644 index 0000000..b3863de --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/gdef.c @@ -0,0 +1,136 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: gdef.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gdef.h" +#ifdef HAVE_WINDOWS_H + #include +#endif + +#include +#include +#include + +#ifdef HAVE_SYS_UTSNAME_H +#include + +#else +#ifdef HAVE_UNISTD_H +#include +#endif + +#endif + + + +void gdef_GetHostName (char machine[], int n) +{ + int j; +#ifdef HAVE_SYS_UTSNAME_H + struct utsname Z; +#else + char *name; +#endif + + if (n <= 0 || machine == NULL) + return; + machine[0] = '\0'; + +#ifdef HAVE_SYS_UTSNAME_H + if (uname(&Z) != -1) { + strncpy (machine, Z.nodename, (size_t) n); + j = strlen (machine); + if (n - j > 2) + strncat (machine, ", ", (size_t) 2); + j = strlen (machine); + if (n - j > 0) + strncat (machine, Z.sysname, (size_t) (n - j)); + machine[n - 1] = '\0'; + return; + } + +#else +#ifdef HAVE_UNISTD_H + gethostname (machine, (size_t) n); + machine[n - 1] = '\0'; + return; + +#else + name = getenv ("HOST"); + if (name != NULL) { + strncpy (machine, name, (size_t) n); + j = strlen (machine); + machine[n - 1] = '\0'; + if (j < n - 3) { + machine[j++] = ','; + machine[j++] = ' '; + } + } + name = getenv ("OSTYPE"); + if (name != NULL) { + if ((int) strlen (name) < n - j) + strncat (machine, name, (size_t) n - j); + machine[n - 1] = '\0'; + } + +#endif +#endif +} + + +/*------------------------------------------------------------------------*/ +#define MAXBYTES 255 + +void gdef_WriteHostName (void) +{ + char machine[1 + MAXBYTES] = {'\0'}; + gdef_GetHostName (machine, MAXBYTES); + printf ("%s\n", machine); +} + +#if 0 +int main() +{ + struct utsname name; + + if (uname(&name) != -1) + printf(" %s\n", name.nodename); + else { + fprintf(stderr, "Can't find system name\n"); + return 1; + } + gdef_GetHostName (0, MAXBYTES); + gdef_WriteHostName (); + return 0; +} +#endif diff --git a/TESTU01/TestU01-1.2.3/mylib/gdef.tex b/TESTU01/TestU01-1.2.3/mylib/gdef.tex new file mode 100644 index 0000000..39b2ce6 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/gdef.tex @@ -0,0 +1,226 @@ +\defmodule {gdef} + +Platform-dependent options are defined here. +These options are used by other modules to decide when +platform-dependent functions must be commented out or not. +Most of these options are set to their true values by the program +{\it configure} in the installation process. The user may choose +to set some of them manually. +\iffalse +Each option must either be left undefined (i.e., the corresponding +macro is put to false, using ``\texttt{\#undef}) +or can be given its proper value (using ``\texttt{\#define} commands). +An option can be defined only under certain conditions. +For example, \texttt{USE\_GMP} can be defined only if GMP +is available, \texttt{HAVE\_ERF} can be defined only if the Unix \texttt{erf} +function is available, and so on. +\fi +This module also contains a function that prints the current host name. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\code\hide +/* gdef.h for ANSI C */ +#ifndef GDEF_H +#define GDEF_H + +#include +#include + +#ifdef HAVE_LONG_LONG +#define USE_LONGLONG +#else +#undef USE_LONGLONG +#endif + +#ifdef HAVE_GMP_H +#define USE_GMP +#else +#undef USE_GMP +#endif +\endhide +\endcode + +\guisec{Global macros} + +\code +#define FALSE 0 +#define TRUE 1 + +typedef int lebool; +\endcode + \tab Defines the boolean type \texttt{lebool}, whose only possible values are + {\tt TRUE} and {\tt FALSE}. + \endtab +\code + + +#ifdef HAVE_STDINT_H +#include +#endif + +#ifndef HAVE_UINT32_T +#if UINT_MAX >= 4294967295UL + typedef unsigned int uint32_t; +#else + typedef unsigned long uint32_t; +#endif +#endif + +#ifndef HAVE_UINT8_T + typedef unsigned char uint8_t; +#endif +\endcode + \tab The 8-bit and 32-bit unsigned integers. + \endtab +\code + + +#define USE_LONGLONG +\endcode + \tab Define this macro if 64-bit integers are available and ensure that + they are defined correctly in the following \texttt{typedef}. Otherwise, + undefine this macro. + \endtab +\code + + +#ifdef USE_LONGLONG + typedef long long longlong; + typedef unsigned long long ulonglong; +#define PRIdLEAST64 "lld" +#define PRIuLEAST64 "llu" +#endif +\endcode + \tab The 64-bit integer types. Note that the 64-bit integers types + \texttt{long long} and \texttt{unsigned long long} may exist and be called + by different names. + The macros \texttt{PRIdLEAST64} and \texttt{PRIuLEAST64} are defined + in the ISO C99 standard in order to print \emph{signed} + and \emph{unsigned} 64-bit integers, respectively. + Define them correctly if they are not already defined, otherwise + comment them out. + \endtab +\hide +\code + + +#if ULONG_MAX == 4294967295UL +#define IS_ULONG32 +#endif +\endcode + \tab This macro is defined if type \texttt {unsigned long} has + exactly 32 bits, otherwise it is undefined. + \endtab +\endhide +\code + + +#undef USE_ANSI_CLOCK +\endcode + \tab On a MS-Windows platform, + %(when the macro \texttt{HAVE\_WINDOWS\_H} is defined), + the MS-Windows function \texttt{GetProcessTimes} will be used to measure + the CPU time used by programs (in module \texttt{chrono}). + + On Linux/Unix platforms, if the macro + \texttt{USE\_ANSI\_CLOCK} is defined, the timers % in module \texttt{chrono} + will call the ANSI C \texttt{clock} function. However, on systems + where the type \texttt{clock\_t} is a 32-bit \texttt{long}, + the time returned + will wrap around to negative values after about 36 minutes. + When the macro \texttt{USE\_ANSI\_CLOCK} is undefined, the + module \texttt{chrono} gets the CPU time used by a program via an + alternate non-ANSI C timer + based on the POSIX (The Portable Operating System Interface) + function \texttt{times}, assuming this function is available. The POSIX + standard is described in the IEEE Std 1003.1-2001 document (see + The Open Group web site at + \url{http://www.opengroup.org/onlinepubs/007904975/toc.htm}). + \endtab +\code + + +#define DIR_SEPARATOR "/" +\endcode + \tab Used to separate directories in the pathname of a file. + It is \texttt{"$/$"} on {Unix-Linux} and most other platforms. + It may have to be set to \texttt{"$\backslash\backslash$"} on some platforms. + \endtab +\code + + +#undef USE_GMP +\endcode + \tab Define this macro if the GNU multi-precision package GMP + is available. GMP is a portable library written in C for arbitrary + precision arithmetic on integers, rational numbers, and floating-point + numbers. See the Free Software Foundation web site at + \url{http://www.gnu.org/software/gmp/manual}. A few random number + generators in library TestU01 use arbitrary large integers, and they + have been implemented with GMP functions. If one wants to use GMP, the + GMP header file (\texttt{gmp.h}) must be in the search path + of the C compiler for included files, and the GMP library must be + linked to create executable programs. + \endtab +\code + + +#undef HAVE_MATHEMATICA +\endcode + \tab Define this macro if the {\em Mathematica\/} +% \footnote{ +% {\em Mathematica} is a registered trademark of {\em Wolfram Research, +% Inc.} Web address: \texttt{www.wolfram.com}} + software \cite{mWOL96a} + and the {\em MathLink} program that allows a C program to call + functions from {\em Mathematica} are available and you want to use them. + This is used only in module \texttt{usoft} + of library TestU01, where the random number generators from + {\em Mathematica} can be called from a C program for testing with TestU01. + + When a C program uses {\em Mathematica}, it must be compiled with the + options + \texttt{-I\$MATHINC -L\$MATHLIB -lML}, where + \texttt{\$MATHINC} is the path to the header file \texttt{mathlink.h} and + \texttt{\$MATHLIB} is the path to the {\em MathLink\/} library \texttt{libML.a}. + For example, in the environment of our lab, both + \texttt{\$MATHINC} and \texttt{\$MATHLIB} must be set to + + \url{/mathematica/5.0/linux/AddOns/MathLink/DeveloperKit/Linux/CompilerAdditions}. + + To run a main program named \texttt{tulip} on a Unix/Linux platform + that calls {\em Mathematica} functions, one may use + \begin{verse} + \texttt{tulip -linkname 'math -mathlink' -linklaunch}. + \end{verse} + \endtab + +% \newpage + +%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Host machine} +\code + +void gdef_GetHostName (char machine[], int n); +\endcode + \tab Returns in \texttt{machine} the host name. + Will copy at most $n$ characters, so the array \texttt{machine[]} + should have a size $\ge n$. This is useful, for example, + to get the name of the machine on which a program is running. + \hpierre{Does this work on any type of system or only on Linux?} + \hrichard{Avec presque tous les syst\`emes Unix ou Linux et ceux qui + respectent le standard POSIX.} + \endtab +\code + + +void gdef_WriteHostName (void); +\endcode + \tab Prints the name of the machine on which a program is running. + This should work on any Unix or Linux machine. + \endtab +\hide +\code +#endif +\endcode +\endhide diff --git a/TESTU01/TestU01-1.2.3/mylib/guidemylib.bbl b/TESTU01/TestU01-1.2.3/mylib/guidemylib.bbl new file mode 100644 index 0000000..db3c8f1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/guidemylib.bbl @@ -0,0 +1,25 @@ +\begin{thebibliography}{1} + +\bibitem{mCLE62a} +C.~W. Clenshaw. +\newblock Chebychev series for mathematical functions. +\newblock National Physical Laboratory Mathematical Tables~5, Her Majesty's + Stationery Office, London, 1962. + +\bibitem{iKNU81a} +D.~E. Knuth. +\newblock {\em The Art of Computer Programming, Vol. 2}. +\newblock Addison-Wesley, Reading, Mass., second edition, 1981. + +\bibitem{rLEC91a} +P.~L'Ecuyer and S.~C{\^o}t{\'e}. +\newblock Implementing a random number package with splitting facilities. +\newblock {\em ACM Transactions on Mathematical Software}, 17(1):98--111, 1991. + +\bibitem{mWOL96a} +S.~Wolfram. +\newblock {\em The Mathematica Book}. +\newblock Wolfram Media/Cambridge University Press, Champaign, USA, third + edition, 1996. + +\end{thebibliography} diff --git a/TESTU01/TestU01-1.2.3/mylib/guidemylib.pdf b/TESTU01/TestU01-1.2.3/mylib/guidemylib.pdf new file mode 100644 index 0000000..f1c64f8 Binary files /dev/null and b/TESTU01/TestU01-1.2.3/mylib/guidemylib.pdf differ diff --git a/TESTU01/TestU01-1.2.3/mylib/guidemylib.tex b/TESTU01/TestU01-1.2.3/mylib/guidemylib.tex new file mode 100644 index 0000000..e6c1875 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/guidemylib.tex @@ -0,0 +1,37 @@ +\documentclass[12pt]{article} +\usepackage{url} + +\input ../doc/myarticle.sty + +\def\pierre#1 {\fbox {\footnote {\ }}\ \footnotetext { From Pierre: #1}} +\def\richard#1 {\fbox {\footnote {\ }}\ \footnotetext { From Richard: #1}} +\def\hpierre#1 {} +\def\hrichard#1 {} +\def\myurl{\url{http://www.iro.umontreal.ca/~lecuyer}} + +\newcommand\guisec[1]{\vspace{20pt} +\noindent\hrulefill\hspace{10pt}{\bf #1}\hspace{10pt}\hrulefill +\vspace{10pt}\nopagebreak} + +% \includeonly{util} + +\begin{document} +\include {titre} +\pagenumbering{roman} +\tableofcontents +\pagenumbering{arabic} + +\include{gdef} +\include{util} +\include{bitset} +\include{chrono} +\include{num} +\include{num2} +\include{tables} +\include{mystr} +\include{addstr} +\include{tcode} + +\bibliographystyle {plain} +\bibliography{stat,random,simul,math,ift} +\end{document} diff --git a/TESTU01/TestU01-1.2.3/mylib/mystr.c b/TESTU01/TestU01-1.2.3/mylib/mystr.c new file mode 100644 index 0000000..dd9b433 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/mystr.c @@ -0,0 +1,171 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: mystr.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "mystr.h" +#include +#include +#include + + +void mystr_Delete (char S[], unsigned int index, unsigned int len) +{ + int i; + unsigned int length = strlen (S); + if (index + len > length) + S[index] = '\0'; + else + for (i = index; (unsigned int) i <= length - len; ++i) + S[i] = S[i + len]; +} + + +void mystr_Insert (char Res[], char Source[], unsigned int Pos) +{ + int i; + unsigned int ResLength = strlen (Res); + unsigned int SourceLength = strlen (Source); + if (Pos > ResLength) + util_Error ("mystr_Insert : Index out of array bound."); + for (i = ResLength; (unsigned) i >= Pos; --i) { + Res[i + SourceLength] = Res[i]; /* end of Res */ + } + for (i = Pos; (unsigned) i < Pos + SourceLength; ++i) + Res[i] = Source[i - Pos]; /* adding Source to Res */ +} + + +void mystr_ItemS (char R[], char S[], const char T[], unsigned int N) +{ + unsigned int i; + char *temp; + temp = strtok (S, T); /* first time */ + for (i = 1; i <= N; ++i) { /* 2nd to Nth time */ + if (temp == NULL) + break; + temp = strtok (NULL, T); + } + if (temp == NULL) { + strncpy (R, "\0", (size_t) 1); + return; + } + strcpy (R, temp); /* assignation */ +} + + +static int mystr_Rmatch (char s[], unsigned int i, char p[], unsigned int j) +{ + int matched; + unsigned int k; + unsigned int s_len = strlen (s); + unsigned int p_len = strlen (p); + if (p[0] == 0) + return 1; + for (;;) { + if ((i > s_len - 1 || s[i] == 0) && (j > p_len - 1 || p[j] == 0)) + return 1; + if (j > p_len - 1 || p[j] == 0) + return 0; + if (p[j] == '*') { + k = i; + if (j == p_len - 1 || p[j + 1] == 0) + return 1; + else { + for (;;) { + matched = mystr_Rmatch (s, k, p, j + 1); + if ((matched || k > s_len - 1) || s[k] == 0) + return matched; + ++k; + } + } + } + if ((p[j] == '?' && s[i]) || (toupper (p[j]) == toupper (s[i]))) { + ++i; + ++j; + } else + return 0; + } + return 0; +} + + +int mystr_Match (char Source[], char Pattern[]) +/* + returns TRUE if the string in Source matches the string in Pattern + The pattern may contain any number of the wild characters '*' and '?' + '?' matches any single character + '*' matches any sequence of charcters (including a zero length sequence) + EG '*m?t*i*' will match 'Automatic' + */ +{ + return mystr_Rmatch (Source, 0, Pattern, 0); +} + + +void mystr_Slice (char R[], char S[], unsigned int P, unsigned int L) +{ + unsigned int i; + if (P + L > strlen (S)) + util_Error ("*** ERROR : mystr_Slice Pattern longer then Source"); + for (i = 0; i < L; i++) { + R[i] = S[i + P]; + } + if (L <= strlen (R) - 1) + R[L] = 0; +} + + +void mystr_Subst (char source[], char OldPattern[], char NewPattern[]) +{ + unsigned int len; + unsigned int index; + char *PatternFound; + PatternFound = strstr (source, OldPattern); + if (PatternFound != NULL) { + len = strlen (OldPattern); + index = PatternFound - source; + mystr_Delete (source, index, len); + mystr_Insert (source, NewPattern, index); + } +} + + +void mystr_Position (char Substring[], char Source[], unsigned int at, + unsigned int *pos, int *found) +{ + char *result = strstr (Source + at, Substring); + if (at > strlen (Source)) + util_Error ("mystr_Position : Index out of array bound."); + if (result != NULL) { + *pos = result - Source; + *found = 1; + } else + *found = 0; +} diff --git a/TESTU01/TestU01-1.2.3/mylib/mystr.tex b/TESTU01/TestU01-1.2.3/mylib/mystr.tex new file mode 100644 index 0000000..1dd501f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/mystr.tex @@ -0,0 +1,75 @@ +\defmodule {mystr} + +This module offers some tools for the manipulation of +character strings. + +\bigskip\hrule +\code\iffalse +/* mystr.h for ANSI C */ + +#ifndef MYSTR_H +#define MYSTR_H +\fi + +void mystr_Delete (char S[], unsigned int index, unsigned int len); +\endcode + \tab Deletes {\tt len} characters from S, starting at position + {\tt index}. + \endtab +\code + + +void mystr_Insert (char Res[], char Source[], unsigned int Pos); +\endcode + \tab Inserts the string {\tt Source} into {\tt Res}, + starting at position {\tt Pos}. + \endtab +\code + + +void mystr_ItemS (char R[], char S[], const char T[], unsigned int N); +\endcode + \tab Returns in R the N-th substring of S (counting from 0). + Substrings are delimited by any character from the set T. + \endtab +\code + + +int mystr_Match (char Source[], char Pattern[]); +\endcode + \tab Returns {\tt 1} if the string {\tt Source} matches the + string {\tt Pattern}, and {\tt 0} otherwise. + The characters ``?'' and ``*'' are recognized as wild characters in the + string {\tt Pattern}. + \endtab +\code + + +void mystr_Slice (char R[], char S[], unsigned int P, unsigned int L); +\endcode + \tab Returns in {\tt R} the substring in {\tt S} beginning at + position {\tt P} and of length {\tt L}. + \endtab +\code + + +void mystr_Subst (char Source[], char OldPattern[], char NewPattern[]); +\endcode + \tab Searches for the string {\tt OldPattern} in the string {\tt Source}, + and replaces its first occurence with {\tt NewPattern}. + \endtab +\code + + +void mystr_Position (char Substring[], char Source[], unsigned int at, + unsigned int * pos, int * found); +\endcode + \tab Searches for the string {\tt Substring} in the string {\tt Source}, + starting at position {\tt at}, and returns the position of its first + occurence in {\tt pos}. + \endtab +\code +\iffalse + +#endif +\fi\endcode diff --git a/TESTU01/TestU01-1.2.3/mylib/num.c b/TESTU01/TestU01-1.2.3/mylib/num.c new file mode 100644 index 0000000..6b419ac --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/num.c @@ -0,0 +1,412 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: num.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "util.h" +#include "bitset.h" +#include "num.h" +#include +#include +#include +#include + + + + +#define Deux53 9007199254740992.0 /* 2^53 */ +#define Deux17 131072.0 /* 2^17 */ +#define UnDeux17 7.62939453125E-6 /* 1 / 2^17 */ +#define MASK32 0xffffffffUL + +double num_TwoExp[num_MaxTwoExp + 1] = { + 1.0, 2.0, 4.0, 8.0, 1.6e1, 3.2e1, + 6.4e1, 1.28e2, 2.56e2, 5.12e2, 1.024e3, + 2.048e3, 4.096e3, 8.192e3, 1.6384e4, 3.2768e4, + 6.5536e4, 1.31072e5, 2.62144e5, 5.24288e5, + 1.048576e6, 2.097152e6, 4.194304e6, 8.388608e6, + 1.6777216e7, 3.3554432e7, 6.7108864e7, + 1.34217728e8, 2.68435456e8, 5.36870912e8, + 1.073741824e9, 2.147483648e9, 4.294967296e9, + 8.589934592e9, 1.7179869184e10, 3.4359738368e10, + 6.8719476736e10, 1.37438953472e11, 2.74877906944e11, + 5.49755813888e11, 1.099511627776e12, 2.199023255552e12, + 4.398046511104e12, 8.796093022208e12, + 1.7592186044416e13, 3.5184372088832e13, + 7.0368744177664e13, 1.40737488355328e14, + 2.81474976710656e14, 5.62949953421312e14, + 1.125899906842624e15, 2.251799813685248e15, + 4.503599627370496e15, 9.007199254740992e15, + 1.8014398509481984e16, 3.6028797018963968e16, + 7.2057594037927936e16, 1.44115188075855872e17, + 2.88230376151711744e17, 5.76460752303423488e17, + 1.152921504606846976e18, 2.305843009213693952e18, + 4.611686018427387904e18, 9.223372036854775808e18, + 1.8446744073709551616e19 +}; + + +double num_TENNEGPOW[] = { + 1.0, 1.0e-1, 1.0e-2, 1.0e-3, 1.0e-4, 1.0e-5, 1.0e-6, 1.0e-7, 1.0e-8, + 1.0e-9, 1.0e-10, 1.0e-11, 1.0e-12, 1.0e-13, 1.0e-14, 1.0e-15, 1.0e-16 +}; + + + +int num_IsNumber (char S[]) +/********************************************************* + * Returns TRUE if the string S begin with a number * + * (with the possibility of spaces and a + or - sign * + * before the number). * + * e.g. * + * ' + 2' returns TRUE * + * '-+ 2' returns FALSE * + * '4hello' returns TRUE * + * 'hello' returns FALSE * + *********************************************************/ +{ + int Max; + int i; + int Sign; + Max = (int) (strlen (S) - 1); + Sign = 0; + for (i = 0; i < Max; i++) { + if (S[i] != ' ') { + if (S[i] == '+' || S[i] == '-') { + if (Sign) { + return 0; + } + /* We already saw a sign */ + Sign = 1; + } else if ((unsigned char) S[i] >= '0' && + (unsigned char) S[i] <= '9') { + return 1; + } else { + return 0; + } + } + } /* end for */ + return 0; /* There's no digit in S */ +} /* end IsNumber() */ + + +void num_IntToStrBase (long k, long b, char S[]) +{ + int Sign; /* insert a '-' if TRUE */ + long Char0; + long i; + long total; + long uppbound; + if (b < 2 || b > 10) { + util_Error ("*** Erreur: IntToStrB demande une b entre 2 et 10 ***"); + } + Char0 = 48; + if (k < 0) { + Sign = 1; + S[0] = '-'; + k = -k; + } else { + if (k == 0) { + S[0] = '0'; + S[1] = '\0'; + return; + } + Sign = 0; + } + i = k; + total = 0; + while (i > 0) { + i = (i / b); + ++total; + } + if (Sign) + uppbound = total + 1; + else + uppbound = total; + S[uppbound] = '\0'; + for (i = 0; i < total - 1; i++) { + S[(uppbound - i) - 1] = + (char) ((int) fmod ((double) k, (double) b) + Char0); + k = (long) (k / b); + } +} + + +/*=========================================================================*/ + +void num_Uint2Uchar (unsigned char *output, unsigned int *input, int L) +{ + int i, j; + + for (i = 0, j = 0; i < L; i++, j += 4) { + output[j + 3] = (unsigned char) (input[i] & 0xff); + output[j + 2] = (unsigned char) ((input[i] >> 8) & 0xff); + output[j + 1] = (unsigned char) ((input[i] >> 16) & 0xff); + output[j] = (unsigned char) ((input[i] >> 24) & 0xff); + } +} + + +/*=========================================================================*/ + +void num_WriteD (double x, int I, int J, int K) +{ + int PosEntier = 0, /* Le nombre de positions occupees par la + partie entiere de x */ + EntierSign, /* Le nombre de chiffres significatifs + avant le point */ + Neg = 0; /* Nombre n'egatif */ + char S[100]; + char *p; + + if (x == 0.0) + EntierSign = 1; + else { + EntierSign = PosEntier = floor (log10 (fabs (x)) + 1); + if (x < 0.0) + Neg = 1; + } + if (EntierSign <= 0) + PosEntier = 1; + + if ((x == 0.0) || + (((EntierSign + J) >= K) && (I >= (PosEntier + J + Neg + 1)))) + printf ("%*.*f", I, J, x); + + else { /* On doit utiliser la notation + scientifique. */ + sprintf (S, "%*.*e", I, K - 1, x); + p = strstr (S, "e+0"); + if (NULL == p) + p = strstr (S, "e-0"); + + /* remove the 0 in e-0 and in e+0 */ + if (p) { + p += 2; + while ((*p = *(p + 1))) + p++; + printf (" "); /* pour utiliser au moins I espaces */ + } + printf ("%s", S); + } +} + + +/***************************************************************************/ + +void num_WriteBits (unsigned long x, int k) +{ + int i, n = CHAR_BIT * sizeof (unsigned long); + unsigned long mask = (unsigned long) 1 << (n - 1); + int spaces; + lebool flag = FALSE; + + if (k > 0) { + spaces = k - n; + for (i = 0; i < spaces; i++) + printf (" "); + } + for (i = 0; i < n; i++) { + if (x & mask) { + printf ("1"); + flag = TRUE; + } else if (flag) + printf ("0"); + else + printf (" "); + mask >>= 1; + } + if (k < 0) { + spaces = -k - n; + for (i = 0; i < spaces; i++) + printf (" "); + } +} + + +/***************************************************************************/ + +#if LONG_MAX == 2147483647L +#define H 32768 /* = 2^d used in MultModL. */ +#else +#define H 2147483648L +#endif + +long num_MultModL (long a, long s, long c, long m) + /* Suppose que 0 < a < m et 0 < s < m. Retourne (a*s + c) % m. */ + /* Cette procedure est tiree de : */ + /* L'Ecuyer, P. et Cote, S., A Random Number Package with */ + /* Splitting Facilities, ACM TOMS, 1991. */ + /* On coupe les entiers en blocs de d bits. H doit etre egal a 2^d. */ +{ + long a0, a1, q, qh, rh, k, p; + if (a < H) { + a0 = a; + p = 0; + } else { + a1 = a / H; + a0 = a - H * a1; + qh = m / H; + rh = m - H * qh; + if (a1 >= H) { + a1 = a1 - H; + k = s / qh; + p = H * (s - k * qh) - k * rh; + if (p < 0) + p = (p + 1) % m + m - 1; + } else /* p = (A2 * s * h) % m. */ + p = 0; + if (a1 != 0) { + q = m / a1; + k = s / q; + p -= k * (m - a1 * q); + if (p > 0) + p -= m; + p += a1 * (s - k * q); + if (p < 0) + p = (p + 1) % m + m - 1; + } /* p = ((A2 * h + a1) * s) % m. */ + k = p / qh; + p = H * (p - k * qh) - k * rh; + if (p < 0) + p = (p + 1) % m + m - 1; + } /* p = ((A2 * h + a1) * h * s) % m */ + if (a0 != 0) { + q = m / a0; + k = s / q; + p -= k * (m - a0 * q); + if (p > 0) + p -= m; + p += a0 * (s - k * q); + if (p < 0) + p = (p + 1) % m + m - 1; + } + p = (p - m) + c; + if (p < 0) + p += m; + return p; +} + +/*************************************************************************/ + +double num_MultModD (double a, double s, double c, double m) +{ + double V; + long k; + V = a * s + c; + if (V >= Deux53 || -V >= Deux53) { + k = a * UnDeux17; + a -= k * Deux17; + V = k * s; + k = V / m; + V -= k * m; + V = V * Deux17 + a * s + c; + } + k = V / m; + V -= k * m; + if (V < 0) + V += m; + return V; +} + + +/**************************************************************************/ + +long num_InvEuclid (long M, long x) +/* + * Compute the inverse of x mod M by the modified Euclide + * algorithm (Knuth V2 p. 325). + */ +{ + long u1 = 0, u3 = M, v1 = 1, v3 = x; + long t1, t3, qq; + if (x == 0) return 0; + + while (v3 != 0) { + qq = u3 / v3; + t1 = u1 - v1 * qq; + t3 = u3 - v3 * qq; + u1 = v1; + v1 = t1; + u3 = v3; + v3 = t3; + } + if (u1 < 0) + u1 += M; + + if (u3 != 1) { /* In this case, the inverse does not exist! */ + fprintf (stderr, + "ERROR in num_InvEuclid: inverse does not exist: m = %ld, x = %ld\n", + M, x); + return 0; + } else + return u1; +} + + +/*------------------------------------------------------------------------*/ + +unsigned long num_InvExpon (int E, unsigned long Z) +/* + * Compute the inverse of Z modulo M = 2^E by exponentiation + */ +{ + int j; + unsigned long res = Z; + + if (Z == 0) return 0; + if (!(Z & 1)) { + fprintf (stderr, + "ERROR in num_InvExpon: inverse does not exist: E = %d, Z = %ld\n", + E, Z); + return 0; + } + for (j = 1; j <= E - 3; j++) + res = res * res * Z; + return res & bitset_MASK[E]; +} + + +/*------------------------------------------------------------------------*/ + +long num_RoundL (double x) +{ + return (x >= 0) ? (long)(x + 0.5) : (long)(x - 0.5); +} + + +double num_RoundD (double x) +{ + double z; + (x >= 0) ? modf(x + 0.5, &z) : modf(x - 0.5, &z); + return z; +} + + +/*------------------------------------------------------------------------*/ diff --git a/TESTU01/TestU01-1.2.3/mylib/num.h b/TESTU01/TestU01-1.2.3/mylib/num.h new file mode 100644 index 0000000..268ceb1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/num.h @@ -0,0 +1,92 @@ + +/* num.h for ANSI C */ + +#ifndef NUM_H +#define NUM_H + +#include "gdef.h" + + +#define num_Pi 3.14159265358979323846 + + +#define num_ebase 2.7182818284590452354 + + +#define num_Rac2 1.41421356237309504880 + + +#define num_1Rac2 0.70710678118654752440 + + +#define num_Ln2 0.69314718055994530941 + + +#define num_1Ln2 1.44269504088896340737 + + +#define num_MaxIntDouble 9007199254740992.0 + + +#define num_MaxTwoExp 64 + + +extern double num_TwoExp[]; + + +#define num_MAXTENNEGPOW 16 + + +extern double num_TENNEGPOW[]; + + +#define num_Log2(x) (num_1Ln2 * log(x)) + + + +long num_RoundL (double x); + + + +double num_RoundD (double x); + + + +int num_IsNumber (char S[]); + + + +void num_IntToStrBase (long k, long b, char S[]); + + + +void num_Uint2Uchar (unsigned char output[], unsigned int input[], int L); + + + +void num_WriteD (double x, int i, int j, int k); + + + +void num_WriteBits (unsigned long x, int k); + + + +long num_MultModL (long a, long s, long c, long m); + + + +double num_MultModD (double a, double s, double c, double m); + + + +long num_InvEuclid (long m, long z); + + + +unsigned long num_InvExpon (int E, unsigned long z); + + +#endif + + diff --git a/TESTU01/TestU01-1.2.3/mylib/num.tex b/TESTU01/TestU01-1.2.3/mylib/num.tex new file mode 100644 index 0000000..8e39947 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/num.tex @@ -0,0 +1,221 @@ +\defmodule {num} + +This module offers some useful constants and basic tools to +manipulate numbers represented in different forms. + +\bigskip\hrule +\code\hide +/* num.h for ANSI C */ + +#ifndef NUM_H +#define NUM_H +\endhide +#include "gdef.h" +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Constants} +\code + +#define num_Pi 3.14159265358979323846 +\endcode + \tab The number $\pi$. + \endtab +\code + +#define num_ebase 2.7182818284590452354 +\endcode + \tab The number $e$. + \endtab +\code + +#define num_Rac2 1.41421356237309504880 +\endcode + \tab $\sqrt{2}$, the square root of 2. + \endtab +\code + +#define num_1Rac2 0.70710678118654752440 +\endcode + \tab $1/\sqrt{2}$. + \endtab +\code + +#define num_Ln2 0.69314718055994530941 +\endcode + \tab $\ln(2)$, the natural logarithm of 2. + \endtab +\code + +#define num_1Ln2 1.44269504088896340737 +\endcode + \tab $1 / \ln(2)$. + \endtab +\code + +#define num_MaxIntDouble 9007199254740992.0 +\endcode + \tab Largest integer $n_0 = 2^{53}$ such that all integers + $n \le n_0$ are represented exactly as a {\tt double}. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Precomputed powers} +\code + +#define num_MaxTwoExp 64 +\endcode + \tab Powers of 2 up to {\tt num\_MaxTwoExp} are stored exactly + in the array {\tt num\_TwoExp}. + \endtab +\code + +extern double num_TwoExp[]; +\endcode + \tab Contains precomputed powers of 2. + One has {\tt num\_TwoExp[i]} $= 2^i$ for $0 \le i \le$ + {\tt num\_MaxTwoExp}. +\endtab +\code + +#define num_MAXTENNEGPOW 16 +\endcode + \tab Negative powers of 10 up to {\tt num\_MAXTENNEGPOW} are stored + in the array {\tt num\_TENNEGPOW}. + \endtab +\code + +extern double num_TENNEGPOW[]; +\endcode + \tab Contains the precomputed negative powers of 10. + One has {\tt TENNEGPOW[j]}$ = 10^{-j}$, for $j=0,\ldots,$ + {\tt num\_MAXTENNEGPOW}. +\endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Prototypes} +\code + +#define num_Log2(x) (num_1Ln2 * log(x)) +\endcode + \tab Gives the logarithm of $x$ in base 2. + \endtab +\code + + +long num_RoundL (double x); +\endcode + \tab Rounds $x$ to the nearest ({\tt long}) integer and returns it. + \endtab +\code + + +double num_RoundD (double x); +\endcode + \tab Rounds $x$ to the nearest ({\tt double}) integer and returns it. + \endtab +\code + + +int num_IsNumber (char S[]); +\endcode +\tab Returns {\tt 1} if the string {\tt S} begins with a number + (with the possibility of spaces and a $+/-$ sign + before the number). For example, `` + 2'' and ``4hello'' + return {\tt 1}, while ``$-+2$'' and ``hello'' return + {\tt 0}. +\endtab +\code + + +void num_IntToStrBase (long k, long b, char S[]); +\endcode + \tab Returns in {\tt S} the string representation of {\tt k} in base + {\tt b}. + \endtab +\code + + +void num_Uint2Uchar (unsigned char output[], unsigned int input[], int L); +\endcode + \tab Transforms the $L$ 32-bit integers contained in {\tt input} into + $4L$ characters and puts them into {\tt output}. The order is such that + the 8 most significant bits of {\tt input[0]} will be in {\tt output[0]}, + the 8 least significant bits of {\tt input[0]} will be in {\tt output[3]}, + and the 8 least significant bits of {\tt input[L-1]} will be in + {\tt output[4L-1]}. Array {\tt output} must have at least $4L$ elements. + \endtab +\code + + +void num_WriteD (double x, int i, int j, int k); +\endcode + \tab Writes {\tt x} to current output. Uses a total of at least {\tt i} + positions (including the sign and point when they appear), + {\tt j} digits after the decimal point and at least {\tt k} + significant digits. The number is rounded if necessary. + If there is not enough space to print the number in decimal notation + with at least {\tt k} significant digits + ({\tt j} or {\tt i} is too small), it will be printed in scientific + notation with at least {\tt k} significant digits. + In that case, {\tt i} is increased if necessary. + Restriction: {\tt j} and {\tt k} must be strictly smaller than {\tt i}. + \endtab +\code + + +void num_WriteBits (unsigned long x, int k); +\endcode + \tab Writes {\tt x} in base 2 in a field of at least + $\max\{b, |k|\}$ positions, where $b$ is the number of bits in an + {\tt unsigned long}. + If $k>0$, the number will be right-justified, otherwise left-justified. + \endtab +\code + + +long num_MultModL (long a, long s, long c, long m); +\endcode +\tab Returns $(as + c) \mod m$. Uses the decomposition technique + of \cite{rLEC91a} to avoid overflow. Supposes that $s < m$. +\endtab +\code + + +double num_MultModD (double a, double s, double c, double m); +\endcode + \tab Returns $(as+c) \mod m$, assuming that + $a$, $s$, $c$, and $m$ are all {\em integers\/} less than $2^{35}$ + (represented exactly). + Works under the assumption that all positive integers less than + $2^{53}$ are represented exactly in floating-point (in {\tt double}). +\endtab +\code + + +long num_InvEuclid (long m, long z); +\endcode + \tab This function computes the inverse $z^{-1}\bmod m$ by the + modified Euclid algorithm (see \cite[p. 325]{iKNU81a}) and returns + the result. If the inverse does not exist, returns 0. +\endtab +\code + + +unsigned long num_InvExpon (int E, unsigned long z); +\endcode + \tab + This function computes the inverse $z^{-1} \bmod 2^E$ + by exponentiation and returns the result. If the inverse does not + exist, returns 0. + Restriction: $E$ not larger than the number of bits + in an {\tt unsigned long}. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/mylib/num2.c b/TESTU01/TestU01-1.2.3/mylib/num2.c new file mode 100644 index 0000000..32827c1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/num2.c @@ -0,0 +1,668 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: num2.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "num2.h" +#include "util.h" +#include "num.h" +#include +#include +#include + +#define EPSILON 1.0E-15 +#define MAXI 50 + +/* The factorials n! from n = 0 to n = 170 */ +static double Factorials[] = { + 1, + 1, + 2, + 6, + 24, + 120, + 720, + 5040, + 40320, + 362880, + 3628800, + 39916800, + 479001600, + 6227020800.0, + 87178291200.0, + 1307674368000.0, + 20922789888000.0, + 355687428096000.0, + 6402373705728000.0, + 1.21645100408832e+17, + 2.43290200817664e+18, + 5.109094217170944e+19, + 1.124000727777608e+21, + 2.585201673888498e+22, + 6.204484017332394e+23, + 1.551121004333099e+25, + 4.032914611266057e+26, + 1.088886945041835e+28, + 3.048883446117138e+29, + 8.841761993739701e+30, + 2.65252859812191e+32, + 8.222838654177922e+33, + 2.631308369336935e+35, + 8.683317618811886e+36, + 2.952327990396041e+38, + 1.033314796638614e+40, + 3.719933267899012e+41, + 1.376375309122634e+43, + 5.23022617466601e+44, + 2.039788208119744e+46, + 8.159152832478977e+47, + 3.34525266131638e+49, + 1.40500611775288e+51, + 6.041526306337383e+52, + 2.658271574788449e+54, + 1.196222208654802e+56, + 5.502622159812088e+57, + 2.586232415111682e+59, + 1.241391559253607e+61, + 6.082818640342675e+62, + 3.041409320171338e+64, + 1.551118753287382e+66, + 8.065817517094388e+67, + 4.274883284060025e+69, + 2.308436973392414e+71, + 1.269640335365828e+73, + 7.109985878048635e+74, + 4.052691950487722e+76, + 2.350561331282879e+78, + 1.386831185456899e+80, + 8.320987112741392e+81, + 5.075802138772248e+83, + 3.146997326038794e+85, + 1.98260831540444e+87, + 1.268869321858842e+89, + 8.247650592082472e+90, + 5.443449390774431e+92, + 3.647111091818868e+94, + 2.480035542436831e+96, + 1.711224524281413e+98, + 1.197857166996989e+100, + 8.504785885678622e+101, + 6.123445837688608e+103, + 4.470115461512683e+105, + 3.307885441519386e+107, + 2.480914081139539e+109, + 1.88549470166605e+111, + 1.451830920282858e+113, + 1.132428117820629e+115, + 8.946182130782973e+116, + 7.156945704626378e+118, + 5.797126020747366e+120, + 4.75364333701284e+122, + 3.945523969720657e+124, + 3.314240134565352e+126, + 2.817104114380549e+128, + 2.422709538367272e+130, + 2.107757298379527e+132, + 1.854826422573984e+134, + 1.650795516090845e+136, + 1.485715964481761e+138, + 1.352001527678402e+140, + 1.24384140546413e+142, + 1.156772507081641e+144, + 1.087366156656742e+146, + 1.032997848823905e+148, + 9.916779348709491e+149, + 9.619275968248206e+151, + 9.426890448883242e+153, + 9.33262154439441e+155, + 9.33262154439441e+157, + 9.425947759838354e+159, + 9.614466715035121e+161, + 9.902900716486175e+163, + 1.029901674514562e+166, + 1.08139675824029e+168, + 1.146280563734708e+170, + 1.226520203196137e+172, + 1.324641819451828e+174, + 1.443859583202493e+176, + 1.588245541522742e+178, + 1.762952551090244e+180, + 1.974506857221073e+182, + 2.231192748659812e+184, + 2.543559733472186e+186, + 2.925093693493014e+188, + 3.393108684451897e+190, + 3.969937160808719e+192, + 4.684525849754288e+194, + 5.574585761207603e+196, + 6.689502913449124e+198, + 8.09429852527344e+200, + 9.875044200833598e+202, + 1.214630436702532e+205, + 1.50614174151114e+207, + 1.882677176888925e+209, + 2.372173242880046e+211, + 3.012660018457658e+213, + 3.856204823625803e+215, + 4.974504222477285e+217, + 6.466855489220472e+219, + 8.471580690878817e+221, + 1.118248651196004e+224, + 1.487270706090685e+226, + 1.992942746161518e+228, + 2.69047270731805e+230, + 3.659042881952547e+232, + 5.01288874827499e+234, + 6.917786472619486e+236, + 9.615723196941086e+238, + 1.346201247571752e+241, + 1.89814375907617e+243, + 2.695364137888161e+245, + 3.854370717180071e+247, + 5.550293832739301e+249, + 8.047926057471987e+251, + 1.17499720439091e+254, + 1.727245890454638e+256, + 2.556323917872864e+258, + 3.808922637630567e+260, + 5.71338395644585e+262, + 8.627209774233235e+264, + 1.311335885683452e+267, + 2.006343905095681e+269, + 3.089769613847349e+271, + 4.789142901463391e+273, + 7.471062926282891e+275, + 1.172956879426414e+278, + 1.853271869493734e+280, + 2.946702272495037e+282, + 4.714723635992059e+284, + 7.590705053947215e+286, + 1.229694218739449e+289, + 2.004401576545302e+291, + 3.287218585534294e+293, + 5.423910666131586e+295, + 9.003691705778433e+297, + 1.503616514864998e+300, + 2.526075744973197e+302, + 4.269068009004703e+304, + 7.257415615307994e+306 +}; + + +#define MLIM 50 + +/* The natural logarithm of factorials n! from n = 0 to 50 */ +static double LnFactorials[MLIM + 1] = { + 0., + 0., + 0.6931471805599453, + 1.791759469228055, + 3.178053830347946, + 4.787491742782046, + 6.579251212010101, + 8.525161361065415, + 10.60460290274525, + 12.80182748008147, + 15.10441257307552, + 17.50230784587389, + 19.98721449566188, + 22.55216385312342, + 25.19122118273868, + 27.89927138384088, + 30.67186010608066, + 33.50507345013688, + 36.39544520803305, + 39.33988418719949, + 42.33561646075348, + 45.3801388984769, + 48.47118135183522, + 51.60667556776437, + 54.7847293981123, + 58.00360522298051, + 61.26170176100199, + 64.55753862700632, + 67.88974313718154, + 71.257038967168, + 74.65823634883016, + 78.09222355331529, + 81.55795945611503, + 85.05446701758153, + 88.58082754219767, + 92.13617560368708, + 95.7196945421432, + 99.3306124547874, + 102.9681986145138, + 106.6317602606434, + 110.3206397147574, + 114.0342117814617, + 117.7718813997451, + 121.5330815154386, + 125.3172711493569, + 129.1239336391272, + 132.9525750356163, + 136.8027226373264, + 140.6739236482343, + 144.5657439463449, + 148.477766951773 +}; + + +/*=========================================================================*/ + +double num2_Factorial (int n) +{ + util_Assert (n >= 0, "num2_Factorial: n < 0"); + if (n <= 170) + return Factorials[n]; + util_Warning (1, "num2_Factorial: n > 170: return inf"); + return 1.0 / 0.0; +} + + +/*=========================================================================*/ + +double num2_LnFactorial (int n) +{ + util_Assert (n >= 0, "num2_LnFactorial: n < 0"); + if (n <= MLIM) { + return LnFactorials[n]; + + } else { + double x = (double) (n + 1); + double y = 1.0 / (x * x); + double z = ((-(5.95238095238E-4 * y) + 7.936500793651E-4) * y - + 2.7777777777778E-3) * y + 8.3333333333333E-2; + z = ((x - 0.5) * log (x) - x) + 9.1893853320467E-1 + z / x; + return z; + } +} + + +/*=========================================================================*/ +#ifndef HAVE_LGAMMA + +/* The new standard ISO_C99 includes the lgamma function in math.h; + otherwise, we shall have to use our own. */ + +double num2_LnGamma (double x) +{ + const double xlimbig = 1.0 / DBL_EPSILON; + const double xlim1 = 18.0; + const double dk2 = 0.91893853320467274178; /* Ln (sqrt (2 Pi)) */ + const double dk1 = 0.9574186990510627; + const int N = 15; /* Degree of Chebyshev polynomial */ + double y = 0, z = 0; + int i, k; + + /* Chebyshev coefficients for lnGamma (x + 3), 0 <= x <= 1 In Yudell Luke: + The special functions and their approximations, Vol. II, Academic Press, + p. 301, 1969. There is an error in the additive constant in the formula: + (Ln (2)). */ + static const double A[] = { + 0.52854303698223459887, + 0.54987644612141411418, + 0.02073980061613665136, + -0.00056916770421543842, + 0.00002324587210400169, + -0.00000113060758570393, + 0.00000006065653098948, + -0.00000000346284357770, + 0.00000000020624998806, + -0.00000000001266351116, + 0.00000000000079531007, + -0.00000000000005082077, + 0.00000000000000329187, + -0.00000000000000021556, + 0.00000000000000001424, + -0.00000000000000000095 + }; + + util_Assert (x > 0.0, "num2_LnGamma: accepts only x > 0"); + if (x > xlim1) { + if (x > xlimbig) + y = 0.0; + else + y = 1.0 / (x * x); + z = ((-(5.95238095238E-4 * y) + 7.936500793651E-4) * y - + 2.7777777777778E-3) * y + 8.3333333333333E-2; + z = ((x - 0.5) * log (x) - x) + dk2 + z / x; + return z; + + } else if (x > 4.0) { + k = (int) x; + z = x - k; + y = 1.0; + for (i = 3; i < k; i++) + y *= z + i; + y = log (y); + + } else if (x <= 0.0) { + return DBL_MAX; + + } else if (x < 3.0) { + k = (int) x; + z = x - k; + y = 1.0; + for (i = 2; i >= k; i--) + y *= z + i; + y = -log (y); + + } else { /* 3 <= x <= 4 */ + z = x - 3.0; + y = 0.0; + } + + z = num2_EvalCheby (A, N, 2.0 * z - 1.0); + return z + dk1 + y; +} + +#endif +/*=========================================================================*/ + +#define NLIM 100 /* pour eviter les debordements */ + +double num2_Combination (int n, int s) +{ + double Res; + int i; + int Diff; + if (s == 0 || s == n) + return 1.0; + if (s < 0) { + util_Warning (1, "num2_Combination: s < 0"); + return 0.0; + } + if (s > n) { + util_Warning (1, "num2_Combination: s > n"); + return 0.0; + } + if (s > (n / 2)) + s = n - s; + if (n <= NLIM) { + Res = 1.0; + Diff = n - s; + for (i = 1; i <= s; i++) { + Res = (Res * (double) (Diff + i)) / (double) (i); + } + return Res; + } else { + Res = (num2_LnFactorial (n) - num2_LnFactorial (s)) + - num2_LnFactorial (n - s); + return exp (Res); + } +} + + +/*=========================================================================*/ +#ifndef HAVE_LOG1P + +double num2_log1p (double x) +{ + /* returns a value equivalent to log (1 + x) accurate also for small x. */ + if (fabs (x) > 0.1) { + return log (1.0 + x); + } else { + double term = x; + double sum = x; + int s = 2; + while (fabs (term) > EPSILON * fabs (sum) && s < MAXI) { + term *= -x; + sum += term / s; + s++; + } + return sum; + } +} + +#endif +/*=========================================================================*/ + +void num2_CalcMatStirling (double ***M, int m, int n) +/* Calcul des elements de la matrice MatStirling [0..m, 0..n]. */ +{ + int i, j, k; + *M = (double **) util_Calloc ((size_t) (m + 1), sizeof (double *)); + for (i = 0; i <= m; i++) + (*M)[i] = (double *) util_Calloc ((size_t) (n + 1), sizeof (double)); + + for (i = 0; i <= m; i++) { + for (j = 0; j <= n; j++) { + (*M)[i][j] = 0.0; + } + } + + (*M)[0][0] = 1.0; + for (j = 1; j <= n; j++) { + (*M)[0][j] = 0.0; + if (j <= m) { + k = j - 1; + (*M)[j][j] = 1.0; + } else + k = m; + for (i = 1; i <= k; i++) { + (*M)[i][j] = (double) (i) * (*M)[i][j - 1] + (*M)[i - 1][j - 1]; + } + } +} + + +/*=========================================================================*/ + +void num2_FreeMatStirling (double ***M, int m) +{ + int i; + for (i = 0; i <= m; i++) + free ((*M)[i]); + free (*M); + *M = NULL; +} + + +/*=========================================================================*/ + +double num2_VolumeSphere (double pLR, int k) +/* Returns volume of unit sphere in dimension k, norm p */ +{ + const double eps = 2.0 * DBL_EPSILON; + int p = pLR; + double kLR = (double) k; + double Vol; + int s; + + util_Assert (pLR >= 0.0, "num2_VolumeSphere: p < 0"); + if (fabs (pLR - p) <= eps) { + switch (p) { + case 0: + return num_TwoExp[k]; + break; + case 1: + return num_TwoExp[k] / num2_Factorial (k); + break; + case 2: + if ((k % 2) == 0) { + return pow (num_Pi, kLR / 2.0) / num2_Factorial (k / 2); + } else { + s = (k + 1) / 2; + return pow (num_Pi, (double) (s) - 1.0) * num2_Factorial (s) * + num_TwoExp[2 * s] / num2_Factorial (2 * s); + } + break; + default: + break; + } + } + Vol = kLR * (num_Ln2 + num2_LnGamma (1.0 + 1.0 / pLR)) - + num2_LnGamma (1.0 + kLR / pLR); + return exp (Vol); +} + + +/*=========================================================================*/ + +double num2_EvalCheby (const double A[], int N, double x) +{ + int j; + double xx; + double b0, b1, b2; + util_Warning (fabs (x) > 1.0, + "Chebychev polynomial evaluated at x outside [-1, 1]"); + xx = 2.0 * x; + b0 = 0.0; + b1 = 0.0; + for (j = N; j >= 0; j--) { + b2 = b1; + b1 = b0; + b0 = (xx * b1 - b2) + A[j]; + } + return (b0 - b2) / 2.0; +} + + +/*=========================================================================*/ +#define DEGREE 6 + +double num2_BesselK025 (double x) +{ + double rac; + double xx; + double temp; + double Res; + double C; + double B; + int j; + static const double c[8] = { + 32177591145.0, + 2099336339520.0, + 16281990144000.0, + 34611957596160.0, + 26640289628160.0, + 7901666082816.0, + 755914244096.0 + }; + + static const double b[8] = { + 75293843625.0, + 2891283595200.0, + 18691126272000.0, + 36807140966400.0, + 27348959232000.0, + 7972533043200.0, + 755914244096.0 + }; + + if (x < 1.E-300) + return DBL_MAX; + + /*------------------------------------------------------------------*/ + /* x > 0.6 => approximation asymptotique rationnelle dans Luke: */ + /* Yudell L.Luke "Mathematical functions and their approximations", */ + /* Academic Press Inc. New York, 1975, p.371 */ + /*------------------------------------------------------------------*/ + if (x >= 0.6) { + B = b[DEGREE]; + C = c[DEGREE]; + for (j = DEGREE; j >= 1; j--) { + B = B * x + b[j - 1]; + C = C * x + c[j - 1]; + } + Res = sqrt (num_Pi / (2.0 * x)) * exp (-x) * (C / B); + return Res; + } + + /*------------------------------------------------------------------*/ + /* x < 0.6 => la serie de K_{1/4} = Pi/Sqrt(2) [I_{-1/4} - I_{1/4}] */ + /*------------------------------------------------------------------*/ + xx = x * x; + rac = pow (x / 2.0, 0.25); + Res = (((xx / 1386.0 + 1.0 / 42.0) * xx + 1.0 / 3.0) * xx + 1.0) / + (1.225416702465177 * rac); + temp = (((xx / 3510.0 + 1.0 / 90.0) * xx + 0.2) * xx + 1.0) * rac / + 0.906402477055477; + Res = num_Pi * (Res - temp) / num_Rac2; + return Res; +} + +#undef DEGREE +/*=========================================================================*/ + +double num2_Digamma (double x) +{ + static const double C7[] = { + 1.3524999667726346383e4, 4.5285601699547289655e4, + 4.5135168469736662555e4, 1.8529011818582610168e4, + 3.3291525149406935532e3, 2.4068032474357201831e2, + 5.1577892000139084710, 6.2283506918984745826e-3 + }; + + static const double D7[] = { + 6.9389111753763444376e-7, 1.9768574263046736421e4, + 4.1255160835353832333e4, 2.9390287119932681918e4, + 9.0819666074855170271e3, 1.2447477785670856039e3, + 6.7429129516378593773e1, 1.0 + }; + + static const double C4[] = { + -2.728175751315296783e-15, -6.481571237661965099e-1, + -4.486165439180193579, -7.016772277667586642, -2.129404451310105168 + }; + + static const double D4[] = { + 7.777885485229616042, 5.461177381032150702e1, + 8.929207004818613702e1, 3.227034937911433614e1, 1.0 + }; + + double prodPj = 0.0; + double prodQj = 0.0; + double digX = 0.0; + + if (x >= 3.0) { + double x2 = 1.0 / (x * x); + int j; + for (j = 4; j >= 0; j--) { + prodPj = prodPj * x2 + C4[j]; + prodQj = prodQj * x2 + D4[j]; + } + digX = log (x) - (0.5 / x) + (prodPj / prodQj); + + } else if (x >= 0.5) { + const double X0 = 1.46163214496836234126; + int j; + for (j = 7; j >= 0; j--) { + prodPj = x * prodPj + C7[j]; + prodQj = x * prodQj + D7[j]; + } + digX = (x - X0) * (prodPj / prodQj); + + } else { + double f = (1.0 - x) - floor (1.0 - x); + digX = num2_Digamma (1.0 - x) + num_Pi / tan (num_Pi * f); + } + + return digX; +} + diff --git a/TESTU01/TestU01-1.2.3/mylib/num2.tex b/TESTU01/TestU01-1.2.3/mylib/num2.tex new file mode 100644 index 0000000..bf2860d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/num2.tex @@ -0,0 +1,156 @@ +\defmodule {num2} + +This module provides procedures to compute a few numerical +quantities such as factorials, combinations, Stirling numbers, +Bessel functions, gamma functions, and so on. +These functions are more esoteric than those provided by {\tt num}. + +\bigskip\hrule +\code\hide +/* num2.h for ANSI C */ + +#ifndef NUM2_H +#define NUM2_H +\endhide +#include "gdef.h" +#include +\endcode + +%%%%%%%%%%%%%%%%%%%% +\guisec{Prototypes} +\code + +double num2_Factorial (int n); +\endcode + \tab The factorial function. Returns the value of $n!$ +\endtab +\code + + +double num2_LnFactorial (int n); +\endcode + \tab Returns the value of $\ln (n!)$, the natural logarithm of the + factorial of $n$. Gives at least 16 decimal digits of precision + (relative error $< 0.5\times 10^{-15}$) +\endtab +\code + + +double num2_Combination (int n, int s); +\endcode + \tab Returns the value of ${n \choose s}$, the number of different combinations + of $s$ objects amongst $n$. % Uses an algorithm that prevents overflows + % (when computing factorials), if possible. + \endtab +\code + + +#ifdef HAVE_LGAMMA +#define num2_LnGamma lgamma +#else + double num2_LnGamma (double x); +#endif +\endcode + \tab Calculates the natural logarithm of the gamma function $\Gamma(x)$ + at {\tt x}. Our {\tt num2\_LnGamma} gives 16 decimal digits + of precision, but is implemented only for $x>0$. + The function {\tt lgamma} is from the {\tt ISO C99} standard math library. + \endtab +\code + + +double num2_Digamma (double x); +\endcode +\tab Returns the value of the logarithmic derivative of the Gamma function + $\psi(x) = \Gamma'(x) / \Gamma(x)$. +\endtab +\code + + +#ifdef HAVE_LOG1P +#define num2_log1p log1p +#else + double num2_log1p (double x); +#endif +\endcode + \tab Returns a value equivalent to {\tt log}$(1 + x)$ accurate also for small + $x$. The function {\tt log1p} is from the {\tt ISO C99} standard math library. + \endtab +\code + + +void num2_CalcMatStirling (double *** M, int m, int n); +\endcode + \tab Calculates the Stirling numbers of the second kind, + \eq + M[i,j] = \left\{\begin{array}{c}j \\ i\end{array}\right\} + \quad \mbox { for $0\le i\le m$ and $0\le i\le j\le n$}. + \label{Stirling2} + \endeq + See D. E. Knuth, {\em The Art of Computer Programming\/}, vol.~1, + second ed., 1973, Section 1.2.6. + The matrix $M$ is the transpose of Knuth's (1973). + This procedure allocates memory for the 2-dimensionnal matrix $M$, + and fills it with the values of Stirling numbers; + the memory should be freed + later with the function {\tt num2\_FreeMatStirling}. + \endtab +\code + + +void num2_FreeMatStirling (double *** M, int m); +\endcode + \tab Frees the memory space used by the Stirling matrix created by calling + {\tt num2\_CalcMatStirling}. The parameter {\tt m} + must be the same as the {\tt m} in {\tt num2\_CalcMatStirling}. + \endtab +\code + + +double num2_VolumeSphere (double p, int t); +\endcode +\tab Calculates the volume $V$ of a sphere of radius 1 in $t$ dimensions + using the norm $L_p$, according to the formula +$$ + V = \frac{\left[2 \Gamma(1 + 1/p)\right]^t} + {\Gamma\left(1 + t/p\right)}, \qquad p > 0, +$$ + where $\Gamma$ is the well-known gamma function. + The case of the sup norm $L_\infty$ is + obtained by choosing $p=0$. + Restrictions: $p\ge 0$ and $t\ge 1$. + \endtab +\code + + +double num2_EvalCheby (const double A[], int N, double x); +\endcode +\tab Evaluates a series of Chebyshev polynomials $T_j$, at point + $x \in [-1, \;1]$, using the method of Clenshaw \cite{mCLE62a}, + i.e. calculates and returns + $$ + y = \frac{A_0}2 + \sum_{j=1}^N A_j T_j(x). + $$ +\endtab +\code + + +double num2_BesselK025 (double x); +\endcode +\tab Returns the value of $K_{1/4}(x)$, where $K_{\nu}$ is the modified + Bessel's + function of the second kind. + The relative error on the returned value is less than + $0.5\times 10^{-6}$ for $x > 10^{-300}$. +\endtab +\code +\hide + +#endif +\endhide +\endcode + + + + + diff --git a/TESTU01/TestU01-1.2.3/mylib/tables.c b/TESTU01/TestU01-1.2.3/mylib/tables.c new file mode 100644 index 0000000..f708a5e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/tables.c @@ -0,0 +1,504 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: tables.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "tables.h" +#include "util.h" +#include "mystr.h" +#include "num.h" + +#include +#include +#include +#include + + + + + + +tables_StyleType Style = tables_Plain; + +static char OuvrantMat = ' '; /* Matrix delimitors */ +static char FermantMat = ' '; + +static char OuvrantVec = ' '; /* Vector delimitors */ +static char FermantVec = ' '; + +static char SepareVec = ' '; /* Element separators */ +static char SepareElem = ' '; + +#define MaxInd 60 +static long HacheTab[MaxInd + 1] = { + 8191, 12109, 16381, 24373, 32749, 48871, 65521, 97777, 131071, 195659, + 262139, 393203, 524287, 786407, 1048573, 1572803, 2097143, 2500097, + 3145711, 3600097, 4194301, 5300003, 6291403, 7300003, 8388593, 9500021, + 10500013, 11500003, 12582917, 13500007, 14500001, 15500011, 16777213, + 17500013, 18500017, 19500101, 20500097, 21300101, 22200001, + 23200097, 24200101, 25165807, 28000097, 30000001, 33554393, 39000001, + 45000097, 50331653, 55000013, 61000001, 67108859, 76000091, 85000007, + 94906247, 134217689, 189812501, 268435399, 379625003, 2147483647, -1 +}; + + +long **tables_CreateMatrixL (int N, int M) +{ + int i; + long **T1; + /* Note: the memory must be allocated in a contiguous way for the matrix + to be later used properly, without problems. Source: comp.lang.c - + Answers to Frequently Asked Questions + http://www.faqs.org/faqs/C-faq/faq/ Questions 6.18, 6.19, 6.20 */ + + T1 = (long **) util_Malloc (N * sizeof (long *)); + T1[0] = (long *) util_Malloc (N * M * sizeof (long)); + for (i = 1; i < N; i++) + T1[i] = T1[0] + i * M; + return T1; +} + + +unsigned long **tables_CreateMatrixUL (int N, int M) +{ + int i; + unsigned long **T3; + + T3 = (unsigned long **) util_Malloc (N * sizeof (unsigned long *)); + T3[0] = (unsigned long *) util_Malloc (N * M * sizeof (unsigned long)); + for (i = 1; i < N; i++) + T3[i] = T3[0] + i * M; + return T3; +} + + +double **tables_CreateMatrixD (int N, int M) +{ + int i; + double **T2; + + T2 = (double **) util_Malloc (N * sizeof (double *)); + T2[0] = (double *) util_Malloc (N * M * sizeof (double)); + for (i = 1; i < N; i++) + T2[i] = T2[0] + i * M; + return T2; +} + + +void tables_DeleteMatrixL (long ***T) +{ + free ((*T)[0]); + free (*T); + *T = NULL; +} + +void tables_DeleteMatrixUL (unsigned long ***T) +{ + free ((*T)[0]); + free (*T); + *T = NULL; +} + +void tables_DeleteMatrixD (double ***T) +{ + free ((*T)[0]); + free (*T); + *T = NULL; +} + + +void tables_CopyTabD (double T1[], double T2[], int n1, int n2) +{ + int i; + for (i = n1; i <= n2; i++) { + T2[i] = T1[i]; + } +} + +void tables_CopyTabL (long T1[], long T2[], int n1, int n2) +{ + int i; + for (i = n1; i <= n2; i++) { + T2[i] = T1[i]; + } +} + +void tables_QuickSortD (double T[], int l, int r) + /* On trie le tableau des observations T[l..r]. */ +{ + int j; /* Indices dans le tableau Tab. */ + int i; + double w; + double x; + i = l; + j = r; + x = T[(l + r) / 2]; + do { + while (T[i] < x) + ++i; + while (x < T[j]) + --j; + if (i <= j) { + w = T[i]; + T[i] = T[j]; + T[j] = w; + ++i; + --j; + } + } while (i <= j); + if (l < j) + tables_QuickSortD (T, l, j); + if (i < r) + tables_QuickSortD (T, i, r); +} + + +void tables_QuickSortL (long T[], int l, int r) + /* On trie le tableau des observations T[l..r]. */ +{ + int j; /* Indices dans le tableau Tab. */ + int i; + long w; + long x; + i = l; + j = r; + x = T[(l + r) / 2]; + do { + while (T[i] < x) + ++i; + while (x < T[j]) + --j; + if (i <= j) { + w = T[i]; + T[i] = T[j]; + T[j] = w; + ++i; + --j; + } + } while (i <= j); + if (l < j) + tables_QuickSortL (T, l, j); + if (i < r) + tables_QuickSortL (T, i, r); +} + + +/*=======================================================================*/ +#ifdef USE_LONGLONG + +void tables_QuickSortLL (longlong T[], int l, int r) +{ + int j; + int i; + longlong w; + longlong x; + i = l; + j = r; + x = T[(l + r) / 2]; + do { + while (T[i] < x) + ++i; + while (x < T[j]) + --j; + if (i <= j) { + w = T[i]; + T[i] = T[j]; + T[j] = w; + ++i; + --j; + } + } while (i <= j); + if (l < j) + tables_QuickSortLL (T, l, j); + if (i < r) + tables_QuickSortLL (T, i, r); +} + +void tables_QuickSortULL (ulonglong T[], int l, int r) +{ + int j; + int i; + ulonglong w; + ulonglong x; + i = l; + j = r; + x = T[(l + r) / 2]; + do { + while (T[i] < x) + ++i; + while (x < T[j]) + --j; + if (i <= j) { + w = T[i]; + T[i] = T[j]; + T[j] = w; + ++i; + --j; + } + } while (i <= j); + if (l < j) + tables_QuickSortULL (T, l, j); + if (i < r) + tables_QuickSortULL (T, i, r); +} + +#endif +/*=======================================================================*/ + +void tables_WriteTabL (long V[], int n1, int n2, int k, int p, char Desc[]) +{ + int i; + printf ("---------------------------------------\n"); + printf ("%s\n", Desc); + if (k > 1) { + printf ("Elements %d to %d\n\n", n1, n2); + for (i = n1; i <= n2; i++) { + printf ("%*ld ", p, V[i]); + if (((i + 1 - n1) % k) == 0) + printf ("\n"); + } + printf ("\n"); + } else { + printf ("\n Index Element\n"); + for (i = n1; i <= n2; i++) + printf ("%6d %12ld\n", i, V[i]); + } + printf ("\n"); +} + + +void tables_WriteTabD (double V[], int n1, int n2, int k, int p1, + int p2, int p3, char Desc[]) +{ + int i; + printf ("---------------------------------------\n"); + printf ("%s\n", Desc); + if (k > 1) { + printf ("Elements %d to %d\n\n", n1, n2); + for (i = n1; i <= n2; i++) { + /* printf ("%*.*G", p1, p2, V[i]); */ + num_WriteD (V[i], p1, p2, p3); + if (((i + 1 - n1) % k) == 0) + printf ("\n"); + } + printf ("\n"); + } else { + printf ("\n Index Element\n"); + for (i = n1; i <= n2; i++) { + printf ("%6d", i); + num_WriteD (V[i], p1, p2, p3); + printf ("\n"); + } + } + printf ("\n"); +} + + +/*=========================================================================*/ +#ifdef USE_LONGLONG + +void tables_WriteTabLL (longlong V[], int n1, int n2, int k, int p, + char Desc[]) +{ + int i; + printf ("---------------------------------------\n"); + printf ("%s\n", Desc); + if (k > 1) { + printf ("Elements %d to %d\n\n", n1, n2); + for (i = n1; i <= n2; i++) { + printf (" %*" PRIdLEAST64, p, V[i]); + if (((i + 1 - n1) % k) == 0) + printf ("\n"); + } + printf ("\n"); + } else { + printf ("\n Index Element\n"); + for (i = n1; i <= n2; i++) + printf ("%6d %12" PRIdLEAST64 "\n", i, V[i]); + } + printf ("\n"); +} + +void tables_WriteTabULL (ulonglong V[], int n1, int n2, int k, int p, + char Desc[]) +{ + int i; + printf ("---------------------------------------\n"); + printf ("%s\n", Desc); + if (k > 1) { + printf ("Elements %d to %d\n\n", n1, n2); + for (i = n1; i <= n2; i++) { + printf (" %*" PRIuLEAST64, p, V[i]); + if (((i + 1 - n1) % k) == 0) + printf ("\n"); + } + printf ("\n"); + } else { + printf ("\n Index Element\n"); + for (i = n1; i <= n2; i++) + printf ("%6d %12" PRIuLEAST64 "\n", i, V[i]); + } + printf ("\n"); +} + +#endif +/*=========================================================================*/ + + +static void FixeDelim (tables_StyleType style) +{ + /* Fixe les delimiteurs pour imprimer une matrice selon un format + approprie */ + Style = style; + switch (style) { + case tables_Mathematica: + OuvrantMat = '{'; + FermantMat = '}'; + OuvrantVec = '{'; + FermantVec = '}'; + SepareVec = ','; + SepareElem = ','; + break; + case tables_Matlab: + OuvrantMat = '['; + FermantMat = ']'; + OuvrantVec = ' '; + FermantVec = ' '; + SepareVec = ' '; + SepareElem = ' '; + break; + default: + OuvrantMat = ' '; + FermantMat = ' '; + OuvrantVec = ' '; + FermantVec = ' '; + SepareVec = ' '; + SepareElem = ' '; + break; + } +} + + +void tables_WriteMatrixL (long **Mat, int i1, int i2, int j1, int j2, + int w, tables_StyleType style, char Nom[]) +{ + int i; + int j; + + FixeDelim (style); + if (strlen (Nom) > 0) { + printf ("%s = ", Nom); + } + printf ("%c\n", OuvrantMat); + for (i = i1; i <= i2; i++) { + printf ("%c", OuvrantVec); + for (j = j1; j <= j2; j++) { + printf ("%*ld", (int) w, Mat[i][j]); + if (j < j2) + printf ("%c", SepareElem); + } + printf ("%c", FermantVec); + if (i < i2) + printf ("%c\n", SepareVec); + } + printf ("%c\n\n", FermantMat); +} + + +void tables_WriteMatrixD (double **Mat, int i1, int i2, int j1, int j2, + int w, int p, tables_StyleType style, char Nom[]) +{ + int k; + int m; + int j; + int i; + unsigned int bidon; + double prec; + double x; + int trouve; + char S[32]; + + FixeDelim (style); + if (strlen (Nom) > 0) { + printf ("%s = ", Nom); + } + prec = pow (10.0, (double) p); + printf ("%c\n", OuvrantMat); + for (i = i1; i <= i2; i++) { + printf ("%c", OuvrantVec); + for (j = j1; j <= j2; j++) { + printf (" "); + switch (style) { + case tables_Mathematica: + x = Mat[i][j]; + if (((x != 0.0) && (fabs (x) < 0.1)) || (fabs (x) > prec)) { + sprintf (S, "%.*G", (int) p, x); + /* automatique avec %G ... : myst_Subst(S, "e", "E"); */ + mystr_Position ("E", S, 0, &bidon, &trouve); + if (trouve) { + mystr_Subst (S, "E", "*10^("); + strncat (S, ")", (size_t) 2); + } + } else + sprintf (S, "%.*f", (int) p, x); + m = (int) strlen (S); + for (k = 1; k <= w - m; k++) { + printf (" "); + } + printf ("%s", S); + break; + default: + /* tables_Matlab, Default */ + printf ("%*.*G", (int) w, (int) p, Mat[i][j]); + break; + } + if (j < j2) + printf ("%c", SepareElem); + } + printf ("%c", FermantVec); + if (i < i2) + printf ("%c\n", SepareVec); + } + printf ("%c\n\n", FermantMat); +} + +long tables_HashPrime (long n, double load) +{ + int i; + double nD; + util_Assert (n > 0, "tables_HashPrime : n <= 0"); + nD = (double) n; + i = 1; + while (i < MaxInd && HacheTab[i] < n) + ++i; + while (i < MaxInd && load * (double) (HacheTab[i]) < nD) + ++i; + util_Assert (HacheTab[i] > 0, "tables_HashPrime failed"); + return HacheTab[i]; +} diff --git a/TESTU01/TestU01-1.2.3/mylib/tables.tex b/TESTU01/TestU01-1.2.3/mylib/tables.tex new file mode 100644 index 0000000..0e500a0 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/tables.tex @@ -0,0 +1,170 @@ +\defmodule {tables} + +This module provides an implementation of variable-sized arrays (matrices), +and procedures to manipulate them. +The advantage is that the size of the array needs not be known +at compile time; it can be specified only during the program execution. +There are also procedures to sort arrays, to +print arrays in different formats, +and a few tools for hashing tables. +The functions {\tt tables\_CreateMatrix...} and +{\tt tables\_DeleteMatrix...} manage memory allocation for +these dynamic matrices. + +As an illustration, the following piece of code declares and creates +a $100\times 500$ table of floating point numbers, assigns a value +to one table entry, and eventually deletes the table: + \begin{verse}{\tt + double ** T;\\ + T = tables\_CreateMatrixD (100, 500);\\ + T[3][7] = 1.234;\\ + \dots \\ + tables\_DeleteMatrixD (\&T); + }\end{verse} + +%%%%%%%%%%%%% +\bigskip\hrule +\code\hide +/* tables.h for ANSI C */ +#ifndef TABLES_H +#define TABLES_H +\endhide +#include "gdef.h" +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Printing styles} +\code + +typedef enum { + tables_Plain, + tables_Mathematica, + tables_Matlab + } tables_StyleType; +\endcode + \tab Printing styles for matrices. + \endtab + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Functions to create, delete, sort, and print tables} +\code + +long ** tables_CreateMatrixL (int M, int N); +unsigned long ** tables_CreateMatrixUL (int M, int N); +double ** tables_CreateMatrixD (int M, int N); +\endcode + \tab Allocates contiguous memory for a dynamic + matrix of {\tt M} rows and {\tt N} columns. Returns the base + address of the allocated space. + \endtab +\code + + +void tables_DeleteMatrixL (long *** T); +void tables_DeleteMatrixUL (unsigned long *** T); +void tables_DeleteMatrixD (double *** T); +\endcode + \tab Releases the memory used by the matrix {\tt T} + (see {\tt tables\_CreateMatrix}) passed by + reference, that is, using the {\tt \&} symbol. + {\tt T} is set to {\tt NULL}. + \endtab +\code + + +void tables_CopyTabL (long T1[], long T2[], int n1, int n2); +void tables_CopyTabD (double T1[], double T2[], int n1, int n2); +\endcode + \tab Copies {\tt T1[n1..n2]} in {\tt T2[n1..n2]}. + \endtab +\code + + +void tables_QuickSortL (long T[], int n1, int n2); +void tables_QuickSortD (double T[], int n1, int n2); + +#ifdef USE_LONGLONG + void tables_QuickSortLL (longlong T[], int n1, int n2); + void tables_QuickSortULL (ulonglong T[], int n1, int n2); +#endif +\endcode + \tab Sort the tables {\tt T[n1..n2]} in increasing order. + \endtab +\code + + +void tables_WriteTabL (long V[], int n1, int n2, int k, int p, char Desc[]); + +#ifdef USE_LONGLONG + void tables_WriteTabLL (longlong V[], int n1, int n2, int k, int p, + char Desc[]); + void tables_WriteTabULL (ulonglong V[], int n1, int n2, int k, int p, + char Desc[]); +#endif +\endcode + \tab Write the elements {\tt n1} to {\tt n2} of table {\tt V}, + {\tt k} per line, {\tt p} positions per element. + If {\tt k} = 1, the index will also be printed. {\tt Desc} + contains a description of the table. + \endtab +\code + + +void tables_WriteTabD (double V[], int n1, int n2, int k, int p1, int p2, + int p3, char Desc[]); +\endcode + \tab Writes the elements {\tt n1} to {\tt n2} of table {\tt V}, + {\tt k} per line, with at least {\tt p1} positions per element, + {\tt p2} digits after the decimal point, and at least {\tt p3} + significant digits. + If {\tt k} = 1, the index + will also be printed. {\tt Desc} contains a description of the table. + \endtab +\code + + +void tables_WriteMatrixD (double** Mat, int i1, int i2, int j1, int j2, + int w, int p, tables_StyleType style, + char Name[]); +\endcode + \tab Writes the submatrix with lines + {\tt i1} $\le i \le $ {\tt i2} and columns + {\tt j1} $\le j \le $ {\tt j2} of the matrix {\tt Mat} with format + {\tt style}. The elements are printed in {\tt w} + positions with a precision of {\tt p} digits. {\tt Name} is + an identifier for the submatrix. + + For {\tt Matlab}, the file containing the matrix must have + the extension {\tt .m}. + For example, if it is named {\tt poil.m}, it will be accessed by the + simple call {\tt poil} in {\tt Matlab}. + For {\tt Mathematica}, if the file is named {\tt poil}, + it will be read using {\tt << poil;}. + \endtab +\code + + +void tables_WriteMatrixL (long** Mat, int i1, int i2, int j1, int j2, int w, + tables_StyleType style, char Name[]); +\endcode + \tab Similar to {\tt tables\_WriteMatrixD}. + \endtab +\code + + +long tables_HashPrime (long n, double load); +\endcode + \tab Returns a prime number $M$ to be used as the size + (the number of elements) of a hashing table. + $M$ will be such that the load factor $n/M$ do not exceed {\tt load}. + If {\tt load} is small, an important part of the table will be unused; that + will accelerate searches and insertions. + This function uses a small sequence of prime numbers; the real load factor + may be significatively smaller than {\tt load} because only a limited + number of prime numbers are in the table. In case of failure, returns $-1$. + \endtab +\code\hide + +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/mylib/tcode.c b/TESTU01/TestU01-1.2.3/mylib/tcode.c new file mode 100644 index 0000000..63230a6 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/tcode.c @@ -0,0 +1,209 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: tcode.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include +#include +#include +#include +#include + + + + + +/*========================== constants =================================*/ + +#define MaxChar 255 /* max. length of a line */ + +#define Mess1 "\nUsage: tcode \n\n" +#define Mess2 "\nERROR: The 2 files must be different\n\n" + + + + +/*============================= variables ==============================*/ + +static char Line[MaxChar + 1] = {0}, /* One line of input */ + FIn[MaxChar + 1] = {0}, /* Input file name */ + FOut[MaxChar + 1] = {0}; /* Output file name */ + +static FILE *fin, /* Input file */ + *fout; /* Output file */ + +static size_t L1, L2, L3, L4, L5, L6, L7, L8; /* Lengths of strings */ + + + + +/**************************************************************************/ + +static void Init (int argc, char *argv[]) +{ + if (argc != 3) { + printf (Mess1); + exit (EXIT_FAILURE); + } + sprintf (FIn, "%.*s", MaxChar, argv[1]); + sprintf (FOut, "%.*s", MaxChar, argv[2]); + if (!strcmp (FIn, FOut)) { + printf (Mess2); + exit (EXIT_FAILURE); + } + + errno = 0; + fin = fopen (FIn, "r"); + if (fin == NULL) { + printf ("\nOpening of %s failed: %s\n\n", FIn, strerror (errno)); + exit (EXIT_FAILURE); + } + errno = 0; + fout = fopen (FOut, "w"); + if (fout == NULL) { + printf ("\nOpening of %s failed: %s\n\n", FOut, strerror (errno)); + exit (EXIT_FAILURE); + } + + L1 = strlen ("\\code"); + L2 = strlen ("\\endcode"); + L3 = strlen ("\\hide"); + L4 = strlen ("\\endhide"); + L5 = strlen ("\\iffalse"); + L6 = strlen ("\\fi"); + L7 = strlen ("\\smallc"); + L8 = strlen ("\\smallcode"); +} + +/**************************************************************************/ + +static void SearchRep (char *A, const char *sub, unsigned int L) +{ + /* Search for TEX command sub, of length L, in line A */ + char *p, *q; + + p = strstr (A, sub); /* search for sub in A */ + if (p) { /* if found */ + if (isalpha ((int) *(p + L))) /* is it only part of a command? */ + SearchRep (A + L, sub, L); /* yes? search rest of line */ + else { + q = p + L; /* no? delete */ + *p++ = ' '; + while ((*p++ = *q++)) + ; + } + } +} + +/**************************************************************************/ + +static void ProcessCode (char *A) +{ + + SearchRep (A, "\\hide", L3); + SearchRep (A, "\\endhide", L4); + SearchRep (A, "\\iffalse", L5); + SearchRep (A, "\\fi", L6); + SearchRep (A, "\\smallcode", L8); + SearchRep (A, "\\smallc", L7); + + fprintf (fout, "%s", A); +} + +/**************************************************************************/ + +static int ProcessLine (char *line) +{ + /* Process a line (or part of a line) of valid code. If at the end of the + line, we are still in a region of valid code, then return 1; otherwise, + return 0. */ + + char *p, *rest; + int code; + + p = strstr (line, "\\endcode"); /* search for "\endcode" */ + if (p) { /* if found */ + *p = '\0'; /* code ends here */ + rest = p + L2; /* step over "\endcode" */ + p = strstr (rest, "\\code"); /* search for "\code" */ + if (p) { + p += L1; /* step over "\code" */ + rest = calloc (MaxChar, sizeof (char)); + strncpy (rest, p, MaxChar); + ProcessCode (line); + code = ProcessLine (rest); + free (rest); + return code; + } else { + ProcessCode (line); + return 0; + } + } else { + ProcessCode (line); + return 1; + } +} + + +/**************************************************************************/ + +int main (int argc, char *argv[]) +{ + char *p, *q; + int isCode = 0; /* If isCode == TRUE, we are in a region of + valid code; otherwise not. */ + + Init (argc, argv); + + while (NULL != fgets (Line, MaxChar, fin)) { /* Not EOF and no error */ + if (isCode) { + isCode = ProcessLine (Line); + } else { + /* search for "\def\code" and drop that line: it is not valid code + but the definition of the TEX command \code */ + if (strstr (Line, "\\def\\code")) + ; + else if ((p = strstr (Line, "\\code"))) { + /* search for "\code". If "\code" is found on a line with a % + before it, then it is a TEX comment and we do not consider + it as starting a region of valid code; */ + *p = '\0'; + q = strchr (Line, '%'); + if (NULL == q) + /* otherwise, it is valid code: process rest of line */ + isCode = ProcessLine (p + L1); + } + } + } + + fprintf (fout, "\n"); + fclose (fout); + fclose (fin); + return 0; +} diff --git a/TESTU01/TestU01-1.2.3/mylib/tcode.tex b/TESTU01/TestU01-1.2.3/mylib/tcode.tex new file mode 100644 index 0000000..55b6536 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/tcode.tex @@ -0,0 +1,84 @@ +\defmodule{tcode} + +\iffalse + Le programme {\tt tcode} permet de produire du code compilable +\`a partir d'une documentation destin\'ee \`a TEX ou LATEX. +Il produit un fichier {\tt FOut} destin\'e \`a un compilateur tel que Modula-2 +(ou autre), \`a partir d'un fichier {\tt FIn} re\c cu \`a l'entr\'ee. +Les noms de ces deux fichiers sont donn\'es par l'usager, avec l'extension, +lors de l'appel du programme. +N'appara\^\i tront dans le second fichier que les parties se trouvant entre +les d\'elimiteurs {\tt\bs{code}} et {\tt\bs{endcode}}. +Toutes les autres commandes TEX et LATEX, m\^eme \`a l'int\'erieur de ces +d\'elimiteurs, seront aussi enlev\'ees. +L'appel se fait sous la forme: +\fi + + +Program {\tt tcode} makes compilable code from a \TeX\ or \LaTeX\ document. It +creates a file {\tt FOut} for a compiler like cc (or any other), starting +from a file {\tt FIn}. The names of these two files must be given by the user, +with appropriate extension, when calling the program. +The two file names (with the extension) must be different. + +Only the text included between the {\tt\bs{code}} and +{\tt\bs{endcode}} delimiters will appear in the second file. Only the following +\LaTeX\ commands can appear between {\tt\bs{code}} and {\tt\bs{endcode}}: + +\begin{verse} + {\tt\bs{hide}}, {\tt\bs{endhide}}, {\tt\bs{iffalse}}, {\tt\bs{fi}}, + {\tt\bs{smallcode}}, {\tt\bs{smallc}}. +\end{verse} + + Everything else between +{\tt\bs{code}} and {\tt\bs{endcode}} must be legal code in the +output file, apart from two exceptions: the \TeX\ command + {\tt\bs{def}\bs{code}}, defining {\tt\bs{code}} will not start a region + of valid code, nor will {\tt\bs{code}} appearing on a line after a + \TeX\ comment character {\tt\%}. + + If one wants code to appear in the compilable file, but + be invisible in the {\tt dvi} file obtained from processing the {\tt tex} +file with \LaTeX, one should put this code between the delimiters +{\tt\bs{hide}} and {\tt\bs{endhide}}, or between the delimiters +{\tt\bs{iffalse}} and {\tt\bs{fi}}. + +The program is called by: + +\begin {center}\tt + tcode \ $\langle$FIn$\rangle$ \ $\langle$FOut$\rangle$ +\end {center} + +\iffalse + Les deux noms de fichiers (avec l'extension) doivent \^etre diff\'erents. +Par exemple, si le fichier destin\'e \`a \LaTeX\ est {\tt chrono.tex} et +que l'on veut en extraire le code compilable et placer ce dernier dans +{\tt chrono.h} (module de d\'efinition), on utilisera la commande: +\fi + +\paragraph{Examples:} +If one wants +to extract the {\it C} code from the \LaTeX\ file {\tt chrono.tex}, + and place it in +the header file {\tt chrono.h}, the following + command should be used: + +\begin {center}\tt + tcode \ chrono.tex \ chrono.h +\end {center} + +To extract {\it Java} code from the \LaTeX\ file {\tt Event.tex}, +and place it in the file {\tt Event.java}, one must use: + +\begin {center}\tt + tcode \ Event.tex \ Event.java +\end {center} +% +%To extract the {\it Modula-2} DEFINITION module from the \LaTeX\ file +% {\tt BIN.tex}, +%and place it in the file {\tt BIN.def}, one must use: +% +%\begin {center}\tt +% tcode \ BIN.tex \ BIN.def +%\end {center} +% \ No newline at end of file diff --git a/TESTU01/TestU01-1.2.3/mylib/titre.tex b/TESTU01/TestU01-1.2.3/mylib/titre.tex new file mode 100644 index 0000000..15f601f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/titre.tex @@ -0,0 +1,30 @@ +\begin{titlepage} + +\null +\begin {flushright} \it Last update: \today \end {flushright} + +\vfill +{ \centerline {\Large\bf MyLib-C }\bigskip\bigskip + \centerline {\large\bf A Small Library of Basic Utilities in ANSI C }} +\vfill + +\centerline {{\bf Pierre L'Ecuyer and Richard Simard} % +\footnote {Francis Picard and Jean-S\'ebastien S\'en\'ecal + have also participated in the development of MyLib.}} +\medskip +\centerline {D\'epartement d'Informatique et de Recherche op\'erationnelle} +\centerline {Universit\'e de Montr\'eal} + +\vfill +% \centerline {\large\bf Note} +\medskip + +This document describes a set of basic utilities, implemented in ANSI C, +used in the software developed in the author's {\em simulation laboratory}. +Most of these tools were originally implemented in the Modula-2 language. +Some of them have been reimplemented in C in order to facilitate +the code translation of other software from Modula-2 to C. + +\vfill +\end{titlepage} + diff --git a/TESTU01/TestU01-1.2.3/mylib/util.c b/TESTU01/TestU01-1.2.3/mylib/util.c new file mode 100644 index 0000000..8216daf --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/util.c @@ -0,0 +1,181 @@ +/*************************************************************************\ + * + * Package: MyLib + * File: util.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" + +#include +#include +#include +#include + + +#define MAXCAR 256 /* Max length of a line of data */ + + + +/************************************************************************/ + +FILE *util_Fopen (const char *path, const char *mode) +{ + FILE *f; + errno = 0; + f = fopen (path, mode); + if (f == NULL) { + fprintf (stdout, "\nOpening of %s failed: %s\n\n", + path, strerror (errno)); + exit (EXIT_FAILURE); + return NULL; /* to eliminate a warning from the compiler */ + } else + return f; +} + +int util_Fclose (FILE * f) +{ + int s; + if (f == NULL) + return 0; + errno = 0; + s = fclose (f); + if (s != 0) + fprintf (stdout, "\nClosing of file failed: %s\n\n", strerror (errno)); + return s; +} + + +/************************************************************************/ + +void *util_Malloc (size_t size) +{ + void *p; + errno = 0; + p = malloc (size); + if (p == NULL) { + fprintf (stdout, "\nmalloc failed: %s\n\n", strerror (errno)); + exit (EXIT_FAILURE); + return NULL; /* to eliminate a warning from the compiler */ + } else + return p; +} + +void *util_Calloc (size_t count, size_t esize) +{ + void *p; + errno = 0; + p = calloc (count, esize); + if (p == NULL) { + fprintf (stdout, "\ncalloc failed: %s\n\n", strerror (errno)); + exit (EXIT_FAILURE); + return NULL; /* to eliminate a warning from the compiler */ + } else + return p; +} + +void *util_Realloc (void *ptr, size_t size) +{ + void *p; + errno = 0; + p = realloc (ptr, size); + if ((p == NULL) && (size != 0)) { + fprintf (stdout, "\nrealloc failed: %s\n\n", strerror (errno)); + exit (EXIT_FAILURE); + return ptr; /* to eliminate a warning from the compiler */ + } else + return p; + +} + +void *util_Free (void *p) +{ + if (p == NULL) + return NULL; + free (p); + return NULL; +} + + +/************************************************************************/ + +void util_WriteBool (lebool b, int d) +{ + if (b) + printf ("%*s", d, "TRUE"); + else + printf ("%*s", d, "FALSE"); +} + + +void util_ReadBool (char S[], lebool *x) +{ + int j; + char B[6]; + j = sscanf (S, " %6s", B); + util_Assert (j > 0, "util_ReadBool: on reading lebool"); + if (!strncmp (B, "TRUE", (size_t) 5)) + *x = TRUE; + else if (!strncmp (B, "FALSE", (size_t) 6)) + *x = FALSE; + else { + util_Error ("util_ReadBool: lebool values must be TRUE or FALSE"); + } +} + + +/************************************************************************/ + +int util_GetLine (FILE *infile, char *Line, char c) +{ + size_t j; + + while (NULL != fgets (Line, MAXCAR, infile)) { /* Not EOF and no error */ + /* Find first non-white character in Line */ + j = strspn (Line, " \t\r\f\v"); + /* Discard blank lines and lines whose first non-white character is c */ + if (Line[j] == '\n' || Line[j] == c) + continue; + else { + char *p; + /* If the character c appears, delete the rest of the line*/ + if ((p = strchr (Line, c))) + *p = '\0'; + + else { + /* Remove the \n char at the end of line */ + j = strlen (Line); + if (Line[j - 1] == '\n') + Line[j - 1] = '\0'; + } + return 0; + } + } + + util_Fclose (infile); + return -1; + /* util_Error ("GetLine: an error has occurred on reading"); */ +} diff --git a/TESTU01/TestU01-1.2.3/mylib/util.tex b/TESTU01/TestU01-1.2.3/mylib/util.tex new file mode 100644 index 0000000..66aaf75 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/mylib/util.tex @@ -0,0 +1,214 @@ +\defmodule {util} + +Safe functions to open and close files, to allocate dynamic memory, +to read/write booleans, and to print error messages. +Some of the ``functions'' are actually implemented as macros, in the +interest of speed. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip\hrule +\code\hide +/* util.h for ANSI C */ +#ifndef UTIL_H +#define UTIL_H +\endhide +#include "gdef.h" +#include +#include +\endcode + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Macros} + +\noindent +{\tt util\_Error (S)}; + + \tab Prints the string {\tt S}, then stops the program. + \endtab +\code +\hide +#define util_Error(S) do { \ + printf ("\n\n******************************************\n"); \ + printf ("ERROR in file %s on line %d\n\n", __FILE__, __LINE__); \ + printf ("%s\n******************************************\n\n", S); \ + exit (EXIT_FAILURE); \ + } while (0) +\endhide +\endcode + +\noindent +{\tt util\_Assert (Assertion, S)}; + + \tab If {\tt lebool Assertion} is {\tt FALSE} (= 0), + then prints the string {\tt S} and stops the program. + \endtab +\code +\hide +#define util_Assert(Cond,S) if (!(Cond)) util_Error(S) +\endhide +\endcode + +\noindent +{\tt util\_Warning (Condition, S)}; + + \tab If {\tt lebool Condition} is {\tt TRUE} ($\not = 0$), + then prints the string {\tt S}. + \endtab +\code +\hide +#define util_Warning(Cond,S) do { \ + if (Cond) { \ + printf ("********* WARNING "); \ + printf ("in file %s on line %d\n", __FILE__, __LINE__); \ + printf ("********* %s\n", S); } \ + } while (0) +\endhide +\endcode + + +\noindent +{\tt util\_Max (x, y)}; + + \tab Returns the largest of the two numbers {\tt x}, {\tt y}. + \endtab +\code +\hide +#define util_Max(x,y) (((x) > (y)) ? (x) : (y)) +\endhide +\endcode + + +\noindent +{\tt util\_Min (x, y)}; + + \tab Returns the smallest of the two numbers {\tt x}, {\tt y}. + \endtab +\code +\hide +#define util_Min(x,y) (((x) < (y)) ? (x) : (y)) +\endhide +\endcode + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Prototypes} +\code + +FILE * util_Fopen (const char *name, const char *mode); +\endcode + \tab + Calls {\tt fopen} (from {\tt stdio.h}) with same arguments, but checks + for errors. + Opens or creates file with name {\tt name} in mode {\tt mode}. Returns a + pointer to + FILE that is associated with the stream. If {\tt name} cannot be accessed, + the program + stops. + \endtab +\code + + +int util_Fclose (FILE *stream); +\endcode + \tab + Calls {\tt fclose} (from {\tt stdio.h}) with same arguments, but checks + for errors. + Closes the file associated with {\tt stream}. If the file is successfully + closed, {\tt 0} + is returned. If an error occurs or the file was already closed, {\tt EOF} + is returned. + \endtab +\code + + +int util_GetLine (FILE *file, char *Line, char c); +\endcode + \tab + Reads a line of data from {\tt file}. Blank lines and comments are + ignored. A comment is any line whose first non-whitespace character + is {\tt c}. If the character {\tt c} appears anywhere on a line that is + not a comment, then {\tt c} and the rest of the line are ignored too. + The function returns $-1$ if end-of-file or an error is encountered, + otherwise it returns 0. + \endtab +\code + + +void util_ReadBool (char S[], lebool *x); +\endcode + \tab + Reads a {\tt lebool} value from string {\tt S} and returns it in $x$. + The possible values are {\tt TRUE} and {\tt FALSE}. + \endtab +\code + + +void util_WriteBool (lebool x, int d); +\endcode + \tab + Writes the value of $x$ in a field of width $d$. If $d < 0$, + $x$ is left-justified, otherwise right-justified. + \endtab +\code + + +void * util_Malloc (size_t size); +\endcode + \tab + Calls {\tt malloc} (from {\tt stdlib.h}) with same arguments, but checks + for errors. + Allocates memory large enough to hold an object of size {\tt size}. A + successful call + returns the base address of the allocated space, otherwise the + programs stops. The standard type {\tt size\_t} is defined in {\tt stdio.h}. + \endtab +\code + + +void * util_Calloc (size_t dim, size_t size); +\endcode + \tab + Calls {\tt calloc} (from {\tt stdlib.h}) with same arguments, but checks + for errors. + Allocates memory large enough to hold an array of {\tt dim} + objects each of size {\tt size}. A successful call + returns the base address of the allocated space, otherwise the programs + stops. The standard type {\tt size\_t} is defined in {\tt stdio.h}. + \endtab +\code + + +void * util_Realloc (void *ptr, size_t size); +\endcode + \tab Calls {\tt realloc} (from {\tt stdlib.h}) with same arguments, but + checks for errors. + Takes a pointer to a memory region previously allocated and referenced by + {\tt ptr}, then changes its + size to {\tt size} while preserving its content. +% The function attempts to keep the same base address for the block, +% but if it is not possible, it allocates a new block of memory, +% copying the relevant portion of the old block and deallocating it. + A successful call + returns the base address of the resized (or new) space, otherwise the + programs stops. The standard type {\tt size\_t} is defined in {\tt stdio.h}. + \endtab +\code + + +void * util_Free (void *p); +\endcode + \tab Calls {\tt free (p)} (from {\tt stdlib.h}) to free + memory allocated by {\tt util\_Malloc}, + {\tt util\_Calloc} or {\tt util\_Realloc}. Always returns the + {\tt NULL} pointer. + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/param/CombCubLCG.par b/TESTU01/TestU01-1.2.3/param/CombCubLCG.par new file mode 100644 index 0000000..7280702 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/CombCubLCG.par @@ -0,0 +1,39 @@ + +# Package: TestU01 +# File: CombCubLCG.par + +# Description: Parameter values for combined Cubic1 with LCG +#----------------------------------------------------------------- + +# Give the name of the family first + +CombCubLCG + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m1 a1 m2 a2 +# where h is (very close to) the base-2 logarithm of the period length, +# m1, a1 are the modulus and the multiplier of the LCG generator, +# m2, a2 are the modulus and the multiplier of the Cubic1 generator. + +#h m1 a1 m2 a2 + +19 1021 65 491 277 +20 1021 65 1013 31 +21 2039 995 1013 31 +22 2039 995 2027 349 +23 4093 209 2027 349 +24 4093 209 4079 3757 +25 8191 884 4079 3757 +26 8191 884 8111 2257 +27 16381 572 8111 2257 +28 16381 572 16319 3013 +29 32749 219 16319 3013 +30 32749 219 32687 4535 +31 65521 17364 32687 4535 +32 65521 17364 65447 27076 +33 131071 43165 65447 27076 +34 131071 43165 130859 48249 +35 262139 92717 130859 48249 +36 262139 92717 262103 173782 diff --git a/TESTU01/TestU01-1.2.3/param/CombCubic2.par b/TESTU01/TestU01-1.2.3/param/CombCubic2.par new file mode 100644 index 0000000..9249776 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/CombCubic2.par @@ -0,0 +1,43 @@ +# Package: TestU01 +# File: CombCubic2.par + +# Description: Parameter values for the CombCubic2 generators +#----------------------------------------------------------------- + +# Give the name of the family first + +CombCubic2 + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m1 m2 a1 a2 +# where h is (very close to) the base-2 logarithm of the period length, +# m1 and m2 are the moduli, a1 and a2 are the multipliers. + + +12 59 47 15 7 +13 101 59 61 15 +14 101 83 61 9 +15 251 101 135 61 +16 251 233 135 61 +17 503 251 445 135 +18 503 491 445 277 +19 1019 503 437 445 +20 1019 1013 437 31 +21 2039 1019 243 437 +22 2039 2027 243 349 +23 4091 2039 494 243 +24 4091 4079 494 3757 +25 8147 4091 2410 494 +26 8147 8111 2410 2257 +27 16361 8147 5595 2410 +28 16361 16319 5595 3013 +29 32693 16361 1190 5595 +30 32693 32687 1190 4535 +31 65519 32693 512 1190 +32 65519 65447 512 27076 +33 131063 65519 110230 512 +34 131063 130859 110230 48249 +35 262133 131063 168686 110230 +36 262133 262103 168686 173782 diff --git a/TESTU01/TestU01-1.2.3/param/CombL2.par b/TESTU01/TestU01-1.2.3/param/CombL2.par new file mode 100644 index 0000000..f6aabd3 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/CombL2.par @@ -0,0 +1,61 @@ +# Package: TestU01 +# File: CombL2.par + +# Description: Parameter values for the combined LCG with 2 components, +# with a good lattice structure up to dimension 8 (at least). +# The components have distinct prime moduli $m_1$ and $m_2$ +# just below $2^{i/2}$ and the period length is $(m_1-1)(m_2-1)/2$. +# The parameters are chosen to get an excellent value of $M_8$. +#----------------------------------------------------------------- + +# Give the name of the family first + +CombL2 + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m1 m2 a1 a2 +# where h is the lsize, m1, m2 are the moduli, a1, a2 are the multipliers. +# + +20 1021 887 299 58 +21 1447 1319 302 740 +22 2039 1907 1190 1747 +23 2887 2819 1991 1689 +24 4093 3947 3701 2946 +25 5791 5639 4007 1110 +26 8191 8039 6033 1412 +27 11579 11423 3469 2224 +28 16381 16223 6943 12052 +29 23167 22943 4458 4768 +30 32749 32603 18484 950 +31 46337 46199 30090 10453 +32 65521 65267 56196 33186 +33 92681 92459 50055 66698 +34 131071 130787 58124 62535 +35 185363 184727 62927 83951 +36 262139 260879 129990 170664 +37 370723 370247 56917 232398 +38 524287 524099 522098 331871 +39 741431 741227 359345 704623 +40 1048573 1048343 67392 885376 +41 1482907 1482263 582455 110266 +42 2097143 2096867 253485 143041 +43 2965819 2965199 2363072 1638245 +44 4194301 4194167 1521356 960675 +45 5931641 5931203 4757768 4554230 +46 8388593 8388287 3767245 4994015 +47 11863279 11863067 3569116 4215227 +48 16777213 16776899 4697850 1826207 +49 23726561 23726063 4264547 8442320 +50 33554393 33553799 23321542 21257326 +51 47453111 47452739 5332562 5283321 +52 67108859 67108187 29916087 15280258 +53 94906249 94905947 34027224 7087788 +54 134217689 134217323 53614808 88545877 +55 189812507 189812303 1367845 28309514 +56 268435399 268435019 9991564 160052200 +57 379625047 379624607 1410469 2962498 +58 536870909 536870723 13375702 535692996 +59 759250111 759250007 4449060 10486370 +60 1073741789 1073740439 3138382 931003446 diff --git a/TESTU01/TestU01-1.2.3/param/CombWH2.par b/TESTU01/TestU01-1.2.3/param/CombWH2.par new file mode 100644 index 0000000..7f9f5ec --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/CombWH2.par @@ -0,0 +1,61 @@ +# Package: TestU01 +# File: CombWH2.par + +# Description: Parameter values for the combined LCG with 2 components, +# with a good lattice structure up to dimension 8 (at least). +# The components have distinct prime moduli $m_1$ and $m_2$ +# just below $2^{i/2}$ and the period length is $(m_1-1)(m_2-1)/2$. +# The parameters are chosen to get an excellent value of $M_8$. +#----------------------------------------------------------------- + +# Give the name of the family first + +CombWH2 + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m1 m2 a1 a2 +# where h is the lsize, m1, m2 are the moduli, a1, a2 are the multipliers. +# + +20 1021 887 299 58 +21 1447 1319 302 740 +22 2039 1907 1190 1747 +23 2887 2819 1991 1689 +24 4093 3947 3701 2946 +25 5791 5639 4007 1110 +26 8191 8039 6033 1412 +27 11579 11423 3469 2224 +28 16381 16223 6943 12052 +29 23167 22943 4458 4768 +30 32749 32603 18484 950 +31 46337 46199 30090 10453 +32 65521 65267 56196 33186 +33 92681 92459 50055 66698 +34 131071 130787 58124 62535 +35 185363 184727 62927 83951 +36 262139 260879 129990 170664 +37 370723 370247 56917 232398 +38 524287 524099 522098 331871 +39 741431 741227 359345 704623 +40 1048573 1048343 67392 885376 +41 1482907 1482263 582455 110266 +42 2097143 2096867 253485 143041 +43 2965819 2965199 2363072 1638245 +44 4194301 4194167 1521356 960675 +45 5931641 5931203 4757768 4554230 +46 8388593 8388287 3767245 4994015 +47 11863279 11863067 3569116 4215227 +48 16777213 16776899 4697850 1826207 +49 23726561 23726063 4264547 8442320 +50 33554393 33553799 23321542 21257326 +51 47453111 47452739 5332562 5283321 +52 67108859 67108187 29916087 15280258 +53 94906249 94905947 34027224 7087788 +54 134217689 134217323 53614808 88545877 +55 189812507 189812303 1367845 28309514 +56 268435399 268435019 9991564 160052200 +57 379625047 379624607 1410469 2962498 +58 536870909 536870723 13375702 535692996 +59 759250111 759250007 4449060 10486370 +60 1073741789 1073740439 3138382 931003446 diff --git a/TESTU01/TestU01-1.2.3/param/Cubic1.par b/TESTU01/TestU01-1.2.3/param/Cubic1.par new file mode 100644 index 0000000..50a933d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/Cubic1.par @@ -0,0 +1,31 @@ +# Package: TestU01 +# File: Cubic1.par + +# Description: Parameter values for the Cubic1 generators +#----------------------------------------------------------------- + +# Give the name of the family first + +Cubic1 + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m a +# where h is (very close to) the base-2 logarithm of m, m is the +# modulus, and a is the multiplier. + + + 6 59 15 + 7 101 61 + 8 251 135 + 9 503 445 +10 1019 437 +11 2039 243 +12 4091 494 +13 8147 2410 +14 16361 5595 +15 32693 1190 +16 65519 512 +17 131063 110230 +18 262133 168686 diff --git a/TESTU01/TestU01-1.2.3/param/InvExpl.par b/TESTU01/TestU01-1.2.3/param/InvExpl.par new file mode 100644 index 0000000..7972c45 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/InvExpl.par @@ -0,0 +1,40 @@ +# Package: TestU01 +# File: InvExpl.par +# Generator: + +# Description: Parameter values for the InvExpl generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +InvExpl + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m +# where h is (very close to) the base-2 logarithm of m, m is the modulus. + + +10 1021 +11 2039 +12 4093 +13 8191 +14 16381 +15 32749 +16 65521 +17 131071 +18 262139 +19 524287 +20 1048573 +21 2097143 +22 4194301 +23 8388593 +24 16777213 +25 33554393 +26 67108859 +27 134217689 +28 268435399 +29 536870909 +30 1073741789 +31 2147483647 diff --git a/TESTU01/TestU01-1.2.3/param/InvExpl2a.par b/TESTU01/TestU01-1.2.3/param/InvExpl2a.par new file mode 100644 index 0000000..833e977 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/InvExpl2a.par @@ -0,0 +1,15 @@ +# Package: TestU01 +# File: InvExpl2a.par +# Generator: uinv_CreateInvExpl2a + +# Description: Parameter values for the InvExpl2a generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +InvExpl2a + +# Give a which will be used for all generators of the family. + + + 18 diff --git a/TESTU01/TestU01-1.2.3/param/InvExpl2b.par b/TESTU01/TestU01-1.2.3/param/InvExpl2b.par new file mode 100644 index 0000000..35219ef --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/InvExpl2b.par @@ -0,0 +1,15 @@ +# Package: TestU01 +# File: InvExpl2b.par +# Generator: uinv_CreateInvExpl2b + +# Description: Parameter values for the InvExpl2b generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +InvExpl2b + +# Give a which will be used for all generators of the family. + + + 18 diff --git a/TESTU01/TestU01-1.2.3/param/InvImpl.par b/TESTU01/TestU01-1.2.3/param/InvImpl.par new file mode 100644 index 0000000..f651a3c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/InvImpl.par @@ -0,0 +1,40 @@ +# Package: TestU01 +# File: InvImpl.par +# Generator: uinv_CreateInvImpl + +# Description: Parameter values for the InvImpl generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +InvImpl + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m a1 a2 +# where h is (very close to) the base-2 logarithm of m, m is the modulus, +# a1 is the additive constant and a2 is the multiplier. + + +10 1021 730 663 +11 2039 1805 1930 +12 4093 1172 770 +13 8191 4837 7660 +14 16381 13073 1997 +15 32749 9343 6439 +16 65521 35907 30770 +17 131071 55544 90795 +18 262139 21830 162959 +19 524287 396733 446660 +20 1048573 633537 57143 +21 2097143 132547 1642238 +22 4194301 173405 3471693 +23 8388593 1439561 1830242 +24 16777213 10355898 1875483 +25 33554393 23321560 483332 +26 67108859 59310754 15280366 +27 134217689 16626702 26032456 +28 268435399 31958755 240379154 +29 536870909 6284080 4697886 +30 1073741789 5796676 1069420043 diff --git a/TESTU01/TestU01-1.2.3/param/InvImpl2a.par b/TESTU01/TestU01-1.2.3/param/InvImpl2a.par new file mode 100644 index 0000000..f9ccf4e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/InvImpl2a.par @@ -0,0 +1,15 @@ +# Package: TestU01 +# File: InvImpl2a.par +# Generator: uinv_CreateInvImpl2a + +# Description: Parameter values for the InvImpl2a generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +InvImpl2a + +# Give a1, a2 which will be used for all generators of the family. + + + 18 131 diff --git a/TESTU01/TestU01-1.2.3/param/InvImpl2b.par b/TESTU01/TestU01-1.2.3/param/InvImpl2b.par new file mode 100644 index 0000000..843cb93 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/InvImpl2b.par @@ -0,0 +1,15 @@ +# Package: TestU01 +# File: InvImpl2b.par +# Generator: uinv_CreateInvImpl2b + +# Description: Parameter values for the InvImpl2b generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +InvImpl2b + +# Give a1, a2 which will be used for all generators of the family. + + + 17 13 diff --git a/TESTU01/TestU01-1.2.3/param/LCGBad2.par b/TESTU01/TestU01-1.2.3/param/LCGBad2.par new file mode 100644 index 0000000..2981454 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LCGBad2.par @@ -0,0 +1,53 @@ +# Package: TestU01 +# File: LCGBad2.par + +# Description: Parameter values for the bad2 (with respect to the spectral +# test in 2 dimensions) LCG. The figure of merit S_2 in dimension 2 is +# approximately 0.05. +#----------------------------------------------------------------- + +# Give the name of the family first + +LCGBad2 + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m a +# where h is (very close to) the base-2 logarithm of m, m is the modulus, +# and a is the multiplier, the constant c is 0. The multiplier a has been +# chosen in such a way that a*m < 2^{53}. Thus we use the floating-point +# version of the LCG as it is often faster than the integer version. + +10 1021 127 +11 2039 1359 +12 4093 5 +13 8191 2341 +14 16381 2731 +15 32749 10 +16 65521 17 +17 131071 68985 +18 262139 203883 +19 524287 458756 +20 1048573 213598 +21 2097143 202947 +22 4194301 4079911 +23 8388593 2696339 +24 16777213 486293 +25 33554393 5431467 +26 67108859 42038579 +27 134217689 24990322 +28 268435399 31842465 +29 536870909 8903330 +30 1073741789 3930720 +31 2147483647 868723 + +32 4294967291 1123161 +33 8589934583 1026767 +34 17179869143 10045 +35 34359738337 10052 +36 68719476731 102254510 +37 137438953447 87666368 +38 274877906899 1045020214 +39 549755813881 809807353 +40 1099511627689 87666376 diff --git a/TESTU01/TestU01-1.2.3/param/LCGGood.par b/TESTU01/TestU01-1.2.3/param/LCGGood.par new file mode 100644 index 0000000..30b2fb4 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LCGGood.par @@ -0,0 +1,73 @@ +# Package: TestU01 +# File: LCGGood.par + +# Description: Parameter values for the good (with respect to the spectral +# test in up to dimension 8) LCG (Linear Congruential Generators). +# The values are taken from L'Ecuyer's article latrules \cite{rLEC99c}. +#----------------------------------------------------------------- + +# Give the name of the family first + +LCGGood + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m a +# where h is (very close to) the base-2 logarithm of m, m is the modulus, +# and a is the multiplier, the constant c is 0. The multiplier a has been +# chosen in such a way that a*m < 2^{53}. Thus we use the floating-point +# version of the LCG as it is often faster than the integer version. + +10 1021 65 +11 2039 995 +12 4093 209 +13 8191 884 +14 16381 572 +15 32749 219 +16 65521 17364 +17 131071 43165 +18 262139 92717 +19 524287 283741 +20 1048573 380985 +21 2097143 360889 +22 4194301 914334 +23 8388593 653276 +24 16777213 6423135 +25 33554393 25907312 +26 67108859 26590841 +27 134217689 45576512 +28 268435399 31792125 +29 536870909 16538103 +30 1073741789 5122456 +31 2147483647 1389796 + +32 4294967291 1588635695 +33 8589934583 7425194315 +34 17179869143 5295517759 +35 34359738337 3124199165 +36 68719476731 49865143810 +37 137438953447 76886758244 +38 274877906899 17838542566 +39 549755813881 61992693052 +40 1099511627689 1038914804222 +41 2199023255531 1013262675629 +42 4398046511093 2214813540776 +43 8796093022151 4114249742626 +44 17592186044399 6307617245999 +45 35184372088777 25933916233908 +46 70368744177643 63975993200055 +47 140737488355213 102306498730560 +48 281474976710597 49235258628958 +49 562949953421231 265609885904224 +50 1125899906842597 1087141320185010 +51 2251799813685119 349044191547257 +52 4503599627370449 4359287924442956 +53 9007199254740881 2333175048965096 +54 18014398509481951 17554612001638734 +55 36028797018963913 33266544676670489 +56 72057594037927931 39159994680362565 +57 144115188075855859 75953708294752990 +58 288230376151711717 252847049180516155 +59 576460752303423433 346764851511064641 +60 1152921504606846883 561860773102413563 diff --git a/TESTU01/TestU01-1.2.3/param/LCGGranger.par b/TESTU01/TestU01-1.2.3/param/LCGGranger.par new file mode 100644 index 0000000..fba33a7 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LCGGranger.par @@ -0,0 +1,34 @@ +# Package: TestU01 +# File: LCGGranger.par + +# Description: Parameter values for the LCG of Jacinthe Granger-Piché. +# They were chosen so as to give a maximal period for some of the combined +# generators (with the cubic and possibly others) in her master's thesis. +#----------------------------------------------------------------- + +# Give the name of the family first + +LCGGranger + +10 1019 440 +11 2039 995 +12 4079 212 +13 8147 619 +14 16223 10730 +15 32603 7513 +16 65267 16086 +17 130787 57113 +18 262127 22725 +19 524243 882 +20 1048343 377158 +21 2097143 360889 +22 4194287 341585 +23 8388287 1869896 +24 16776899 213590 +25 33553799 14704570 +26 67108187 35190319 +27 134217323 912557 +28 268435019 12222884 +29 536870723 10896430 +30 1073740439 2848890 +31 2147483579 3396173 diff --git a/TESTU01/TestU01-1.2.3/param/LCGPow2.par b/TESTU01/TestU01-1.2.3/param/LCGPow2.par new file mode 100644 index 0000000..47a1c5d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LCGPow2.par @@ -0,0 +1,53 @@ +# Package: TestU01 +# File: LCGPow2.par + +# Description: Parameter values for LCG with a good lattice structure, +# with the modulus equal to 2^h and period length also equal to 2^h. +#----------------------------------------------------------------- + +# Give the name of the family first + +LCGPow2 + + +# For each generator, the following parameters must be given in +# the right order on the same line +# h a +# where m = 2^h, m is the modulus, and a is the multiplier, and +# the additice constant c = 1. + +10 109 +11 37 +12 2117 +13 7517 +14 4661 +15 5125 +16 47989 +17 94941 +18 45005 +19 27949 +20 724765 +21 1386397 +22 2920253 +23 2500717 +24 14672629 +25 22605581 +26 19799485 +27 132354781 +28 245516805 +29 85334093 +30 79762909 +31 37769685 + +32 2891336453 +33 3766383685 +34 3999037245 +35 23946934451 +36 55839444821 +37 107609022189 +38 269689778213 +38 297431448197 +40 330169576829 + +# 48 40596478153731 +# 60 841513432527741947 diff --git a/TESTU01/TestU01-1.2.3/param/LCGWu2.par b/TESTU01/TestU01-1.2.3/param/LCGWu2.par new file mode 100644 index 0000000..1e8fc42 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LCGWu2.par @@ -0,0 +1,57 @@ +# Package: TestU01 +# File: LCGWu2.par + +# Description: Parameter values for the LCG of type Wu2. They have a good +# lattice structure but with the restriction that the multiplier is a sum +# or a difference of two powers of 2, as suggested by P. C. Wu \cite{rWU97a}. +#----------------------------------------------------------------- + +# Give the name of the family first + +LCGWu2 + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m a +# where h is (very close to) the base-2 logarithm of m, m is the modulus, +# and a is the multiplier, the constant c is 0. The multiplier a has been +# chosen in such a way that a*m < 2^{53}. Thus we use the floating-point +# version of the LCG as it is often faster than the integer version. +# The binary representation of a is given in a comment on the same line + +10 1021 65 # 1000001 +11 2039 -72 # -1001000 +12 4093 960 # 1111000000 +13 8191 504 # 111111000 +14 16381 96 # 1100000 +15 32749 8256 # 10000001000000 +16 65521 8256 # 10000001000000 +17 131071 -320 # -101000000 +18 262139 384 # 110000000 +19 524287 -3968 # -111110000000 +20 1048573 15360 # 11110000000000 +21 2097143 -2032 # -11111110000 +22 4194301 67584 # 10000100000000000 +23 8388593 2096640 # 111111111111000000000 +24 16777213 1044480 # 11111111000000000000 +25 33554393 8256 # 10000001000000 +26 67108859 -16512 # -100000010000000 +27 134217689 16842752 # 1000000010000000000000000 +28 268435399 264192 # 1000000100000000000 +29 536870909 32640 # 111111110000000 +30 1073741789 40960 # 1010000000000000 +31 2147483647 -67584 # -10000100000000000 + +32 4294967291 130560 # 11111111000000000 +33 8589934583 4194336 # 10000000000000000100000 +# 34 17179869143 -2097136 # -111111111111111110000 +34 17179869143 132096 # 100000010000000000 +35 34359738337 1073745920 # 1000000000000000001000000000000 +# 36 68719476731 -17039360 # -1000001000000000000000000 +36 68719476731 16744448 # 111111111000000000000000 +# 37 137438953447 -8590458880 # -1000000000000010000000000000000000 +37 137438953447 8388576 # 11111111111111111100000 +# 38 274877906899 -491520 # -1111000000000000000 +38 274877906899 17178820608 # 1111111111111100000000000000000000 +39 549755813881 8590458880 # 1000000000000010000000000000000000 +40 1099511627689 8650752 # 100001000000000000000000 diff --git a/TESTU01/TestU01-1.2.3/param/LFSR1.par b/TESTU01/TestU01-1.2.3/param/LFSR1.par new file mode 100644 index 0000000..7dc8f3e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LFSR1.par @@ -0,0 +1,73 @@ +# Package: TestU01 +# File: LFSR1.par + +# Description: Parameter values for the LFSR1 generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +LFSR1 + + +# For each generator, the following parameters must be given in +# the right order on the same line +# k q s +# where the parameters are the same as in utaus_CreateTaus. + +# The following parameters are the results of exhaustive searches. +# When there exists no primitive trinomial of degree k, k has been set to +# zero. + + +10 3 4 +11 2 7 +0 0 0 +0 0 0 +0 0 0 +15 4 9 +0 0 0 +17 5 9 +18 7 10 +0 0 0 +20 3 13 +21 2 12 +22 1 13 +23 5 13 +0 0 0 +25 3 16 +0 0 0 +0 0 0 +28 9 16 +29 2 20 +0 0 0 +31 3 12 +0 0 0 +33 13 15 +0 0 0 +35 2 21 +36 11 16 +0 0 0 +0 0 0 +39 14 23 +0 0 0 +41 3 24 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +47 5 30 +0 0 0 +49 12 27 +0 0 0 +0 0 0 +52 19 31 +0 0 0 +0 0 0 +55 24 21 +0 0 0 +57 7 31 +58 19 35 +0 0 0 +60 11 34 +0 0 0 diff --git a/TESTU01/TestU01-1.2.3/param/LFSR2.par b/TESTU01/TestU01-1.2.3/param/LFSR2.par new file mode 100644 index 0000000..61d347e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LFSR2.par @@ -0,0 +1,129 @@ +# Package: TestU01 +# File: LFSR2.par + +# Description: Parameter values for the LFSR2 generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +LFSR2 + + +# For each generator, the following parameters must be given in +# the right order on three lines +# LSize +# k1 q1 s1 +# k2 q2 s2 +# where the parameters are the same as in utaus_CreateCombTaus2. + +# The following parameters are the results of exhaustive searches. +# All are ME-CF, except where mentioned. + + +10 +7 1 2 +3 1 1 + +11 +6 1 1 +5 2 2 + +12 +7 1 5 # Not ME +5 2 1 + +13 +7 1 3 +6 1 4 + +14 +9 4 3 +5 2 2 + +15 +11 2 6 +4 1 1 + +16 +11 2 3 +5 2 2 + +17 +10 3 5 +7 3 3 + +18 +11 2 5 +7 1 2 + +19 +10 3 4 +9 4 2 + +20 +11 2 8 # Not ME +9 4 4 + +21 +11 2 3 +10 3 4 + +22 +15 4 8 +7 1 6 + +23 +17 3 10 +6 1 1 + +24 +17 3 7 +7 1 5 # Not ME + +25 +18 7 5 +7 1 4 + +26 +15 7 4 +11 2 7 + +27 +17 5 10 +10 3 2 + +28 +17 3 11 # Not ME +11 2 8 + +29 +18 7 10 +11 2 6 + +30 +21 2 12 # Not ME +9 4 5 + +31 +20 3 8 # Only ME, not CF +11 2 6 + +32 +17 3 12 +15 4 6 + +33 +23 5 10 # Only ME, not CF +10 3 4 + +34 +23 5 8 +11 2 7 + +35 +18 7 11 +17 5 8 + +36 +25 7 14 +11 2 5 diff --git a/TESTU01/TestU01-1.2.3/param/LFSR3.par b/TESTU01/TestU01-1.2.3/param/LFSR3.par new file mode 100644 index 0000000..4dcaff4 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/LFSR3.par @@ -0,0 +1,137 @@ +# Package: TestU01 +# File: LFSR3.par + +# Description: Parameter values for the LFSR3 generators. +#----------------------------------------------------------------- + +# Give the name of the family first + +LFSR3 + + +# For each generator, the following parameters must be given in +# the right order on four lines +# LSize +# k1 q1 s1 +# k2 q2 s2 +# k3 q3 s3 +# where the parameters are the same as in utaus_CreateCombTaus3. + +# The following parameters are the results of exhaustive searches. +# All are ME-CF, except where mentioned. + + +14 +7 3 3 +4 1 2 +3 1 2 + +15 +7 1 2 # Not ME: Somme des ecarts = 1 +5 2 3 +3 1 1 + +16 +7 1 3 # Not ME: Somme des ecarts = 1 +5 2 3 +4 1 2 + +17 +7 1 1 +6 1 5 +4 1 2 + +18 +7 1 5 +6 1 1 +5 2 3 + +19 +11 2 4 +5 2 2 +3 1 2 + +20 +9 4 3 # ME but not CF. +7 1 5 +4 1 1 + +21 +9 4 3 +7 1 5 +5 2 1 + +22 +11 2 8 +6 1 4 +5 2 3 + +23 +11 2 2 +7 1 4 +5 2 3 + +24 +11 2 7 # ME but not CF +7 1 2 +6 1 5 + +25 +11 2 3 # Not ME. Somme des ecarts = 1 +9 4 1 +5 2 2 + +26 +10 3 2 +9 4 3 +7 3 1 + +27 +11 2 2 +9 4 3 +7 3 4 + +28 +11 2 4 +10 3 7 + 7 3 3 + +29 +17 3 4 + 7 1 2 + 5 2 3 + +30 +11 2 3 # Not ME. Somme des ecarts = 2 +10 3 5 + 9 4 2 + +31 +17 3 7 + 9 4 5 + 5 2 2 + +32 +15 1 8 # ME but not CF. +11 2 3 + 6 1 1 + +33 +17 3 9 + 9 4 5 + 7 3 2 + +34 +17 3 4 +10 3 2 + 7 1 3 + +35 +17 3 4 +11 2 6 + 7 1 5 + +36 +17 5 8 +10 3 5 + 9 4 1 diff --git a/TESTU01/TestU01-1.2.3/param/MRG2.par b/TESTU01/TestU01-1.2.3/param/MRG2.par new file mode 100644 index 0000000..62d716b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/MRG2.par @@ -0,0 +1,60 @@ +# Package: TestU01 +# File: MRG2.par + +# Description: Parameter values for the MRG of order 2. They have a good +# lattice structure up to dimension 8 (at least), with a prime +# modulus $m$ just below $2^{i/2}$ and period length $m^2-1$. + +#----------------------------------------------------------------- + +# Give the name of the family first + +MRG2 + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m a0 a1 +# where h is the lsize, m is the modulus, a0 and a1 are the multipliers. +# + +20 1021 730 663 +21 1447 196 -533 +22 2039 1805 1930 +23 2887 2665 -1633 +24 4093 1172 770 +25 5791 496 -3921 +26 8191 4837 7660 +27 11579 5452 -3612 +28 16381 13073 1997 +29 23167 2502 -6323 +30 32749 9343 6439 +31 46337 18036 -46220 +32 65521 35907 30770 +33 92681 62875 -68441 +34 131071 55544 90795 +35 185363 122015 -54479 +36 262139 21830 162959 +37 370723 158214 -171270 +38 524287 396733 446660 +39 741431 528783 -723184 +40 1048573 633537 57143 +41 1482907 456124 -1294947 +42 2097143 132547 1642238 +43 2965819 2675288 -804847 +44 4194301 173405 3471693 +45 5931641 936277 -163136 +46 8388593 1439561 1830242 +47 11863279 11265990 -7978568 +48 16777213 10355898 1875483 +49 23726561 14681237 -21097402 +50 33554393 23321560 483332 +51 47453111 36472661 -1279605 +52 67108859 59310754 15280366 +53 94906249 59517650 -92194958 +54 134217689 16626702 26032456 +55 189812507 43186395 -45884916 +56 268435399 31958755 -28056245 +57 379625047 8207583 -9894783 +58 536870909 6284080 4697886 +59 759250111 11568066 -8989107 +60 1073741789 5796676 -4321746 diff --git a/TESTU01/TestU01-1.2.3/param/MRG3.par b/TESTU01/TestU01-1.2.3/param/MRG3.par new file mode 100644 index 0000000..51264ac --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/MRG3.par @@ -0,0 +1,70 @@ +# Package: TestU01 +# File: MRG3.par + +# Description: Parameter values for the MRG of order 3. They have a good +# lattice structure up to dimension 8 (at least), with a prime +# modulus $m$ just below $2^{i/3}$ and period length $m^3-1$. + +#----------------------------------------------------------------- + +# Give the name of the family first + +MRG3 + +# For each generator, the following parameters must be given in +# the right order on the same line +# h m a0 a1 a2 +# where h is the lsize, m is the modulus, a0, a1 and a2 are the multipliers. +# + +30 911 389 411 665 +31 1289 118 343 506 +32 1621 1112 1473 893 +33 1973 735 877 1555 +34 2579 1859 2079 1374 +35 3229 388 2309 2274 +36 3989 1473 1706 3224 +37 5153 2755 1910 3847 +38 6491 2767 615 391 +39 8093 960 5934 5674 +40 10289 4891 7950 8949 +41 13001 9418 10485 6858 +42 16301 5841 6920 12989 +43 20639 15308 3754 3083 +44 25997 5008 7778 23683 +45 32693 11732 13966 26162 +46 41231 10313 33193 13927 +47 51971 13974 39132 30073 +48 65381 14014 39120 30143 +49 82529 1923 56024 7737 +50 103913 40506 59922 68233 +51 130859 46750 71933 62870 +52 164249 83533 83931 6878 +53 208001 44249 162798 116315 +54 262139 112352 202967 95663 +55 329993 44242 261100 181889 +56 415787 293866 214663 214943 +57 524201 177871 399571 161193 +58 660509 109762 457713 345692 +59 832121 109792 556037 411401 +60 1048517 374459 825588 325032 + +63 2096993 767709 1644815 652699 + +66 4194023 1521371 3315922 1275263 + +69 8388371 2995924 6691008 2520492 + +72 16776623 6010556 13375750 5010812 + +75 33554393 12039895 26777810 9991554 + +78 67108721 24065767 53614836 19985837 + +81 134217467 12039879 26777852 9991570 + +84 268434827 6010521 13375757 5010878 + +87 536870267 2995942 6691051 2520445 + +90 1073740163 1521397 3315999 1275337 diff --git a/TESTU01/TestU01-1.2.3/param/Makefile.am b/TESTU01/TestU01-1.2.3/param/Makefile.am new file mode 100644 index 0000000..4d03410 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/Makefile.am @@ -0,0 +1,7 @@ +pardir = ${prefix}/share/TestU01/param + +par_DATA = CombCubLCG.par InvExpl.par InvImpl2b.par LCGWu2.par \ + CombCubic2.par InvExpl2a.par LCGBad2.par LFSR1.par TausLCG2.par \ + CombL2.par InvExpl2b.par LCGGood.par LFSR2.par MRG3.par \ + CombWH2.par InvImpl.par LCGGranger.par LFSR3.par \ + Cubic1.par InvImpl2a.par LCGPow2.par MRG2.par diff --git a/TESTU01/TestU01-1.2.3/param/Makefile.in b/TESTU01/TestU01-1.2.3/param/Makefile.in new file mode 100644 index 0000000..ecdc320 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/Makefile.in @@ -0,0 +1,361 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = param +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h \ + $(top_builddir)/include/gdefconf.h +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(pardir)" +parDATA_INSTALL = $(INSTALL_DATA) +DATA = $(par_DATA) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +pardir = ${prefix}/share/TestU01/param +par_DATA = CombCubLCG.par InvExpl.par InvImpl2b.par LCGWu2.par \ + CombCubic2.par InvExpl2a.par LCGBad2.par LFSR1.par TausLCG2.par \ + CombL2.par InvExpl2b.par LCGGood.par LFSR2.par MRG3.par \ + CombWH2.par InvImpl.par LCGGranger.par LFSR3.par \ + Cubic1.par InvImpl2a.par LCGPow2.par MRG2.par + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu param/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu param/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-parDATA: $(par_DATA) + @$(NORMAL_INSTALL) + test -z "$(pardir)" || $(MKDIR_P) "$(DESTDIR)$(pardir)" + @list='$(par_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(parDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(pardir)/$$f'"; \ + $(parDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(pardir)/$$f"; \ + done + +uninstall-parDATA: + @$(NORMAL_UNINSTALL) + @list='$(par_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(pardir)/$$f'"; \ + rm -f "$(DESTDIR)$(pardir)/$$f"; \ + done +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(DATA) +installdirs: + for dir in "$(DESTDIR)$(pardir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-parDATA + +install-dvi: install-dvi-am + +install-exec-am: + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-parDATA + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + distclean distclean-generic distclean-libtool distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-parDATA \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + uninstall uninstall-am uninstall-parDATA + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/param/TausLCG2.par b/TESTU01/TestU01-1.2.3/param/TausLCG2.par new file mode 100644 index 0000000..c7d9843 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/param/TausLCG2.par @@ -0,0 +1,193 @@ +# Package: TestU01 +# File: TausLCG2.par + +# Description: Parameter values for combined CombTaus2 with LCG +# Each member of the family calls generator ulec_CreateCombTausLCG21. +#----------------------------------------------------------------- + +# Give the name of the family first + +TausLCG2 + +# For each generator, the following parameters must be given in +# the right order on three lines +# LSize +# k1 q1 s1 k2 q2 s2 +# m a +# where LSize is (very close to) the base-2 logarithm of the period length, +# k1, q1, s1 are the parameters of the first Taus component, and +# k2, q2, s2 are the parameters of the second Taus component in the +# CombTaus2 generator +# m, a are the modulus and the multiplier of the LCG generator. + +20 + 7 1 2 3 1 1 + 1021 65 + +21 + 7 1 2 3 1 1 + 2039 995 + +22 + 6 1 1 5 2 2 + 2039 995 + +23 + 6 1 1 5 2 2 + 4093 209 + +24 + 7 1 5 5 2 1 + 4093 209 + +25 + 7 1 5 5 2 1 + 8191 884 + +26 + 7 1 3 6 1 4 + 8191 884 + +27 + 7 1 3 6 1 4 + 16381 572 + +28 + 9 4 3 5 2 2 + 16381 572 + +29 + 9 4 3 5 2 2 + 32749 219 + +30 + 11 2 6 4 1 1 + 32749 219 + +31 + 11 2 6 4 1 1 + 65521 17364 + +32 + 11 2 3 5 2 2 + 65521 17364 + +33 + 11 2 3 5 2 2 + 131071 43165 + +34 + 10 3 5 7 3 3 + 131071 43165 + +35 + 10 3 5 7 3 3 + 262139 92717 + +36 + 11 2 5 7 1 2 + 262139 92717 + +37 + 11 2 5 7 1 2 + 524287 283741 + +38 + 10 3 4 9 4 2 + 524287 283741 + +39 + 10 3 4 9 4 2 + 1048573 380985 + +40 + 11 2 8 9 4 4 + 1048573 380985 + +41 + 11 2 8 9 4 4 + 2097143 360889 + +42 + 11 2 3 10 3 4 + 2097143 360889 + +43 + 11 2 3 10 3 4 + 4194301 914334 + +44 + 15 4 8 7 1 6 + 4194301 914334 + +45 + 15 4 8 7 1 6 + 8388593 653276 + +46 + 17 3 10 6 1 1 + 8388593 653276 + +47 + 17 3 10 6 1 1 + 16777213 6423135 + +48 + 17 3 7 7 1 5 + 16777213 6423135 + +49 + 17 3 7 7 1 5 + 33554393 25907312 + +50 + 18 7 5 7 1 4 + 33554393 25907312 + +51 + 18 7 5 7 1 4 + 67108859 26590841 + +52 + 15 7 4 11 2 7 + 67108859 26590841 + +53 + 15 7 4 11 2 7 + 134217689 45576512 + +54 + 17 5 10 10 3 2 + 134217689 45576512 + +55 + 17 5 10 10 3 2 + 268435399 31792125 + +56 + 17 3 11 11 2 8 + 268435399 31792125 + +57 + 17 3 11 11 2 8 + 536870909 16538103 + +58 + 18 7 10 11 2 6 + 536870909 16538103 + +59 + 18 7 10 11 2 6 + 1073741789 5122456 + +60 + 21 2 12 9 4 5 + 1073741789 5122456 + +61 + 21 2 12 9 4 5 + 2147483647 1389796 + +62 + 20 3 8 11 2 6 + 2147483647 1389796 diff --git a/TESTU01/TestU01-1.2.3/probdist/Makefile.am b/TESTU01/TestU01-1.2.3/probdist/Makefile.am new file mode 100644 index 0000000..be500ba --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/include/Makefile.def + +lib_LTLIBRARIES = libprobdist.la +libprobdist_la_SOURCES = $(PROBDISTSOURCES) +libprobdist_la_LIBADD = $(top_builddir)/mylib/libmylib.la +libprobdist_la_LDFLAGS = -no-undefined -version-info 0:1:0 + +EXTRA_DIST = guideprobdist.tex titre.tex copyright.tex guideprobdist.bbl + +doc_DATA = guideprobdist.pdf diff --git a/TESTU01/TestU01-1.2.3/probdist/Makefile.in b/TESTU01/TestU01-1.2.3/probdist/Makefile.in new file mode 100644 index 0000000..c84130c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/Makefile.in @@ -0,0 +1,540 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(top_srcdir)/include/Makefile.def +subdir = probdist +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h \ + $(top_builddir)/include/gdefconf.h +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +libprobdist_la_DEPENDENCIES = $(top_builddir)/mylib/libmylib.la +am__objects_1 = fmass.lo fdist.lo fbar.lo finv.lo gofs.lo gofw.lo \ + statcoll.lo wdist.lo +am_libprobdist_la_OBJECTS = $(am__objects_1) +libprobdist_la_OBJECTS = $(am_libprobdist_la_OBJECTS) +libprobdist_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libprobdist_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I. -I$(top_builddir)/include@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libprobdist_la_SOURCES) +DIST_SOURCES = $(libprobdist_la_SOURCES) +docDATA_INSTALL = $(INSTALL_DATA) +DATA = $(doc_DATA) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = ${prefix}/share/TestU01/doc +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +MYLIB = ${top_srcdir}/mylib +PROBDIST = ${top_srcdir}/probdist +TESTU01 = ${top_srcdir}/testu01 +MYLIBHEADERS = gdef.h addstr.h bitset.h chrono.h mystr.h num.h num2.h tables.h util.h +MYLIBSOURCES = gdef.c addstr.c bitset.c chrono.c mystr.c num.c num2.c tables.c util.c +MYLIBTEX = $(MYLIB)/gdef.tex $(MYLIB)/addstr.tex $(MYLIB)/bitset.tex $(MYLIB)/chrono.tex $(MYLIB)/mystr.tex $(MYLIB)/num.tex $(MYLIB)/num2.tex $(MYLIB)/tables.tex $(MYLIB)/util.tex +PROBDISTHEADERS = fmass.h fdist.h fbar.h finv.h gofs.h gofw.h statcoll.h wdist.h +PROBDISTSOURCES = fmass.c fdist.c fbar.c finv.c gofs.c gofw.c statcoll.c wdist.c +PROBDISTTEX = $(PROBDIST)/fmass.tex $(PROBDIST)/fdist.tex $(PROBDIST)/fbar.tex $(PROBDIST)/finv.tex $(PROBDIST)/gofs.tex $(PROBDIST)/gofw.tex $(PROBDIST)/statcoll.tex $(PROBDIST)/wdist.tex +TESTU01HEADERS = unif01.h ulcg.h umrg.h ucarry.h utaus.h ugfsr.h uinv.h uquad.h ucubic.h ulec.h utezuka.h umarsa.h uweyl.h uknuth.h uwu.h unumrec.h uvaria.h usoft.h ugranger.h ucrypto.h ufile.h udeng.h utouzin.h uautomata.h uxorshift.h ubrent.h rijndael-alg-fst.h tu01_sha1.h scatter.h swrite.h sres.h smultin.h sknuth.h smarsa.h sstring.h svaria.h snpair.h swalk.h sentrop.h sspectral.h scomp.h sspacings.h vectorsF2.h bbattery.h ffam.h fcong.h ffsr.h ftab.h fres.h fcho.h fmultin.h fmarsa.h fknuth.h fwalk.h fstring.h fspectral.h fvaria.h fnpair.h +TESTU01SOURCES = unif01.c ulcg.c umrg.c ucarry.c utaus.c ugfsr.c uinv.c uquad.c ucubic.c ulec.c utezuka.c umarsa.c uweyl.c uknuth.c uwu.c unumrec.c uvaria.c usoft.c ugranger.c ucrypto.c ufile.c udeng.c utouzin.c uautomata.c uxorshift.c ubrent.c rijndael-alg-fst.c tu01_sha1.c scatter.c swrite.c sres.c smultin.c sknuth.c smarsa.c sstring.c svaria.c snpair.c swalk.c sentrop.c sspectral.c scomp.c sspacings.c vectorsF2.c bbattery.c ffam.c fcong.c ffsr.c ftab.c fres.c fcho.c fmultin.c fmarsa.c fknuth.c fwalk.c fstring.c fspectral.c fvaria.c fnpair.c +TESTU01TEX = $(TESTU01)/unif01.tex $(TESTU01)/ulcg.tex \ + $(TESTU01)/umrg.tex $(TESTU01)/ucarry.tex $(TESTU01)/utaus.tex \ + $(TESTU01)/ugfsr.tex $(TESTU01)/uinv.tex $(TESTU01)/uquad.tex \ + $(TESTU01)/ucubic.tex $(TESTU01)/ulec.tex \ + $(TESTU01)/utezuka.tex $(TESTU01)/umarsa.tex \ + $(TESTU01)/uweyl.tex $(TESTU01)/uknuth.tex $(TESTU01)/uwu.tex \ + $(TESTU01)/unumrec.tex $(TESTU01)/uvaria.tex \ + $(TESTU01)/usoft.tex $(TESTU01)/ugranger.tex \ + $(TESTU01)/ucrypto.tex $(TESTU01)/ufile.tex \ + $(TESTU01)/udeng.tex $(TESTU01)/utouzin.tex \ + $(TESTU01)/uautomata.tex $(TESTU01)/uxorshift.tex \ + $(TESTU01)/ubrent.tex $(TESTU01)/rijndael-alg-fst.tex \ + $(TESTU01)/tu01_sha1.tex $(TESTU01)/scatter.tex \ + $(TESTU01)/swrite.tex $(TESTU01)/sres.tex \ + $(TESTU01)/smultin.tex $(TESTU01)/sknuth.tex \ + $(TESTU01)/smarsa.tex $(TESTU01)/sstring.tex \ + $(TESTU01)/svaria.tex $(TESTU01)/snpair.tex \ + $(TESTU01)/swalk.tex $(TESTU01)/sentrop.tex \ + $(TESTU01)/sspectral.tex $(TESTU01)/scomp.tex \ + $(TESTU01)/sspacings.tex $(TESTU01)/vectorsF2.tex \ + $(TESTU01)/bbattery.tex $(TESTU01)/ffam.tex \ + $(TESTU01)/fcong.tex $(TESTU01)/ffsr.tex $(TESTU01)/ftab.tex \ + $(TESTU01)/fres.tex $(TESTU01)/fcho.tex $(TESTU01)/fmultin.tex \ + $(TESTU01)/fmarsa.tex $(TESTU01)/fknuth.tex \ + $(TESTU01)/fwalk.tex $(TESTU01)/fstring.tex \ + $(TESTU01)/fspectral.tex $(TESTU01)/fvaria.tex \ + $(TESTU01)/fnpair.tex +lib_LTLIBRARIES = libprobdist.la +libprobdist_la_SOURCES = $(PROBDISTSOURCES) +libprobdist_la_LIBADD = $(top_builddir)/mylib/libmylib.la +libprobdist_la_LDFLAGS = -no-undefined -version-info 0:1:0 +EXTRA_DIST = guideprobdist.tex titre.tex copyright.tex guideprobdist.bbl +doc_DATA = guideprobdist.pdf +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/include/Makefile.def $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu probdist/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu probdist/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libprobdist.la: $(libprobdist_la_OBJECTS) $(libprobdist_la_DEPENDENCIES) + $(libprobdist_la_LINK) -rpath $(libdir) $(libprobdist_la_OBJECTS) $(libprobdist_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fbar.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdist.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/finv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmass.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gofs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gofw.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/statcoll.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wdist.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-docDATA: $(doc_DATA) + @$(NORMAL_INSTALL) + test -z "$(docdir)" || $(MKDIR_P) "$(DESTDIR)$(docdir)" + @list='$(doc_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(docDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(docdir)/$$f'"; \ + $(docDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(docdir)/$$f"; \ + done + +uninstall-docDATA: + @$(NORMAL_UNINSTALL) + @list='$(doc_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(docdir)/$$f'"; \ + rm -f "$(DESTDIR)$(docdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(DATA) +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-docDATA + +install-dvi: install-dvi-am + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-docDATA uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am \ + install-docDATA install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-libLTLIBRARIES install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-docDATA \ + uninstall-libLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/probdist/copyright.tex b/TESTU01/TestU01-1.2.3/probdist/copyright.tex new file mode 100644 index 0000000..4b22902 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/copyright.tex @@ -0,0 +1,26 @@ +\section*{Copyright} + +%\begin{verbatim} + Copyright \copyright {} 2002 by Pierre L'Ecuyer, + Universit\'e de Montr\'eal.\\ + Web address: \url{http://www.iro.umontreal.ca/~lecuyer/} \\ + All rights reserved. + +\noindent Redistribution and use in source and binary forms, with or without + modification, are permitted without a fee for private, research, + academic, or other non-commercial purposes. + Any use of this software in a commercial environment requires a + written licence from the copyright owner. + +\noindent Any changes made to this package must be clearly identified as such. + +\noindent In scientific publications which used this software, a reference to it + would be appreciated. + +\noindent Redistributions of source code must retain this copyright notice + and the following disclaimer: + +\noindent THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +%\end{verbatim} diff --git a/TESTU01/TestU01-1.2.3/probdist/fbar.c b/TESTU01/TestU01-1.2.3/probdist/fbar.c new file mode 100644 index 0000000..d196b95 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/fbar.c @@ -0,0 +1,1313 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: fbar.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "fbar.h" +#include "fdist.h" + +#include "num.h" +#include "num2.h" +#include "util.h" +#include "gdef.h" + +#include +#include + +double fdist_belog(double); +extern const double fdist_XINF; +extern const double fdist_XBIG; +extern const double fdist_XBIGM; + +/* EpsArray[j]: Epsilon required for j decimal degits of precision */ +static const double EpsArray[] = { + 0.5, 0.5E-1, 0.5E-2, 0.5E-3, 0.5E-4, 0.5E-5, 0.5E-6, 0.5E-7, 0.5E-8, + 0.5E-9, 0.5E-10, 0.5E-11, 0.5E-12, 0.5E-13, 0.5E-14, 0.5E-15, 0.5E-16, + 0.5E-17, 0.5E-18, 0.5E-19, 0.5E-20, 0.5E-21, 0.5E-22, 0.5E-23, 0.5E-24, + 0.5E-25, 0.5E-26, 0.5E-27, 0.5E-28, 0.5E-29, 0.5E-30, 0.5E-31, 0.5E-32, + 0.5E-33, 0.5E-34, 0.5E-35 +}; + +/* Compute IMAX extra terms in the tails of discrete distributions */ +static const long IMAX = 20; + + + +/*=========================================================================*/ + +double fbar_Unif (double x) +{ + if (x <= 0.0) + return 1.0; + if (x >= 1.0) + return 0.0; + return 1.0 - x; +} + + +/*=========================================================================*/ + +double fbar_Expon (double x) +{ + if (x <= 0.0) + return 1.0; + if (x >= fdist_XBIGM) + return 0.0; + return exp (-x); +} + + +/*=========================================================================*/ + +double fbar_Weibull (double c, double x) +{ + double temp; + util_Assert (c > 0.0, "fbar_Weibull: c <= 0"); + if (x <= 0.0) + return 1.0; + if (x >= DBL_MAX_EXP * FLT_RADIX && c >= 1.0) + return 0.0; + temp = c*log(x); + if (temp >= DBL_MAX_EXP * num_Ln2) + return 0.0; + temp = exp(temp); + return (exp (-temp)); +} + + +/*=========================================================================*/ + +double fbar_Logistic (double x) +{ + if (x <= -fdist_XBIG) { + return 1.0; + } + if (x >= fdist_XBIG) { + return exp (-x); + } + return 1.0 / (1.0 + exp (x)); +} + + +/*=========================================================================*/ + +double fbar_Pareto (double c, double x) +{ + + util_Assert (c > 0.0, "fbar_Pareto: c <= 0"); + if (x <= 1.0) + return 1.0; + return (pow (x, -c)); +} + +/**************************************************************************/ + +double fbar_Normal1 (double x) +/* + * Returns P[X >= x] = 1 - F(x) where F is the normal distribution by + * computing the complementary distribution directly; it is thus more + * precise in the tail. + */ +{ + static const double A[25] = { + 6.10143081923200418E-1, + -4.34841272712577472E-1, + 1.76351193643605501E-1, + -6.07107956092494149E-2, + 1.77120689956941145E-2, + -4.32111938556729382E-3, + 8.54216676887098679E-4, + -1.27155090609162743E-4, + 1.12481672436711895E-5, + 3.13063885421820973E-7, + -2.70988068537762022E-7, + 3.07376227014076884E-8, + 2.51562038481762294E-9, + -1.02892992132031913E-9, + 2.99440521199499394E-11, + 2.60517896872669363E-11, + -2.63483992417196939E-12, + -6.43404509890636443E-13, + 1.12457401801663447E-13, + 1.7281533389986098E-14, + -4.2641016949424E-15, + -5.4537197788E-16, + 1.5869760776E-16, + 2.08998378E-17, + -0.5900E-17 + }; + const double kk = 5.30330085889910643300; /* 3.75 Sqrt(2) */ + double y, t; + int Neg; + + if (x >= fdist_XBIG) { + return 0.0; + } + if (x <= -fdist_XBIG) { + return 1.0; + } + + if (x >= 0.0) + Neg = 0; + else { + Neg = 1; + x = -x; + } + + t = (x - kk) / (x + kk); + y = num2_EvalCheby (A, 24, t); + y = y * exp (-x * x / 2.0) / 2.0; + + if (Neg == 1) + return (1.0 - y); + else + return (y); +} + + +/*=========================================================================*/ + +double fbar_Normal2 (double x) +{ + static const double V[121] = { + 1.2533141373155, 1.137490921203605, 1.037824575853727, + 0.951527192071207, 0.8763644564536924, 0.8105337152790306, + 0.7525711790634081, 0.7012808218544303, 0.6556795424187987, + 0.61495459615093, 0.5784303460476312, 0.5455421356582171, + 0.5158156382179634, 0.4888504415275737, 0.4643069280394423, + 0.4418957328326002, 0.4213692292880546, 0.4025146181296722, + 0.3851482907984348, 0.3691112106902635, 0.3542651113297938, + 0.3404893532870847, 0.3276783146905521, 0.31573921586941, + 0.3045902987101033, 0.2941592970402893, 0.284382146748493, + 0.2752018941576065, 0.2665677689682238, 0.2584343943120386, + 0.2507611114439651, 0.243511400615456, 0.2366523829135607, + 0.230154390478801, 0.2239905946538289, 0.2181366833614714, + 0.2125705804420318, 0.2072722008565011, 0.2022232366330547, + 0.1974069692375194, 0.1928081047153158, 0.1884126285076003, + 0.1842076773079702, 0.1801814257143918, 0.1763229857571027, + 0.1726223176578506, 0.1690701504076941, 0.1656579109468773, + 0.1623776608968675, 0.1592220399363674, 0.1561842150339759, + 0.153257834853479, 0.1504369887362691, 0.1477161697413935, + 0.145090241289131, 0.1425544070104023, 0.1401041834530503, + 0.1377353753382303, 0.1354440530967635, 0.1332265324471292, + 0.1310793558044918, 0.1289992753343376, 0.126983237485437, + 0.1250283688553504, 0.1231319632579323, 0.1212914698765462, + 0.119504482399253, 0.1177687290432979, 0.1160820633859823, + 0.1144424559276431, 0.112847986320103, 0.1112968362007359, + 0.1097872825783083, 0.1083176917221132, 0.1068865135106745, + 0.1054922762005562, 0.1041335815795983, 0.1028091004723001, + 0.1015175685681028, 0.1002577825460485, 0.09902859647173194, + 0.09782891844465691, 0.09665770747608191, 0.09551397057921558, + 0.09439676005522439, 0.09330517095996169, 0.09223833873763035, + 0.09119543700877471, 0.09017567550106469, 0.08917829811230435, + 0.08820258109597616, 0.08724783136042988, 0.08631338487354936, + 0.08539860516539227, 0.08450288192189578, 0.08362562966329139, + 0.08276628650136918, 0.08192431297018954, 0.08109919092525536, + 0.08029042250654048, 0.07949752916111721, 0.07872005072144664, + 0.07795754453568722, 0.07720958464664668, 0.07647576101624852, + 0.07575567879261112, 0.07504895761704659, 0.07435523096847724, + 0.07367414554294564, 0.07300536066605566, 0.07234854773633338, + 0.07170338969763433, 0.07106958053885212, 0.07044682481930167, + 0.06983483721825942, 0.06923334210724434, 0.06864207314371742, + 0.06806077288496332, 0.0674891924209997, 0.06692709102543307, + 0.06637423582325017 +}; + + int j; + lebool negatif; + double t, u, z, h; + double r, r1, r2, r3, r4, r5, r6, r7, r8; + + if (x >= fdist_XBIG) { + return 0.0; + } + if (x <= -fdist_XBIG) { + return 1.0; + } + if (x < 0.0) { + negatif = TRUE; + x = -x; + } else { + negatif = FALSE; + } + j = (int) (8.0 * x + 0.5); + if (j > 120) + j = 120; + z = 0.125 * j; + h = x - z; + r = V[j]; + r1 = r * z - 1.0; + r2 = 0.5 * (r + z * r1); + r3 = (r1 + z * r2) / 3.0; + r4 = 0.25 * (r2 + z * r3); + r5 = 0.2 * (r3 + z * r4); + r6 = (r4 + z * r5) / 6.0; + r7 = (r5 + z * r6) / 7.0; + r8 = 0.125 * (r6 + z * r7); + t = r + h * (r1 + h * (r2 + h * (r3 + h * (r4 + h * (r5 + h * (r6 + + h * (r7 + h * r8))))))); + u = t * exp (-0.5 * x * x - 0.9189385332046727); + if (negatif) + return 1.0 - u; + else + return u; +} + + +/*=========================================================================*/ +#ifdef HAVE_ERF + +double fbar_Normal3 (double x) +{ + return 0.5 * erfc (x * num_1Rac2); +} + +#endif +/*=========================================================================*/ + +double fbar_BiNormal1 (double x, double y, double rho, int ndig) +{ + return fdist_BiNormal1(-x, -y, rho, ndig); +} + + +/*=========================================================================*/ + +double fbar_BiNormal2 (double x, double y, double rho) +{ + return fdist_BiNormal2 (-x, -y, rho); +} + + +/*=========================================================================*/ + +double fbar_LogNormal (double mu, double sigma, double x) +{ + util_Assert (sigma > 0.0, "fbar_LogNormal: sigma <= 0"); + if (x <= 0.0) + return 1.0; + return fbar_Normal1 ((log (x) - mu) / sigma); +} + + +/*=========================================================================*/ + +double fbar_JohnsonSB (double alpha, double beta, double a, double b, + double x) +{ + util_Assert (beta > 0.0, "fbar_JohnsonSB: beta <= 0"); + util_Assert (b > a, "fbar_JohnsonSB: b <= a"); + if (x <= a) + return 1.0; + if (x >= b) + return 0.0; + return fbar_Normal1 (alpha + beta * log ((x - a) / (b - x))); +} + + +/*=========================================================================*/ + +double fbar_JohnsonSU (double alpha, double beta, double x) +{ + const double XLIM = 1.0e10; + double r; + lebool negative = FALSE; + util_Assert (beta > 0.0, "fbar_JohnsonSU: beta <= 0"); + if (x < 0.0) { + negative = TRUE; + x = -x; + } + /* compute r = x + sqrt (x * x + 1) */ + if (x < XLIM) + r = x + sqrt (x * x + 1.0); + else + r = 2.0 * x; + if (negative) + r = 1.0 / r; + + if (r > 0.0) + return fbar_Normal1 (alpha + beta * log (r)); + else + return 1.0; +} + + +/*=========================================================================*/ + +static double F2AD[103]; /* Tables for the approximation of the */ +static double CoAD[103]; /* Anderson-Darling distribution */ + +static void AndersonDarlingInit (void) +{ + F2AD[0] = 0.0; F2AD[1] = 1.7315E-10; + F2AD[2] = 2.80781E-5; F2AD[3] = 1.40856E-3; + F2AD[4] = 9.58772E-3; F2AD[5] = 2.960552E-2; + F2AD[6] = 6.185146E-2; F2AD[7] = 1.0357152E-1; + F2AD[8] = 1.5127241E-1; F2AD[9] = 2.0190317E-1; + F2AD[10] = 2.5318023E-1; F2AD[11] = 3.0354278E-1; + F2AD[12] = 3.5200015E-1; F2AD[13] = 3.9797537E-1; + F2AD[14] = 4.4117692E-1; F2AD[15] = 4.8150305E-1; + F2AD[16] = 5.1897375E-1; F2AD[17] = 5.5368396E-1; + F2AD[18] = 5.8577199E-1; F2AD[19] = 6.1539864E-1; + F2AD[20] = 6.4273362E-1; F2AD[21] = 6.6794694E-1; + F2AD[22] = 6.9120359E-1; F2AD[23] = 7.126605E-1; + F2AD[24] = 7.3246483E-1; F2AD[25] = 7.507533E-1; + F2AD[26] = 7.6765207E-1; F2AD[27] = 7.8327703E-1; + F2AD[28] = 7.9773426E-1; F2AD[29] = 8.1112067E-1; + F2AD[30] = 8.2352466E-1; F2AD[31] = 8.3502676E-1; + F2AD[32] = 8.4570037E-1; F2AD[33] = 8.5561231E-1; + F2AD[34] = 8.6482346E-1; F2AD[35] = 8.7338931E-1; + F2AD[36] = 8.8136046E-1; F2AD[37] = 8.8878306E-1; + F2AD[38] = 8.9569925E-1; F2AD[39] = 9.0214757E-1; + F2AD[40] = 9.081653E-1; F2AD[41] = 9.1378043E-1; + F2AD[42] = 9.1902284E-1; F2AD[43] = 9.2392345E-1; + F2AD[44] = 9.2850516E-1; F2AD[45] = 9.3279084E-1; + F2AD[46] = 9.3680149E-1; F2AD[47] = 9.4055647E-1; + F2AD[48] = 9.440736E-1; F2AD[49] = 9.4736933E-1; + F2AD[50] = 9.5045883E-1; F2AD[51] = 9.5335611E-1; + F2AD[52] = 9.5607414E-1; F2AD[53] = 9.586249E-1; + F2AD[54] = 9.6101951E-1; F2AD[55] = 9.6326825E-1; + F2AD[56] = 9.6538067E-1; F2AD[57] = 9.6736563E-1; + F2AD[58] = 9.6923135E-1; F2AD[59] = 9.7098548E-1; + F2AD[60] = 9.7263514E-1; F2AD[61] = 9.7418694E-1; + F2AD[62] = 9.7564704E-1; F2AD[63] = 9.7702119E-1; + F2AD[64] = 9.7831473E-1; F2AD[65] = 9.7953267E-1; + F2AD[66] = 9.8067966E-1; F2AD[67] = 9.8176005E-1; + F2AD[68] = 9.827779E-1; F2AD[69] = 9.8373702E-1; + F2AD[70] = 9.8464096E-1; F2AD[71] = 9.8549304E-1; + F2AD[72] = 9.8629637E-1; F2AD[73] = 9.8705386E-1; + F2AD[74] = 9.8776824E-1; F2AD[75] = 9.8844206E-1; + F2AD[76] = 9.8907773E-1; F2AD[77] = 9.8967747E-1; + F2AD[78] = 9.9024341E-1; F2AD[79] = 9.9077752E-1; + F2AD[80] = 9.9128164E-1; F2AD[81] = 9.9175753E-1; + F2AD[82] = 9.9220682E-1; F2AD[83] = 9.9263105E-1; + F2AD[84] = 9.9303165E-1; F2AD[85] = 9.9340998E-1; + F2AD[86] = 9.9376733E-1; F2AD[87] = 9.9410488E-1; + F2AD[88] = 9.9442377E-1; F2AD[89] = 9.9472506E-1; + F2AD[90] = 9.9500974E-1; F2AD[91] = 9.9527876E-1; + F2AD[92] = 9.95533E-1; F2AD[93] = 9.9577329E-1; + F2AD[94] = 9.9600042E-1; F2AD[95] = 9.9621513E-1; + F2AD[96] = 9.964181E-1; F2AD[97] = 0.99661; + F2AD[98] = 9.9679145E-1; F2AD[99] = 9.9696303E-1; + F2AD[100] = 9.9712528E-1; F2AD[101] = 9.9727872E-1; + F2AD[102] = 9.9742384E-1; + + CoAD[0] = 0.0; + CoAD[1] = 0.0; CoAD[2] = 0.0; + CoAD[3] = 0.0; CoAD[4] = 0.0; + CoAD[5] = -1.87E-3; CoAD[6] = 0.00898; + CoAD[7] = 0.0209; CoAD[8] = 0.03087; + CoAD[9] = 0.0377; CoAD[10] = 0.0414; + CoAD[11] = 0.04386; CoAD[12] = 0.043; + CoAD[13] = 0.0419; CoAD[14] = 0.0403; + CoAD[15] = 0.038; CoAD[16] = 3.54804E-2; + CoAD[17] = 0.032; CoAD[18] = 0.0293; + CoAD[19] = 2.61949E-2; CoAD[20] = 0.0228; + CoAD[21] = 0.0192; CoAD[22] = 1.59865E-2; + CoAD[23] = 0.0129; CoAD[24] = 0.0107; + CoAD[25] = 8.2464E-3; CoAD[26] = 0.00611; + CoAD[27] = 0.00363; CoAD[28] = 1.32272E-3; + CoAD[29] = -5.87E-4; CoAD[30] = -2.75E-3; + CoAD[31] = -3.95248E-3; CoAD[32] = -5.34E-3; + CoAD[33] = -6.892E-3; CoAD[34] = -8.10208E-3; + CoAD[35] = -8.93E-3; CoAD[36] = -9.552E-3; + CoAD[37] = -1.04605E-2; CoAD[38] = -0.0112; + CoAD[39] = -1.175E-2; CoAD[40] = -1.20216E-2; + CoAD[41] = -0.0124; CoAD[42] = -1.253E-2; + CoAD[43] = -1.27076E-2; CoAD[44] = -0.0129; + CoAD[45] = -1.267E-2; CoAD[46] = -1.22015E-2; + CoAD[47] = -0.0122; CoAD[48] = -1.186E-2; + CoAD[49] = -1.17218E-2; CoAD[50] = -0.0114; + CoAD[51] = -1.113E-2; CoAD[52] = -1.08459E-2; + CoAD[53] = -0.0104; CoAD[54] = -9.93E-3; + CoAD[55] = -9.5252E-3; CoAD[56] = -9.24E-3; + CoAD[57] = -9.16E-3; CoAD[58] = -8.8004E-3; + CoAD[59] = -8.63E-3; CoAD[60] = -8.336E-3; + CoAD[61] = -8.10512E-3; CoAD[62] = -7.94E-3; + CoAD[63] = -7.71E-3; CoAD[64] = -7.55064E-3; + CoAD[65] = -7.25E-3; CoAD[66] = -7.11E-3; + CoAD[67] = -6.834E-3; CoAD[68] = -0.0065; + CoAD[69] = -6.28E-3; CoAD[70] = -6.11008E-3; + CoAD[71] = -5.86E-3; CoAD[72] = -5.673E-3; + CoAD[73] = -5.35008E-3; CoAD[74] = -5.11E-3; + CoAD[75] = -4.786E-3; CoAD[76] = -4.59144E-3; + CoAD[77] = -4.38E-3; CoAD[78] = -4.15E-3; + CoAD[79] = -4.07696E-3; CoAD[80] = -3.93E-3; + CoAD[81] = -3.83E-3; CoAD[82] = -3.74656E-3; + CoAD[83] = -3.49E-3; CoAD[84] = -3.33E-3; + CoAD[85] = -3.20064E-3; CoAD[86] = -3.09E-3; + CoAD[87] = -2.93E-3; CoAD[88] = -2.78136E-3; + CoAD[89] = -2.72E-3; CoAD[90] = -2.66E-3; + CoAD[91] = -2.56208E-3; CoAD[92] = -2.43E-3; + CoAD[93] = -2.28E-3; CoAD[94] = -2.13536E-3; + CoAD[95] = -2.083E-3; CoAD[96] = -1.94E-3; + CoAD[97] = -1.82E-3; CoAD[98] = -1.77E-3; + CoAD[99] = -1.72E-3; CoAD[100] = -1.71104E-3; + CoAD[101] = -1.741E-3; CoAD[102] = -0.0016; + +} + +double fbar_AndersonDarling (long N, double X) +{ + /* This function is not very precise for x < 0.05 */ + const double h = 0.05; /* the step of the interpolation table */ + static int ADFlag = 0; + double q; + double Res, Cor; + int i; + + if (N == 1) { + if (X <= 0.38629436111989) + return 1.0; + if (X >= fdist_XBIGM) + return 0.0; + if (X < 6.0) { + q = 1.0 - 4.0 * exp(-X - 1.0); + return 1.0 - sqrt (q); + } else { + q = 4.0 * exp(-X - 1.0); + return 0.5*q*(1.0 + 0.25*q*(1.0 + 0.5*q*(1.0 + 0.125*q*(5.0 + 3.5*q)))); + } + } + + if (N <= 0) { + util_Warning (1, "fbar_AndersonDarling: N < 1"); + return -1.0; + } + + if (X > 10.0) + /* Sinclair-Spurr upper tail approximation (3.5) */ + return 1.732 * exp(-X) / sqrt(num_Pi * X); + + if (X > 5.0) { + /* asymptotic X: our empirical fit */ + Res = exp (-0.56 - 1.06 * X); + q = exp (-1.03 - 1.06 * X); /* Empirical correction in 1/N */ + return Res + q / N; + } + + if (X <= 0.2) + return 1.0 - fdist_AndersonDarling (N, X); + + if (ADFlag == 0) { + AndersonDarlingInit (); + ADFlag = 1; + } + + i = 1 + (int) (X / h); + q = X / h - i; + + /* Newton backwards quadratic interpolation */ + Res = (F2AD[i - 2] - 2.0 * F2AD[i - 1] + F2AD[i]) * q * (q + 1.0) / 2.0 + + (F2AD[i] - F2AD[i - 1]) * q + F2AD[i]; + + /* Empirical correction in 1/N */ + Cor = (CoAD[i] * (q + 1.0) - CoAD[i - 1] * q) / N; + + Res = 1.0 - Res - Cor; + if (Res >= 1.0) + return 1.0; + if (Res <= 0.0) + return 0.0; + return Res; +} + + +/*=========================================================================*/ + +double fbar_ChiSquare1 (long N, double x) +/* + * Returns an approximation of the complementary Chi square cdf (N degrees + * of freedom). Similar to p:116 of W.J.Kennedy Jr and J.E.Gentle. + * Statistical computing, Dekker, New York, 1980. More precise in the + * tail than simply returning 1 - fdist_ChiSquare. + */ +{ + const double XBIG_CHI = 2000.0; + const double tiers = 0.33333333333333333; + const double pt2 = 0.22222222222222222; + const double moinshuit = -8.3; + const double gam = 0.8862269254527579825931; + double H, E, DemiX, Terme, Sommation, Y; + long i; + + util_Assert (N > 0, "Calling fbar_ChiSquare1 with N < 1"); + if (x <= 0.0) + return 1.0; + if (N >= 150) { + if (x >= N * fdist_XBIG) + return 0.0; + } else { + if (x >= XBIG_CHI) + return 0.0; + } + + if (N > 1000) { + if (x < 2.0) + return 1.0; + x = (pow ((x / N), tiers) - (1.0 - pt2 / N)) / sqrt (pt2 / N); + if (x > 35.0) + return 0.0; + if (x <= moinshuit) + return 1.0; + return fbar_Normal1 (x); + } + + DemiX = x / 2.0; + + if (!(N & 1)) { /* even N */ + Terme = exp (-DemiX); + Sommation = Terme; + for (i = 1; i < N / 2; i++) { + Terme = Terme * DemiX / i; + Sommation += Terme; + } + Y = Sommation; + + } else { + H = 2.0 * fbar_Normal1 (sqrt (x)); + if (N == 1) + return H; + + E = exp (-DemiX); + Terme = sqrt (DemiX) * E / gam; + for (i = 3; i < N; i += 2) { + H += Terme; + Terme = Terme * DemiX * 2.0 / i; + } + Y = H + Terme; + } + + if (Y > 1.0) + return 1.0; + else + return Y; +} + + +/*=========================================================================*/ + +double fbar_ChiSquare2 (long n, int d, double x) +{ + util_Assert (n > 0, "fbar_ChiSquare2: n <= 0"); + if (x <= 0.0) + return 1.0; + return fbar_Gamma (n / 2.0, d, x / 2.0); +} + + +/*=========================================================================*/ + +double fbar_Gamma (double alpha, int d, double x) +{ + const double aLIM = 1.0E5; + const double RENORM = 1.0E100; + const double EPS = EpsArray[d]; + double V[6]; + double v, res, A, B, R, term, dif; + int i; + + util_Assert (alpha > 0.0, "fbar_Gamma: a <= 0"); + util_Assert (d > 0, "fbar_Gamma: d <= 0"); + util_Assert (d < 16, "fbar_Gamma: d > 15"); + if (x <= 0.0) + return 1.0; + if (1.0 == alpha) + return fbar_Expon (x); + + if (alpha >= 70.0) { + if (x >= alpha * fdist_XBIG) + return 0.0; + } else { + if (x >= fdist_XBIGM) + return 0.0; + } + + if (alpha >= aLIM) { + double d2 = x + 1.0/3.0 - alpha - 0.02/alpha; + double S = alpha - 1.0/2.0; + double z = d2 * sqrt((1 + fdist_belog(S/x))/x); + return fbar_Normal1 (z); + } + + if (x <= 1.0 || x < alpha) + return 1.0 - fdist_Gamma (alpha, d, x); + + v = exp (alpha * log (x) - x - num2_LnGamma (alpha)); + + A = 1.0 - alpha; + B = A + x + 1.0; + term = 0.0; + V[0] = 1.0; + V[1] = x; + V[2] = x + 1.0; + V[3] = x * B; + res = V[2] / V[3]; + + do { + A += 1.0; + B += 2.0; + term += 1.0; + V[4] = B * V[2] - A * term * V[0]; + V[5] = B * V[3] - A * term * V[1]; + if (V[5] != 0.0) { + R = V[4] / V[5]; + dif = fabs (res - R); + if (dif <= EPS * R) + return (v * res); + res = R; + } + for (i = 0; i < 4; i++) + V[i] = V[i + 2]; + if (fabs (V[4]) >= RENORM) { + for (i = 0; i < 4; i++) + V[i] /= RENORM; + } + } while (1); + + /* to eliminate a warning from the compiler; never reached */ + return 0.0; +} + + +/*=========================================================================*/ + +static double KSPlusbarAsymp (long n, double x) +{ + /* Compute the probability of the KSPlus distribution using + an asymptotic formula */ + double t = (6.0*n*x + 1); + double z = t*t/(18.0*n); + double v = 1.0 - (2.0*z*z - 4.0*z - 1.0)/(18.0*n); + if (v <= 0.0) + return 0.0; + v = v*exp(-z); + if (v >= 1.0) + return 1.0; + return v; +} + + +/*-------------------------------------------------------------------------*/ + +static double KSPlusbarUpper (long n, double x) +{ + /* Compute the probability of the KSPlus distribution in the upper + tail using Smirnov's stable formula */ + const double EPSILON = 1.0E-10; + double q; + double Sum = 0.0; + double term; + double t; + double LogCom; + double LOGJMAX; + int j; + int jmax = (int)(n - n*x); + + /* We must avoid log(0) for j = jmax and q ~ 1.0 */ + if ((1.0 - x - (double)jmax / n) <= 0.0) + jmax--; + + j = jmax/2; + LogCom = num2_LnFactorial((int)n) - num2_LnFactorial(j) - + num2_LnFactorial((int)(n-j)); + LOGJMAX = LogCom; + + while (j > 0) { + q = (double)j / n + x; + term = LogCom + (j - 1)*log (q) + (n - j)*num2_log1p (-q); + t = exp (term); + Sum += t; + LogCom += log ((double)j / (n - j + 1)); + if (t <= Sum*EPSILON) + break; + j--; + } + + j = jmax/2; + LogCom = LOGJMAX + log ((double)(n - j)/(j + 1)); + j++; + + while (j <= jmax) { + q = (double)j / n + x; + term = LogCom + (j - 1)*log(q) + (n - j)*num2_log1p(-q); + t = exp (term); + Sum += t; + LogCom += log ((double)(n - j)/(j + 1)); + if (t <= Sum*EPSILON) + break; + j++; + } + + Sum *= x; + /* add the term j = 0 */ + Sum += exp (n*num2_log1p (-x)); + return Sum; +} + + +/*=========================================================================*/ + +double fbar_KSPlus (long N, double x) +{ + const double NxParam = 6.5; /* frontier: alternating series */ + const long NParam = 4000; /* frontier: non-alternating series */ + const long NAsymp = 200000; /* frontier: asymptotic */ + + util_Assert (N > 0, "Calling fbar_KSPlus with N < 1"); + if (x <= 0.0) + return 1.0; + if ((x >= 1.0) || (N*x*x >= 370.0)) + return 0.0; + if (N == 1) + return 1.0 - x; + + if (N * x <= NxParam) + return 1.0 - fdist_KSPlus (N, x); + + if (N >= NAsymp) + return KSPlusbarAsymp (N, x); + + if ((N <= NParam) || (N*x*x > 1.0)) + return KSPlusbarUpper(N, x); + +/* return (1.0 - 2.0*x/3.0)*exp(-2.0*N*x*x); */ + return KSPlusbarAsymp (N, x); +} + + +/*=========================================================================*/ + +static double KSSpecial (long n, double x) +{ +#define NLIM 20 + + if ((n * x * x >= 370.0) || (x >= 1.0)) + return 0.0; + if (x <= 0.5 / n) + return 1.0; + if (n == 1) + return 2.0 - 2.0 * x; + + if (x <= 1.0 / n) { + double w; + double t = 2.0 * x - 1.0 / n; + if (n <= NLIM) { + w = num2_Factorial ((int) n); + return 1.0 - w * pow (t, (double) n); + } + w = num2_LnFactorial ((int) n) + n * log (t); + return 1.0 - exp (w); + } + + if (x >= 1.0 - 1.0 / n) { + return 2.0 * pow (1.0 - x, (double) n); + } + return -1.0; +} + +#undef NLIM +/*-------------------------------------------------------------------------*/ + +double fbar_KS1 (long n, double x) +{ + double v = KSSpecial(n, x); + if (v >= 0.0) + return v; + + if (n <= 400) { + if (n*x*x < 4.0) + return 1.0 - fdist_KS1(n, x); + else + return 2.0 * KSPlusbarUpper(n, x); + } + + if (n*x*x >= 2.2) { + if (n <= 200000) + return 2.0 * KSPlusbarUpper(n, x); + return 2.0*KSPlusbarAsymp (n, x); + } + + return 1.0 - fdist_KS1(n, x); +} + + +/*=========================================================================*/ + +double fbar_CramerMises (long N, double x) +{ + return 1.0 - fdist_CramerMises (N, x); +} + + +double fbar_WatsonG (long N, double x) +{ + return 1.0 - fdist_WatsonG (N, x); +} + + +/*=========================================================================*/ + +double fbar_WatsonU (long N, double x) +{ +/* + * Only the asymptotic form has been implemented. In the trivial case + * N = 1, we simply return 0.5 + */ + const double xSepare = 0.15; + if (x <= 0.0) + return 1.0; + if (x >= fdist_XBIG) + return 0.0; + + if (N == 1) /* N = 1, degenerate case */ + return 0.5; + + if (x > xSepare) { + /* this series converges rapidly for x > 0.15 */ + const int JMAX = 10; + int j; + double signe; + double v; + double terme; + double somme; + v = exp (-(x * 2.0 * num_Pi * num_Pi)); + signe = 1.0; + somme = 0.0; + j = 1; + do { + terme = pow (v, (double) j * j); + somme += signe * terme; + signe = -signe; + ++j; + } while (!(terme < DBL_EPSILON || j > JMAX)); + util_Warning (j > JMAX, "fbar_WatsonU: sum1 has not converged"); + v = 2.0 * somme; + if (v <= 0.0) + return 0.0; + return v; + } + + return 1.0 - fdist_WatsonU (N, x); +} + + +/*=========================================================================*/ + + + + +/******************************\ + * + * DISCRETE DISTRIBUTIONS + * +\******************************/ + + +/*=========================================================================*/ + +static const double epsilonScan = 1.0E-7; + +static double ScanGlaz (long N, double d, long m) +{ + long j, jmoy; + double temp; + double jr, jm1r, Nr = N; + int signe; + double q = 1.0 - d; + double Q4, Q3, Q2, Q1; + double Bin, BinMoy; + + jmoy = (long) ((N + 1) * d); /* max term of the Binomial */ + if (jmoy < m - 1) + jmoy = m - 1; + + /*---------------------------------------------------------*/ + /* Compute Q1: formula (2.5) in Glaz (1989) */ + /* Compute Q2: formula (A.6) in Berman and Eagleson (1985) */ + /* Compute Q3, Q4 : Theorem (3.2) in Glaz (1989) */ + /*---------------------------------------------------------*/ + + /* compute the probability of term j = jmoy */ + Q1 = 0.0; + for (j = 1; j <= jmoy; j++) { + jr = j; + Q1 += log (Nr - jr + 1.0) - log (jr); + } + Q1 += jmoy * log (d) + (Nr - jmoy) * log (q); + BinMoy = exp (Q1); + Q1 = BinMoy; + jm1r = jmoy - m + 1; + if ((jmoy - m + 1) & 1) + signe = -1; + else + signe = 1; + Q2 = signe * BinMoy; + Q3 = signe * BinMoy * (2.0 - jm1r * jm1r + jm1r); + Q4 = signe * BinMoy * (jm1r + 1.0) * (jm1r + 2.0) * (6.0 + jm1r * jm1r - + 5.0 * jm1r); + + /* compute the probability of terms j > jmoy */ + if ((jmoy - m + 1) & 1) + signe = -1; + else + signe = 1; + + jm1r = jmoy - m + 1; + Bin = BinMoy; + for (j = jmoy + 1; j <= N; j++) { + jr = j; + jm1r += 1.0; + signe = -signe; + Bin = (Bin * (Nr - jr + 1.0) * d) / (jr * q); + if (Bin < epsilonScan) + break; + Q1 += Bin; + Q2 += signe * Bin; + Q3 += signe * Bin * (2.0 - jm1r * jm1r + jm1r); + Q4 += signe * Bin * (jm1r + 1.0) * (jm1r + 2.0) * (6.0 + jm1r * jm1r - + 5.0 * jm1r); + } + + Q1 = 1.0 - Q1; + Q3 /= 2.0; + Q4 /= 12.0; + if (m == 3) { + /* Problem with this formula; I do not get the same results as Glaz */ + Q4 = ((Nr * (Nr - 1.0) * d * d * pow (q, Nr - 2.0)) / 8.0 + + Nr * d * 2.0 * pow (1.0 - 2.0 * d, Nr - 1.0)) + - 4.0 * pow (1.0 - 2.0 * d, Nr); + if (d < 1.0 / 3.0) { + Q4 += Nr * d * 2.0 * pow (1.0 - 3.0 * d, Nr - 1.0) + + 4.0 * pow (1.0 - 3.0 * d, Nr); + } + } + /* compute probability: Glaz, equations (3.2) and (3.3) */ + Q3 = Q1 - Q2 - Q3; + Q4 = Q3 - Q4; + /* when the approximation is bad, avoid overflow */ + temp = log (Q3) + (Nr - m - 2.0) * log (Q4 / Q3); + if (temp >= 0.0) + return 0.0; + if (temp < (-30.0)) + return 1.0; + Q4 = exp (temp); + return 1.0 - Q4; +} + +/*----------------------------------------------------------------------*/ + +static double ScanWNeff (long N, double d, long m) +{ + double q = 1.0 - d; + double temp; + double Bin; + double Sum; + long j; + + /*--------------------------------------*/ + /* Anderson-Titterington: equation (4) */ + /*--------------------------------------*/ + + /* compute the probability of term j = m */ + Sum = 0.0; + for (j = 1; j <= m; j++) { + Sum += log ((double) (N - j + 1)) - log ((double) j); + } + Sum += m * log (d) + (N - m) * log (q); + Bin = exp (Sum); + temp = (m / d - N - 1.0) * Bin; + Sum = Bin; + + /* compute the probability of terms j > m */ + for (j = m + 1; j <= N; j++) { + Bin *= (N - j + 1) * d / (j * q); + if (Bin < epsilonScan) + break; + Sum += Bin; + } + Sum = 2.0 * Sum + temp; + return Sum; +} + +/*----------------------------------------------------------------------*/ + +static double ScanAsympt (long N, double d, long m) +{ + double Kappa; + double temp; + double Theta; + double Sum; + + /*--------------------------------------------------------------*/ + /* Anderson-Titterington: asymptotic formula after equation (4) */ + /*--------------------------------------------------------------*/ + + Theta = sqrt (d / (1.0 - d)); + temp = sqrt ((double) N); + Kappa = m / (d * temp) - temp; + temp = Theta * Kappa; + temp = temp * temp / 2.0; + Sum = 2.0 * fbar_Normal1 (Theta * Kappa) + + (Kappa * Theta * exp (-temp)) / (d * sqrt (2.0 * num_Pi)); + return Sum; +} + +/*----------------------------------------------------------------------*/ + +double fbar_Scan (long N, double d, long m) +{ + double mu; + double prob; + + util_Assert (N >= 2, "Calling fbar_Scan with N < 2"); + util_Assert (d > 0.0 && d < 1.0, + "Calling fbar_Scan with d outside (0,1)"); + if (m > N) + return 0.0; + if (m <= 1) + return 1.0; + if (m <= 2) { + if ((N - 1) * d >= 1.0) + return 1.0; + return (1.0 - pow (1.0 - (N - 1) * d, (double) N)); + } + if (d >= 0.5 && m <= (N + 1) / 2.0) + return 1.0; + if (d > 0.5) + return (-1.0); /* Error */ + /* util_Assert (d <= 0.5, "Calling fbar_Scan with d > 1/2"); */ + + mu = N * d; /* mean of a binomial */ + if (m <= mu + d) + return 1.0; + if (mu <= 10.0) + return ScanGlaz (N, d, m); + prob = ScanAsympt (N, d, m); + if ((d >= 0.3 && N >= 50.0) || (N * d * d >= 250.0 && d < 0.3)) { + if (prob <= 0.4) + return prob; + } + prob = ScanWNeff (N, d, m); + if (prob <= 0.4) + return prob; + prob = ScanGlaz (N, d, m); + if (prob > 0.4 && prob <= 1.0) + return prob; + return 1.0; +} + + +/*=========================================================================*/ + +double fbar_Geometric (double p, long n) +{ + util_Assert (p >= 0.0 && p <= 1.0, "fbar_Geometric: p not in [0, 1]"); + if (n <= 0) + return 1.0; + if (p >= 1.0) /* In fact, p == 1 */ + return 0.0; + if (p <= 0.0) /* In fact, p == 0 */ + return 1.0; + + return pow (1.0 - p, (double) n); +} + + +/*=========================================================================*/ + +double fbar_Poisson1 (double lam, long s) +{ + const double lamlim = 150.0; + long i; + double term, sum; + + util_Assert (lam >= 0.0, "fbar_Poisson1: lambda < 0"); + if (s <= 0) + return 1.0; + + /* If lam > lamlim, we use the Chi2 distribution according to the exact + relation, with 2s + 2 degrees of freedom + + fdist_Poisson (lam, s) = 1 - fdist_ChiSquare (2s + 2, 2*lam) + + which also equals 1 - fdist_Gamma (s + 1, lam) */ + if (lam > lamlim) + return fdist_Gamma ((double) s, 15, lam); + + if (s <= lam) + return 1.0 - fdist_Poisson1 (lam, s - 1); + + /* Sum at least IMAX prob. terms from i = s to i = oo */ + sum = term = fmass_PoissonTerm1 (lam, s); + i = s + 1; + while (term > fmass_Epsilon || i <= s + IMAX) { + term *= lam / i; + sum += term; + i++; + } + return sum; +} + + +/*=========================================================================*/ + +double fbar_Poisson2 (fmass_INFO W, long s) +/* + * fbar_Poisson (lam, s) = 1 - fdist_Poisson (lam, s - 1) + */ +{ + double lam; + + util_Assert (W != NULL, "fbar_Poisson2: fmass_INFO is NULL pointer"); + lam = W->paramR[0]; + + if (s <= 0) + return 1.0; + + /* For large lam, we use the Chi2 distribution according to the exact + relation, with 2s + 2 degrees of freedom + + fdist_Poisson (lam, s) = 1 - fdist_ChiSquare (2s + 2, 2*lam) + fdist_Poisson (lam, s) = 1 - fdist_Gamma (s + 1, lam) + */ + + if (W->cdf == NULL) + return fdist_Gamma ((double) s, 15, lam); + + if (s > W->smax) + return fbar_Poisson1 (lam, s); + + if (s < W->smin) + return 1.0; + + if (s > W->smed) + /* We keep the complementary distribution in the upper part of cdf */ + return W->cdf[s - W->smin]; + else + return 1.0 - W->cdf[s - 1 - W->smin]; +} + + +/*=========================================================================*/ + +double fbar_Binomial2 (fmass_INFO W, long s) +{ + double p; + long n; + + util_Assert (W != NULL, "fbar_Binomial2: fmass_INFO is NULL pointer"); + n = W->paramI[0]; + p = W->paramR[0]; + util_Assert (p >= 0.0 && p <= 1.0, "fbar_Binomial2: p not in [0, 1]"); + + if (0 == n) + return 1.0; + if (s < 1) + return 1.0; + if (s > n) + return 0.0; + if (p == 0.0) + return 0.0; + if (p == 1.0) + return 1.0; + + if (W->cdf != NULL) { + if (s >= W->smax) { + /* Add IMAX dominant terms to get a few decimals in the tail */ + const double q = 1.0 - p; + double z, sum, term; + long i; + sum = term = fmass_BinomialTerm3 (n, p, s); + if (fabs (q) > 0.0) { + z = p / q; + } else { + z = 0.0; + util_Warning (1, "fbar_Binomial2: p / q = infinite"); + } + i = s; + while (i < n && i < s + IMAX) { + term = term * z * (n - i) / (i + 1); + sum += term; + i++; + } + return sum; + /* return fdist_Beta (s, n - s + 1, 10, p); */ + } + + if (s <= W->smin) + return 1.0; + + if (s > W->smed) + /* We keep the complementary distribution in the upper part of cdf */ + return W->cdf[s - W->smin]; + else + return 1.0 - W->cdf[s - 1 - W->smin]; + + } else { + return 1.0 - fdist_Binomial1 (n, p, s - 1); + } +} + + +/*=========================================================================*/ + +double fbar_NegaBin2 (fmass_INFO W, long s) +{ + double p; + long n; + + util_Assert (W != NULL, "fbar_NegaBin2: fmass_INFO is NULL pointer"); + n = W->paramI[0]; + p = W->paramR[0]; + util_Assert (p >= 0.0 && p <= 1.0, "fbar_NegaBin2: p not in [0, 1]"); + + if (s < 1) + return 1.0; + if (p >= 1.0) /* In fact, p == 1 */ + return 0.0; + if (p <= 0.0) /* In fact, p == 0 */ + return 1.0; + + if (W->cdf == NULL) + return fdist_Binomial1 (s - 1 + n, p, n - 1); + + if (s >= W->smax) + return fdist_Binomial1 (s - 1 + n, p, n - 1); + if (s <= W->smin) + return 1.0; + if (s > W->smed) + /* We keep the complementary distribution in the upper part of cdf */ + return W->cdf[s - W->smin]; + else + return 1.0 - W->cdf[s - 1 - W->smin]; + +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/probdist/fbar.tex b/TESTU01/TestU01-1.2.3/probdist/fbar.tex new file mode 100644 index 0000000..d681859 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/fbar.tex @@ -0,0 +1,371 @@ +\defmodule {fbar} + +This module is similar to {\tt fdist}, except that it provides procedures +to compute or approximate the complementary distribution function of $X$, +which we define as $\bar F(x) = P[X\ge x]$, instead of $F(x)=P[X\le x]$. +Note that with our definition of $\bar F$, one has +$\bar F(x) = 1 - F(x)$ for continuous distributions and +$\bar F(x) = 1 - F(x-1)$ for discrete distributions over the integers. +This is non-standard but we find it convenient. + +For more details about the specific distributions, +see the module {\tt fdist}. +When $F(x)$ is very close to 1, these procedures generally provide much +more precise values of $\bar F(x)$ than using $1-F(x)$ where $F(x)$ is +computed by a procedure from {\tt fdist}. + + +\bigskip +\hrule +\code\hide +/* fbar.h for ANSI C */ +#ifndef FBAR_H +#define FBAR_H +\endhide +#include "gdef.h" +#include "fmass.h" +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Continuous distributions} + +\code + +double fbar_Unif (double x); +\endcode + \tab + Returns $1-x$ for $x \in [0, 1]$, 1 for $x<0$, and 0 for $x>1$. + This is the complementary uniform distribution function over $[0, 1]$. + \endtab +\code + + +double fbar_Expon (double x); +\endcode + \tab + Returns the complementary exponential distribution: + $\bar F(x) = e^{- x}$ for $x>0$, and $=1$ for $x\le 0$. +% This is the complementary exponential distribution with mean $\mu$.\\ +% Restriction: {\tt mu} = $\mu > 0$. + \endtab +\code + + +double fbar_Weibull (double alpha, double x); +\endcode + \tab + Returns the complementary standard Weibull distribution function + with shape parameter $\alpha$ \cite{tJOH95a}, defined by + $\bar F(x) = e^{- x^\alpha}$ for $x>0$ and 1 for $x\le 0$. + Restriction: $\alpha > 0$. + \endtab +\code + + +double fbar_Logistic (double x); +\endcode + \tab + Returns $\bar F(x) = 1/(1 + e^{x})$, the complementary standard + logistic distribution function evaluated at $x$ \cite{tJOH95b}. + \endtab +\code + + +double fbar_Pareto (double c, double x); +\endcode + \tab + Returns $\bar F(x) = 1/x^c$ for $x\ge 1$ and 1 for $x\le 1$, + which is the complementary standard Pareto + distribution function \cite{tJOH95a}. + Restriction: $c > 0$. + \endtab +\code + + +double fbar_Normal1 (double x); +\endcode + \tab + Returns an approximation of $1 - \Phi(x)$, + where $\Phi$ is the standard normal distribution function, + with mean 0 and variance 1. + Uses a Chebyshev series giving 16 decimal digits of + precision \cite{tSCH78a}. + \endtab +\code + + +double fbar_Normal2 (double x); +\endcode + \tab + Returns an approximation of $1 - \Phi(x)$, where $\Phi$ is the standard + normal distribution function, with mean 0 and variance 1. + Uses Marsaglia's et al \cite{rMAR94b} fast method + with tables lookup. Returns 15 decimal digits of precision. + This function is approximately 1.3 times faster than {\tt fbar\_Normal1}. + \endtab +\code + + +#ifdef HAVE_ERF + double fbar_Normal3 (double x); +#endif +\endcode + \tab + Returns an approximation of $1 - \Phi(x)$, + where $\Phi$ is the standard normal distribution function, + with mean 0 and variance 1. + Uses the {\tt erfc} function from the standard Unix C library. The macro + {\tt HAVE\_ERF} from {\tt mylib/gdef} must be defined. This function + is twice as fast as {\tt fbar\_Normal2}. + \endtab +\code + + +double fbar_BiNormal1 (double x, double y, double rho, int ndig); +\endcode + \tab + Returns the value $u$ of the upper standard bivariate normal distribution, + given by +\begin{eqnarray} + u &=& \frac{1}{2\pi\sqrt{1 - \rho^2}} \int^{\infty}_x + \int^{\infty}_y e^{-T} dy\, dx \label{eq.binormal3} \\[5pt] + T &=& \frac{x^2 -2\rho x y + y^2}{2(1-\rho^2)}, \nonumber +\end{eqnarray} + where $\rho = ${ \tt rho} is the correlation between $x$ and $y$, and + \texttt{ndig} is the number of decimal digits of accuracy. + It calls the function {\tt fdist\_BiNormal1}. The absolute error + is expected to be smaller than $10^{-d}$, where $d={}$\texttt{ndig}. + Restriction: \texttt{ndig}${} \le 15$. + \endtab +\code + + +double fbar_BiNormal2 (double x, double y, double rho); +\endcode + \tab + Returns the value of the upper standard bivariate normal distribution as + defined in (\ref{eq.binormal3}) above. + It calls the function {\tt fdist\_BiNormal2} (see the description in + module {\tt fdist}). The function gives + an absolute error less than $5 \cdot 10^{-16}$. + \endtab +\code + + +double fbar_ChiSquare1 (long N, double x); +\endcode + \tab + Returns $\bar F(x)$, the complementary + chi-square distribution function with + $N$ degrees of freedom. + Uses the approximation given in \cite[p.116]{tKEN80a} for $N\le 1000$, + and the normal approximation for $N > 1000$. Gives no more than 4 + decimals of precision for $N > 1000$. + \endtab +\code + + +double fbar_ChiSquare2 (long N, int d, double x); +\endcode + \tab Returns $\bar F(x)$, the complementary chi-square distribution + function with $N$ degrees of freedom, by calling + {\tt fbar\_Gamma (N/2, d, x/2)}. + The function will do its best to return $d$ decimals + digits of precision (but there is no guarantee). + Restrictions: $N>0$ and $0 < d \le 15$. + \endtab +\code + + +double fbar_Gamma (double a, int d, double x); +\endcode + \tab + Returns an approximation \cite{tBAT70a} of the complementary {\em gamma\/} + distribution function with parameter $a$. + The function tries to return $d$ decimals digits of precision. +%, but there is no guarantee. + For $a$ not too large (e.g., $a \le 1000$), + $d$ gives a good idea of the precision attained. +%% For d = 16, gives at least 13 decimals of precision for $a \le 1000$, +%% and at least 10 decimals for $1000 < a \le 100000$. + Restrictions: $a>0$ and $0 < d \le 15$. + \endtab +\code + + +double fbar_KS1 (long n, double x); +\endcode +\tab Returns the complementary Kolmogorov-Smirnov distribution +$\bar F(x) = P[D_n \ge x]$ in a form that is more precise in the upper tail, +using the program described in \cite{LECz09}. +It returns at least 10 decimal digits of precision everywhere for all + $n \le 400$, + at least 6 decimal digits of precision for $400 < n \le 200000$, +and a few correct digits (1 to 5) for $n > 200000$. + Restrictions: $n\ge 1$ and $0 \le x \le 1$. +\endtab +\code + + +double fbar_KSPlus (long n, double x); +\endcode +\tab Returns the complementary Kolmogorov-Smirnov+ distribution +$\bar F(x) = P[D_n^+ \ge x]$ in a form that is more precise in the upper +tail. It should return at least 8 decimal digits of precision everywhere. +% It becomes more precise as $x$ or $n$ increase. + Restrictions: $n>0$ and $0 \le x \le 1$. +\endtab +\code + + +double fbar_LogNormal (double mu, double sigma, double x); + +double fbar_JohnsonSB (double alpha, double beta, double a, double b, + double x); + +double fbar_JohnsonSU (double alpha, double beta, double x); + +double fbar_CramerMises (long n, double x); + +double fbar_WatsonU (long n, double x); + +double fbar_WatsonG (long n, double x); + +double fbar_AndersonDarling (long n, double x); +\endcode + \tab Return the complementary distribution function $P[X\ge x]$. + See the description of the respective functions in \texttt{fdist}. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Discrete distributions} + +\code + +double fbar_Geometric (double p, long s); +\endcode + \tab Returns the complementary distribution function of + a geometric random variable $X$ with parameter $p$, + $\bar F(s) = P[X\ge s] = (1-p)^s$ + for $s\ge 0$. + Restriction: $0 \le p \le 1$. + \endtab +\code + + +double fbar_Poisson1 (double lambda, long s); +\endcode + \tab Returns the complementary distribution function $P[X\ge s]$ + for a Poisson random variable $X$ with parameter $\lambda$. + Computes and adds the non-negligible terms in the tail. + Restriction: $\lambda > 0$. + \endtab +\code + + +double fbar_Poisson2 (fmass_INFO W, long s); +\endcode + \tab Returns the complementary Poisson distribution function, + using the structure {\tt W} which must have been created previously + by calling {\tt fmass\_CreatePoisson} with the desired $\lambda$. +% Restriction: only integral values of $s$ are meaningful. + \endtab +\code + + +double fbar_Binomial2 (fmass_INFO W, long s); +\endcode + \tab Returns the complementary distribution function $P[X\ge s]$ + for a binomial random variable $X$, + using the structure {\tt W} which must have been created previously + by calling {\tt fmass\_CreateBinomial} with the desired values of + $n$ and $p$. + \endtab +\code + + +double fbar_NegaBin2 (fmass_INFO W, long s); +\endcode + \tab Returns the complementary distribution function $P[X\ge s]$ + for a negative binomial random variable $X$, + using the structure {\tt W} + which must have been created previously + by calling {\tt fmass\_CreateNegaBin} with the desired values of + $n$ and $p$. + \endtab +\code + + +double fbar_Scan (long N, double d, long m); +\endcode + \tab Return $P[S_N(d) \ge m]$, where $S_N(d)$ is the scan statistic + (see \cite{tGLA89a} and {\tt gofs\_Scan}), defined as + \eq + S_N(d) = \sup_{0\le y\le 1-d} \eta[y,\,y+d], \eqlabel{eq:scan} + \endeq + where $d$ is a constant in $(0, 1)$, + $\eta[y,\,y+d]$ is the number of observations falling inside + the interval $[y, y+d]$, from a sample of $N$ i.i.d.\ $U(0,1)$ + random variables. + One has (see \cite {tAND95b}), + \begin {eqnarray} + P[S_N(d) \ge m] + &\approx& \left({m\over d}-N-1\right) b(m) + + 2 \sum_{i=m}^{N} b(i) \eqlabel{DistScan1} \\[6pt] + &\approx& 2(1-\Phi(\theta\kappa)) + \theta\kappa + {\exp[-\theta^2\kappa^2 /2] \over d \sqrt{2\pi}} + \eqlabel {DistScan2} + \end {eqnarray} + where $\Phi$ is the standard normal distribution function, + \begin {eqnarray*} + b(i) &=& {N \choose i} d^i (1-d)^{N-i}, \\[4pt] + \theta &=& \sqrt{\frac d{1-d}}, \\[4pt] + \kappa &=& \frac m{d \sqrt{N}} - \sqrt{N}. + \end {eqnarray*} + For $d \le 1/2$, (\ref{DistScan1}) is exact for $m > N/2$, + but only an approximation otherwise. + The approximation (\ref{DistScan2}) is good when + $N d^2$ is large or when $d > 0.3$ and $N>50$. + In other cases, this implementation sometimes use the approximation + proposed by Glaz \cite{tGLA89a}. + For more information, see \cite {tAND95b,tGLA89a,tWAL87a}. + The approximation returned by this function is generally good when + it is close to 0, but is not very reliable when it exceeds, say, 0.4. +%% +\ifdetailed %%%%%% + If $m \le (N + 1)d$, the function returns 1. + Else, if $Nd \le 10$, it returns the approximation given by + Glaz \cite{tGLA89a}. + If $Nd > 10$, it computes (\ref{DistScan2}) or (\ref{DistScan1}) + and returns the result if it does not exceed 0.4, otherwise it computes + the approximation from \cite{tGLA89a}, returns it if it is less than 1.0, +% inside the interval $(0.4, 1.0)$, + and returns 1.0 otherwise. + \hpierre{Even if it 0.40001 in the first approximation, and 0.3999 + in the second one?} + \hrichard{C'est ce qui est programm\'e. Probablement que dans ce cas, + l'approximation est tellement mauvaise que nous avons d\'ecid\'e de + retourner 1. On pourrait retourner 0 au lieu??} + \hpierre {\c Ca n'a pas de bon sens. Je ne vois pas pourquoi elle serait + ``tellement mauvaise'' dans le cas cit\'e avec 0.3999 et subitement + bonne si la seconde approximation retourne 0.4. + Il me semble que dans un tel cas on devrait retourner quelque chose + aux alentours de 0.4. + Et ce qui est g\^enant c'est qu'en retournant 0 ou 1 comme p-valeur, + on croira que l'hypoth\`ese nulle est rejet\'ee! } + The relative error can + reach 10\%\ when $Nd \le 10$ or when the returned value + is less than 0.4. For $m > Nd$ and $Nd > 10$, a returned value + that exceeds $0.4$ should be regarded as unreliable. + For $m = 3$, the returned values are totally unreliable. + (There may be an error in the original formulae in \cite{tGLA89a}). +\fi %%%% detailed + Restrictions: $N \ge 2$ and $d \le 1/2$.\\ + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/probdist/fdist.c b/TESTU01/TestU01-1.2.3/probdist/fdist.c new file mode 100644 index 0000000..57271e0 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/fdist.c @@ -0,0 +1,3585 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: fdist.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "fdist.h" +#include "fmass.h" +#include "fbar.h" + +#include "num.h" +#include "num2.h" +#include "util.h" +#include "tables.h" + +#include +#include +#include +#include + + +double fdist_belog (double); +void fdist_CalcB4 (double, double *, double *, double *, double *); +static double Pomeranz (long n, double x); + + +const double fdist_XINF = DBL_MAX; /* x infinity for some distributions */ +const double fdist_XBIG = 100.0; /* x infinity for some distributions */ +const double fdist_XBIGM = 1000.0; /* x infinity for some distributions */ + +/* EpsArray[j]: Epsilon required for j decimal degits of precision */ +static const double EpsArray[] = { + 0.5, 0.5E-1, 0.5E-2, 0.5E-3, 0.5E-4, 0.5E-5, 0.5E-6, 0.5E-7, 0.5E-8, + 0.5E-9, 0.5E-10, 0.5E-11, 0.5E-12, 0.5E-13, 0.5E-14, 0.5E-15, 0.5E-16, + 0.5E-17, 0.5E-18, 0.5E-19, 0.5E-20, 0.5E-21, 0.5E-22, 0.5E-23, 0.5E-24, + 0.5E-25, 0.5E-26, 0.5E-27, 0.5E-28, 0.5E-29, 0.5E-30, 0.5E-31, 0.5E-32, + 0.5E-33, 0.5E-34, 0.5E-35 +}; + +/* static const double EpsilonLR = 1.0E-15; */ +#define X_EPSILON 1.0e-3 /* For x --> 0 */ + +#define TWOPI 6.28318530717958647688 + + + +/*-------------------------------------------------------------------------*/ + +double fdist_belog (double x) +/* + * This is the function (1 - x*x + 2*x*log(x)) / ((1 - x)*(1 - x)) + */ +{ + if (x > 1.0) + return -fdist_belog(1.0/x); + if (x < 1.0e-20) + return 1.0; + if (x < 0.9) + return (1.0 - x * x + 2.0 * x * log (x)) / ((1.0 - x) * (1.0 - x)); + if (x == 1.0) + return 0.0; + { + /* For x near 1, use a series expansion to avoid loss of precision. */ + double term; + const double EPS = 1.0e-12; + const double Y = 1.0 - x; + double ypow = 1.0; + double sum = 0.0; + int j = 2; + do { + ypow *= Y; + term = ypow / (j * (j + 1)); + sum += term; + j++; + } while (fabs (term / sum) > EPS); + + return 2.0 * sum; + } +} + + +/*=========================================================================*/ + +double fdist_Unif (double x) +{ + if (x <= 0.0) + return 0.0; + if (x >= 1.0) + return 1.0; + return x; +} + + +/*=========================================================================*/ + +double fdist_Expon (double x) +{ + if (x <= 0.0) + return 0.0; + if (x >= fdist_XBIG) + return 1.0; + if (x > X_EPSILON) + return 1.0 - exp (-x); + + /* Avoid loss of precision for small x */ + return x * (1.0 - x * (0.5 - x*(1.0 / 6.0 - x/24.0))); +} + + +/*=========================================================================*/ + +double fdist_Weibull (double c, double x) +{ + double y; + util_Assert (c > 0.0, "fdist_Weibull: c <= 0"); + if (x <= 0.0) + return 0.0; + if (x >= fdist_XBIG && c >= 1.0) + return 1.0; + + y = c*log(x); + if (y >= 5.0) + return 1.0; + y = exp(y); + + if (y > X_EPSILON) + return (1.0 - exp (-y)); + + /* Avoid loss of precision for small y */ + return y * (1.0 - y * (0.5 - y*(1.0/6.0 - y/24.0))); +} + + +/*=========================================================================*/ + +double fdist_ExtremeValue (double x) +{ + if (x <= -10.0) + return 0.0; + if (x >= fdist_XBIG) + return 1.0; + return exp (-exp (-x)); +} + + +/*=========================================================================*/ + +double fdist_Logistic (double x) +{ + if (x <= -fdist_XBIG) + return exp (x); + if (x >= fdist_XBIG) + return 1.0; + return 1.0 / (1.0 + exp (-x)); +} + + +/*=========================================================================*/ + +double fdist_Pareto (double c, double x) +{ + double y = c*log(x); + util_Assert (c > 0.0, "fdist_Pareto: c <= 0"); + if (x <= 1.0) + return 0.0; + if (y >= 50.0) + return 1.0; + y = exp(y); + return (1.0 - 1.0 / y); +} + + +/*=========================================================================*/ + +double fdist_Normal1 (double x) +/* + * Returns P[X <= x] for the normal distribution. + * As in p:90 of W.J.Kennedy Jr and J.E.Gentle. Statistical computing. + * Dekker, New York, 1980. + */ +{ + static const double Racinedeux = 1.4142135623730950488; + static const double racineunsurpi = 0.56418958354775628694; + + static const double p10 = 2.4266795523053175e2; + static const double p11 = 2.1979261618294152e1; + static const double p12 = 6.9963834886191355; + static const double p13 = -3.5609843701815385e-2; + + static const double p20 = 3.004592610201616005e2; + static const double p21 = 4.519189537118729422e2; + static const double p22 = 3.393208167343436870e2; + static const double p23 = 1.529892850469404039e2; + static const double p24 = 4.316222722205673530e1; + static const double p25 = 7.211758250883093659e0; + static const double p26 = 5.641955174789739711e-1; + static const double p27 = -1.368648573827167067e-7; + + static const double p30 = -2.99610707703542174e-3; + static const double p31 = -4.94730910623250734e-2; + static const double p32 = -2.26956593539686930e-1; + static const double p33 = -2.78661308609647788e-1; + static const double p34 = -2.23192459734184686e-2; + + static const double q10 = 2.1505887586986120e2; + static const double q11 = 9.1164905404514901e1; + static const double q12 = 1.5082797630407787e1; + static const double q13 = 1.0; + + static const double q20 = 3.004592609569832933e2; + static const double q21 = 7.909509253278980272e2; + static const double q22 = 9.313540948506096211e2; + static const double q23 = 6.389802644656311665e2; + static const double q24 = 2.775854447439876434e2; + static const double q25 = 7.700015293522947295e1; + static const double q26 = 1.278272731962942351e1; + static const double q27 = 1.0; + + static const double q30 = 1.06209230528467918e-2; + static const double q31 = 1.91308926107829841e-1; + static const double q32 = 1.05167510706793207e0; + static const double q33 = 1.98733201817135256e0; + static const double q34 = 1.0; + + static const double xasymp = 40.0; + double Ycarre, unsurY2, Y, R, erf; + + if (x < -xasymp) + return 0.0; + if (x > xasymp) + return 1.0; + + if (x < 0.0) + return 1.0 - fdist_Normal1 (-x); + + Y = x / Racinedeux; + Ycarre = x * x / 2.0; + if (Y < 0.447) { + R = (p10 + Ycarre * (p11 + Ycarre * (p12 + Ycarre * p13))) / + (q10 + Ycarre * (q11 + Ycarre * (q12 + Ycarre * q13))); + erf = Y * R; + } else { + if (Y <= 4.0) { + R = (p20 + Y * (p21 + Y * (p22 + Y * (p23 + Y * (p24 + Y * (p25 + + Y * (p26 + Y * p27))))))) / (q20 + Y * (q21 + + Y * (q22 + Y * (q23 + Y * (q24 + Y * (q25 + Y * (q26 + + Y * q27))))))); + if (-Ycarre < DBL_MIN_EXP * num_Ln2) + erf = 1.0; + else + erf = 1.0 - exp (-Ycarre) * R; + } else { + double temp; + unsurY2 = 1.0 / Ycarre; + R = (p30 + unsurY2 * (p31 + unsurY2 * (p32 + unsurY2 * + (p33 + unsurY2 * p34)))) / (q30 + unsurY2 * + (q31 + unsurY2 * (q32 + unsurY2 * (q33 + unsurY2 * q34)))); + if (-Ycarre < DBL_MIN_EXP * num_Ln2) + temp = 0.0; + else + temp = exp (-Ycarre); + erf = 1.0 - (temp / Y) * (racineunsurpi + R / Ycarre); + } + } + return ((1.0 + erf) / 2.0); +} + + +/**************************************************************************/ +/* + * The precision of double is 16 decimals; we shall thus use COEFFMAX = 24 + * coefficients. But the approximation is good to 30 decimals of precision + * with 44 coefficients. + */ +#define COEFFMAX 24 + +static const double Normal2_A[44] = { + 6.10143081923200417926465815756e-1, + -4.34841272712577471828182820888e-1, + 1.76351193643605501125840298123e-1, + -6.0710795609249414860051215825e-2, + 1.7712068995694114486147141191e-2, + -4.321119385567293818599864968e-3, + 8.54216676887098678819832055e-4, + -1.27155090609162742628893940e-4, + 1.1248167243671189468847072e-5, + 3.13063885421820972630152e-7, + -2.70988068537762022009086e-7, + 3.0737622701407688440959e-8, + 2.515620384817622937314e-9, + -1.028929921320319127590e-9, + 2.9944052119949939363e-11, + 2.6051789687266936290e-11, + -2.634839924171969386e-12, + -6.43404509890636443e-13, + 1.12457401801663447e-13, + 1.7281533389986098e-14, + -4.264101694942375e-15, + -5.45371977880191e-16, + 1.58697607761671e-16, + 2.0899837844334e-17, + -5.900526869409e-18, + -9.41893387554e-19, + 2.14977356470e-19, + 4.6660985008e-20, + -7.243011862e-21, + -2.387966824e-21, + 1.91177535e-22, + 1.20482568e-22, + -6.72377e-25, + -5.747997e-24, + -4.28493e-25, + 2.44856e-25, + 4.3793e-26, + -8.151e-27, + -3.089e-27, + 9.3e-29, + 1.74e-28, + 1.6e-29, + -8.0e-30, + -2.0e-30 +}; + + +double fdist_Normal2 (double x) +/* + * Returns P[X < x] for the normal distribution. + * As in J. L. Schonfelder, Math. of Computation, Vol. 32, + * pp 1232--1240, (1978). + */ +{ + double t, r; + if (x <= -fdist_XBIG) + return 0.0; + if (x >= fdist_XBIG) + return 1.0; + + x = -x / num_Rac2; + if (x < 0) { + x = -x; + t = (x - 3.75) / (x + 3.75); + r = 1.0 - 0.5 * exp (-x * x) * num2_EvalCheby (Normal2_A, COEFFMAX, t); + } else { + t = (x - 3.75) / (x + 3.75); + r = 0.5 * exp (-x * x) * num2_EvalCheby (Normal2_A, COEFFMAX, t); + } + return (r); +} + + +/*=========================================================================*/ +#ifdef HAVE_ERF + +double fdist_Normal3 (double x) +{ + return (erfc (-x * num_1Rac2)) / 2.0; +} + +#endif + + +/*=========================================================================*/ + +double fdist_Normal4 (double x) +{ + static const double V[121] = { + 1.2533141373155, 1.137490921203605, 1.037824575853727, + 0.951527192071207, 0.8763644564536924, 0.8105337152790306, + 0.7525711790634081, 0.7012808218544303, 0.6556795424187987, + 0.61495459615093, 0.5784303460476312, 0.5455421356582171, + 0.5158156382179634, 0.4888504415275737, 0.4643069280394423, + 0.4418957328326002, 0.4213692292880546, 0.4025146181296722, + 0.3851482907984348, 0.3691112106902635, 0.3542651113297938, + 0.3404893532870847, 0.3276783146905521, 0.31573921586941, + 0.3045902987101033, 0.2941592970402893, 0.284382146748493, + 0.2752018941576065, 0.2665677689682238, 0.2584343943120386, + 0.2507611114439651, 0.243511400615456, 0.2366523829135607, + 0.230154390478801, 0.2239905946538289, 0.2181366833614714, + 0.2125705804420318, 0.2072722008565011, 0.2022232366330547, + 0.1974069692375194, 0.1928081047153158, 0.1884126285076003, + 0.1842076773079702, 0.1801814257143918, 0.1763229857571027, + 0.1726223176578506, 0.1690701504076941, 0.1656579109468773, + 0.1623776608968675, 0.1592220399363674, 0.1561842150339759, + 0.153257834853479, 0.1504369887362691, 0.1477161697413935, + 0.145090241289131, 0.1425544070104023, 0.1401041834530503, + 0.1377353753382303, 0.1354440530967635, 0.1332265324471292, + 0.1310793558044918, 0.1289992753343376, 0.126983237485437, + 0.1250283688553504, 0.1231319632579323, 0.1212914698765462, + 0.119504482399253, 0.1177687290432979, 0.1160820633859823, + 0.1144424559276431, 0.112847986320103, 0.1112968362007359, + 0.1097872825783083, 0.1083176917221132, 0.1068865135106745, + 0.1054922762005562, 0.1041335815795983, 0.1028091004723001, + 0.1015175685681028, 0.1002577825460485, 0.09902859647173194, + 0.09782891844465691, 0.09665770747608191, 0.09551397057921558, + 0.09439676005522439, 0.09330517095996169, 0.09223833873763035, + 0.09119543700877471, 0.09017567550106469, 0.08917829811230435, + 0.08820258109597616, 0.08724783136042988, 0.08631338487354936, + 0.08539860516539227, 0.08450288192189578, 0.08362562966329139, + 0.08276628650136918, 0.08192431297018954, 0.08109919092525536, + 0.08029042250654048, 0.07949752916111721, 0.07872005072144664, + 0.07795754453568722, 0.07720958464664668, 0.07647576101624852, + 0.07575567879261112, 0.07504895761704659, 0.07435523096847724, + 0.07367414554294564, 0.07300536066605566, 0.07234854773633338, + 0.07170338969763433, 0.07106958053885212, 0.07044682481930167, + 0.06983483721825942, 0.06923334210724434, 0.06864207314371742, + 0.06806077288496332, 0.0674891924209997, 0.06692709102543307, + 0.06637423582325017 + }; + + int j; + lebool negatif; + double t, u, z, h; + double r, r1, r2, r3, r4, r5, r6, r7, r8; + + if (x <= -fdist_XBIG) + return 0.0; + if (x >= fdist_XBIG) + return 1.0; + if (x < 0.0) { + negatif = TRUE; + x = -x; + } else { + negatif = FALSE; + } + j = (int) (8.0 * x + 0.5); + if (j > 120) + j = 120; + z = 0.125 * j; + h = x - z; + r = V[j]; + r1 = r * z - 1.0; + r2 = 0.5 * (r + z * r1); + r3 = (r1 + z * r2) / 3.0; + r4 = 0.25 * (r2 + z * r3); + r5 = 0.2 * (r3 + z * r4); + r6 = (r4 + z * r5) / 6.0; + r7 = (r5 + z * r6) / 7.0; + r8 = 0.125 * (r6 + z * r7); + t = r + h * (r1 + h * (r2 + h * (r3 + h * (r4 + h * (r5 + h * (r6 + + h * (r7 + h * r8))))))); + u = t * exp (-0.5 * x * x - 0.9189385332046727); + if (negatif) + return u; + else + return 1.0 - u; +} + + +/*=========================================================================*/ + +static double InitBiNormal (double x, double y, double rho) +{ + /* The special cases of the BiNormal */ + if (fabs (rho) > 1.0) { + util_Error ("fdist_BiNormal: |rho| > 1"); + return -1.0; + } + if (x == 0.0 && y == 0.0) + return 0.25 + asin(rho)/TWOPI; + if (rho == 1.0) { + x = util_Min(x,y); + return fdist_Normal2 (x); + } + if (rho == 0.0) { + return fdist_Normal2 (x) * fdist_Normal2 (y); + } + if (rho == -1.0) { + if (y <= -x) + return 0.0; + else + return fdist_Normal2 (x) - fdist_Normal2 (-y); + } + if ((x <= -fdist_XBIG) || (y <= -fdist_XBIG)) + return 0.0; + if (x >= fdist_XBIG) + return fdist_Normal2 (y); + if (y >= fdist_XBIG) + return fdist_Normal2 (x); + + return -2.0; +} + + +/*=========================================================================*/ + +double fdist_BiNormal1 (double x, double y, double rho, int ndig) +{ + double a2, ap, b, cn, conex, ex, g2, gh, gk, gw, h2, h4, rr, s1, s2, + sgn, sn, sp, sqr, t, w2, wh, wk; + int is = -1; + int flag = 1; + const double ah = -x; + const double ak = -y; + const double con = num_Pi * num_TENNEGPOW[ndig]; + const double EPSILON = 0.5 * num_TENNEGPOW[ndig]; + + util_Assert (ndig <= 15, "fdist_BiNormal1: ndig > 15"); + + b = InitBiNormal (x, y, rho); + if (b >= 0.0) + return b; + + gh = fdist_Normal2 (-ah) / 2.0; + gk = fdist_Normal2 (-ak) / 2.0; + + b = 0; + rr = (1 - rho) * (1 + rho); + sqr = sqrt (rr); + flag = 1; + if (ah != 0) { + b = gh; + if (ah * ak < 0) + b = b - .5; + else if (ah * ak == 0) { + flag = 0; + } + } else if (ak == 0) { + return asin (rho) / TWOPI + .25; + } + if (flag) + b += gk; + if (ah != 0) { + flag = 0; + wh = -ah; + wk = (ak / ah - rho) / sqr; + gw = 2 * gh; + is = -1; + } + + do { + if (flag) { + wh = -ak; + wk = (ah / ak - rho) / sqr; + gw = 2 * gk; + is = 1; + } + flag = 1; + sgn = -1; + t = 0; + if (wk != 0) { + if (fabs (wk) >= 1) { + if (fabs (wk) == 1) { + t = wk * gw * (1 - gw) / 2; + b = b + sgn * t; + if (is >= 0) + break; + else + continue; + } else { + sgn = -sgn; + wh = wh * wk; + g2 = fdist_Normal2 (wh); + wk = 1 / wk; + if (wk < 0) + b = b + .5; + b = b - (gw + g2) / 2 + gw * g2; + } + } + h2 = wh * wh; + a2 = wk * wk; + h4 = h2 * .5; + ex = 0; + if (h4 < 150.0) + ex = exp (-h4); + w2 = h4 * ex; + ap = 1; + s2 = ap - ex; + sp = ap; + s1 = 0; + sn = s1; + conex = fabs (con / wk); + do { + cn = ap * s2 / (sn + sp); + s1 = s1 + cn; + if (fabs (cn) <= conex) + break; + sn = sp; + sp = sp + 1; + s2 = s2 - w2; + w2 = w2 * h4 / sp; + ap = -ap * a2; + } while (1); + t = (atan (wk) - wk * s1) / TWOPI; + b = b + sgn * t; + } + if (is >= 0) + break; + } while (ak != 0); + + if (b < EPSILON) + b = 0; + if (b > 1) + b = 1; + return b; +} + + +/*=========================================================================*/ + +double fdist_BiNormal2 (double dh, double dk, double rho) +{ + const double twopi = 2.0 * num_Pi; + double W[11][3]; + double X[11][3]; + double h, k, hk, bvn, hs, asr, sn, as, a, b, c, d, sp, rs, ep, bs, xs; + int i, lg, ng, is; + + bvn = InitBiNormal (dh, dk, rho); + if (bvn >= 0.0) + return bvn; +/* + I have made small changes in Genz's Matlab function to make it compatible + with module fdist. (R. Simard) +*/ + +/* +// Copyright (C) 2005, Alan Genz, All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided the following conditions are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The contributor name(s) may not be used to endorse or promote +// products derived from this software without specific prior written +// permission. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// function p = bvnl( dh, dk, r ) +// +// A function for computing bivariate normal probabilities. +// bvnl calculates the probability that x < dh and y < dk. +// parameters +// dh 1st upper integration limit +// dk 2nd upper integration limit +// r correlation coefficient +// +// Author +// Alan Genz +// Department of Mathematics +// Washington State University +// Pullman, Wa 99164-3113 +// Email : alangenz@wsu.edu +// This function is based on the method described by +// Drezner, Z and G.O. Wesolowsky, (1989), +// On the computation of the bivariate normal inegral, +// Journal of Statist. Comput. Simul. 35, pp. 101-107, +// with major modifications for double precision, for |r| close to 1, +// and for matlab by Alan Genz - last modifications 7/98. +// +// p = bvnu( -dh, -dk, r ); +// return +// +// end bvnl +// +// function p = bvnu( dh, dk, r ) +// +// A function for computing bivariate normal probabilities. +// bvnu calculates the probability that x > dh and y > dk. +// parameters +// dh 1st lower integration limit +// dk 2nd lower integration limit +// r correlation coefficient +// +// Author +// Alan Genz +// Department of Mathematics +// Washington State University +// Pullman, Wa 99164-3113 +// Email : alangenz@wsu.edu +// +// This function is based on the method described by +// Drezner, Z and G.O. Wesolowsky, (1989), +// On the computation of the bivariate normal inegral, +// Journal of Statist. Comput. Simul. 35, pp. 101-107, +// with major modifications for double precision, for |r| close to 1, +// and for matlab by Alan Genz - last modifications 7/98. +// Note: to compute the probability that x < dh and y < dk, use +// bvnu( -dh, -dk, r ). +// +*/ + if (fabs (rho) < 0.3) { + ng = 0; + lg = 3; +/* Gauss Legendre points and weights, n = 6 */ + W[1][0] = 0.1713244923791705; + W[2][0] = 0.3607615730481384; + W[3][0] = 0.4679139345726904; + + X[1][0] = 0.9324695142031522; + X[2][0] = 0.6612093864662647; + X[3][0] = 0.2386191860831970; + + } else if (fabs (rho) < 0.75) { + ng = 1; + lg = 6; +/* Gauss Legendre points and weights, n = 12 */ + W[1][1] = 0.4717533638651177e-1; + W[2][1] = 0.1069393259953183; + W[3][1] = 0.1600783285433464; + W[4][1] = 0.2031674267230659; + W[5][1] = 0.2334925365383547; + W[6][1] = 0.2491470458134029; + + X[1][1] = 0.9815606342467191; + X[2][1] = 0.9041172563704750; + X[3][1] = 0.7699026741943050; + X[4][1] = 0.5873179542866171; + X[5][1] = 0.3678314989981802; + X[6][1] = 0.1252334085114692; + + } else { + ng = 2; + lg = 10; +/* Gauss Legendre points and weights, n = 20 */ + W[1][2] = 0.1761400713915212e-1; + W[2][2] = 0.4060142980038694e-1; + W[3][2] = 0.6267204833410906e-1; + W[4][2] = 0.8327674157670475e-1; + W[5][2] = 0.1019301198172404; + W[6][2] = 0.1181945319615184; + W[7][2] = 0.1316886384491766; + W[8][2] = 0.1420961093183821; + W[9][2] = 0.1491729864726037; + W[10][2] = 0.1527533871307259; + + X[1][2] = 0.9931285991850949; + X[2][2] = 0.9639719272779138; + X[3][2] = 0.9122344282513259; + X[4][2] = 0.8391169718222188; + X[5][2] = 0.7463319064601508; + X[6][2] = 0.6360536807265150; + X[7][2] = 0.5108670019508271; + X[8][2] = 0.3737060887154196; + X[9][2] = 0.2277858511416451; + X[10][2] = 0.7652652113349733e-1; + } + + h = -dh; + k = -dk; + hk = h * k; + bvn = 0; + if (fabs (rho) < 0.925) { + hs = (h * h + k * k) / 2.0; + asr = asin (rho); + for (i = 1; i <= lg; ++i) { + sn = sin (asr * (1.0 - X[i][ng]) / 2.0); + bvn += W[i][ng] * exp ((sn * hk - hs) / (1.0 - sn * sn)); + sn = sin (asr * (1.0 + X[i][ng]) / 2.0); + bvn += W[i][ng] * exp ((sn * hk - hs) / (1.0 - sn * sn)); + } + bvn = + bvn * asr / (4.0 * num_Pi) + fdist_Normal2 (-h) * fdist_Normal2 (-k); + + } else { + if (rho < 0.0) { + k = -k; + hk = -hk; + } + if (fabs (rho) < 1.0) { + as = (1.0 - rho) * (1.0 + rho); + a = sqrt (as); + bs = (h - k) * (h - k); + c = (4.0 - hk) / 8.0; + d = (12.0 - hk) / 16.0; + asr = -(bs / as + hk) / 2.0; + if (asr > -100.0) + bvn = + a * exp (asr) * (1.0 - c * (bs - as) * (1.0 - + d * bs / 5.0) / 3.0 + c * d * as * as / 5.0); + + if (-hk < 100.0) { + b = sqrt (bs); + sp = sqrt (twopi) * fdist_Normal2 (-b / a); + bvn = bvn - exp (-hk / 2.0) * sp * b * (1.0 - c * bs * (1.0 - + d * bs / 5.0) / 3.0); + } + a = a / 2.0; + for (i = 1; i <= lg; ++i) { + for (is = -1; is <= 1; is += 2) { + xs = (a * (is * X[i][ng] + 1.0)); + xs = xs * xs; + rs = sqrt (1.0 - xs); + asr = -(bs / xs + hk) / 2.0; + if (asr > -100.0) { + sp = (1.0 + c * xs * (1.0 + d * xs)); + ep = exp (-hk * (1.0 - rs) / (2.0 * (1.0 + rs))) / rs; + bvn += a * W[i][ng] * exp (asr) * (ep - sp); + } + } + } + bvn = -bvn / twopi; + } + if (rho > 0.0) { + if (k > h) + h = k; + bvn += fdist_Normal2 (-h); + } + if (rho < 0.0) { + xs = fdist_Normal2 (-h) - fdist_Normal2 (-k); + if (xs < 0.0) + xs = 0.0; + bvn = -bvn + xs; + } + } + if (bvn <= 0.0) + return 0.0; + if (bvn >= 1.0) + return 1.0; + return bvn; +} + + +/*=========================================================================*/ + +double fdist_LogNormal (double mu, double sigma, double x) +{ + util_Assert (sigma > 0.0, "fdist_LogNormal: sigma <= 0"); + if (x <= 0.0) + return 0.0; + return fdist_Normal2 ((log (x) - mu) / sigma); +} + + +/*=========================================================================*/ + +double fdist_JohnsonSB (double alpha, double beta, double a, double b, + double x) +{ + util_Assert (beta > 0.0, "fdist_JohnsonSB: beta <= 0"); + util_Assert (b > a, "fdist_JohnsonSB: b <= a"); + if (x <= a) + return 0.0; + if (x >= b) + return 1.0; + return fdist_Normal2 (alpha + beta * log ((x - a) / (b - x))); +} + + +/*=========================================================================*/ + +double fdist_JohnsonSU (double alpha, double beta, double x) +{ + const double XLIM = 1.0e10; + double r; + lebool negative = FALSE; + util_Assert (beta > 0.0, "fdist_JohnsonSU: beta <= 0"); + if (x < 0.0) { + negative = TRUE; + x = -x; + } + /* compute r = x + sqrt (x * x + 1) */ + if (x < XLIM) + r = x + sqrt (x * x + 1.0); + else + r = 2.0 * x; + if (negative) + r = 1.0 / r; + + if (r > 0.0) + return fdist_Normal2 (alpha + beta * log (r)); + else + return 0.0; +} + + +/**************************************************************************/ + +double fdist_ChiSquare1 (long N, double x) +/* + * Returns an approximation of the Chi square cdf (N degrees of freedom) + * As in p:116 of W.J.Kennedy Jr and J.E.Gentle. Statistical computing, + * Dekker, New York, 1980. + */ +{ + const double tiers = 0.33333333333333333; + const double pt2 = 0.22222222222222222; + const double moinsdixhuit = -18.8055; + const double gam = 0.8862269254527579825931; + double H, H2, E, DemiX, Terme, Sommation, Y = 0; + long i; + + util_Assert (N > 0, "fdist_ChiSquare1: k < 1"); + if (x <= 0.0) + return 0.0; + if (x >= fdist_XBIG * N) + return 1.0; + + if (N > 1000) { + if (x < 2.0) + return 0.0; + x = (pow ((x / N), tiers) - (1.0 - pt2 / N)) / sqrt (pt2 / N); + if (x > 5.0) + return 1.0; + if (x < moinsdixhuit) + return 0.0; + return fdist_Normal2 (x); + + } else { + DemiX = x / 2.0; + if (!(N & 1)) { /* even N */ + if (-DemiX < DBL_MIN_EXP * num_Ln2) + Terme = 0.0; + else + Terme = exp (-DemiX); + Sommation = Terme; + for (i = 1; i < N / 2; i++) { + Terme = Terme * DemiX / ((double) i); + Sommation += Terme; + } + Y = 1.0 - Sommation; + } else { + H2 = -1.0 + 2.0 * fdist_Normal2 (sqrt (x)); + if (N == 1) + return H2; + if (-DemiX < DBL_MIN_EXP * num_Ln2) + E = 0.0; + else + E = exp (-DemiX); + Terme = sqrt (DemiX) * E / gam; + H = H2; + for (i = 3; i < N; i += 2) { + H -= Terme; + Terme = Terme * DemiX * 2.0 / ((double) i); + } + Y = H - Terme; + } + } + if (Y < 0.0) + return 0.0; + else + return Y; +} + + +/*=========================================================================*/ + +double fdist_ChiSquare2 (long n, int d, double x) +{ + util_Assert (n > 0, "fdist_ChiSquare2: n <= 0"); + if (x <= 0.0) + return 0.0; + if (x >= fdist_XBIG * n) + return 1.0; + return fdist_Gamma (n / 2.0, d, x / 2.0); +} + + +/*=========================================================================*/ + +#define Student_n1 20 +#define Student_x1 8.01 +#define Student_kmax 200 +#define Student_eps 0.5E-16 + +double fdist_Student1 (long n, double x) +{ + double a, u, b, y, z, z2, prec; + long k; + + util_Assert (n > 0, "fdist_Student1: n <= 0"); + if (n == 1) { + if (x < -0.5) + return atan(-1.0/x) / num_Pi; + return 0.5 + (atan (x)) / num_Pi; + } + + if (n == 2) { + z = 1.0 + x * x / 2.0; + if (x >= 0.) + return 0.5 + x / (2.0 * sqrt (z) * num_Rac2); + else + return 0.25 / (z * (0.5 - x /(2.0*sqrt(z)*num_Rac2))); + } + + /* first case: small n and small x */ + if (n <= Student_n1 && x <= Student_x1) { + b = 1.0 + x * x / n; + y = x / sqrt ((double) n); + z = 1.0; + for (k = n - 2; k >= 2; k -= 2) { + z = 1.0 + z * (k - 1.0) / (k * b); + } + if (n % 2 == 0) { + u = (1.0 + z * y / sqrt (b)) / 2.0; + if (u >= 0.) + return u; + else + return 0.; + } else { + if (y > -1.0) + return (0.5 + (atan (y) + z * y / b) / num_Pi); + else { + u = (atan (-1.0 / y) + z * y / b) / num_Pi; + if (u >= 0.) + return u; + else + return 0.; + } + } + + /* second case: large n and small x */ + } else if (x < Student_x1) { + a = n - 0.5; + b = 48.0 * a * a; + z2 = a * num2_log1p (x * x / n); + z = sqrt (z2); + y = (((((64.0 * z2 + 788.0) * z2 + 9801.0) * z2 + 89775.0) * z2 + + 543375.0) * z2 + 1788885.0) * z / (210.0 * b * b * b); + y -= + (((4.0 * z2 + 33.0) * z2 + 240.0) * z2 + 855.0) * z / (10.0 * b * b); + y += z + (z2 + 3.0) * z / b; + if (x >= 0.0) + return fbar_Normal1 (-y); + else + return fbar_Normal1 (y); + + /* third case: large x */ + } else { + /* Compute the Student probability density */ + b = 1.0 + x * x / n; + /* to avoid overflow with the 2 Gamma functions, use their logarithm. + However, for large n, there will be some loss of precision */ + y = num2_LnGamma ((n + 1) / 2.0) - num2_LnGamma (n / 2.0); + y = exp (y); + y *= pow (b, -(n + 1) / 2.0) / sqrt (num_Pi * n); + + y *= 2.0 * sqrt (n * b); + z = y / n; + k = 2; + z2 = prec = 10.0; + while (k < Student_kmax && prec > Student_eps) { + y *= (k - 1) / (k * b); + z += y / (n + k); + prec = fabs (z - z2); + z2 = z; + k += 2; + } + util_Warning (k >= Student_kmax, "fdist_Student1: k >= Student_kmax"); + if (x >= 0.0) + return 1.0 - z / 2.0; + else + return z / 2.0; + } +} + +/*=========================================================================*/ + +double fdist_Student2 (long n, int d, double x) +{ + util_Assert (n > 0, "fdist_Student2: n <= 0"); + util_Assert (d > 0, "fdist_Student2: d <= 0"); + util_Assert (d <= 15, "fdist_Student2: d > 15"); + if (x <= -fdist_XBIG) + return 0.0; + if (x >= fdist_XBIG) + return 1.0; + + if (x >= 0.0) + return 0.5 * (1.0 + fdist_Beta (0.5, 0.5 * n, d, x * x / (n + x * x))); + else + return 0.5 * (fdist_Beta (0.5 * n, 0.5, d, n / (n + x * x))); +} + +/*=========================================================================*/ + +double fdist_Gamma (double alpha, int d, double x) +{ + const double ALIM = 1.0e5; + const double EPS = EpsArray[d]; + + util_Assert (alpha > 0.0, "fdist_Gamma: a <= 0"); + util_Assert (d > 0, "fdist_Gamma: d <= 0"); + util_Assert (d < 16, "fdist_Gamma: d > 15"); + if (x <= 0.0) + return 0.0; + if (1.0 == alpha) + return fdist_Expon (x); + + if (alpha >= ALIM) { + double d2 = x + 1.0/3.0 - alpha - 0.02/alpha; + double S = alpha - 1.0/2.0; + double z = d2 * sqrt((1 + fdist_belog(S/x))/x); + return fdist_Normal2 (z); + } + + if (x <= 1.0 || x < alpha) { + double v, z, an, term; + v = exp (alpha * log (x) - x - num2_LnGamma (alpha)); + z = 1.0; + term = 1.0; + an = alpha; + do { + an += 1.0; + term *= x / an; + z += term; + } while (term >= EPS * z); + return z * v / alpha; + + } else + return 1.0 - fbar_Gamma (alpha, d, x); +} + + +/*=========================================================================*/ + +static double Isubx_pq_small (double p, double q, double x, int d) +/* + * Evaluates fdist_Beta (p, q, d, x) when 0 < p <= 1 and 0 < q <= 2 to a + * precision of d = -log10 (2 epsilon) decimal digits. Uses a series + * expansion in powers of x. + */ +{ + + int k = 0; + double s, u, v; + double epsilon; + util_Assert (p > 0.0 && p <= 1.0, "Isubx_pq_small: p not in (0, 1] "); + util_Assert (q > 0.0 && q <= 2.0, "Isubx_pq_small: q not in (0, 2] "); + + epsilon = EpsArray[d]; + u = pow (x, p); + s = u / p; + do { + u = (k + 1 - q) * x * u / (k + 1); + v = u / (k + 1 + p); + s += v; + k++; + } while ((fabs (v) / s) > epsilon); + + v = num2_LnGamma (p + q) - num2_LnGamma (p) - num2_LnGamma (q); + return s * exp (v); +} + +/*-------------------------------------------------------------------------*/ + +static void forward (double p, double q, double x, double I0, double I1, + int nmax, double I[]) +/* + * Given I0 = fdist_Beta (p, q, x) and I1 = fdist_Beta (p, q + 1, x), + * generates fdist_Beta (p, q + n, x) for n = 0, 1, 2, ..., nmax, and + * stores the result in I. + */ +{ + + int n; + + I[0] = I0; + if (nmax > 0) + I[1] = I1; + for (n = 1; n < nmax; n++) + I[n + 1] = (1 + (n - 1 + p + q) * (1. - x) / (n + q)) * I[n] + - (n - 1 + p + q) * (1. - x) * I[n - 1] / (n + q); +} + +/*-------------------------------------------------------------------------*/ + +static void backward (double p, double q, double x, double I0, int d, + int nmax, double I[]) +/* + * Given I0 = fdist_Beta (p, q, x), generates fdist_Beta (p + n, q, x) + * for n = 0, 1, 2,..., nmax to d significant digits, using a variant of + * J.C.P. Miller's backward recurrence algorithm. Stores the result in I. + */ +{ + + int n, nu, m, again, ntab; + double *Itemp, *Iapprox, *Rr; + double epsilon, r; + + I[0] = I0; + if (nmax == 0) + return; + + epsilon = EpsArray[d]; + nu = 2 * nmax + 5; + ntab = 64; + while (ntab <= nu) + ntab *= 2; + + Rr = (double *) util_Calloc ((size_t) ntab, sizeof (double)); + Iapprox = (double *) util_Calloc ((size_t) ntab, sizeof (double)); + Itemp = (double *) util_Calloc ((size_t) ntab, sizeof (double)); + + for (n = 1; n <= nmax; n++) + Iapprox[n] = 0.0; + for (n = 0; n <= nmax; n++) + Itemp[n] = I[n]; + + do { + n = nu; + r = 0.0; + do { + r = (n - 1 + p + q) * x / (n + p + (n - 1 + p + q) * x - (n + p) * r); + if (n <= nmax) + Rr[n - 1] = r; + n--; + } while (n >= 1); + + for (n = 0; n < nmax; n++) + Itemp[n + 1] = Rr[n] * Itemp[n]; + + again = 0; + for (n = 1; n <= nmax; n++) { + if (fabs ((Itemp[n] - Iapprox[n])/Itemp[n]) > epsilon) { + again++; + for (m = 1; m <= nmax; m++) + Iapprox[m] = Itemp[m]; + nu += 5; + if (ntab <= nu) { + ntab *= 2; + Rr = (double *) util_Realloc (Rr, ntab * sizeof (double)); + Iapprox = (double *) util_Realloc (Iapprox, ntab * sizeof (double)); + Itemp = (double *) util_Realloc (Itemp, ntab * sizeof (double)); + } + break; + } + } + } while (again); + + for (n = 0; n <= nmax; n++) + I[n] = Itemp[n]; + util_Free (Rr); + util_Free (Iapprox); + util_Free (Itemp); +} + +/*-------------------------------------------------------------------------*/ +static const double RENORM = 1.0e300; + +static void Isubx_q_fixed (double p, double q, double x, int d, int nmax, + double I[]) +/* + * Generates fdist_Beta (p + n, q, x), 0 < p <= 1, for n = 0, 1, 2,..., + * nmax to d significant digits, using procedure backward. First reduces + * q modulo 1 to q0, where 0 < q0 <= 1. + */ +{ + + int m, mmax; + double s, q0, Iq0, Iq1; + double *Iq; + + util_Assert (p > 0.0 && p <= 1.0, "Isubx_q_fixed: p not in (0, 1] "); + m = (int) q; /* integer part of q */ + s = q - m; /* fractionnal part of q */ + if (s > 0) { + q0 = s; + mmax = m; + } else { + q0 = s + 1; + mmax = m - 1; + } + Iq0 = RENORM * Isubx_pq_small (p, q0, x, d); + if (mmax > 0) + Iq1 = RENORM * Isubx_pq_small (p, q0 + 1.0, x, d); + + Iq = (double *) util_Calloc ((size_t) mmax + 1, sizeof (double)); + forward (p, q0, x, Iq0, Iq1, mmax, Iq); + backward (p, q, x, Iq[mmax], d, nmax, I); + for (m = 0; m <= nmax; m++) + I[m] /= RENORM; + util_Free (Iq); +} + +/*-------------------------------------------------------------------------*/ + +static void Isubx_p_fixed (double p, double q, double x, int d, int nmax, + double I[]) +/* + * Generates fdist_Beta (p, q + n, x), 0 < q <= 1, for n = 0, 1, 2,..., + * nmax to d significant digits, using procedure forward. + */ +{ + + int m, mmax; + double s, p0, I0, Iq0, I1, Iq1; + double *Ip; + + util_Assert (q > 0.0 && q <= 1.0, "Isubx_p_fixed: q not in (0, 1] "); + + m = (int) p; /* integer part of p */ + s = p - m; /* fractionnal part of p */ + if (s > 0) { + p0 = s; + mmax = m; + } else { + p0 = s + 1; + mmax = m - 1; + } + I0 = RENORM * Isubx_pq_small (p0, q, x, d); + I1 = RENORM * Isubx_pq_small (p0, q + 1.0, x, d); + + Ip = (double *) util_Calloc ((size_t) mmax + 1, sizeof (double)); + backward (p0, q, x, I0, d, mmax, Ip); + Iq0 = Ip[mmax]; + backward (p0, q + 1.0, x, I1, d, mmax, Ip); + Iq1 = Ip[mmax]; + forward (p, q, x, Iq0, Iq1, nmax, I); + for (m = 0; m <= nmax; m++) + I[m] /= RENORM; + util_Free (Ip); +} + +/*-------------------------------------------------------------------------*/ + +static void Beta_q_fixed (double p, double q, double x, int d, int nmax, + double I[]) +{ + int n; + util_Assert (p > 0.0 && p <= 1.0, "Beta_q_fixed: p not in (0, 1]"); + util_Assert (q > 0.0, "Beta_q_fixed: q <= 0"); + util_Assert (nmax >= 0, "Beta_q_fixed: nmax < 0"); + if (x == 0.0 || x == 1.0) { + for (n = 0; n <= nmax; n++) + I[n] = x; + return; + } + if (x <= 0.5) + Isubx_q_fixed (p, q, x, d, nmax, I); + else { + Isubx_p_fixed (q, p, 1.0 - x, d, nmax, I); + for (n = 0; n <= nmax; n++) + I[n] = 1.0 - I[n]; + } +} + +/*-------------------------------------------------------------------------*/ + +static void Beta_p_fixed (double p, double q, double x, int d, int nmax, + double I[]) +{ + int n; + util_Assert (q > 0.0 && q <= 1.0, "Beta_p_fixed: q not in (0, 1]"); + util_Assert (p > 0.0, "Beta_p_fixed: p <= 0"); + util_Assert (nmax >= 0, "Beta_p_fixed: nmax < 0"); + if (x == 0.0 || x == 1.0) { + for (n = 0; n <= nmax; n++) + I[n] = x; + return; + } + if (x <= 0.5) + Isubx_p_fixed (p, q, x, d, nmax, I); + else { + Isubx_q_fixed (q, p, 1.0 - x, d, nmax, I); + for (n = 0; n <= nmax; n++) + I[n] = 1.0 - I[n]; + } +} + + +/*-------------------------------------------------------------------------*/ +/* + * The exact section of fdist_Beta below is very slow for large parameters. + * It is an old algorithm of Gautschi of 1964. There is an algorithm + * for fdist_Beta (1994) that is recent and is supposed to be very fast + * (I MUST write the exact reference for later; I think it may have been in + * Mathematics of Computations???) + */ +double fdist_Beta (double p, double q, int d, double x) +/* + * I[j] will contain either the values of fdist_Beta (p0 + j, q, d, x), + * where 0 < p0 <= 1, for j = 0, 1, 2, ..., n, with p = p0 + n; or the + * values of fdist_Beta (p, q0 + j, d, x), where 0 < q0 <= 1, for j = 0, + * 1, 2, ..., n, with q = q0 + n. + */ +{ + + const double pqmax = 1000.0; + const double pqlim = 30.0; + int n, flag; + double p0, q0, u, temp, yd, gam, h1, h3, y; + double *I; + + util_Assert (p > 0.0, "fdist_Beta: p <= 0"); + util_Assert (q > 0.0, "fdist_Beta: q <= 0"); + util_Assert (d > 0, "fdist_Beta: d <= 0"); + util_Assert (d < 16, "fdist_Beta: d > 15"); + if (x <= 0.0) + return 0.0; + if (x >= 1.0) + return 1.0; + + if (util_Max (p, q) <= pqmax) { + if (p < q) { + n = (int) p; /* integer part of p */ + p0 = p - n; /* fractionnal part of p */ + if (p0 <= 0.0) { /* p0 == 0 not allowed */ + p0 = 1.0; + n--; + } + I = (double *) util_Calloc ((size_t) n + 1, sizeof (double)); + Beta_q_fixed (p0, q, x, d, n, I); + u = I[n]; + util_Free (I); + /* There may be numerical errors far in the tails giving very small + negative values instead of 0. */ + if (u <= 0.0) + return 0.0; + else if (u <= 1.0) + return u; + else + return 1.0; + + } else { + n = (int) q; /* integer part of q */ + q0 = q - n; /* fractionnal part of q */ + if (q0 <= 0.0) { /* q0 == 0 not allowed */ + q0 = 1.0; + n--; + } + I = (double *) util_Calloc ((size_t) n + 1, sizeof (double)); + Beta_p_fixed (p, q0, x, d, n, I); + u = I[n]; + util_Free (I); + /* There may be numerical errors far in the tails giving very small + negative values instead of 0. */ + if (u <= 0.0) + return 0.0; + else if (u <= 1.0) + return u; + else + return 1.0; + } + } + + if ((p > pqmax && q < pqlim) || (q > pqmax && p < pqlim)) { + /* Bol'shev approximation for large max(p, q) and small min(p, q) */ + if (x > 0.5) + return 1.0 - fdist_Beta (q, p, d, 1.0 - x); + + if (p < q) { + u = p; + p = q; + q = u; + flag = 0; + } else { + flag = 1; + } + u = p + 0.5 * q - 0.5; + if (!flag) + temp = x / (2.0 - x); + else + temp = (1.0 - x) / (1.0 + x); + yd = 2.0 * u * temp; + gam = + (exp (q * log (yd) - yd - num2_LnGamma (q)) * (2.0 * yd * yd - (q - + 1.0) * yd - (q * q - 1.0))) / (24.0 * u * u); + if (flag) { + yd = fbar_Gamma (q, d, yd); + return yd - gam; + } else { + yd = fdist_Gamma (q, d, yd); + return yd + gam; + } + } + + /* Normal approximation of Peizer and Pratt */ + h1 = p + q - 1.0; + y = 1.0 - x; + h3 = sqrt ((1.0 + y * fdist_belog ((p - 0.5) / (h1 * x)) + + x * fdist_belog ((q - 0.5) / (h1 * y))) + / ((h1 + 1.0 / 6.0) * x * y)) + * ((h1 + 1.0 / 3.0 + 0.02 * (1.0 / p + 1.0 / q + 1.0 / (p + q))) + * x - p + 1.0 / 3.0 - 0.02 / p - 0.01 / (p + q)); + + return fdist_Normal2 (h3); + +} + + +/*=========================================================================*/ +#define EPSILON 1.0e-15 /* Tolerance */ +#define EPSBETA 0.5e-10 /* < 0.75 sqrt(DBL_EPSILON) */ +#define ALPHALIM 100000.0 /* Limiting alpha for normal approx. */ +#define MAXJ 2000 /* Max number of terms in series */ +#define INV2PI 0.6366197723675813 /* 2 / PI */ +#define LOG4 1.38629436111989062 /* Ln(4) */ +#define OneRac2 0.70710678118654752 /* 1/sqrt(2) */ +#define SQPI_2 0.88622692545275801 /* Sqrt(Pi) / 2 */ +#define LOG_SQPI_2 -0.1207822376352453 /* Ln(Sqrt(Pi) / 2) */ + + + +/*------------------------------------------------------------------------*/ + +static double series1 (double alpha, double x) +/* + * Compute the series for F(x). + * This series is used for alpha < 1 and x close to 0. + */ +{ + int j; + double sum, term; + double poc; + poc = 1.0; + sum = 1.0 / alpha; + j = 1; + do { + poc *= x * (j - alpha) / j; + term = poc / (j + alpha); + sum += term; + ++j; + } while ((term > sum * EPSILON) && (j < MAXJ)); + + return sum * pow (x, alpha); +} + + +/*------------------------------------------------------------------------*/ + +static double series2 (double alpha, double y) +/* + * Compute the series for G(y). y = 0.5 - x. + * This series is used for alpha < 1 and x close to 1/2. + */ +{ + int j; + double term, sum; + double poc; + const double z = 4.0 * y * y; + + /* Compute the series for G(y) */ + poc = sum = 1.0; + j = 1; + do { + poc *= z * (j - alpha) / j; + term = poc / (2 * j + 1); + sum += term; + ++j; + } while ((term > sum * EPSILON) && (j < MAXJ)); + + return sum * y; +} + + +/*------------------------------------------------------------------------*/ + +static double series3 (double alpha, double x) +/* + * Compute the series for F(x). + * This series is used for alpha > 1 and x close to 0. + */ +{ + int j; + double sum, term; + const double z = -x / (1.0 - x); + + sum = term = 1.0; + j = 1; + do { + term *= z * (j - alpha) / (j + alpha); + sum += term; + ++j; + } while ((fabs (term) > sum * EPSILON) && (j < MAXJ)); + + return sum * x; +} + + +/*------------------------------------------------------------------------*/ + +static double series4 (double alpha, double y) +/* + * Compute the series for G(y). y = 0.5 - x. + * This series is used for alpha > 1 and x close to 1/2. + */ +{ + int j; + double term, sum; + const double z = 4.0 * y * y; + + term = sum = 1.0; + j = 1; + do { + term *= z * (j + alpha - 0.5) / (0.5 + j); + sum += term; + ++j; + } while ((term > sum * EPSILON) && (j < MAXJ)); + + return sum * y; +} + + +/*-------------------------------------------------------------------------*/ + +static double Peizer (double alpha, double x) +/* + * Normal approximation of Peizer and Pratt + */ +{ + const double y = 1.0 - x; + double z; + z = sqrt ((1.0 - y * fdist_belog (2.0 * x) - x * fdist_belog (2.0 * y)) + / ((2.0*alpha - 5.0 / 6.0) * x * y)) * + (2.0*x - 1.0) * (alpha - 1.0 / 3.0 + 0.025 / alpha); + + return fdist_Normal2 (z); +} + + +/*------------------------------------------------------------------------*/ + +void fdist_CalcB4 (double alpha, double *pB, double *plogB, double *pC, + double *plogC) +{ + /* Compute Beta(alpha, alpha) and Beta(alpha, alpha)*4^(alpha-1). */ + double temp; + + if (alpha <= EPSBETA) { + /* For a -> 0, B(a,a) = (2/a)*(1 - 1.645*a^2 + O(a^3)) */ + *pB = 2.0 / alpha; + *pC = *pB / (4.0*(1.0 - alpha*LOG4)); + + } else if (alpha <= 1.0) { + *plogB = 2.0 * num2_LnGamma (alpha) - num2_LnGamma (2.0*alpha); + *plogC = *plogB + (alpha - 1.0)*LOG4; + *pC = exp(*plogC); + *pB = exp(*plogB); + + } else if (alpha <= 10.0) { + *plogC = num2_LnGamma (alpha) - num2_LnGamma (0.5 + alpha) + LOG_SQPI_2; + *plogB = *plogC - (alpha - 1.0)*LOG4; + + } else if (alpha <= 200.0) { + /* Convergent series for Gamma(x + 0.5) / Gamma(x) */ + double term = 1.0; + double sum = 1.0; + int i = 1; + while (term > EPSILON*sum) { + term *= (i - 1.5)*(i - 1.5) /(i*(alpha + i - 1.5)); + sum += term; + i++; + } + temp = SQPI_2 / sqrt ((alpha - 0.5)*sum); + *plogC = log(temp); + *plogB = *plogC - (alpha - 1.0)*LOG4; + + } else { + /* Asymptotic series for Gamma(a + 0.5) / (Gamma(a) * Sqrt(a)) */ + double u = 1.0 / (8.0*alpha); + temp = 1.0 + u*(-1.0 + u*(0.5 + u*(2.5 - u*(2.625 + 49.875*u)))); + /* This is 4^(alpha - 1)*B(alpha, alpha) */ + temp = SQPI_2 / (sqrt(alpha) * temp); + *plogC = log(temp); + *plogB = *plogC - (alpha - 1.0)*LOG4; + } +} + + +/*------------------------------------------------------------------------*/ + +double fdist_BetaSymmetric (double alpha, double x) +/* + * Compute the cumulative probability of the symmetrical beta distribution. + * Returns a negative value on error, otherwise returns u in [0, 1]. + */ +{ + double temp, u, logB, logC; + int isUpper; /* True if x > 0.5 */ + double B = 0.; /* Beta(alpha, alpha) */ + double C, x0; + + if (alpha <= 0.0) { + util_Assert (1, "fdist_BetaSymmetric: p <= 0\n"); + return -1.0; + } + if (x <= 0.0) return 0.0; + if (x >= 1.0) return 1.0; + if (x == 0.5) return 0.5; + if (alpha == 1.0) return x; /* alpha = 1 is the uniform law */ + if (alpha == 0.5) /* alpha = 1/2 is the arcsin law */ + return INV2PI * asin(sqrt(x)); + + if (alpha > ALPHALIM) + return Peizer (alpha, x); + + if (x > 0.5) { + x = 1.0 - x; + isUpper = 1; + } else + isUpper = 0; + + fdist_CalcB4 (alpha, &B, &logB, &C, &logC); + + if (alpha <= 1.0) { + /* For x = x0, both series use the same number of terms to get the + required precision */ + if (x > 0.25) { + temp = -log (alpha); + if (alpha >= 1.0e-6) + x0 = 0.25 + 0.005 * temp; + else + x0 = 0.13863 + .01235 * temp; + } else + x0 = 0.25; + + if (x <= x0) + u = (series1 (alpha, x)) / B; + else + u = 0.5 - (series2 (alpha, 0.5 - x)) / C; + + } else { /* 1 < alpha < ALPHALIM */ + if (alpha < 400.0) + x0 = 0.5 - 0.45 / sqrt(alpha); + else + x0 = 0.5 - 1.0 / sqrt(alpha); + if (x0 < 0.25) + x0 = 0.25; + + if (x <= x0) { + temp = (alpha - 1.0) * log (x * (1.0 - x)) - logB; + u = series3 (alpha, x) * exp(temp) / alpha; + + } else { + const double y = 0.5 - x; + temp = num2_log1p(-4.0*y*y); + temp = alpha * temp - logC; + u = 0.5 - (series4 (alpha, y)) * exp(temp); + } + } + + if (isUpper) + return 1.0 - u; + else + return u; +} + + +/*=========================================================================*/ +#define NLIM 20 + +static double KSSpecial (long n, double x) +{ + /* For nx^2 > 18, fbar_KS(n, x) is smaller than DBL_EPSILON */ + if ((n*x*x >= 18.0) || (x >= 1.0)) + return 1.0; + + if (x <= 0.5 / n) + return 0.0; + + if (n == 1) + return 2.0 * x - 1.0; + + if (x <= 1.0 / n) { + double t = 2.0 * x - 1.0 / n; + double w; + if (n <= NLIM) { + w = num2_Factorial ((int) n); + return w * pow (t, (double) n); + } + w = num2_LnFactorial ((int) n) + n * log (t); + return exp (w); + } + + if (x >= 1.0 - 1.0 / n) { + return 1.0 - 2.0 * pow (1.0 - x, (double) n); + } + + return -1.0; +} + +#undef NLIM +/*-------------------------------------------------------------------------*/ + +static double Pelz (long n, double x) +{ + /* + Approximating the Lower Tail-Areas of the Kolmogorov-Smirnov + One-Sample Statistic, + Wolfgang Pelz and I. J. Good, + Journal of the Royal Statistical Society, Series B. + Vol. 38, No. 2 (1976), pp. 152-156 + */ + + const int JMAX = 20; + const double EPS = 1.0e-10; + const double C = 2.506628274631001; /* sqrt(2*Pi) */ + const double C2 = 1.2533141373155001; /* sqrt(Pi/2) */ + const double PI2 = num_Pi * num_Pi; + const double PI4 = PI2 * PI2; + const double RACN = sqrt((double)n); + const double z = RACN*x; + const double z2 = z * z; + const double z4 = z2 * z2; + const double z6 = z4 * z2; + const double w = PI2 / (2.0 * z*z); + double ti, term, tom; + double sum; + int j; + + term = 1; + j = 0; + sum = 0; + while (j <= JMAX && term > EPS * sum) { + ti = j + 0.5; + term = exp (-ti * ti * w); + sum += term; + j++; + } + sum *= C / z; + + term = 1; + tom = 0; + j = 0; + while (j <= JMAX && fabs(term) > EPS * fabs(tom)) { + ti = j + 0.5; + term = (PI2 * ti * ti - z2) * exp (-ti * ti * w); + tom += term; + j++; + } + sum += tom * C2 / (RACN * 3.0 * z4); + + term = 1; + tom = 0; + j = 0; + while (j <= JMAX && fabs(term) > EPS * fabs(tom)) { + ti = j + 0.5; + term = 6*z6 + 2*z4 + PI2*(2*z4 - 5*z2)*ti*ti + + PI4*(1 - 2*z2)*ti*ti*ti*ti; + term *= exp (-ti * ti * w); + tom += term; + j++; + } + sum += tom * C2 / (n * 36.0 * z * z6); + + term = 1; + tom = 0; + j = 1; + while (j <= JMAX && term > EPS * tom) { + ti = j; + term = PI2 * ti * ti * exp (-ti * ti * w); + tom += term; + j++; + } + sum -= tom * C2 / (n * 18.0 * z * z2); + + term = 1; + tom = 0; + j = 0; + while (j <= JMAX && fabs(term) > EPS * fabs(tom)) { + ti = j + 0.5; + ti = ti * ti; + term = -30*z6 -90*z6*z2 + PI2*(135*z4 - 96*z6)*ti + + PI4*(212*z4 - 60*z2)*ti*ti + PI2*PI4*ti*ti*ti*(5 - 30*z2); + term *= exp (-ti * w); + tom += term; + j++; + } + sum += tom * C2 / (RACN * n * 3240.0 * z4 * z6); + + term = 1; + tom = 0; + j = 1; + while (j <= JMAX && fabs(term) > EPS * fabs(tom)) { + ti = j*j; + term = (3*PI2 * ti * z2 - PI4*ti*ti) * exp (-ti * w); + tom += term; + j++; + } + sum += tom * C2 / (RACN * n * 108.0 * z6); + + return sum; +} + + +/*=========================================================================*/ + +static void mMultiply (double *A, double *B, double *C, int m) +{ + int i, j, k; + double s; + for (i = 0; i < m; i++) + for (j = 0; j < m; j++) { + s = 0.0; + for (k = 0; k < m; k++) + s += A[i * m + k] * B[k * m + j]; + C[i * m + j] = s; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void mPower (double *A, int eA, double *V, int *eV, int m, int n) +{ + double *B; + int eB, i; + if (n == 1) { + for (i = 0; i < m * m; i++) + V[i] = A[i]; + *eV = eA; + return; + } + mPower (A, eA, V, eV, m, n / 2); + B = (double *) malloc (m * m * sizeof (double)); + mMultiply (V, V, B, m); + eB = 2 * (*eV); + + if (n % 2 == 0) { + for (i = 0; i < m * m; i++) + V[i] = B[i]; + *eV = eB; + } else { + mMultiply (A, B, V, m); + *eV = eA + eB; + } + + if (V[(m / 2) * m + (m / 2)] > 1.0e140) { + for (i = 0; i < m * m; i++) + V[i] = V[i] * 1.0e-140; + *eV += 140; + } + free (B); +} + + +/*-------------------------------------------------------------------------*/ + +double fdist_KS2 (long N0, double x) +{ + int k, m, i, j, g, eH, eQ; + const int n = N0; + const double d = x; + double h, s, *H, *Q; + + /* OMIT NEXT 3 LINES IF YOU REQUIRE >7 DIGIT ACCURACY IN THE RIGHT TAIL */ +#if 1 + s = d * d * n; + if (s > 7.24 || (s > 3.76 && n > 99)) + return 1 - 2 * exp (-(2.000071 + 0.331 / sqrt ((double) n) + + 1.409 / n) * s); +#endif + k = (int) (n * d) + 1; + m = 2 * k - 1; + h = k - n * d; + H = (double *) malloc (m * m * sizeof (double)); + Q = (double *) malloc (m * m * sizeof (double)); + + for (i = 0; i < m; i++) + for (j = 0; j < m; j++) + if (i - j + 1 < 0) + H[i * m + j] = 0; + else + H[i * m + j] = 1; + + for (i = 0; i < m; i++) { + H[i * m] -= pow (h, (double) (i + 1)); + H[(m - 1) * m + i] -= pow (h, (double) (m - i)); + } + + H[(m - 1) * m] += (2 * h - 1 > 0 ? pow (2 * h - 1, (double) m) : 0); + + for (i = 0; i < m; i++) + for (j = 0; j < m; j++) + if (i - j + 1 > 0) + for (g = 1; g <= i - j + 1; g++) + H[i * m + j] /= g; + + eH = 0; + mPower (H, eH, Q, &eQ, m, n); + s = Q[(k - 1) * m + k - 1]; + for (i = 1; i <= n; i++) { + s = s * i / n; + if (s < 1.0e-140) { + s *= 1.0e140; + eQ -= 140; + } + } + s *= pow (10.0, (double) eQ); + free (H); + free (Q); + return s; +} + + +/*=========================================================================*/ + +static double Pomeranz (long n, double x) +{ + const double EPS = 5.0e-13; /* for floors and ceilings */ + const int ENO = 350; + const double RENO = ldexp(1.0, ENO); /* for renormalization of V */ + const double IRENO = 1.0/RENO; + int coreno; /* counter: how many renormalizations */ + const double t = n*x; + double sum, maxsum; + int i, j, k, s; + int r1, r2; /* Indices i and i-1 for V[i][] */ + int jlow, jup, klow, kup, kup0; + double w, z; + double *A; + double **V; + double **H; /* work variables = pow(w, j-k) / Factorial(j-k) */ + + A = (double*) util_Calloc ((size_t) (2*n + 3), sizeof (double)); + V = (double **) tables_CreateMatrixD (2, n + 2); + H = (double **) tables_CreateMatrixD (4, n + 1); + + A[0] = A[1] = 0; + z = t - floor(t); + w = ceil(t) - t; + if (w < z) + z = w; + A[2] = z; + A[3] = 1.0 - A[2]; + for (i = 4; i <= 2*n + 1; i++) + A[i] = A[i-2] + 1.0; + A[2*n + 2] = n; + + for (j = 1; j <= n+1; j++) + V[0][j] = 0; + for (j = 2; j <= n+1; j++) + V[1][j] = 0; + V[1][1] = RENO; + coreno = 1; + + /* Precompute H[][] = (A[j] - A[j-1]^(j-k) / (j-k)! for speed */ + H[0][0] = 1; + w = 2.0 * A[2] / n; + for (j = 1; j <= n; j++) + H[0][j] = w * H[0][j - 1] / j; + + H[1][0] = 1; + w = (1.0 - 2.0*A[2])/n; + for (j = 1; j <= n; j++) + H[1][j] = w*H[1][j-1] / j; + + H[2][0] = 1; + w = A[2]/n; + for (j = 1; j <= n; j++) + H[2][j] = w*H[2][j-1] / j; + + H[3][0] = 1; + for (j = 1; j <= n; j++) + H[3][j] = 0; + + r1 = 0; + r2 = 1; + for (i = 2; i <= 2 * n + 2; i++) { + jlow = 2 + floor (A[i] - t + EPS); + if (jlow < 1) + jlow = 1; + jup = ceil (A[i] + t - EPS); + if (jup > n + 1) + jup = n + 1; + + klow = 2 + floor (A[i - 1] - t + EPS); + if (klow < 1) + klow = 1; + kup0 = ceil (A[i - 1] + t - EPS); + + /* Find to which case it corresponds */ + w = (A[i] - A[i-1])/n; + s = -1; + for (j = 0; j < 4; j++) { + if (fabs(w - H[j][1]) <= EPS) { + s = j; + break; + } + } + util_Assert (s >= 0, "Pomeranz: s < 0"); + + maxsum = -1; + r1 = (r1 + 1) & 1; /* i - 1 */ + r2 = (r2 + 1) & 1; /* i */ + + for (j = jlow; j <= jup; j++) { + kup = kup0; + if (kup > j) + kup = j; + sum = 0; + for (k = kup; k >= klow; k--) + sum += V[r1][k] * H[s][j - k]; + V[r2][j] = sum; + if (sum > maxsum) + maxsum = sum; + } + + if (maxsum < IRENO) { + /* V is too small: renormalize to avoid underflow of prob */ + for (j = jlow; j <= jup; j++) + V[r2][j] *= RENO; + coreno++; /* keep track of log of RENO */ + } + } + + z = V[r2][n+1]; + util_Free (A); + tables_DeleteMatrixD (&H); + tables_DeleteMatrixD (&V); + + w = num2_LnFactorial(n) - coreno*ENO*num_Ln2 + log(z); + if (w >= 0.) + return 1.; + return exp(w); +} + + +/*-------------------------------------------------------------------------*/ +#define NSEP 400 +#define NSEP2 4000 +#define ZSEP 4.0 +#define ZSEP2 0.2 + +double fdist_KS1 (long n, double x) +{ + double u = KSSpecial(n, x); + if (u >= 0.0) + return u; + + if (n <= NSEP) { + if (n*x*x < ZSEP) + return Pomeranz (n, x); + else + return 1. - fbar_KS1(n, x); + } + + if (n*x*x <= ZSEP2 && n <= NSEP2) + return Pomeranz (n, x); + + return Pelz (n, x); +} + + +/*=========================================================================*/ + +double fdist_KSPlus (long N, double x) +{ + const double NxParam = 6.5; /* frontier: alternating series */ + const long NParam = 4000; /* frontier: non-alternating series */ + double q; + double Sum; + double term; + + util_Assert (N > 0, "Calling fdist_KSPlus with N < 1"); + if (x <= 0.0) + return 0.0; + if ((x >= 1.0) || (N*x*x >= 25.0)) + return 1.0; + if (N == 1) + return x; + + /*--------------------------------------------------------------*/ + /* the alternating series is stable and fast for N*x very small */ + /*--------------------------------------------------------------*/ + + if (N * x <= NxParam) { + const double Epsilon = 1.0E-300; + double LogCom = log ((double) N); + int Sign = -1; + long j; + long jmax = (long) (N * x); + Sum = 0.0; + + for (j = 1; j <= jmax; j++) { + double jreal = j; + double Njreal = N - j; + q = jreal / N - x; + /* we must avoid log(0.0) for j = jmax and N*x near an integer */ + if (-q > Epsilon) { + term = LogCom + jreal * log (-q) + (Njreal - 1.0) * num2_log1p (-q); + Sum += Sign * exp (term); + } + Sign = -Sign; + LogCom += log (Njreal / (j + 1)); + } + /* add the term j = 0 */ + Sum += exp ((N - 1) * num2_log1p (x)); + if (Sum >= 0.0) + return Sum * x; + else + return 0.0; + } + + if (N <= NParam) { + double Njreal; + double jreal; + long j; + long jmax; + double LogCom = log ((double) N); + Sum = 0.0; + jmax = (long) (N * (1.0 - x)); + if (1.0 - x - (double) jmax/N <= 0.0) + --jmax; + + for (j = 1; j <= jmax; j++) { + jreal = j; + Njreal = N - j; + q = jreal / N + x; + term = LogCom + (jreal - 1.0) * log (q) + Njreal * num2_log1p(-q); + Sum += exp (term); + LogCom += log (Njreal / (jreal + 1.0)); + } + Sum *= x; + + /* add the term j = 0; avoid log(0.0) */ + if (1.0 > x) + Sum += exp (N * num2_log1p(-x)); + Sum = 1.0 - Sum; + if (Sum >= 0.0) + return Sum; + else + return 0.0; + } + + /*---------------------------*/ + /* Use an asymptotic formula */ + /*---------------------------*/ + + term = 2.0 / 3.0; + q = x * x * N; + Sum = 1.0 - exp (-2.0 * q) * (1.0 - term * x * (1.0 - x * (1.0 - term * q) + - term / N * (0.2 - 19.0 / 15.0 * q + term * q * q))); + if (Sum >= 0.0) + return Sum; + else + return 0.0; +} + + +/*=========================================================================*/ + +double fdist_KSPlusJumpOne (long N, double a, double x) +{ + const double EpsilonLR = 1.E-15; + const double Epsilon = 1.0E-290; + const double NxaParam = 6.5; /* frontier: alternating series */ + double LogCom; + double q, p1, q1; + double Sum = 0.0; + double term; + double Njreal; + double jreal; + int Sign; + long j; + long jmax; + + util_Assert (N >= 1, "Calling fdist_KSPlusJumpOne with N < 1"); + util_Assert (a < 1.0 && a > 0.0, + "Calling fdist_KSPlusJumpOne with a outside (0, 1)"); + if (x <= 0.0) + return 0.0; + if (x + a >= 1.0) + return 1.0; + LogCom = log ((double) N); + + /*--------------------------------------------------------------------*/ + /* the alternating series is stable and fast for N*(x + a) very small */ + /*--------------------------------------------------------------------*/ + if (N * (x + a) < NxaParam && a + x < 0.5) { + jmax = (long) (N * (x + a)); + for (j = 1; j <= jmax; j++) { + jreal = j; + Njreal = N - j; + q = jreal / N - x; + if ((q < 0.0 && (j & 1)) || ((q > 1.0) && ((N - j - 1) & 1))) + Sign = -1; + else + Sign = 1; + + /* we must avoid log(0.0) */ + q1 = fabs (q); + p1 = fabs (1.0 - q); + if (q1 > Epsilon && p1 > Epsilon) { + term = LogCom + jreal * log (q1) + (Njreal - 1.0) * log (p1); + Sum += Sign * exp (term); + } + LogCom += log (Njreal / (jreal + 1.0)); + } + /* add the term j = 0 */ + Sum += exp ((N - 1) * num2_log1p(x)); + return Sum * x; + } + + /*---------------------------------------------*/ + /* For N(x + a) >= NxaParam or (a + x) > 0.5, */ + /* use the non-alternating series. */ + /*---------------------------------------------*/ + + /* EpsilonLR because the distribution has a jump */ + jmax = (long) (N * (1.0 - a - x - EpsilonLR)); + for (j = 1; j <= jmax; j++) { + jreal = j; + Njreal = N - jreal; + q = jreal / N + x; + if (1.0 - q > Epsilon) { + term = LogCom + (jreal - 1.0) * log (q) + Njreal * num2_log1p (-q); + Sum += exp (term); + } + LogCom += log (Njreal / (jreal + 1.0)); + } + Sum *= x; + + /* add the term j = 0 */ + if (1.0 - x > Epsilon) + Sum += exp (N * num2_log1p (-x)); + return 1.0 - Sum; +} + + +/*=========================================================================*/ +#if 0 +static lebool IsJump (fdist_FUNC_JUMPS * H, double xa, double xb, + double ya, double yb, int NJ) + /* Find a more precise value for the position of the jump in (xa, xb). */ + /* Return FALSE if there is no jump, TRUE if there is a jump. */ +{ + const double eps = DBL_EPSILON; + const int imax = DBL_MANT_DIG; + const double epsY = H->epsY; + double *par = H->par; + wdist_CFUNC F = H->F; + int i = 0; + double x = 1.0, y; + + /* Binary search to refine the x-coordinate of the jump */ + while ((i < imax) && (xb - xa > eps * x)) { + i++; + x = (xb + xa) / 2.0; + y = F (par, x); + if (y - ya > epsY) { + yb = y; + xb = x; + } else { + ya = y; + xa = x; + } + } + + if (yb - ya < epsY) + return FALSE; + H->xJump[NJ] = (xb + xa) / 2.0; + H->yLeftJump[NJ] = ya; + H->yRightJump[NJ] = yb; + return TRUE; +} + +/*-------------------------------------------------------------------------*/ + +void fdist_FindJumps (fdist_FUNC_JUMPS * H, int Detail) +{ + int i, NJ; + double yRight; + double yLeft; + double x; + const double epsX = H->epsX; + const double epsY = H->epsY; + double *par = H->par; + wdist_CFUNC F = H->F; + + /* Assume no more than 30 jumps initially */ + NJ = 30; + H->xJump = (double *) util_Calloc ((size_t) NJ + 1, sizeof (double)); + H->yLeftJump = (double *) util_Calloc ((size_t) NJ + 1, sizeof (double)); + H->yRightJump = (double *) util_Calloc ((size_t) NJ + 1, sizeof (double)); + + i = 0; + if (H->xa > H->xb) { + x = H->xa; + H->xa = H->xb; + H->xb = x; + } + x = H->xa; + yLeft = F (par, x); + while (x < H->xb) { + x += epsX; + yRight = F (par, x); + if (yRight - yLeft > epsY) { + /* this should be a jump */ + ++i; + if (i > NJ) { + NJ *= 2; + H->xJump = (double *) util_Realloc (H->xJump, + (NJ + 1) * sizeof (double)); + H->yLeftJump = (double *) util_Realloc (H->yLeftJump, + (NJ + 1) * sizeof (double)); + H->yRightJump = (double *) util_Realloc (H->yRightJump, + (NJ + 1) * sizeof (double)); + } + if (IsJump (H, x - epsX, x, yLeft, yRight, i) == FALSE) + i--; + } + yLeft = yRight; + } + NJ = i; + H->xJump = (double *) util_Realloc (H->xJump, (NJ + 1) * sizeof (double)); + H->yLeftJump = (double *) util_Realloc (H->yLeftJump, + (NJ + 1) * sizeof (double)); + H->yRightJump = (double *) util_Realloc (H->yRightJump, + (NJ + 1) * sizeof (double)); + H->NJumps = NJ; + + if (Detail > 0) { + printf ("\n========================================================="); + printf ("\nCalling fdist_FindJumps for function %-32s\n", H->doc); + printf ("\nInterval = (%g, %g)\n", H->xa, H->xb); + printf ("epsX = %10.5g\nepsY = %10.5g\n", epsX, epsY); + printf ("Number of jumps = %4d\n", NJ); + if (NJ == 0) + return; + printf ("Jumps of the function:\n\n"); + printf (" x yLeft yRight" + " yRight - yLeft\n\n"); + for (i = 1; i <= NJ; i++) { + printf (" %19.15g %19.15g %19.15g %19.15g\n", H->xJump[i], + H->yLeftJump[i], H->yRightJump[i], + H->yRightJump[i] - H->yLeftJump[i]); + } + printf + ("\n=========================================================\n\n"); + } +} + + +/*=========================================================================*/ + +void fdist_FreeJumps (fdist_FUNC_JUMPS * H) +{ + util_Free (H->xJump); + util_Free (H->yLeftJump); + util_Free (H->yRightJump); +} + + +/*=========================================================================*/ + +double fdist_KSMinusJumpsMany (fdist_FUNC_JUMPS * H, double dMoins) +{ + int k, j, i, jsup; + double comb, temp, y; + double *C, *B; + const int M = H->par[0]; + const int NJ = H->NJumps; + + util_Assert (M <= 64, "fdist_KSMinusJumpsMany: sample N too large"); + jsup = M * (1.0 - dMoins - EpsilonLR); + util_Assert (jsup >= 0, "fdist_KSMinusJumpsMany: jsup < 0"); + B = (double *) util_Calloc ((size_t) jsup + 1, sizeof (double)); + C = (double *) util_Calloc ((size_t) jsup + 1, sizeof (double)); + + j = 0; + while (j <= jsup) { + y = dMoins + ((double) j) / M; + i = 1; + while (i <= NJ && y > H->yRightJump[i]) + ++i; + /* I believe that Conover is wrong here, because this gives a */ + /* distribution that is continuous on the left, while probability */ + /* distributions must be continuous on the right. That could be */ + /* why these KS distributions with jumps don't seem to work. */ + /* I may also have some bugs in these functions. */ + + if (i > NJ || y < H->yLeftJump[i]) + C[j] = 1.0 - y; + else + C[j] = 1.0 - H->yRightJump[i]; + ++j; + } + + B[0] = 1.0; + for (k = 1; k <= jsup; k++) { + if (C[k] <= 0.0) + B[k] = 0.0; + else { + temp = 0.0; + comb = 1.0; + for (j = 0; j < k; j++) { + temp += comb * B[j] * pow (C[j], (double) (k - j)); + comb *= ((double) (k - j)) / (j + 1); + } + B[k] = 1.0 - temp; + } + } + temp = 0.0; + comb = 1.0; + for (j = 0; j <= jsup; j++) { + temp += comb * B[j] * pow (C[j], (double) (M - j)); + comb *= ((double) (M - j)) / (j + 1); + } + util_Warning (temp > 1.0 || temp < 0.0, + "fdist_KSMinusJumpsMany: Probabilities outside [0, 1]"); + util_Free (C); + util_Free (B); + return temp; +} + + +/*=========================================================================*/ + +double fdist_KSPlusJumpsMany (fdist_FUNC_JUMPS * H, double dPlus) +{ + int k, j, i, jsup; + double comb, temp, y; + double *F, *E; + const int M = H->par[0]; + const int NJ = H->NJumps; + + util_Assert (M <= 64, "fdist_KSPlusJumpsMany: sample N too large"); + jsup = M * (1.0 - dPlus - EpsilonLR); + util_Assert (jsup >= 0, "fdist_KSPlusJumpsMany: jsup < 0"); + E = (double *) util_Calloc ((size_t) jsup + 1, sizeof (double)); + F = (double *) util_Calloc ((size_t) jsup + 1, sizeof (double)); + + j = 0; + while (j <= jsup) { + y = (1.0 - dPlus) - ((double) j) / M; + i = 1; + while (i <= NJ && y >= H->yRightJump[i]) + ++i; + + if (i > NJ || y <= H->yLeftJump[i]) + F[j] = y; + else + F[j] = H->yLeftJump[i]; + ++j; + } + + E[0] = 1.0; + for (k = 1; k <= jsup; k++) { + if (F[k] <= 0.0) + E[k] = 0.0; + else { + temp = 0.0; + comb = 1.0; + for (j = 0; j < k; j++) { + temp += comb * E[j] * pow (F[j], (double) (k - j)); + comb *= ((double) (k - j)) / (j + 1); + } + E[k] = 1.0 - temp; + } + } + temp = 0.0; + comb = 1.0; + for (j = 0; j <= jsup; j++) { + temp += comb * E[j] * pow (F[j], (double) (M - j)); + comb *= ((double) (M - j)) / (j + 1); + } + util_Warning (temp > 1.0 || temp < 0.0, + "fdist_KSPlusJumpsMany: Probabilities outside [0, 1]"); + util_Free (E); + util_Free (F); + return temp; +} +#endif + +/*=========================================================================*/ + +double fdist_CramerMises (long N, double x) +{ + const double Epsilon = DBL_EPSILON; + const int jmax = 10; + int j; + double Cor, Res, arg; + double termX, termS, termJ; + static const double A[10] = { + 1.0, + 1.11803398875, + 1.125, + 1.12673477358, + 1.1274116945, + 1.12774323743, + 1.1279296875, + 1.12804477649, + 1.12812074678, + 1.12817350091 + }; + + util_Assert (N > 0, "fdist_CramerMises: N <= 0"); + + if (N == 1) { + if (x <= 1.0 / 12.0) + return 0.0; + if (x >= 1.0 / 3.0) + return 1.0; + return 2.0 * sqrt (x - 1.0 / 12.0); + } + + if (x <= 0.002 || x < 1.0 / (12.0*N)) + return 0.0; + if (x > 3.95 || x >= N/3.0) + return 1.0; + + termX = 0.0625 / x; /* 1 / (16x) */ + Res = 0.0; + j = 0; + do { + termJ = 4 * j + 1; + arg = termJ * termJ * termX; + termS = A[j] * exp (-arg) * num2_BesselK025 (arg); + Res += termS; + ++j; + } while (!(termS < Epsilon || j > jmax)); + + util_Warning (j > jmax, "fdist_CramerMises: iterations have not converged"); + Res /= num_Pi * sqrt (x); + + /* Empirical correction in 1/N */ + if (x < 0.0092) + Cor = 0.0; + else if (x < 0.03) + Cor = -0.0121763 + x * (2.56672 - 132.571 * x); + else if (x < 0.06) + Cor = 0.108688 + x * (-7.14677 + 58.0662 * x); + else if (x < 0.19) + Cor = -0.0539444 + x * (-2.22024 + x * (25.0407 - 64.9233 * x)); + else if (x < 0.5) + Cor = -0.251455 + x * (2.46087 + x * (-8.92836 + x * (14.0988 - + x * (5.5204 + 4.61784 * x)))); + else if (x <= 1.1) + Cor = 0.0782122 + x * (-0.519924 + x * (1.75148 + + x * (-2.72035 + x * (1.94487 - 0.524911 * x)))); + else + Cor = exp (-0.244889 - 4.26506 * x); + + Res += Cor / N; + /* This empirical correction is not very precise, so ... */ + if (Res <= 1.0) + return Res; + else + return 1.0; +} + + +/*=========================================================================*/ + +double fdist_WatsonU (long N, double x) +/* + * Only the asymptotic form has been implemented. In the trivial case + * N = 1, we simply return 0.5 + */ +{ + const int JMAX = 10; + const double xSepare = 0.15; + int j; + double v; + double terme; + double somme; + + if (x <= 0.0) + return 0.0; + if (x >= fdist_XBIG) + return 1.0; + + if (N == 1) /* N = 1, degenerate case */ + return 0.5; + + if (x > xSepare) + return 1.0 - fbar_WatsonU (N, x); + + /* this series converges rapidly for x <= 0.15 */ + v = exp (-(0.125 / x)); + somme = v; + j = 2; + do { + terme = pow (v, (double) (2 * j - 1) * (2 * j - 1)); + somme += terme; + ++j; + } while (!(terme < v * DBL_EPSILON || j > JMAX)); + util_Warning (j > JMAX, "fdist_WatsonU: sum2 has not converged"); + + v = 2.0 * somme / sqrt (2.0 * num_Pi * x); + if (v >= 1.0) + return 1.0; + return v; +} + + +/*=========================================================================*/ + +static double YWA[143]; /* Tables for a spline approximation */ +static double MWA[143]; /* of the WatsonG distribution */ +static double CoWA[143]; /* Empirical correction in 1/sqrt(n) */ + +static void WatsonGInit (void) +/* + * Initialization procedure for fdist_WatsonG + */ +{ + int j; + + YWA[0] = 1.8121832847E-39; YWA[1] = 2.0503176304E-32; + YWA[2] = 4.6139577764E-27; YWA[3] = 6.5869745929E-23; + YWA[4] = 1.2765816107E-19; YWA[5] = 5.6251923105E-17; + YWA[6] = 8.0747150511E-15; YWA[7] = 4.8819994144E-13; + YWA[8] = 1.4996052497E-11; YWA[9] = 2.6903519441E-10; + YWA[10] = 3.1322929018E-9; YWA[11] = 2.5659643046E-8; + YWA[12] = 1.5749759318E-7; YWA[13] = 7.6105096466E-7; + YWA[14] = 3.0113293541E-6; YWA[15] = 1.0070166837E-5; + YWA[16] = 2.9199826692E-5; YWA[17] = 7.4970409372E-5; + YWA[18] = 1.7340586581E-4; YWA[19] = 3.6654236297E-4; + YWA[20] = 7.165864865E-4; YWA[21] = 1.3087767385E-3; + YWA[22] = 2.2522044209E-3; YWA[23] = 3.6781862572E-3; + YWA[24] = 5.7361958631E-3; YWA[25] = 8.5877444706E-3; + YWA[26] = 1.23988738E-2; YWA[27] = 1.73320516E-2; + YWA[28] = 2.35382479E-2; YWA[29] = 3.11498548E-2; + YWA[30] = 4.02749297E-2; YWA[31] = 5.09930445E-2; + YWA[32] = 6.33528333E-2; YWA[33] = 7.73711747E-2; + YWA[34] = 9.30338324E-2; YWA[35] = 1.10297306E-1; + YWA[36] = 1.290916098E-1; YWA[37] = 1.493236984E-1; + YWA[38] = 1.708812741E-1; YWA[39] = 1.936367476E-1; + YWA[40] = 2.174511609E-1; YWA[41] = 2.42177928E-1; + YWA[42] = 2.676662852E-1; YWA[43] = 2.937643828E-1; + YWA[44] = 3.203219784E-1; YWA[45] = 3.471927188E-1; + YWA[46] = 3.742360163E-1; YWA[47] = 4.013185392E-1; + YWA[48] = 4.283153467E-1; YWA[49] = 4.551107027E-1; + YWA[50] = 4.815986082E-1; YWA[51] = 5.076830902E-1; + YWA[52] = 5.332782852E-1; YWA[53] = 5.583083531E-1; + YWA[54] = 5.827072528E-1; YWA[55] = 6.064184099E-1; + YWA[56] = 6.293943006E-1; YWA[57] = 6.515959739E-1; + YWA[58] = 6.729925313E-1; YWA[59] = 6.935605784E-1; + YWA[60] = 7.132836621E-1; YWA[61] = 7.321517033E-1; + YWA[62] = 7.501604333E-1; YWA[63] = 7.673108406E-1; + YWA[64] = 7.836086337E-1; YWA[65] = 7.99063723E-1; + YWA[66] = 8.136897251E-1; YWA[67] = 8.275034914E-1; + YWA[68] = 8.405246632E-1; YWA[69] = 8.527752531E-1; + YWA[70] = 8.642792535E-1; YWA[71] = 8.750622738E-1; + YWA[72] = 8.851512032E-1; YWA[73] = 8.945739017E-1; + YWA[74] = 9.033589176E-1; YWA[75] = 9.115352296E-1; + YWA[76] = 9.19132015E-1; YWA[77] = 9.261784413E-1; + YWA[78] = 9.327034806E-1; YWA[79] = 9.387357465E-1; + YWA[80] = 9.44303351E-1; YWA[81] = 9.494337813E-1; + YWA[82] = 9.541537951E-1; YWA[83] = 9.584893325E-1; + YWA[84] = 9.624654445E-1; YWA[85] = 9.661062352E-1; + YWA[86] = 9.694348183E-1; YWA[87] = 9.724732859E-1; + YWA[88] = 9.752426872E-1; YWA[89] = 9.777630186E-1; + YWA[90] = 9.800532221E-1; YWA[91] = 9.821311912E-1; + YWA[92] = 9.840137844E-1; YWA[93] = 9.85716844E-1; + YWA[94] = 9.872552203E-1; YWA[95] = 9.886428002E-1; + YWA[96] = 9.898925389E-1; YWA[97] = 9.910164946E-1; + YWA[98] = 9.920258656E-1; YWA[99] = 9.929310287E-1; + YWA[100] = 9.937415788E-1; YWA[101] = 9.944663692E-1; + YWA[102] = 9.95113552E-1; YWA[103] = 9.956906185E-1; + YWA[104] = 9.962044387E-1; YWA[105] = 9.966613009E-1; + YWA[106] = 9.970669496E-1; YWA[107] = 9.974266225E-1; + YWA[108] = 9.977450862E-1; YWA[109] = 9.980266707E-1; + YWA[110] = 9.982753021E-1; YWA[111] = 9.984945338E-1; + YWA[112] = 9.98687576E-1; YWA[113] = 9.98857324E-1; + YWA[114] = 9.990063842E-1; YWA[115] = 9.991370993E-1; + YWA[116] = 9.992515708E-1; YWA[117] = 9.99351681E-1; + YWA[118] = 9.994391129E-1; YWA[119] = 9.995153688E-1; + YWA[120] = 9.995817875E-1; YWA[121] = 9.996395602E-1; + YWA[122] = 9.996897446E-1; YWA[123] = 9.997332791E-1; + YWA[124] = 9.997709943E-1; YWA[125] = 9.998036243E-1; + YWA[126] = 9.998318172E-1; YWA[127] = 9.998561438E-1; + YWA[128] = 9.998771066E-1; YWA[129] = 9.998951466E-1; + YWA[130] = 9.999106508E-1; YWA[131] = 9.99923958E-1; + YWA[132] = 9.999353645E-1; YWA[133] = 9.999451288E-1; + YWA[134] = 9.999534765E-1; YWA[135] = 9.999606035E-1; + YWA[136] = 9.999666805E-1; YWA[137] = 9.999718553E-1; + YWA[138] = 9.999762562E-1; YWA[139] = 9.999799939E-1; + YWA[140] = 9.999831643E-1; YWA[141] = 9.999858E-1; + YWA[142] = 9.999883E-1; + + MWA[0] = 0.0; MWA[1] = 6.909E-15; + MWA[2] = 2.763E-14; MWA[3] = 1.036E-13; + MWA[4] = 3.792E-13; MWA[5] = 4.773E-12; + MWA[6] = 4.59E-10; MWA[7] = 2.649E-8; + MWA[8] = 7.353E-7; MWA[9] = 1.14E-5; + MWA[10] = 1.102E-4; MWA[11] = 7.276E-4; + MWA[12] = 3.538E-3; MWA[13] = 0.01342; + MWA[14] = 0.04157; MWA[15] = 0.1088; + MWA[16] = 0.2474; MWA[17] = 0.4999; + MWA[18] = 0.913; MWA[19] = 1.53; + MWA[20] = 2.381; MWA[21] = 3.475; + MWA[22] = 4.795; MWA[23] = 6.3; + MWA[24] = 7.928; MWA[25] = 9.602; + MWA[26] = 11.24; MWA[27] = 12.76; + MWA[28] = 14.1; MWA[29] = 15.18; + MWA[30] = 15.98; MWA[31] = 16.47; + MWA[32] = 16.64; MWA[33] = 16.49; + MWA[34] = 16.05; MWA[35] = 15.35; + MWA[36] = 14.41; MWA[37] = 13.28; + MWA[38] = 12.0; MWA[39] = 10.6; + MWA[40] = 9.13; MWA[41] = 7.618; + MWA[42] = 6.095; MWA[43] = 4.588; + MWA[44] = 3.122; MWA[45] = 1.713; + MWA[46] = 0.3782; MWA[47] = -0.8726; + MWA[48] = -2.031; MWA[49] = -3.091; + MWA[50] = -4.051; MWA[51] = -4.91; + MWA[52] = -5.668; MWA[53] = -6.327; + MWA[54] = -6.893; MWA[55] = -7.367; + MWA[56] = -7.756; MWA[57] = -8.064; + MWA[58] = -8.297; MWA[59] = -8.46; + MWA[60] = -8.56; MWA[61] = -8.602; + MWA[62] = -8.591; MWA[63] = -8.533; + MWA[64] = -8.433; MWA[65] = -8.296; + MWA[66] = -8.127; MWA[67] = -7.93; + MWA[68] = -7.709; MWA[69] = -7.469; + MWA[70] = -7.212; MWA[71] = -6.943; + MWA[72] = -6.663; MWA[73] = -6.378; + MWA[74] = -6.087; MWA[75] = -5.795; + MWA[76] = -5.503; MWA[77] = -5.213; + MWA[78] = -4.927; MWA[79] = -4.646; + MWA[80] = -4.371; MWA[81] = -4.103; + MWA[82] = -3.843; MWA[83] = -3.593; + MWA[84] = -3.352; MWA[85] = -3.12; + MWA[86] = -2.899; MWA[87] = -2.689; + MWA[88] = -2.489; MWA[89] = -2.3; + MWA[90] = -2.121; MWA[91] = -1.952; + MWA[92] = -1.794; MWA[93] = -1.645; + MWA[94] = -1.506; MWA[95] = -1.377; + MWA[96] = -1.256; MWA[97] = -1.144; + MWA[98] = -1.041; MWA[99] = -0.9449; + MWA[100] = -0.8564; MWA[101] = -0.775; + MWA[102] = -0.7001; MWA[103] = -0.6315; + MWA[104] = -0.5687; MWA[105] = -0.5113; + MWA[106] = -0.459; MWA[107] = -0.4114; + MWA[108] = -0.3681; MWA[109] = -0.3289; + MWA[110] = -0.2934; MWA[111] = -0.2614; + MWA[112] = -0.2325; MWA[113] = -0.2064; + MWA[114] = -0.183; MWA[115] = -0.1621; + MWA[116] = -0.1433; MWA[117] = -0.1265; + MWA[118] = -0.1115; MWA[119] = -9.813E-2; + MWA[120] = -8.624E-2; MWA[121] = -7.569E-2; + MWA[122] = -6.632E-2; MWA[123] = -5.803E-2; + MWA[124] = -5.071E-2; MWA[125] = -4.424E-2; + MWA[126] = -3.855E-2; MWA[127] = -3.353E-2; + MWA[128] = -2.914E-2; MWA[129] = -2.528E-2; + MWA[130] = -0.0219; MWA[131] = -1.894E-2; + MWA[132] = -1.637E-2; MWA[133] = -1.412E-2; + MWA[134] = -1.217E-2; MWA[135] = -1.046E-2; + MWA[136] = -8.988E-3; MWA[137] = -7.72E-3; + MWA[138] = -6.567E-3; MWA[139] = -5.802E-3; + MWA[140] = -0.0053; MWA[141] = -4.7E-4; + MWA[142] = -4.3E-4; + + for (j = 0; j <= 11; j++) + CoWA[j] = 0.0; + + CoWA[12] = 1.25E-5; CoWA[13] = 3.87E-5; + CoWA[14] = 1.004E-4; CoWA[15] = 2.703E-4; + CoWA[16] = 6.507E-4; CoWA[17] = 1.3985E-3; + CoWA[18] = 2.8353E-3; CoWA[19] = 5.1911E-3; + CoWA[20] = 8.9486E-3; CoWA[21] = 1.41773E-2; + CoWA[22] = 2.16551E-2; CoWA[23] = 3.1489E-2; + CoWA[24] = 4.34123E-2; CoWA[25] = 5.78719E-2; + CoWA[26] = 7.46921E-2; CoWA[27] = 9.45265E-2; + CoWA[28] = 1.165183E-1; CoWA[29] = 1.406353E-1; + CoWA[30] = 1.662849E-1; CoWA[31] = 1.929895E-1; + CoWA[32] = 2.189347E-1; CoWA[33] = 2.457772E-1; + CoWA[34] = 2.704794E-1; CoWA[35] = 2.947906E-1; + CoWA[36] = 3.169854E-1; CoWA[37] = 3.377435E-1; + CoWA[38] = 3.573555E-1; CoWA[39] = 3.751205E-1; + CoWA[40] = 3.906829E-1; CoWA[41] = 4.039806E-1; + CoWA[42] = 4.142483E-1; CoWA[43] = 4.22779E-1; + CoWA[44] = 4.288013E-1; CoWA[45] = 4.330353E-1; + CoWA[46] = 4.34452E-1; CoWA[47] = 4.338138E-1; + CoWA[48] = 4.31504E-1; CoWA[49] = 4.272541E-1; + CoWA[50] = 4.220568E-1; CoWA[51] = 4.158229E-1; + CoWA[52] = 4.083281E-1; CoWA[53] = 3.981182E-1; + CoWA[54] = 3.871678E-1; CoWA[55] = 3.755527E-1; + CoWA[56] = 3.628823E-1; CoWA[57] = 3.520135E-1; + CoWA[58] = 3.400924E-1; CoWA[59] = 3.280532E-1; + CoWA[60] = 3.139477E-1; CoWA[61] = 2.997087E-1; + CoWA[62] = 2.849179E-1; CoWA[63] = 2.710475E-1; + CoWA[64] = 2.576478E-1; CoWA[65] = 2.449155E-1; + CoWA[66] = 2.317447E-1; CoWA[67] = 2.193161E-1; + CoWA[68] = 2.072622E-1; CoWA[69] = 1.956955E-1; + CoWA[70] = 1.846514E-1; CoWA[71] = 1.734096E-1; + CoWA[72] = 1.622678E-1; CoWA[73] = 1.520447E-1; + CoWA[74] = 1.416351E-1; CoWA[75] = 1.32136E-1; + CoWA[76] = 1.231861E-1; CoWA[77] = 1.150411E-1; + CoWA[78] = 1.071536E-1; CoWA[79] = 9.9465E-2; + CoWA[80] = 9.22347E-2; CoWA[81] = 8.54394E-2; + CoWA[82] = 7.87697E-2; CoWA[83] = 7.23848E-2; + CoWA[84] = 6.6587E-2; CoWA[85] = 6.15849E-2; + CoWA[86] = 5.6573E-2; CoWA[87] = 5.17893E-2; + CoWA[88] = 4.70011E-2; CoWA[89] = 4.2886E-2; + CoWA[90] = 3.91224E-2; CoWA[91] = 3.53163E-2; + CoWA[92] = 3.20884E-2; CoWA[93] = 2.92264E-2; + CoWA[94] = 2.66058E-2; CoWA[95] = 2.37352E-2; + CoWA[96] = 2.14669E-2; CoWA[97] = 1.94848E-2; + CoWA[98] = 1.75591E-2; CoWA[99] = 1.58232E-2; + CoWA[100] = 1.40302E-2; CoWA[101] = 1.24349E-2; + CoWA[102] = 1.11856E-2; CoWA[103] = 9.9765E-3; + CoWA[104] = 8.9492E-3; CoWA[105] = 8.0063E-3; + CoWA[106] = 7.1509E-3; CoWA[107] = 6.3196E-3; + CoWA[108] = 5.6856E-3; CoWA[109] = 5.0686E-3; + CoWA[110] = 4.5085E-3; CoWA[111] = 3.9895E-3; + CoWA[112] = 3.4804E-3; CoWA[113] = 3.0447E-3; + CoWA[114] = 2.7012E-3; CoWA[115] = 2.2984E-3; + CoWA[116] = 2.0283E-3; CoWA[117] = 1.7399E-3; + CoWA[118] = 1.5032E-3; CoWA[119] = 1.3267E-3; + CoWA[120] = 1.1531E-3; CoWA[121] = 9.92E-4; + CoWA[122] = 9.211E-4; CoWA[123] = 8.296E-4; + CoWA[124] = 6.991E-4; CoWA[125] = 5.84E-4; + CoWA[126] = 5.12E-4; CoWA[127] = 4.314E-4; + CoWA[128] = 3.593E-4; CoWA[129] = 3.014E-4; + CoWA[130] = 2.401E-4; CoWA[131] = 2.004E-4; + CoWA[132] = 1.614E-4; CoWA[133] = 1.257E-4; + CoWA[134] = 1.112E-4; CoWA[135] = 9.22E-5; + CoWA[136] = 8.77E-5; CoWA[137] = 6.22E-5; + CoWA[138] = 4.93E-5; CoWA[139] = 3.92E-5; + CoWA[140] = 3.15E-5; CoWA[141] = 1.03E-5; + CoWA[142] = 9.6E-6; +} + + +/*-------------------------------------------------------------------------*/ + +double fdist_WatsonG (long n, double X) +/* + * Approximation of the cumulative distribution function of the + * fdist_WatsonG statistics by the cubic spline function. + * Y[.] - tabular value of the statistic; + * M[.] - tabular value of the first derivative; + */ +{ + static int WatsonFlag = 0; + const double MinArg = 0.15; + const double MaxArg = 1.5; + const double MinTab = 0.1; + const double Step = 0.01; + int i, j; + double Tj; + double Ti; + double R; + double P; + double H; + double Res; + + util_Assert (n > 0, "fdist_WatsonG: N <= 0"); + + if (n == 1) /* n = 1, degenerate case */ + return 0.5; + + if (!WatsonFlag) { + /* Initialization of the interpolation table */ + WatsonGInit (); + WatsonFlag = 1; + } + + if (X <= MinArg) + return 0.0; + if (X >= 10.0) + return 1.0; + if (X > MaxArg) { + R = exp (19.0 - 20.0 * X); + Res = 1.0 - R; + /* Empirical Correction in 1/sqrt(n) */ + R = exp (13.34 - 15.26 * X) / sqrt ((double) n); + Res += R; + /* The correction in 1/sqrt(n) is not always precise */ + if (Res >= 1.0) + return 1.0; + else + return Res; + } + + /* Search of the correct slot in the interpolation table */ + i = (int) ((X - MinTab) / Step) + 1; + Ti = MinTab + i * Step; + Tj = Ti - Step; + /* Approximation within the slot */ + j = i - 1; + H = X - Tj; + R = Ti - X; + P = Step * Step / 6.0; + Res = ((MWA[j] * R * R * R + MWA[i] * H * H * H) / 6.0) / Step; + Res += ((YWA[j] - MWA[j] * P) * R + (YWA[i] - MWA[i] * P) * H) / Step; + + /* Empirical correction in 1/sqrt(n) */ + Res += (CoWA[i] * H + CoWA[j] * R) / (Step * sqrt ((double) n)); + + if (Res >= 1.0) + return 1.0; + return Res; +} + + +/*=========================================================================*/ +#define AD_X0 0.38629436111989062 +#define AD_X1 37.816242111357 + +static double AD_N_1 (double x) +{ + /* The Anderson-Darling distribution for N = 1 */ + double term; + if (x <= AD_X0) + return 0.0; + if (x >= AD_X1) + return 1.0; + if (x - AD_X0 >= 1.0e-3) + term = 1.0 - 4.0 * exp (-x - 1.0); + else { + const double q = x - AD_X0; + term = q*(1.0 - q*(0.5 - q/6.0)); + } + return sqrt (term); +} + +#undef AD_X0 +#undef AD_X1 +/*=========================================================================*/ + +double fdist_AndersonDarling (long N, double x) +{ + if (1 == N) + return AD_N_1 (x); + util_Assert (N > 0, "fdist_AndersonDarling: N <= 0"); + + if (x <= 0.0) + return 0.0; + if (x >= fdist_XBIG) + return 1.0; + + if (x <= 0.2) { + /* Sinclair and Spurr lower tail approximation (3.6) */ + double q; + q = 1.784 + 0.9936*x + 0.03287/x - (2.018 + 0.2029/x)/sqrt (x); + if (q < -18.0) + return exp(q); + q = 1.0 + exp(q); + return 1.0 - 1.0 / q; + } + return 1.0 - fbar_AndersonDarling (N, x); +} + + +/*=========================================================================*/ +/* The following code is part of Marsaglia's file ADinf.c. + Very little has been changed to adapt it to ProbDist. The file was + downloaded from the site of the Journal of Statistical Software + http://www.jstatsoft.org/v09/i02/ +*/ + +/*--------------------------------------------------------------------------*/ + /* This is file ADinf.c */ +/* +A procedure for evaluating the limiting distribution of the + Anderson-Darling statistic A_n= +-n-(1/n)[ln(x_1(1-x_n)+3ln(x_2(1-x_{n-1})+5ln(x_3(1-x_{n-2})+... + +(2n-1)ln(x_n(1-x_1))] + where x_1infty} Pr[A_n 150.) + return 0.; + a = 2.22144146907918 * exp (-t) / sqrt (t); + /* initialization requires cPhi */ + /* if you have erfc(), replace 2*cPhi(sqrt(2*t)) with erfc(sqrt(t)) */ + b = 3.93740248643060 * 2. * fbar_Normal2 (sqrt (2 * t)); + + r = z * .125; + f = a + b * r; + for (i = 1; i < 200; i++) { + c = ((i - .5 - t) * b + t * a) / i; + a = b; + b = c; + r *= z / (8 * i + 8); + if (fabs (r) < 1e-40 || fabs (c) < 1.e-40) + return f; + fnew = f + c * r; + if (f == fnew) + return f; + f = fnew; + } + return f; +} + + +static double ADinf (double z) +{ + int j; + double ad, adnew, r; + if (z < .01) + return 0.; /* avoids exponent limits; ADinf(.01)=.528e-52 */ + r = 1. / z; + ad = r * ADf (z, 0); + for (j = 1; j < 100; j++) { + r *= (.5 - j) / j; + adnew = ad + (4 * j + 1) * r * ADf (z, j); + if (ad == adnew) { + return ad; + } + ad = adnew; + } + return ad; + +} + + +/*------------------------------------------------------------------------*/ +/* The following code is part of Marsaglia's file AnDarl.c. + Very little has been changed to adapt it to ProbDist. The file was + downloaded from the site of the Journal of Statistical Software + http://www.jstatsoft.org/v09/i02/ +--------------------------------------*/ + +/* + Anderson-Darling test for uniformity. Given an ordered set + x_10. */ +static double adinf (double z) +{ + if (z < 2.) + return exp (-1.2337141 / z) / sqrt (z) * (2.00012 + (.247105 - + (.0649821 - (.0347962 - (.011672 - + .00168691 * z) * z) * z) * z) * z); + /* max |error| < .000002 for z<2, (p=.90816...) */ + return + exp (-exp (1.0776 - (2.30695 - (.43424 - (.082433 - (.008056 - + .0003146 * z) * z) * z) * z) * z)); + /* max |error|<.0000008 for 4 .8) { + v = (-130.2137 + (745.2337 - (1705.091 - (1950.646 - (1116.360 - + 255.7844 * x) * x) * x) * x) * x) / n; + return x + v; + } + c = .01265 + .1757 / n; + if (x < c) { + v = x / c; + v = sqrt (v) * (1. - v) * (49 * v - 102); + return x + v * (.0037 / (n * n) + .00078 / n + .00006) / n; + } + v = (x - c) / (.8 - c); + v = -.00022633 + (6.54034 - (14.6538 - (14.458 - (8.259 - + 1.91864 * v) * v) * v) * v) * v; + return x + v * (.04213 + .01365 / n) / n; +} + +/* You must give the ADtest(int n, double *x) routine a sorted array + x[0]<=x[1]<=..<=x[n-1] + that you are testing for uniformity. + It will return the p-value associated + with the Anderson-Darling test, using + the above adinf() and errfix( , ) + Not well-suited for n<7, + (accuracy could drop to 3 digits). +*/ + + +/*=========================================================================*/ +#if 0 + +double fdist_AndersonDarling2 (long N, double x) +{ + /* This version uses the more exact limiting distribution ADinf */ + if (1 == N) + return AD_N_1 (x); + return AD (N, x, 0); +} + +#else + +double fdist_AndersonDarling2 (long N, double x) +{ + /* This version uses the approximate limiting distribution adinf */ + if (1 == N) + return AD_N_1 (x); + return AD ((int)N, x, 1); +} + +#endif +/*=========================================================================*/ + + +/***************************************\ + * + * DISCRETE DISTRIBUTIONS + * +\***************************************/ + + + + +/*=========================================================================*/ + +double fdist_Geometric (double p, long s) +{ + util_Assert (p >= 0.0 && p <= 1.0, "fdist_Geometric: p not in [0, 1]"); + if (s < 0) + return 0.0; + if (p >= 1.0) /* In fact, p == 1 */ + return 1.0; + if (p <= 0.0) /* In fact, p == 0 */ + return 0.0; + return 1.0 - pow (1.0 - p, (double) (s + 1)); +} + + +/*=========================================================================*/ + +double fdist_Poisson1 (double lam, long s) +/* + * On our machine, computing a value using fdist_Gamma is faster than the + * naive computation for lamlim > 150.0, slower for lamlim < 150.0 + */ +{ + const double lamlim = 150.0; + long i; + double term, sum; + + util_Assert (lam >= 0.0, "fdist_Poisson1: lambda < 0"); + if (lam == 0.0) + return 1.0; + if (s < 0) + return 0.0; + + /* If lam > lamlim, we use the Chi2 distribution according to the exact + relation, with 2s + 2 degrees of freedom fdist_Poisson (lam, s) = 1 - + fdist_ChiSquare (2s + 2, 2*lam) which also equals 1 - fdist_Gamma (s + + 1, lam) */ + if (lam > lamlim) + return fbar_Gamma (s + 1.0, 15, lam); + + /* Naive computation: sum all prob. from i = 0 to i = s */ + sum = term = exp (-lam); + for (i = 1; i <= s; i++) { + term *= lam / i; + sum += term; + } + return sum; +} + + +/*=========================================================================*/ + +double fdist_Poisson2 (fmass_INFO W, long s) +{ + double lam; + util_Assert (W != NULL, "fdist_Poisson2: fmass_INFO is NULL pointer"); + lam = W->paramR[0]; + + if (s < 0) + return 0.0; + if (lam == 0.0) + return 1.0; + + /* For large lam, we use the Chi2 distribution according to the exact + relation, with 2s + 2 degrees of freedom + + fdist_Poisson (lam, s) = 1 - fdist_ChiSquare (2s + 2, 2*lam) + + which equals also 1 - fdist_Gamma (s + 1, lam) */ + if (W->cdf == NULL) + return fbar_Gamma (s + 1.0, 15, lam); + + if (s >= W->smax) + return 1.0; + + if (s < W->smin) { + /* Sum RMAX dominant terms to get a few decimals in the lower tail. One + could also call fbar_Gamma (s + 1.0, 15, lam) */ + const long RMAX = 20; + long i; + double term = fmass_PoissonTerm1 (lam, s); + double Sum = term; + i = s; + while (i > 0 && i >= s - RMAX) { + term = term * i / lam; + i--; + Sum += term; + } + return Sum; + } + + if (s <= W->smed) + return W->cdf[s - W->smin]; + else + /* We keep the complementary distribution in the upper part of cdf */ + return 1.0 - W->cdf[s + 1 - W->smin]; +} + + +/*=========================================================================*/ + +double fdist_Binomial1 (long n, double p, long s) +{ + const int nlim1 = 10000; + const double varlim = 100.0; + double epsilon = fmass_Epsilon; + double y, z, q = 1.0 - p; + double sum, term, termmid; + long i, mid; + int flag = 0; + + util_Assert (p >= 0.0 && p <= 1.0, "fdist_Binomial1: p not in [0, 1]"); + util_Assert (n >= 0, "fdist_Binomial1: n < 0"); + + if (0 == n) + return 1.0; + if (s < 0) + return 0.0; + if (s >= n) + return 1.0; + if (p <= 0.0) + return 1.0; + if (p >= 1.0) + return 0.0; /* For any s < n */ + + if (n < nlim1) { /* Exact Binomial */ + /* Sum RMAX terms to get a few decimals in the lower tail */ + const long RMAX = 20; + mid = (long) ((n + 1) * p); + if (mid > s) + mid = s; + sum = term = termmid = fmass_BinomialTerm3 (n, p, mid); + + z = q / p; + i = mid; + while (term >= epsilon || i >= mid - RMAX) { + term *= z * i / (n - i + 1); + sum += term; + i--; + if (i == 0) break; + } + + z = p / q; + term = termmid; + for (i = mid; i < s; i++) { + term *= z * (n - i) / (i + 1); + if (term < epsilon) + break; + sum += term; + } + return sum; + + } else { + if ((p > 0.5) || ((p == 0.5) && (s > n / 2))) { + /* use F(p, n, s) = 1 - F(q, n, n-s-1) */ + p = q; + q = 1.0 - p; + flag = 1; + s = n - s - 1; + } + if (n * p * q > varlim) { /* Normal approximation */ + /* Uses the Camp-Paulson approximation based on the F-distribution. + Its maximum absolute error is smaller than 0.007 / sqrt (npq). + Ref: W. Molenaar; Approximations to the Poisson, Binomial,.... + QA273.6 M64, p. 93 (1970) */ + term = pow ((s + 1) * q / ((n - s) * p), 1.0 / 3.0); + y = term * (9 - 1.0 / (s + 1)) - 9 + 1.0 / (n - s); + z = 3.0 * sqrt (term * term / (s + 1) + 1.0 / (n - s)); + y /= z; + if (flag) { + return fbar_Normal1 (y); + } else { + return fdist_Normal2 (y); + } + + } else { /* Poisson approximation */ + /* Uses a Bol'shev approximation based on the Poisson distribution. + Error is O(1/n^4) as n -> infinity. Ref: W. Molenaar; + Approximations to the Poisson, Binomial,.... QA273.6 M64, p. 107, + Table 6.2, Formule lambda_9 (1970). */ + y = (2 * n - s) * p / (2.0 - p); + z = (2.0 * y * y - s * y - (double)s * s - 2 * s) / (6 * (2 * n - + (double)s) * (2 * n - s)); + z = y / (1 - z); + if (flag) { + return fbar_Poisson1 (z, s - 1); + } else { + return fdist_Poisson1 (z, s); + } + } + } +} + + +/*=========================================================================*/ + +double fdist_Binomial2 (fmass_INFO W, long s) +{ + double p; + long n; + + util_Assert (W != NULL, "fdist_Binomial2: fmass_INFO is NULL pointer"); + n = W->paramI[0]; + p = W->paramR[0]; + util_Assert (p >= 0.0 && p <= 1.0, "fdist_Binomial2: p not in [0, 1]"); + + if (0 == n) + return 1.0; + if (s < 0) + return 0.0; + if (s >= n) + return 1.0; + if (p == 0.0) + return 1.0; + if (p == 1.0) + return 0.0; + + if (W->cdf != NULL) { + if (s >= W->smax) + return 1.0; + if (s < W->smin) { + /* Sum RMAX terms to get a few decimals in the lower tail */ + const long RMAX = 20; + long i; + double term = fmass_BinomialTerm3 (n, p, s); + double Sum = term; + const double z = (1.0 - p) / p; + i = s; + while (i > 0 && i >= s - RMAX) { + term *= z * i / (n - i + 1); + i--; + Sum += term; + } + return Sum; + } + if (s <= W->smed) + return W->cdf[s - W->smin]; + else + /* We keep the complementary distribution in the upper part of cdf */ + return 1.0 - W->cdf[s + 1 - W->smin]; + + } else { + return fdist_Binomial1 (n, p, s); + } +} + + +/*=========================================================================*/ + +double fdist_NegaBin1 (long n, double p, long s) +{ + const double epsilon = fmass_Epsilon; + const long lim1 = 100000; + double sum, term, termmode; + long i, mode; + + util_Assert (p >= 0.0 && p <= 1.0, "fdist_NegaBin1: p not in [0, 1]"); + util_Assert (n > 0, "fdist_NegaBin1: n < 1"); + + if (s < 0) + return 0.0; + if (p >= 1.0) /* In fact, p == 1 */ + return 1.0; + if (p <= 0.0) /* In fact, p == 0 */ + return 0.0; + + /* Compute the maximum term */ + mode = 1 + (long) ((n * (1.0 - p) - 1.0) / p); + if (mode > s) + mode = s; + + if (mode <= lim1) { + sum = term = termmode = fmass_NegaBinTerm1 (n, p, mode); + for (i = mode; i > 0; i--) { + term *= i / ((1.0 - p) * (n + i - 1)); + if (term < epsilon) + break; + sum += term; + } + + term = termmode; + for (i = mode; i < s; i++) { + term *= (1.0 - p) * (n + i) / (i + 1); + if (term < epsilon) + break; + sum += term; + } + if (sum <= 1.0) + return sum; + else + return 1.0; + + } else { + return 1.0 - fdist_Binomial1 (s + n, p, n - 1); + } +} + + +/*=========================================================================*/ + +double fdist_NegaBin2 (fmass_INFO W, long s) +{ + double p; + long n; + + util_Assert (W != NULL, "fdist_NegaBin2: fmass_INFO is NULL pointer"); + n = W->paramI[0]; + p = W->paramR[0]; + util_Assert (p >= 0.0 && p <= 1.0, "fdist_NegaBin2: p not in [0, 1]"); + + if (s < 0) + return 0.0; + if (p >= 1.0) /* In fact, p == 1 */ + return 1.0; + if (p <= 0.0) /* In fact, p == 0 */ + return 0.0; + + if (W->cdf != NULL) { + if (s >= W->smax) + return 1.0; + if (s < W->smin) + return fdist_NegaBin1 (n, p, s); + if (s <= W->smed) + return W->cdf[s - W->smin]; + else + /* We keep the complementary distribution in the upper part of cdf */ + return 1.0 - W->cdf[s + 1 - W->smin]; + + } else { + return fdist_NegaBin1 (n, p, s); + } +} + + +/*=========================================================================*/ + +double fdist_Scan (long N, double d, long m) +{ + return 1.0 - fbar_Scan (N, d, m); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/probdist/fdist.tex b/TESTU01/TestU01-1.2.3/probdist/fdist.tex new file mode 100644 index 0000000..f6789e1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/fdist.tex @@ -0,0 +1,926 @@ +\defmodule {fdist} + +This module provides procedures to compute (or approximate) +the distribution functions of several standard types of random variables +and of certain goodness-of-fit test statistics. +Recall that the distribution function of a continuous random variable $X$ +with density $f$ is +\eq + F(x) = P[X\le x] = \int_{-\infty}^x f(x)dx +\endeq +while that of a discrete random variable $X$ with mass function $f$ +over the set of integers is +\eq + F(x) = P[X\le x] = \sum_{s=-\infty}^x f(x). +\endeq +All the procedures in this module return $F(x)$ for some +probability distribution. + +Most distributions are implemented only in standardized form here, +i.e., with the location parameter set to 0 and the scale parameter +set to 1. To shift the distribution by $x_0$ and rescale by $c$, +it suffices to replace $x$ by $(x-x_0)/c$ in the argument when +calling the function. + +%\begin{detailed} + For some of the discrete distributions, the value of $F(x)$ can be + simply recovered from a table that would have been previously + constructed; see the module {\tt fmass} for the details. + This permits one to avoid recomputing the sums. +%\end{detailed} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip\hrule\medskip +\code\hide +/* fdist.h for ANSI C */ +#ifndef FDIST_H +#define FDIST_H +\endhide +#include "gdef.h" +#include "fmass.h" +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Continuous distributions} + +\code + +double fdist_Unif (double x); +\endcode + \tab + Returns $x$ for $x \in [0, 1]$, returns 0 for $x < 0$, and returns 1 + for $x > 1$. This is the uniform distribution function over $[0, 1]$. + \endtab +\code + + +double fdist_Expon (double x); +\endcode + \tab + Returns + \eq + F(x) = 1 - e^{- x} \eqlabel{eq:Fexpon} + \endeq + for $x > 0$, and 0 for $x<0$. This is the standard exponential + distribution \cite{tJOH95a} with mean 1. + \endtab +\code + + +double fdist_Weibull (double alpha, double x); +\endcode + \tab + Returns + \eq + F(x) = 1 - e^{- x^\alpha}, \eqlabel{eq:Fweibull} + \endeq + for $x>0$, and 0 for $x\le 0$. + This is the standard Weibull distribution function \cite{tJOH95a} with shape + parameter $\alpha$. + Restriction: $\alpha > 0$. + \hpierre {D'habitude la Weibull a 2 ou 3 param\'etres. Il faudrait + peut-etre ajouter les autres param\`etres. M\^eme chose pour les autres + loi de probabilit\'es qui suivent? } + \endtab +\code + + +double fdist_ExtremeValue (double x); +\endcode + \tab + Returns + \eq + F(x) = e^{-e^{-x}}, \eqlabel{eq:Fextreme} + \endeq + the standard extreme value distribution function \cite{tJOH95b}. + \endtab +\code + + +double fdist_Logistic (double x); +\endcode + \tab + Returns + \eq F(x) = \frac 1{1 + e^{-x}} = + \frac12\left(1 + \tanh \left(\frac{x}{2}\right)\right), + \eqlabel{eq:Flogistic} + \endeq + the standard logistic distribution function \cite{tJOH95b}. + \endtab +\code + + +double fdist_Pareto (double c, double x); +\endcode + \tab + Returns + \eq + F(x) = 1 - \frac 1 {x^c}, + \eqlabel{eq:Fpareto} + \endeq + for $x\ge 1$ and 0 for $x<1$. This is + the standard Pareto distribution function \cite{tJOH95a}. + Restriction: $c > 0$. + \endtab +\code + + +double fdist_Normal1 (double x); +\endcode + \tab + Returns an approximation of $\Phi(x)$, where $\Phi$ is the standard normal + distribution function, with mean 0 and variance 1. + Uses the approximation given in \cite[page 90]{tKEN80a}. This distribution + is less precise than {\tt fdist\_Normal2} in the lower tail, as it will + not compute probabilities smaller than {\tt DBL\_EPSILON}. + \endtab +\code + + +double fdist_Normal2 (double x); +\endcode + \tab + Returns an approximation of $\Phi(x)$, + where $\Phi$ is the standard normal distribution function, + with mean 0 and variance 1. + Uses the Chebyshev approximation proposed in \cite{tSCH78a}, + which gives 15 decimals of precision nearly everywhere. +% In the paper, the author gives the coefficients with 30 decimals of +% precision. + This function is 1.5 times slower than {\tt fdist\_Normal1}. + \endtab +\code + + +#ifdef HAVE_ERF + double fdist_Normal3 (double x); +#endif +\endcode + \tab + \hpierre{Je trouve ces {\tt ifdef} tr\`es laids. Pas moyen de cacher + cela d'une certaine mani\`ere? De plus {\tt HAVE\_ERF} n'est pas + d\'efini ni expliqu\'e. } +\hrichard {Toutes les macros HAVE OU USE proviennent du module gdef de mylib. +Si on veut que l'utilisateur puisse les utiliser ou non, d\'ependant +de sa machine, il faut qu'il les voit; sinon, il faudra l'\'eliminer.} + Returns an approximation of $\Phi(x)$, + where $\Phi$ is the standard normal distribution function, + with mean 0 and variance 1. + Uses the {\tt erf} function from the standard Unix C library. The macro + {\tt HAVE\_ERF} from {\tt mylib/gdef} must be defined. On some machines, + this function is twice as fast as {\tt fdist\_Normal1}. + \endtab +\code + + +double fdist_Normal4 (double x); +\endcode + \tab + Returns an approximation of $\Phi(x)$, where $\Phi$ is the standard + normal distribution function, with mean 0 and variance 1. + Uses Marsaglia's et al \cite{rMAR94b} fast method + with tables lookup. Returns 15 decimal digits of precision. + This function is as fast as {\tt fdist\_Normal1} (no more no less). + \endtab +\code + + +double fdist_BiNormal1 (double x, double y, double rho, int ndig); +\endcode + \tab + Returns the value $u$ of the standard bivariate normal distribution, + given by +\begin{eqnarray} + u &=& \frac{1}{2\pi\sqrt{1 - \rho^2}} \int_{-\infty}^x + \int_{-\infty}^y e^{-T} dy\, dx \label{eq.binormal1} \\[5pt] + T &=& \frac{x^2 -2\rho x y + y^2}{2(1-\rho^2)}, \nonumber +\end{eqnarray} + where $\rho = ${ \tt rho} is the correlation between $x$ and $y$, and + \texttt{ndig} is the number of decimal digits of accuracy. + The code was translated from the Fortran program written + by T. G. Donnelly \cite{tDON73a} and copyrighted by the ACM (see + \url{http://www.acm.org/pubs/copyright_policy/#Notice}). The absolute error + is expected to be smaller than $10^{-d}$, where $d={}$\texttt{ndig}. + Restriction: \texttt{ndig}${} \le 15$. + \endtab +\code + + +double fdist_BiNormal2 (double x, double y, double rho); +\endcode + \tab + Returns the value of the standard bivariate normal distribution as + defined in (\ref{eq.binormal1}) above. + It was translated directly from the Matlab code written by Alan Genz + and available from his web page (the code is copyrighted by Alan Genz, + and is included in this package with the kind permission of its author). + The algorithm, described in \cite{tGEN04a}, is a modified form of the + algorithm proposed in \cite{tDRE89a}. The program's accuracy results + in an absolute error less than $5 \cdot 10^{-16}$. + \endtab +\code + + +double fdist_LogNormal (double mu, double sigma, double x); +\endcode + \tab + Returns the lognormal distribution function, defined by \cite{tJOH95a} + \eq + F(x) = \Phi \left(\frac{\ln (x) - \mu}{\sigma}\right) + \endeq + for $x>0$ and 0 for $x\le 0$, + where $\Phi$ is the standard normal distribution. + Restriction: $\sigma > 0$. + \endtab +\code + + +double fdist_JohnsonSB (double alpha, double beta, double a, double b, + double x); +\endcode + \tab + Returns the Johnson JSB distribution function \cite{sLAW00a}: + \eq + F(x) = \Phi\left(\alpha + \beta\ln\left(\frac{x-a}{b-x} \right)\right), + \endeq + where $\Phi$ is the standard normal distribution. + Restrictions: $\beta>0$, $a < b$, and $a \le x \le b$. + \endtab +\code + + +double fdist_JohnsonSU (double alpha, double beta, double x); +\endcode + \tab + Returns the Johnson JSU distribution function \cite{sLAW00a}: + \eq + F(x) = \Phi\left(\alpha + \beta\ln\left(x + + \sqrt{x^2 + 1} \right)\right) + \endeq + where $\Phi$ is the standard normal distribution. + Restriction: $\beta>0$. + \endtab +\code + + +double fdist_ChiSquare1 (long k, double x); +\endcode + \tab + Returns an approximation of the chi-square distribution function + with $k$ degrees of freedom, +\iffalse + whose density is + \eq + f(x) = \eqlabel{eq:Fchi2} + \endeq + for $x\ge 0$. +\fi + which is a special case of the gamma distribution, with shape parameter + $k/2$ and scale parameter $1/2$. + Uses the approximation given in \cite[p.116]{tKEN80a} for $k\le 1000$, + and the normal approximation for $k > 1000$. Gives no more than 4 + decimals of precision for $k > 1000$. + \endtab +\code + + +double fdist_ChiSquare2 (long k, int d, double x); +\endcode + \tab + Returns an approximation of the chi-square distribution function + with $k$ degrees of freedom, by calling {\tt fdist\_Gamma (k/2, d, x/2)}. + The function will do its best to return $d$ decimals + digits of precision (but there is no guarantee). + For $k$ not too large (e.g., $k \le 1000$), + $d$ gives a good idea of the precision attained. + Restrictions: $k>0$ and $0 < d \le 15$. + \endtab +\code + + +double fdist_Student1 (long n, double x); +\endcode + \tab + Returns the approximation of \cite[p.96]{tKEN80a} for the + {\em Student-$t$\/} distribution function with $n$ degrees of freedom, + whose density is + \eq + f(x) = \frac{\Gamma\left((n + 1)/2 \right)} + {\Gamma(n/2) \sqrt{\pi n}} + \left[1 + \frac{x^2}{n}\right]^{-(n+1)/2}, + \qquad \qquad -\infty < x < \infty. \eqlabel{eq:fstudent} + \endeq + Gives at least 12 decimals of precision for $n \le 10^3$, and at least + 10 decimals for $10^3 < n \le 10^5$. + Restriction: $n>0$. + \endtab +\code + + +double fdist_Student2 (long n, int d, double x); +\endcode + \tab + Returns an approximation of the {\em Student-$t$\/} distribution + function with $n$ degrees of freedom, with density (\ref{eq:fstudent}). + Uses the relationship (see \cite{tJOH95a}) + \eq + 2 F(x) = \left\{ \begin{array}{ll} + I_{n/2, 1/2}(n/(n+x^2)) & \mbox{ for } x<0,\\[5pt] + I_{1/2, n/2}(x^2/(n+x^2)) & \mbox{ for } x\ge 0, + \end{array}\right. \eqlabel{eq:student-beta} + \endeq + where $I_{p,q}$ is the {\em beta\/} distribution function with + parameters $p$ and $q$ +\hrichard {Dans Kotz et Johnson et aussi dans Kendall, + la distribution {\em beta\/} est + not\'ee $I_{p, q}(x)$. Je crois que \c ca pourrait \^etre assez standard. } + (also called the incomplete {\em beta\/} ratio) defined in + (\ref{eq:Fbeta}), which is approximated by calling {\tt fdist\_Beta}. + The function tries to return $d$ decimals digits of precision + (but there is no guarantee). + Restrictions: $n>0$ and $0 < d \le 15$. + \endtab +\code + + +double fdist_Gamma (double a, int d, double x); +\endcode + \tab + Returns an approximation, based on \cite{tBAT70a}, of the {\em gamma\/} + distribution function with parameter $a$, whose density is + \eq + f(x) = \frac {x^{a-1} e^{-x}}{\Gamma(a)}, + \endeq + for $x\ge 0$, where $\Gamma$ is the gamma function, defined by + \eq + \Gamma(\alpha) = \int_0^\infty x^{\alpha-1} e^{-x} dx. + \label{eq:Gamma} + \endeq +%% One has $\Gamma(\alpha) = (\alpha-1)!$ when $\alpha$ is an integer. + The function tries to return $d$ decimals digits of precision. +%, but there is no guarantee. + For $a$ not too large (e.g., $a \le 1000$), + $d$ gives a good idea of the precision attained. +%% For d = 16, gives at least 13 decimals of precision for $a \le 1000$, +%% and at least 10 decimals for $1000 < a \le 100000$. + For $a \ge 100000$, uses a normal approximation given in \cite{tPEI68a}. + Restrictions: $a>0$ and $0 < d \le 15$. + \endtab +\code + + +double fdist_Beta (double p, double q, int d, double x); +\endcode + \tab + Returns an approximation of + \eq + F(x) = I_{p,q}(x) + = \int_0^x \frac {t^{p-1} (1 - t)^{q-1}}{B(p, q)} dt, + \eqlabel{eq:Fbeta} + \endeq + the {\em beta\/} distribution function with parameters $p$ and $q$, + evaluated at $x \in [0, 1]$, where $B(p,q)$ is the {\em beta\/} function + defined by + \eq + B(p,q) = \frac{\Gamma (p) \Gamma (q)}{ \Gamma (p+q)}, + \endeq + where $\Gamma (x)$ is the Gamma function defined in (\ref{eq:Gamma}). + For $\max(p, q) \le 1000$, use a recurrence relation in $p$ and $q$ for + {\tt fdist\_Beta}, given in \cite{tGAU64a,tGAU64b}. + Else, if $\min(p, q) \le 30$, + use an approximation due to Bol'shev \cite{tMAR78a}. Otherwise, use a + normal approximation \cite{tPEI68a}. + The function tries to return $d$ decimals digits of precision. + For $d\le 13$, when the normal approximation is {\em not\/} used, + $d$ gives a good idea of the precision attained. + Restrictions: $p>0$, $q>0$, $x \in [0, 1]$ and $0 < d \le 15$. + \endtab +\code + + +double fdist_BetaSymmetric (double p, double x); +\endcode + \tab + Returns an approximation of the symmetrical {\em beta\/} distribution + function $F(x)$ with parameters $p = q$ as defined in (\ref{eq:Fbeta}). + Uses four different hypergeometric series + (for the four cases $x$ close to 0 and $p \le 1$, + $x$ close to 0 and $p > 1$, $x$ close to 1/2 and $p \le 1$, + and $x$ close to 1/2 and $p > 1$) + to compute $F(x)$. + For $p > 100000$, uses a normal approximation given in \cite{tPEI68a}. + Restrictions: $p>0$ and $x \in [0, 1]$. + \endtab +\code + + +double fdist_KSPlus (long n, double x); +\endcode + \tab Returns $p = P[D_n^+ \le x]$, where + \eq \eqlabel{eq:KSPlus} + D_n^+ = \sup_{-\infty < s < \infty} [\hat F_n(s) - F(s)]^+ + \endeq + is the positive Kolmogorov-Smirnov statistic for a sample of size $n$ + whose empirical distribution function is $\hat F_n$, + under the hypothesis that the observations follow a continuous distribution + function $F$. + (Recall that $x^+$ represents $\max (0, x)$, the positive part of $x$.) + The statistic + \eq \eqlabel{eq:KSMinus} + D_n^- = \sup_{-\infty < s < \infty} [F(s) - \hat F_n(s)]^+ + \endeq + has the same distribution as $D_n^+$. + Procedures for computing these statistics are availables in + module {\tt gofs}. + The distribution function of $D_n^+$ can be approximated via the + following expressions: + \begin {eqnarray} + P[D_n^+ \le x] + &=& 1 - x \sum_{i=0}^{\lfloor n(1-x)\rfloor} + \left(\matrix{n\cr i\cr}\right) + \left({i\over n} + x \right)^{i-1} + \left(1 - {i\over n} - x \right)^{n-i} \label {DistKS1} \\[4pt] + &=& x \sum_{j=0}^{\lfloor nx \rfloor} + \left(\matrix{n\cr j\cr}\right) + \left({j\over n} - x \right)^j + \left(1 - {j\over n} + x \right)^{n-j-1} \label {DistKS2} \\[4pt] + &\approx& 1 - e^{-2 n x^2} \left[1 - {2x\over 3} \left( + 1 - x\left(1 - {2 n x^2 \over 3}\right) \right.\right. + \nonumber\\[4pt] + && \left.\left. - {2\over 3n} \left({1\over 5} - {19 n x^2 \over 15} + + {2n^2 x^4 \over 3}\right) \right) + O(n^{-2}) \right]. + \label {DistKS3} + \end {eqnarray} + Formula (\ref{DistKS1}) and (\ref{DistKS2}) can be found in + \cite{tDUR73a}, equations (2.1.12) and (2.1.16), while (\ref{DistKS3}) + can be found in \cite{tDAR60a}. + Formula (\ref{DistKS2}) contains less terms than (\ref{DistKS1}) + when $x < 0.5$, but becomes numerically unstable as $nx$ increases. +% because its terms alternate in sign and become large +% (in absolute value) compared to their sum. + The approximation (\ref{DistKS3}) is simpler to compute and excellent + when $nx$ is large. + Our implementation uses (\ref{DistKS2}) when $nx < 6.5$, + (\ref{DistKS1}) when $nx \ge 6.5$ and $n \le 4000$, + and (\ref{DistKS3}) when $nx \ge 6.5$ and $n > 4000$. +% The relative error on $p(x) = P[D_n^+ \le x]$ is always less than +% $10^{-5}$, and the relative error on $1-p(x)$ is less than +% $10^{-1}$ when $1-p(x) > 10^{-10}$. +% The {\em absolute\/} error on $1-p(x)$ is less than $10^{-11}$ +% when $1-p(x) < 10^{-10}$. +% It must be noted that Korolyuk \cite{tKOR59a} and many others +% gave an erroneous formula for the asymptotic form (\ref{DistKS3}). +% Darling \cite{tDAR60a} gives the correct formula with references. + \endtab +\code + + +double fdist_KS1 (long n, double x); +\endcode + \tab Returns $u = P[D_n \le x]$ % using the program described in \cite{LECz09}, + where $D_n = \max\{D_n^+, D_n^-\}$ + is the two-sided Kolmogorov-Smirnov statistic \cite{tBRO07a} for a sample + of size $n$, and $D_n^+$ and $D_n^-$ are defined in (\ref{eq:KSPlus}) and + (\ref{eq:KSMinus}). + This method uses Pomeranz's recursion formula \cite{tBRO08a,tPOM74a} for +$n \le 400$, which return at least 13 decimal digits of precision. It uses +the Pelz-Good asymptotic expansion \cite{tPEL76a} in the central part of + the range for $n > 400$ and returns at least 6 decimal digits of precision + everywhere for $400 < n \le 4000$. For $n > 4000$, it returns at least + 2 decimal digits of precision for all $u > 10^{-22}$, and at least + 5 decimal digits of precision for all $u > 10^{-7}$. +For a given $n$, the precision increases as $x$ increases. + This method is much faster than {\tt fdist\_KS2} for moderate or large $n$. + \endtab +\code + + +double fdist_KS2 (long n, double x); +\endcode +\tab Another version of the Kolmogorov-Smirnov distribution +$ P[D_n \le x]$, using Durbin's matrix formula \cite{tDUR73a}. +It is astronomically slow for large $n$. According to its authors +\cite{tMAR03a}, it should return at least 7 decimal digits +of precision. +\endtab +\code + + +double fdist_KSPlusJumpOne (long n, double a, double x); +\endcode + \tab + Similar to {\tt fdist\_KSPlus} but for the case where the distribution + function $F$ has a jump of size $a$ at a given point $x_0$, + is zero at the left of $x_0$, + and is continuous at the right of $x_0$. + The Kolmogorov-Smirnov statistic is defined in that case as + \eq + D_n^+(a) = \sup_{a\le u\le 1} \left(\hat F_n(F^{-1}(u)) - u\right) + = \max_{\rule{0pt}{7pt} \lfloor 1+an\rfloor \le j \le n} + \left(j/n - F(V_{(j)})\right). + \eqlabel{eq:KSPlusJumpOne} + \endeq +\iffalse %%%%% + and + \eq + D_n^-(a) = \sup_{a\le u\le 1} \left(u - \hat F_n(F^{-1}(u))\right) + = \max_{\rule{0pt}{7pt} \lfloor 1+an\rfloor \le j \le n} + \left(F(V_{(j)})-(j-1)/n\right), + \endeq + \pierre {It seems that $D_n^-(a)$ has a {\em different\/} distribution + function. } +\fi %%%% + where $V_{(1)},\dots,V_{(n)}$ are the observations sorted by increasing + order. The procedure returns an approximation of + $P[D_n^+(a) \le x]$ computed via + \begin {eqnarray} + P[D_n^+(a) \le x] + &=& 1 - x \sum_{i=0}^{\lfloor n(1-a-x)\rfloor} + \left(\matrix{n\cr i\cr}\right) + \left({i\over n} + x \right)^{i-1} + \left(1 - {i\over n} - x \right)^{n-i} \eqlabel{DistKSJ1} \\[6pt] + &=& x \sum_{j=0}^{\lfloor n(a+x) \rfloor} + \left(\matrix{n\cr j\cr}\right) + \left({j\over n} - x \right)^j + \left(1 - {j\over n} + x \right)^{n-j-1}. \eqlabel{DistKSJ2} + \end {eqnarray} +% La fonction de r\'epartition est la m\^eme pour ---> WRONG! +% \eq +% D_n^-(a) = \sup_{a\le u\le 1} (u - \hat F(F^{-1}(u))) +% = \max_{\lfloor 1+an\rfloor \le j \le n} (F(T_{(j)})-(j-1)/n), +% \endeq +% et aussi lorsque le supremum est sur $0\le u \le 1-a$ au lieu de +% $a\le u\le 1$. + \hpierre {R\'ef\'erences pour ces formules?} + The current implementation uses formula (\ref{DistKSJ2}) + when $n(x+a) < 6.5$ and $x+a < 0.5$, and uses (\ref{DistKSJ1}) + when $nx \ge 6.5$ or $x+a \ge 0.5$. + Restriction: $0 < a < 1$. + \endtab +\hide %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\code +#if 0 + +void fdist_FindJumps (fdist_FUNC_JUMPS *H, int Detail); +\endcode + \tab + Find empirically all the jumps of the function {\tt H->F(H->par, x)} + in the interval {\tt (H->xa, H->xb)} by advancing with steps of size + {\tt epsX} along the {\tt x} direction. If the value {\tt y} of the + function differs by more than {\tt epsY} over such a step, it will be + considered as a possible jump (discontinuity) of the function. + If {\tt epsX} is chosen very small, the time taken to explore the + interval could be very long. If {\tt epsX} is chosen very large, some + jumps will not be found. + {\tt epsY/epsX} should be chosen larger than the largest + slope of the function at continuous points in the interval. + The number of jumps is returned in {\tt H->NJumps}; the position + {\tt x} of the $i$-th jump will be kept in + {\tt H->xJump[i], i = 1,2,...,H->NJumps}. + The value of the function immediately to the left and to the right + of jump $i$ will be kept in {\tt H->yLeftJump[i]} and + {\tt H->yRightJump[i]} respectively. The name of the function can be + kept in {\tt H->doc}. + If {\tt Detail $>$ 0}, very detailed information will be printed about + the jumps. + \endtab +\code + + +void fdist_FreeJumps (fdist_FUNC_JUMPS *H); +\endcode + \tab + Free the memory allocated internally by {\tt fdist\_FindJumps} (and only + that memory, that is {\tt xJump, yLeftJump, yRightJump}) + to keep information about the jumps of {\tt H}. + This should be called when one has no more use for the jumps. {\tt H} + itself and the other fields of {\tt H} that are allocated by + the user (v.g. {\tt par, doc}) must be released explicitly by the user. + \endtab +\code + + +double fdist_KSMinusJumpsMany (fdist_FUNC_JUMPS *H, double x); +\endcode + \tab + Return the $p$-value $P[D_{\!N}^- \ge x]$, where $D_{\!N}^-$ is the + Kolmogorov-Smirnov statistic (\ref{eq:KSMinus}) for a sample of size + $N =$ {\tt H->par->paramI[0]}, under + the hypothesis that the observations follow a law with a discontinuous + cumulative distribution function {\tt H->F}. The distribution function + {\tt H->F} has {\tt H->NJumps} jumps; the $x$ coordinate of jump $i$ + is in {\tt H->xJump[i], i = 1, 2, ..., NJumps}, and the values of {\tt H->F} + immediately to the left and to the right of jump $i$ are in + {\tt H->yLeftJump[i]} and {\tt H->yRightJump[i]}. + + This distribution function is computed following the method + proposed in \cite{tCON72a}. The sample size $N$ should not exceed + 64, otherwise loss of precision in the computations + will make the results meaningless. + \endtab +\code + + +double fdist_KSPlusJumpsMany (fdist_FUNC_JUMPS *H, double x); +#endif +\endcode + \tab + Similar to {\tt fdist\_KSMinusJumpsMany}, but for $D_N^+$, defined + in (\ref{eq:KSPlus}). + \endtab +\endhide %%%%%%%%%%%%%%%%%%%%% +\code + + +double fdist_CramerMises (long n, double x); +\endcode + \tab Returns an approximation of $P[W_n^2 \le x]$, where $W_n^2$ is the + Cram\'er von Mises statistic (see \cite{tSTE70a,tSTE86b,tAND52a,tKNO74a}) + defined in (\ref{eq:CraMis}), + for a sample of independent uniforms over $(0,1)$. + The approximation is based on the + distribution function of $W^2 = \lim_{n\to\infty} W_n^2$, which has + the following series expansion derived + by Anderson and Darling \cite{tAND52a}: + \begin{equation} + P(W^2 \le x) \ = \ \frac1{\pi\sqrt x} \sum_{j=0}^\infty (-1)^j {-1/2 + \choose j} \sqrt{4j+1}\;\; {\rm exp}\left\{-\frac{(4j+1)^2}{16 x}\right\} + {\rm K}_{1/4}\left(\frac{(4j+1)^2}{16 x}\right), + \eqlabel{eq:DistCM1} + \end{equation} + where ${\rm K}_{\nu}$ is the modified Bessel function of the + second kind. + To correct for the deviation between $P(W_n^2\le x)$ and $P(W^2\le x)$, + we add a correction in $1/n$, obtained empirically by simulation. + For $n = 10$, 20, 40, the error is less than + 0.002, 0.001, and 0.0005, respectively, while for + $n \ge 100$ it is less than 0.0005. + For $n \to\infty$, we estimate that the procedure returns + at least 6 decimal digits of precision. + For $n = 1$, the procedure computes the exact distribution: + $P(W_1^2 \le x) = 2 \sqrt {x - 1/12}$ for $1/12 \le x \le 1/3$. + \endtab +\code + + +double fdist_WatsonG (long n, double x); +\endcode + \tab Returns an approximation of $P[G_n \le x]$, where $G_n$ is the + Watson statistic defined in (\ref{eq:WatsonG}), + for a sample of independent uniforms over $(0,1)$. + The approximation is computed in a similar way as for + {\tt fdist\_CramerMises}. + To implement this procedure, a table of the values of + $g(x) = \lim_{n\to\infty} P[G_n \le x]$ and of its derivative + was first computed by numerical integration. + For $x \le 1.5$, the procedure uses this table with cubic spline + interpolation. + For $x > 1.5$, it uses the empirical curve $g(x) = 1 - e^{19 - 20x}$. + A correction of order $1/\sqrt{n}$, obtained + empirically from $10^7$ simulation runs with $n = 256$ and also + implemented as an interpolation table with an exponential tail, + is then added. + The absolute error is estimated to be less than + 0.01, 0.005, 0.002, 0.0008, 0.0005, 0.0005, 0.0005 for + $n = 16$, 32, 64, 128, 256, 512, 1024, respectively. + For the trivial case $n=1$, always returns 0.5. + \endtab +\code + + +double fdist_WatsonU (long n, double x); +\endcode + \tab Returns $P[U^2 \le x]$, where $U^2$ is the Watson statistic + defined in (\ref{eq:WatsonU}) in the limit when $n \to\infty$, + for a sample of independent uniforms over $(0,1)$. + Only this limiting distribution (when $n \to\infty$) is implemented. + It is given by + \begin{equation} + P(U^2 \le x) \ = \ 1 + 2 \sum_{j=1}^\infty (-1)^j e^{-2 j^2 \pi^2 x} + \eqlabel{eq:DistWU1} + \end{equation} + This sum converges extremely fast except for small $x$, where alternating + successive terms give rise to numerical instability. + But with the Poisson summation formula \cite{mLAN73a}, + the sum can be transformed to + \begin{equation} + P(U^2 \le x) \ = \ \sqrt{\frac2{\pi x}}\; \sum_{j=0}^\infty + e^{- (2 j+1)^2/8 x} \eqlabel{eq:DistWU2} + \end{equation} + which can be used for small $x$. + The current implementation uses (\ref{eq:DistWU1}) for $x > 0.15$, + and (\ref{eq:DistWU2}) for $x \le 0.15$. + The absolute difference between the returned value and $P[U_n^2 \le x]$ + is estimated to be less than 0.01 for $n \ge 8$. + For the trivial case $n=1$, always returns 0.5. + \endtab +\code + + +double fdist_AndersonDarling (long n, double x); +\endcode + \tab Returns $F_n(x) = P[A_n^2 \le x]$, where $A_n^2$ is the + Anderson-Darling statistic \cite{tAND52a} defined in (\ref{eq:Andar}), + for a sample of independent uniforms over $(0,1)$. + The approximation is computed similarly as for + {\tt fdist\_CramerMises}. + To implement this procedure, an interpolation table of the values of + $F(x) = \lim_{n\to\infty} P[A_n^2 \le x]$ + was first computed by numerical integration. + Then a linear correction in $1/n$, obtained by simulation, was added. + For $x \le 5$, the procedure approximates $F_n(x) = P[A_n^2 \le x]$ by + interpolation. For $5 < x < 10$, it uses the empirical curve + $F_n(x) \approx 1 - e^{-1.06x - 0.56} - e^{-1.06x - 1.03}/n$, + which includes the empirical correction in $1/n$. + The absolute error on $F_n(x)$ is estimated to be + less than $0.001$ for $n > 6$ except far in the tails. + For $n = 2$, 3, 4, 6, it is estimated to be + less than 0.04, 0.01, 0.005, 0.002, respectively. + In the lower tail ($x < 0.2$), the approximation (3.6) of Sinclair + and Spurr \cite{tSIN88a} +$$ + F(x) = 1 - \frac1{1 + \exp{\left(1.784 + 0.9936x + + \frac{0.03287}{x} + - \frac{(2.018 + {0.2029}/{x})}{\sqrt x}\right)}} +$$ + is used without correction for finite $n$. In the far upper tail + ($x > 10$), the approximation (3.5) of Sinclair + and Spurr \cite{tSIN88a} +$$ + F(x) = 1 - \frac{1.732 \exp(-x)}{\sqrt{\pi x}} +$$ + is used without correction for finite $n$. + For $n=1$, the procedure returns the exact value, + $F_1(x) = \sqrt{1 - 4e^{-x-1}}$ for $x\ge \ln(4) - 1$. + \endtab +\code + + +double fdist_AndersonDarling2 (long n, double x); +\endcode + \tab Returns the value of the Anderson-Darling distribution at $x$ + for a sample of $n$ independent uniforms over $(0,1)$ using Marsaglia's + and al. algorithm \cite{tMAR04a}. First the limiting distribution + for $n\to\infty$ is computed to within 6-digit accuracy according to the + authors. Then an empirical correction obtained by simulation is added + for finite $n$. + For $n=1$, the procedure returns the exact value, + $F_1(x) = \sqrt{1 - 4e^{-x-1}}$ for $x\ge \ln(4) - 1$. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Discrete distributions} + +\code + +double fdist_Geometric (double p, long s); +\endcode + \tab Returns + \eq + F(s) = \sum_{j = 0}^s p\, (1-p)^{j} ~=~ 1 - (1-p)^{s+1}, + \eqlabel{eq:Fgeometric} + \endeq + the distribution function of a geometric random variable with + parameter $p$, evaluated at $s$. + Restriction: $0 \le p \le 1$. + \endtab +\code + + +double fdist_Poisson1 (double lambda, long s); +\endcode + \tab Returns + \eq + F_\lambda(s) = e^{-\lambda} \sum_{j=0}^s\; \frac{\lambda^j}{j!}, + \eqlabel{eq:FPoisson} + \endeq + the Poisson distribution function + with parameter $\lambda =$ {\tt lambda}, evaluated at $s$. +\ifdetailed + This procedure adds all the non-negligible terms of the sum + if $\lambda \le 150$; otherwise it uses the relationship + $F_\lambda(s) = 1 - G_{s + 1}(\lambda)$, in which $G_{s+1}$ is the + gamma distribution with parameter $s+1$, computed via {\tt + fdist\_Gamma}. +\fi + \hpierre{Suggestions: lorsque $s>\lambda$, calculer plutot + les termes de $1-F(s)$ ? Et si $\lambda > 150$ mais $s$ est petit, + ne vaut-il pas mieux utiliser la somme? Peut-etre mettre la limite + sur $s$ a la place? } + \hrichard{ Si $\lambda$ est grand, on risque d'avoir d\'epassement de + capacit\'e avec le facteur $e^{-\lambda}$ et l'autre facteur aussi, + si on somme les termes + explicitement. D'ailleurs, avec grand $\lambda$, la probabilit\'e + d'avoir des petits $s$ est n\'egligeable. C'est pourquoi j'ai mis la + limite sur $\lambda$ et non sur $s$.\\ Pour $s>\lambda$, la queue + de Poisson \'etant plus allong\'ee vers le haut que vers le bas, il + n'est pas \'evident que ce serait plus efficace de calculer + $1-F(s)$, et ce serait beaucoup plus compliqu\'e.} + \hpierre {Et pourquoi prendre $10^5$ au lieu de 150 dans CreatePoisson? + Si on a 5 a 10 appels a faire, il me semble qu'appeler ``gamma'' + est beaucoup plus efficace que de calculer des tableaux de taille + $10^5$? } + \hrichard {Dans le cas o\`u $\lambda = 10^5$, on ne calcule pas des + tableaux de taille $10^5$, mais 2 tableaux de taille 4849. Les + autres termes sont $< 10^{-16}$ et ne sont ni calcul\'es ni + conserv\'es.} + In the cases where the Poisson distribution must be computed more than + once with the same $\lambda$, % and $\lambda$ is not too large, + it is more efficient to use + {\tt fdist\_Poisson2} instead of {\tt fdist\_Poisson1}. + Restriction: $\lambda > 0$. + \endtab +\code + + +double fdist_Poisson2 (fmass_INFO W, long s); +\endcode + \tab Returns the Poisson distribution function (\ref{eq:FPoisson}) + from the structure {\tt W}, which must have been created previously + by calling {\tt fmass\_CreatePoisson} with the desired $\lambda$. +% Restriction: only integral values of $s$ are meaningful. + \endtab +\code + + +double fdist_Binomial1 (long n, double p, long s); +\endcode + \tab Returns + \eq + F(s) = \sum_{j=0}^s {n \choose j}\; p^j (1-p)^{n-j}, + \eqlabel{eq:Fbinomial} + \endeq + the distribution function of a binomial random variable with parameters + $n$ and $p$, evaluated at $s$. +\ifdetailed + If $n \le 10000$, the non-negligible terms of the sum are + added explicitly. + If $n > 10000$ and $np(1-p) > 100$, the Camp-Paulson normal + approximation \cite{tCAM51a,tMOL70a} is used, otherwise, a Poisson + approximation due to Bol'shev \cite{tBOL64a,tMOL70a} is used. +\fi + When the binomial distribution has to be computed more than + once with the same parameters $n$ and $p$, it is more efficient to use + {\tt fdist\_Binomial2} instead of {\tt fdist\_Binomial1}, + unless $n$ is very large (e.g., $n > 10^5$). + Restrictions: $0 \le p \le 1$ and $n \ge 0$. + \endtab +\code + + +double fdist_Binomial2 (fmass_INFO W, long s); +\endcode + \tab Returns the binomial distribution function (\ref{eq:Fbinomial}) + from the structure {\tt W}, which must have been created previously + by calling {\tt fmass\_CreateBinomial} with the desired values of + $n$ and $p$. + \endtab +\code + + +double fdist_NegaBin1 (long n, double p, long s); +\endcode + \tab Returns + \eq + F(s) = \sum_{j = 0}^s {n + j - 1 \choose j} p^n (1-p)^{j}, + \eqlabel{eq:Fnegabin} + \endeq + the distribution function of a negative binomial random variable with + parameters $n$ and $p$, evaluated at $s$. + If this distribution has to be computed more than + once with the same $n$ and $p$, it is more efficient to use + {\tt fdist\_NegaBin2} instead of {\tt fdist\_NegaBin1}, + unless $n$ is very large. +% (e.g., $n > 10000$). ?? + Restrictions: $n \ge 0$ and $0 \le p \le 1$. + \endtab +\code + + +double fdist_NegaBin2 (fmass_INFO W, long s); +\endcode + \tab Returns the negative binomial distribution function + (\ref{eq:Fnegabin}) from the structure {\tt W}, + which must have been created previously + by calling {\tt fmass\_CreateBinomial} with the desired values of + $n$ and $p$. + \endtab +\code + + +double fdist_Scan (long N, double d, long m); +\endcode + \tab Returns $F(m)$, the distribution function of the scan statistic + with parameters $N$ and $d$, evaluated at $m$. + For a description of this statistic and its distribution, see + {\tt fbar\_Scan}, which computes its complementary distribution + $\bar F(m) = 1 - F(m-1)$. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/probdist/finv.c b/TESTU01/TestU01-1.2.3/probdist/finv.c new file mode 100644 index 0000000..c5c022f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/finv.c @@ -0,0 +1,2002 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: finv.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "finv.h" +#include "fdist.h" +#include "wdist.h" + +#include "num.h" +#include "num2.h" +#include "util.h" +#include "gdef.h" + +#include +#include +#include +#include + + +double fdist_belog(double); +void fdist_CalcB4 (double, double *, double *, double *, double *); + +#define TRACE0(x) printf ("*** " #x " "); + + +extern const double fdist_XINF; +extern const double fdist_XBIG; +extern const double fdist_XBIGM; + +/* EpsArray[j]: Epsilon required for j decimal degits of precision */ +static const double EpsArray[] = { + 0.5, 0.5E-1, 0.5E-2, 0.5E-3, 0.5E-4, 0.5E-5, 0.5E-6, 0.5E-7, 0.5E-8, + 0.5E-9, 0.5E-10, 0.5E-11, 0.5E-12, 0.5E-13, 0.5E-14, 0.5E-15, 0.5E-16, + 0.5E-17, 0.5E-18, 0.5E-19, 0.5E-20, 0.5E-21, 0.5E-22, 0.5E-23, 0.5E-24, + 0.5E-25, 0.5E-26, 0.5E-27, 0.5E-28, 0.5E-29, 0.5E-30, 0.5E-31, 0.5E-32, + 0.5E-33, 0.5E-34, 0.5E-35 +}; + + + + +/*=========================================================================*/ + +double finv_Expon (double u) +{ + util_Assert (u >= 0.0 && u <= 1.0, "finv_Expon: u not in [0, 1]"); + if (u >= 1.0) { + util_Warning (1, "finv_Expon: u = 1"); + return fdist_XBIGM; + } + if (u <= 0.0) + return 0.0; + return -num2_log1p (-u); +} + + +/*=========================================================================*/ + +double finv_Weibull (double c, double u) +{ + double t; + + util_Assert (c > 0.0, "finv_Weibull: c <= 0"); + util_Assert (u >= 0.0 && u <= 1.0, "finv_Weibull: u not in [0, 1]"); + if (u <= 0.0) + return 0.0; + if (u >= 1.0) { + util_Warning (1, "finv_Weibull: u = 1"); + return fdist_XINF; + } + + t = -num2_log1p (-u); + if (log10 (t) >= c * DBL_MAX_10_EXP) { + util_Warning (1, "finv_Weibull: u --> 1"); + return fdist_XINF; + } + + return pow (t, 1.0 / c); +} + + +/*=========================================================================*/ + +double finv_ExtremeValue (double u) +{ + + util_Assert (u >= 0.0 && u <= 1.0, "finv_ExtremeValue: u not in [0, 1]"); + if (u >= 1.0) { + util_Warning (1, "finv_ExtremeValue: u = 1"); + return fdist_XBIG; + } + if (u <= 0.0) { + util_Warning (1, "finv_ExtremeValue: u = 0"); + return -fdist_XBIG; + } + return -log (-log (u)); +} + + +/*=========================================================================*/ + +double finv_Logistic (double u) +{ + util_Assert (u >= 0.0 && u <= 1.0, "finv_Logistic: u not in [0, 1]"); + if (u >= 1.0) { + util_Warning (1, "finv_Logistic: u = 1"); + return fdist_XBIGM; + } + if (u <= 0.0) { + util_Warning (1, "finv_Logistic: u = 0"); + return -fdist_XBIGM; + } + return log(u / (1.0 - u)); +} + + +/*=========================================================================*/ + +double finv_Pareto (double c, double u) +{ + double t; + util_Assert (c > 0.0, "finv_Pareto: c <= 0"); + util_Assert (u >= 0.0 && u <= 1.0, "finv_Pareto: u not in [0, 1]"); + if (u <= 0.0) + return 1.0; + t = -num2_log1p (-u); + + if ((u >= 1.0) || t >= c * DBL_MAX_EXP) { + util_Warning (1, "finv_Pareto: u = 1 or t >= c * DBL_MAX_EXP"); + return fdist_XINF; + } + return pow (1.0 / (1 - u), 1.0 / c); +} + + +/**************************************************************************/ + +double finv_Normal3 (double y) +/* + * Returns Inverse of the cdf of the normal distribution + * As in P.Bratley, B.L.Fox, and L.E.Schrage. A Guide to Simulation + * Springer-Verlag, New York, second edition, 1987. + * in Figure L27 + */ +{ + static const double plim = 1.0e-18; + static const double p0 = -0.322232431088; + static const double p1 = -1.0; + static const double p2 = -0.342242088547; + static const double p3 = -0.0204231210245; + static const double p4 = -0.453642210148e-4; + + static const double q0 = 0.099348462606; + static const double q1 = 0.588581570495; + static const double q2 = 0.531103462366; + static const double q3 = 0.10353775285; + static const double q4 = 0.38560700634e-2; + + double p; + double vtemp, Y; + + p = y; + if (p > 0.5) + p = 1.0 - p; + + if (p >= plim) { + Y = sqrt (-log (p * p)); + vtemp = Y + ((((Y * p4 + p3) * Y + p2) * Y + p1) * Y + p0) / + ((((Y * q4 + q3) * Y + q2) * Y + q1) * Y + q0); + if (y < 0.5) + vtemp = -vtemp; + return vtemp; + } else { + vtemp = 8.0; + if (y < 0.0) { + printf ("Error: Negative Value in finv_Normal3\n"); + exit (EXIT_FAILURE); + } + if (y < 0.5) + vtemp = -vtemp; + return vtemp; + } +} + + +/**************************************************************************/ + +static const double InvNormal1P1[7] = { + 0.160304955844066229311E2, + -0.90784959262960326650E2, + 0.18644914861620987391E3, + -0.16900142734642382420E3, + 0.6545466284794487048E2, + -0.864213011587247794E1, + 0.1760587821390590 +}; + +static const double InvNormal1Q1[7] = { + 0.147806470715138316110E2, + -0.91374167024260313396E2, + 0.21015790486205317714E3, + -0.22210254121855132366E3, + 0.10760453916055123830E3, + -0.206010730328265443E2, + 0.1E1 +}; + +static const double InvNormal1P2[8] = { + -0.152389263440726128E-1, + 0.3444556924136125216, + -0.29344398672542478687E1, + 0.11763505705217827302E2, + -0.22655292823101104193E2, + 0.19121334396580330163E2, + -0.5478927619598318769E1, + 0.237516689024448000 +}; + +static const double InvNormal1Q2[8] = { + -0.108465169602059954E-1, + 0.2610628885843078511, + -0.24068318104393757995E1, + 0.10695129973387014469E2, + -0.23716715521596581025E2, + 0.24640158943917284883E2, + -0.10014376349783070835E2, + 0.1E1 +}; + +static const double InvNormal1P3[11] = { + 0.56451977709864482298E-4, + 0.53504147487893013765E-2, + 0.12969550099727352403, + 0.10426158549298266122E1, + 0.28302677901754489974E1, + 0.26255672879448072726E1, + 0.20789742630174917228E1, + 0.72718806231556811306, + 0.66816807711804989575E-1, + -0.17791004575111759979E-1, + 0.22419563223346345828E-2 +}; + +static const double InvNormal1Q3[9] = { + 0.56451699862760651514E-4, + 0.53505587067930653953E-2, + 0.12986615416911646934, + 0.10542932232626491195E1, + 0.30379331173522206237E1, + 0.37631168536405028901E1, + 0.38782858277042011263E1, + 0.20372431817412177929E1, + 0.1E1 +}; + +double finv_Normal1 (double x) +/* + * Returns the inverse of the cdf of the normal distribution. + * Rational approximations giving 16 decimals of precision. + * The authors also give an approximation with 23 decimals of + * precision. + * J.M. Blair, C.A. Edwards, J.H. Johnson, "Rational Chebyshev + * approximations for the Inverse of the Error Function", in + * Mathematics of Computation, Vol. 30, 136, pp 827, (1976) + */ +{ + int i, negatif; + double z, v, numer, denom; + + util_Assert (x >= 0.0, "finv_Normal1: u < 0"); + util_Assert (x <= 1.0, "finv_Normal1: u > 1"); + if (x <= 0.0) { + util_Warning (1, "finv_Normal1: u = 0"); + return -fdist_XBIG; + } + + /* Transform x as argument of InvErf */ + z = x; + x = 2.0 * x - 1.0; + if (x >= 1.0) { + util_Warning (1, "finv_Normal1: u = 1"); + return fdist_XBIG; + } + if (x < 0.0) { + x = -x; + negatif = 1; + } else { + negatif = 0; + } + + if (x <= 0.75) { + v = x * x - 0.5625; + numer = denom = 0.0; + /* Evaluation of the 2 polynomials by Horner */ + for (i = 6; i >= 0; i--) { + numer = numer * v + InvNormal1P1[i]; + denom = denom * v + InvNormal1Q1[i]; + } + z = x * numer / denom; + + } else if (x <= 0.9375) { + v = x * x - 0.87890625; + numer = denom = 0.0; + for (i = 7; i >= 0; i--) { + numer = numer * v + InvNormal1P2[i]; + denom = denom * v + InvNormal1Q2[i]; + } + z = x * numer / denom; + } else { + if (z > 1.0e-1) + v = 1.0 / sqrt (-log (1.0 - x)); + else + v = 1.0 / sqrt (-log (2.0*z)); + numer = denom = 0.0; + for (i = 10; i >= 0; i--) + numer = numer * v + InvNormal1P3[i]; + for (i = 8; i >= 0; i--) + denom = denom * v + InvNormal1Q3[i]; + z = (1.0 / v) * numer / denom; + } + + if (negatif) + return -(z * num_Rac2); + else + return z * num_Rac2; +} + + +/*=========================================================================*/ + +typedef union { + float u; + int i; +} Uvalue; + + +double finv_Normal2 (double u) +{ + static const double A[1025] = { + 6.33795775455, 6.33321372178, 6.32860807635, + 6.32413288056, 6.31978086301, 6.31554534594, + 6.31142018224, 6.30739970055, 6.30347865735, + 6.29965219486, 6.29591580408, 6.29226529211, + 6.28869675323, 6.28520654322, 6.28179125646, + 6.27844770553, 6.27517290294, 6.27196404468, + 6.2688184955, 6.26573377562, 6.26270754867, + 6.25973761088, 6.25682188116, 6.25395839218, + 6.25114528219, 6.24838078761, 6.2456632362, + 6.24299104087, 6.240362694, 6.23777676216, + 6.23523188139, 6.23272675268, 6.23026013799, + 6.22543778081, 6.22075598811, 6.2162067, + 6.21178253304, 6.20747670647, 6.20328297819, + 6.19919558917, 6.19520921468, 6.19131892165, + 6.18752013112, 6.18380858505, 6.180180317, + 6.17663162601, 6.1731590534, 6.16975936206, + 6.16642951782, 6.16316667288, 6.15996815078, + 6.1568314329, 6.15375414629, 6.15073405259, + 6.14776903807, 6.14485710448, 6.14199636082, + 6.13918501574, 6.13642137069, 6.13370381356, + 6.13103081295, 6.12840091282, 6.12581272765, + 6.12326493791, 6.12075628597, 6.11585165173, + 6.11108986339, 6.10646273321, 6.10196276044, + 6.09758305644, 6.09331727974, 6.08915957943, + 6.08510454578, 6.08114716689, 6.07728279052, + 6.07350709041, 6.06981603653, 6.06620586849, + 6.06267307204, 6.05921435799, 6.05582664334, + 6.05250703436, 6.04925281142, 6.04606141524, + 6.0429304345, 6.03985759465, 6.03684074773, + 6.03387786311, 6.03096701912, 6.02810639533, + 6.02529426559, 6.0225289916, 6.01980901702, + 6.01713286212, 6.01449911878, 6.01190644597, + 6.00935356553, 6.00436236049, 5.99951639563, + 5.99480734912, 5.99022759726, 5.98577013833, + 5.98142852661, 5.9771968149, 5.97306950434, + 5.96904150032, 5.96510807378, 5.96126482692, + 5.95750766299, 5.95383275929, 5.95023654327, + 5.94671567111, 5.94326700856, 5.93988761376, + 5.93657472175, 5.9333257306, 5.93013818875, + 5.92700978364, 5.92393833142, 5.92092176747, + 5.91795813793, 5.91504559188, 5.91218237419, + 5.90936681905, 5.90659734398, 5.90387244436, + 5.90119068838, 5.89855071241, 5.89595121674, + 5.89086876372, 5.88593406746, 5.88113866541, + 5.87647480476, 5.87193536504, 5.86751379108, + 5.86320403456, 5.85900050299, 5.85489801495, + 5.85089176064, 5.84697726716, 5.84315036764, + 5.83940717394, 5.83574405227, 5.83215760142, + 5.82864463328, 5.82520215541, 5.82182735527, + 5.81851758606, 5.81527035394, 5.81208330646, + 5.80895422198, 5.80588100021, 5.80286165344, + 5.79989429868, 5.79697715037, 5.79410851379, + 5.79128677896, 5.78851041509, 5.78577796547, + 5.78308804272, 5.78043932448, 5.7752605134, + 5.77023210866, 5.76534549972, 5.76059279799, + 5.75596675813, 5.75146070984, 5.74706849845, + 5.74278443301, 5.73860324073, 5.73452002692, + 5.73053023962, 5.72662963823, 5.72281426575, + 5.71908042393, 5.71542465116, 5.7118437027, + 5.70833453283, 5.70489427893, 5.70152024702, + 5.69820989876, 5.69496083963, 5.69177080831, + 5.68863766688, 5.68555939205, 5.68253406704, + 5.67955987426, 5.67663508853, 5.67375807094, + 5.67092726314, 5.66814118219, 5.6653984157, + 5.66269761746, 5.65741684752, 5.65228927845, + 5.64730614385, 5.64245941209, 5.6377417063, + 5.63314623489, 5.62866673113, 5.62429740032, + 5.6200328734, 5.61586816622, 5.61179864349, + 5.60781998693, 5.60392816693, 5.6001194173, + 5.5963902128, 5.59273724893, 5.58915742386, + 5.58564782214, 5.58220570003, 5.57882847227, + 5.57551370004, 5.57225908009, 5.56906243489, + 5.56592170358, 5.56283493377, 5.55980027406, + 5.55681596716, 5.55388034364, 5.55099181609, + 5.54814887388, 5.54535007824, 5.5425940578, + 5.53720516928, 5.53197243466, 5.52688692307, + 5.52194045196, 5.5171255056, 5.51243516442, + 5.50786304341, 5.50340323832, 5.49905027849, + 5.4947990853, 5.49064493552, 5.4865834288, + 5.48261045887, 5.47872218783, 5.4749150232, + 5.47118559738, 5.46753074927, 5.46394750763, + 5.46043307616, 5.45698482001, 5.45360025356, + 5.45027702931, 5.44701292782, 5.44380584855, + 5.44065380149, 5.43755489952, 5.43450735142, + 5.43150945548, 5.42855959358, 5.42565622584, + 5.42279788561, 5.41998317492, 5.41447936842, + 5.40913484272, 5.40394049304, 5.39888797725, + 5.39396963282, 5.38917840481, 5.38450778312, + 5.37995174765, 5.37550472027, 5.37116152244, + 5.36691733786, 5.36276767939, 5.35870835965, + 5.35473546482, 5.3508453313, 5.34703452473, + 5.34329982125, 5.33963819058, 5.3360467808, + 5.33252290459, 5.32906402674, 5.32566775291, + 5.32233181932, 5.31905408341, 5.31583251534, + 5.31266519015, 5.30955028069, 5.30648605108, + 5.30347085068, 5.30050310862, 5.29758132874, + 5.29470408485, 5.28907782499, 5.28361416415, + 5.27830381332, 5.2731382613, 5.26810969, + 5.26321090103, 5.25843525172, 5.2537765992, + 5.24922925139, 5.24478792384, 5.24044770161, + 5.23620400551, 5.23205256217, 5.22798937729, + 5.22401071182, 5.2201130606, 5.21629313323, + 5.21254783681, 5.20887426039, 5.205269661, + 5.20173145085, 5.19825718588, 5.19484455528, + 5.19149137189, 5.1881955636, 5.18495516531, + 5.18176831175, 5.17863323075, 5.17554823716, + 5.17251172724, 5.16952217346, 5.16657811973, + 5.16082101937, 5.15523004763, 5.14979571985, + 5.14450934531, 5.13936294072, 5.13434915534, + 5.12946120568, 5.12469281843, 5.1200381805, + 5.11549189488, 5.11104894181, 5.10670464433, + 5.10245463765, 5.09829484194, 5.09422143797, + 5.09023084532, 5.08631970285, 5.08248485106, + 5.0787233163, 5.07503229637, 5.0714091476, + 5.06785137307, 5.06435661191, 5.06092262957, + 5.05754730896, 5.05422864229, 5.05096472372, + 5.0477537425, 5.04459397676, 5.04148378777, + 5.03842161464, 5.03540596946, 5.02950864968, + 5.02378122248, 5.01821399503, 5.01279808548, + 5.00752533468, 5.0023882297, 4.99737983708, + 4.99249374467, 4.98772401045, 4.98306511755, + 4.97851193459, 4.97405968039, 4.96970389282, + 4.96544040091, 4.96126529999, 4.95717492946, + 4.95316585275, 4.94923483945, 4.94537884901, + 4.94159501614, 4.93788063759, 4.93423316006, + 4.93065016935, 4.92712938035, 4.92366862801, + 4.92026585904, 4.91691912431, 4.91362657193, + 4.91038644087, 4.90719705507, 4.90405681805, + 4.90096420796, 4.89491612703, 4.8890419637, + 4.88333180298, 4.87777655906, 4.87236788511, + 4.86709809501, 4.86196009527, 4.85694732544, + 4.85205370587, 4.8472735917, 4.84260173228, + 4.8380332352, 4.8335635343, 4.82918836126, + 4.82490372013, 4.8207058646, 4.81659127758, + 4.81255665279, 4.80859887824, 4.8047150212, + 4.80090231471, 4.79715814524, 4.79348004153, + 4.78986566443, 4.78631279763, 4.78281933914, + 4.77938329358, 4.77600276506, 4.77267595063, + 4.76940113431, 4.76617668159, 4.76300103427, + 4.75679027709, 4.7507577546, 4.7448933141, + 4.73918765149, 4.73363221901, 4.72821914523, + 4.72294116527, 4.71779155991, 4.71276410212, + 4.70785300996, 4.70305290507, 4.69835877584, + 4.6937659447, 4.689270039, 4.68486696501, + 4.68055288459, 4.67632419431, 4.67217750662, + 4.66810963292, 4.6641175682, 4.66019847719, + 4.65634968177, 4.65256864953, 4.64885298336, + 4.64520041195, 4.64160878112, 4.63807604585, + 4.63460026304, 4.63117958481, 4.62781225236, + 4.6244965903, 4.6212310015, 4.61484401763, + 4.60863991397, 4.60260828265, 4.59673958525, + 4.59102505831, 4.58545663137, 4.58002685553, + 4.57472884104, 4.56955620253, 4.56450301082, + 4.55956375032, 4.55473328135, 4.55000680661, + 4.54537984133, 4.54084818664, 4.5364079057, + 4.53205530226, 4.52778690138, 4.52359943209, + 4.51948981163, 4.51545513127, 4.51149264343, + 4.5075997499, 4.50377399122, 4.50001303691, + 4.49631467662, 4.49267681191, 4.4890974489, + 4.48557469132, 4.48210673427, 4.47869185842, + 4.47532842465, 4.46874969883, 4.46235887005, + 4.45614525563, 4.45009906476, 4.44421130165, + 4.43847368137, 4.43287855675, 4.42741885424, + 4.42208801786, 4.41687995966, 4.41178901614, + 4.4068099095, 4.40193771332, 4.39716782193, + 4.39249592307, 4.3879179734, 4.38343017655, + 4.37902896328, 4.37471097372, 4.37047304122, + 4.36631217778, 4.3622255608, 4.35821052107, + 4.35426453179, 4.35038519863, 4.34657025053, + 4.34281753142, 4.33912499252, 4.33549068532, + 4.33191275513, 4.32838943511, 4.32491904083, + 4.31813067359, 4.31153564248, 4.3051229678, + 4.29888258592, 4.2928052498, 4.28688244266, + 4.28110630283, 4.27546955801, 4.26996546758, + 4.26458777186, 4.25933064724, 4.25418866648, + 4.24915676339, 4.2442302014, 4.23940454548, + 4.234675637, 4.23003957111, 4.22549267647, + 4.22103149691, 4.2166527749, 4.21235343653, + 4.20813057793, 4.20398145293, 4.19990346176, + 4.19589414084, 4.19195115337, 4.18807228072, + 4.18425541464, 4.18049854994, 4.17679977794, + 4.17315728028, 4.16956932335, 4.16255048996, + 4.15573091512, 4.14909929681, 4.14264527528, + 4.13635933075, 4.1302326947, 4.12425727258, + 4.11842557618, 4.11273066434, 4.1071660908, + 4.10172585798, 4.09640437621, 4.0911964274, + 4.08609713269, 4.08110192358, 4.07620651603, + 4.07140688728, 4.0666992549, 4.06208005798, + 4.05754594009, 4.05309373387, 4.04872044701, + 4.04442324957, 4.04019946237, 4.03604654644, + 4.03196209338, 4.02794381649, 4.0239895427, + 4.02009720515, 4.0162648363, 4.01249056171, + 4.00877259417, 4.00149883606, 3.99443081604, + 3.98755688078, 3.98086634771, 3.97434939969, + 3.96799699364, 3.96180078097, 3.95575303793, + 3.94984660457, 3.94407483096, 3.93843152965, + 3.93291093367, 3.92750765903, 3.9222166715, + 3.91703325678, 3.91195299388, 3.90697173117, + 3.90208556486, 3.89729081955, 3.89258403075, + 3.88796192889, 3.88342142501, 3.87895959754, + 3.87457368047, 3.87026105237, 3.86601922652, + 3.86184584173, 3.85773865405, 3.85369552908, + 3.84971443491, 3.84579343567, 3.8419306855, + 3.83437296653, 3.82702811235, 3.81988408487, + 3.81292984787, 3.80615525838, 3.79955097242, + 3.79310836293, 3.78681944792, 3.7806768275, + 3.77467362835, 3.76880345477, 3.76306034518, + 3.75743873361, 3.75193341525, 3.74653951576, + 3.74125246377, 3.73606796613, 3.73098198575, + 3.72599072151, 3.72109059012, 3.71627820978, + 3.71155038522, 3.70690409424, 3.70233647531, + 3.69784481637, 3.69342654456, 3.68907921677, + 3.68480051108, 3.68058821879, 3.67644023716, + 3.67235456274, 3.66832928512, 3.66045271041, + 3.65279688532, 3.64534934809, 3.63809867295, + 3.63103435798, 3.62414672762, 3.61742684789, + 3.6108664521, 3.60445787576, 3.59819399923, + 3.592068197, 3.58607429286, 3.58020651993, + 3.57445948514, 3.56882813748, 3.5633077395, + 3.5578938418, 3.55258226001, 3.54736905409, + 3.54225050954, 3.53722312046, 3.53228357414, + 3.52742873704, 3.52265564207, 3.51796147693, + 3.51334357346, 3.50879939795, 3.50432654219, + 3.49992271527, 3.49558573607, 3.4913135263, + 3.48710410411, 3.47886614237, 3.47085771144, + 3.46306588016, 3.45547879117, 3.44808554464, + 3.44087609744, 3.4338411752, 3.42697219544, + 3.42026120015, 3.41370079626, 3.40728410324, + 3.40100470653, 3.39485661617, 3.38883422999, + 3.38293230069, 3.37714590628, 3.37147042368, + 3.36590150482, 3.36043505519, 3.35506721435, + 3.34979433839, 3.34461298392, 3.33951989355, + 3.33451198267, 3.3295863274, 3.32474015352, + 3.3199708264, 3.31527584174, 3.31065281706, + 3.3060994839, 3.3016136806, 3.29719334569, + 3.28854129969, 3.28012863599, 3.27194189999, + 3.26396875282, 3.25619785067, 3.24861874006, + 3.24122176661, 3.23399799517, 3.22693913976, + 3.22003750184, 3.21328591581, 3.20667770063, + 3.2002066169, 3.19386682855, 3.18765286865, + 3.18155960874, 3.17558223129, 3.16971620498, + 3.1639572623, 3.15830137938, 3.15274475767, + 3.14728380734, 3.14191513221, 3.13663551594, + 3.13144190952, 3.12633141979, 3.12130129892, + 3.11634893481, 3.11147184224, 3.10666765471, + 3.10193411699, 3.0972690782, 3.08813637782, + 3.07925420286, 3.07060851058, 3.0621864209, + 3.0539760908, 3.04596660532, 3.03814788252, + 3.03051059033, 3.02304607359, 3.01574628977, + 3.00860375216, 3.00161147949, 2.9947629512, + 2.98805206756, 2.98147311398, 2.97502072908, + 2.96868987601, 2.96247581659, 2.95637408809, + 2.95038048206, 2.94449102535, 2.93870196271, + 2.93300974113, 2.92741099539, 2.92190253507, + 2.9164813325, 2.91114451188, 2.90588933915, + 2.90071321284, 2.89561365554, 2.8905883061, + 2.88563491243, 2.8759354898, 2.86649931119, + 2.85731166746, 2.84835906508, 2.83962909503, + 2.83111031887, 2.82279216952, 2.8146648644, + 2.80671932916, 2.79894713055, 2.79134041701, + 2.78389186607, 2.77659463754, 2.76944233182, + 2.76242895259, 2.75554887345, 2.74879680789, + 2.74216778225, 2.73565711142, 2.72926037674, + 2.72297340607, 2.71679225565, 2.71071319364, + 2.70473268509, 2.69884737824, 2.693054092, + 2.68734980447, 2.68173164244, 2.6761968717, + 2.67074288817, 2.66536720972, 2.66006746862, + 2.64968685818, 2.63958415075, 2.6297438751, + 2.62015183589, 2.61079497623, 2.60166125833, + 2.59273955939, 2.5840195806, 2.5754917671, + 2.5671472376, 2.55897772201, 2.55097550632, + 2.54313338341, 2.53544460937, 2.52790286427, + 2.52050221719, 2.51323709464, 2.50610225225, + 2.49909274914, 2.4922039248, 2.4854313781, + 2.4787709483, 2.47221869765, 2.4657708957, + 2.45942400483, 2.45317466714, 2.44701969236, + 2.44095604678, 2.43498084314, 2.42909133123, + 2.42328488933, 2.41755901624, 2.40633953091, + 2.39541501107, 2.38476910497, 2.37438680605, + 2.36425430827, 2.35435888041, 2.34468875653, + 2.33523304007, 2.3259816196, 2.31692509462, + 2.30805470992, 2.2993622974, 2.29084022432, + 2.28248134715, 2.27427897031, 2.26622680921, + 2.25831895701, 2.25054985471, 2.24291426415, + 2.23540724356, 2.22802412548, 2.22076049665, + 2.2136121797, 2.20657521654, 2.19964585312, + 2.19282052555, 2.18609584736, 2.17946859779, + 2.1729357111, 2.1664942667, 2.16014147999, + 2.15387469406, 2.14158908915, 2.12961846912, + 2.11794545368, 2.10655408816, 2.09542969053, + 2.08455871841, 2.07392865314, 2.06352789832, + 2.05334569055, 2.04337202094, 2.03359756554, + 2.02401362372, 2.01461206336, 2.00538527192, + 1.99632611278, 1.98742788593, 1.97868429286, + 1.97008940476, 1.9616376339, 1.95332370775, + 1.94514264545, 1.93708973655, 1.92916052156, + 1.92135077429, 1.91365648573, 1.90607384923, + 1.89859924703, 1.89122923782, 1.88396054536, + 1.87679004798, 1.86971476892, 1.86273186742, + 1.84903246517, 1.83567153691, 1.82263048664, + 1.80989223848, 1.79744107395, 1.78526249044, + 1.77334307781, 1.76167041036, 1.75023295184, + 1.73901997173, 1.72802147122, 1.71722811751, + 1.70663118536, 1.69622250501, 1.68599441547, + 1.67593972277, 1.66605166239, 1.65632386534, + 1.64675032767, 1.63732538277, 1.62804367632, + 1.61890014354, 1.60988998842, 1.60100866489, + 1.59225185952, 1.5836154758, 1.57509561963, + 1.56668858607, 1.55839084718, 1.55019904079, + 1.54210996014, 1.53412054435, 1.51842914115, + 1.50310294313, 1.48812189602, 1.47346757795, + 1.45912302502, 1.44507257982, 1.4313017591, + 1.417797138, 1.40454624816, 1.391537488, + 1.37876004322, 1.36620381637, 1.35385936408, + 1.34171784108, 1.32977095018, 1.3180108973, + 1.30643035113, 1.29502240671, 1.28378055261, + 1.27269864119, 1.26177086164, 1.25099171546, + 1.24035599423, 1.22985875922, 1.21949532285, + 1.20926123171, 1.19915225099, 1.1891643502, + 1.17929369001, 1.16953661021, 1.15988961853, + 1.15034938038, 1.13157655839, 1.11319427716, + 1.09518065276, 1.07751556704, 1.06018047944, + 1.04315826332, 1.02643306314, 1.00999016925, + 0.993815907861, 0.977897543941, 0.962223195295, + 0.946781756301, 0.931562830007, 0.916556667533, + 0.90175411383, 0.887146559019, 0.872725894627, + 0.858484474142, 0.844415077375, 0.830510878205, + 0.816765415315, 0.803172565598, 0.789726519943, + 0.776421761148, 0.763253043733, 0.750215375468, + 0.737304000439, 0.724514383492, 0.711842195939, + 0.699283302383, 0.686833748575, 0.674489750196, + 0.650104070648, 0.626099012346, 0.602449453164, + 0.579132162256, 0.556125593619, 0.533409706241, + 0.510965806738, 0.488776411115, 0.466825122853, + 0.445096524986, 0.423576084201, 0.402250065322, + 0.381105454764, 0.36012989179, 0.339311606539, + 0.318639363964, 0.29810241293, 0.277690439822, + 0.257393526101, 0.237202109329, 0.21710694721, + 0.197099084294, 0.177169820992, 0.15731068461, + 0.137513402144, 0.117769874579, 0.0980721524887, + 0.0784124127331, 0.0587829360689, 0.0391760855031, + 0.0195842852301, 0 +}; + + static const double B[1025] = { + 468043598.745, 454185281.982, 441133386.786, + 428819269.757, 417181876.023, 406166717.813, + 395725013.783, 385812960.329, 376391111.851, + 367423851.404, 358878936.738, 350727109.464, + 342941757.343, 335498621.458, 328375541.45, + 321552233.174, 315010094.053, 308732032.185, + 302702315.899, 296906440.935, 291331012.915, + 285963643.058, 280792855.461, 275808004.446, + 270999200.737, 266357245.389, 261873570.517, + 257540186.041, 253349631.735, 249294933.976, + 245369566.664, 241567415.856, 237882747.698, + 230844652.301, 224215968.814, 217961855.044, + 212051320.023, 206456705.678, 201153250.091, + 196118717.706, 191333084.832, 186778271.013, + 182437908.646, 178297144.629, 174342468.981, + 170561566.22, 166943186.067, 163477030.605, + 160153655.481, 156964383.183, 153901226.667, + 150956821.959, 148124368.489, 145397576.172, + 142770618.331, 140238089.759, 137794969.238, + 135436586.005, 133158589.665, 130956923.161, + 128827798.432, 126767674.455, 124773237.414, + 122841382.741, 120969198.842, 117393074.498, + 114024901.787, 110846987.361, 107843593.262, + 105000673.785, 102305653.75, 99747240.7669, + 97315265.5629, 95000545.5991, 92794768.101, + 90690389.3539, 88680547.6828, 86758987.9953, + 84919996.1313, 83158341.5649, 81469227.2427, + 79848245.5433, 78291339.5027, 76794768.5853, + 75355078.3902, 73969073.775, 72633794.9552, + 71346496.2016, 70104626.8117, 68905814.0771, + 67747848.0069, 66628667.5985, 65546348.4768, + 64499091.7445, 63485213.9074, 62503137.7568, + 61551384.1017, 59733373.2481, 58021039.3817, + 56405393.2293, 54878438.8023, 53433039.7483, + 52062806.7313, 50762002.0764, 49525458.6675, + 48348510.6706, 47226934.1194, 46156895.7613, + 45134908.8531, 44157794.8309, 43222649.9599, + 42326816.2279, 41467855.862, 40643528.9565, + 39851773.7738, 39090689.3553, 38358520.1316, + 37653642.2677, 36974551.5205, 36319852.4159, + 35688248.581, 35078534.0907, 34489585.7054, + 33920355.8956, 33369866.562, 32837203.3696, + 32321510.6295, 31821986.6654, 31337879.6134, + 30413135.3113, 29542122.4706, 28720271.6567, + 27943518.2501, 27208234.5323, 26511172.4564, + 25849415.1891, 25220335.8956, 24621562.5335, + 24050947.6575, 23506542.4223, 22986574.1168, + 22489426.6833, 22013623.7674, 21557813.9244, + 21120757.6673, 20701316.0956, 20298440.8828, + 19911165.4376, 19538597.0812, 19179910.1071, + 18834339.6081, 18501175.9757, 18179759.9851, + 17869478.3966, 17569760.0097, 17280072.1174, + 16999917.3132, 16728830.6117, 16466376.8456, + 16212148.3111, 15965762.6321, 15495105.5155, + 15051783.6023, 14633472.8806, 14238106.0377, + 13863837.9303, 13509016.4872, 13172158.0713, + 12851926.5229, 12547115.2589, 12256631.9188, + 11979485.1457, 11714773.1625, 11461673.8654, + 11219436.2047, 10987372.6619, 10764852.663, + 10551296.7957, 10346171.7177, 10148985.6613, + 9959284.45525, 9776647.99501, 9600687.10337, + 9431040.73252, 9267373.46466, 9109373.27455, + 8956749.52272, 8809231.15191, 8666565.06313, + 8528514.65085, 8394858.47935, 8265389.08465, + 8139911.88833, 7900214.37602, 7674431.7041, + 7461381.19, 7260010.7574, 7069381.37083, + 6888652.23304, 6717068.2507, 6553949.37303, + 6398681.4844, 6250708.59292, 6109526.10467, + 5974675.01146, 5845736.85046, 5722329.31864, + 5604102.4449, 5490735.23866, 5381932.74725, + 5277423.465, 5176957.04587, 5080302.27894, + 4987245.29223, 4897587.95517, 4811146.45477, + 4727750.02357, 4647239.80112, 4569467.81256, + 4494296.05084, 4421595.65018, 4351246.14058, + 4283134.77418, 4217155.91547, 4153210.48844, + 4031053.45636, 3915984.28239, 3807400.7263, + 3704767.03978, 3607605.02544, 3515486.5018, + 3428026.92286, 3344879.95083, 3265732.81994, + 3190302.35977, 3118331.57125, 3049586.66763, + 2983854.50841, 2920940.3665, 2860665.97936, + 2802867.84264, 2747395.71194, 2694111.28361, + 2642887.03006, 2593605.16898, 2546156.74866, + 2500440.83456, 2456363.78429, 2413838.59984, + 2372784.34781, 2333125.63928, 2294792.16242, + 2257718.26156, 2221842.55759, 2187107.60483, + 2153459.58052, 2120848.00323, 2058547.45994, + 1999859.79463, 1944478.13147, 1892129.468, + 1842570.12107, 1795581.88886, 1750968.80087, + 1708554.35336, 1668179.14769, 1629698.86458, + 1592982.5198, 1557910.95684, 1524375.53953, + 1492277.01457, 1461524.51863, 1432034.70898, + 1403731.00015, 1376542.89185, 1350405.37546, + 1325258.40889, 1301046.45049, 1277718.04459, + 1255225.45204, 1233524.32016, 1212573.38728, + 1192334.21771, 1172770.96356, 1153850.15023, + 1135540.48296, 1117812.67195, 1100639.27416, + 1083994.54978, 1052195.90814, 1022240.22693, + 993971.022577, 967249.079973, 941950.131258, + 917962.899577, 895187.442482, 873533.742731, + 852920.504418, 833274.120331, 814527.782755, + 796620.715006, 779497.504963, 763107.525152, + 747404.426526, 732345.695244, 717892.263476, + 704008.166703, 690660.241153, 677817.855988, + 665452.675682, 653538.448664, 642050.818932, + 630967.157747, 620266.41297, 609928.973904, + 599936.549831, 590272.060629, 580919.538101, + 571864.036815, 563091.553384, 554588.953291, + 538344.816665, 523041.548206, 508599.29108, + 494946.998456, 482021.249542, 469765.251724, + 458127.995525, 447063.535752, 436530.377359, + 426490.948641, 416911.147609, 407759.949924, + 399009.068882, 390632.659531, 382607.060391, + 374910.567309, 367523.234875, 360426.701557, + 353604.035312, 347039.596927, 340718.91876, + 334628.596889, 328756.19497, 323090.158348, + 317619.737168, 312334.917401, 307226.358847, + 302285.339317, 297503.704266, 292873.821293, + 288388.538937, 284041.149331, 275735.234396, + 267910.070584, 260524.871062, 253543.347354, + 246933.104947, 240665.13389, 234713.377391, + 229054.364815, 223666.898142, 218531.783, + 213631.597053, 208950.489813, 204474.009027, + 200188.949594, 196083.221672, 192145.735205, + 188366.298503, 184735.528953, 181244.774164, + 177886.04218, 174651.939551, 171535.616247, + 168530.716557, 165631.335218, 162831.978148, + 160127.527208, 157513.208541, 154984.564055, + 152537.425701, 150167.892222, 147872.308115, + 145647.244544, 141395.994603, 137390.624505, + 133610.283442, 130036.419482, 126652.470773, + 123443.605264, 120396.500282, 117499.155002, + 114740.730226, 112111.41094, 109602.287952, + 107205.255591, 104912.922975, 102718.536798, + 100615.913924, 98599.3823607, 96663.7294285, + 94804.156116, 93016.2367777, 91295.8834589, + 89639.3142378, 88043.0250685, 86503.7646782, + 85018.5121417, 83584.4568033, 82198.980265, + 80859.6401976, 79564.1557618, 78310.3944557, + 77096.3602287, 75920.1827217, 74780.1075103, + 72601.7735874, 70549.3244291, 68612.0902638, + 66780.5772822, 65046.3097201, 63401.6967477, + 61839.9197339, 60354.8363331, 58940.8985361, + 57593.0823673, 56306.8273413, 55077.9841309, + 53902.7691783, 52777.7251933, 51699.6866696, + 50665.7496879, 49673.2453971, 48719.716661, + 47802.8974376, 46920.6945257, 46071.1713659, + 45252.5336325, 44463.1163889, 43701.3726106, + 42965.8629118, 42255.2463268, 41568.2720255, + 40903.7718523, 40260.6535941, 39637.8948977, + 39034.5377622, 38449.6835453, 37332.1592893, + 36279.1577368, 35285.2130631, 34345.4616221, + 33455.5611057, 32611.6223983, 31810.1518596, + 31048.0022185, 30322.3306142, 29630.5625994, + 28970.3611385, 28339.5998107, 27736.3395662, + 27158.8084976, 26605.3841795, 26074.5782033, + 25565.0225957, 25075.4578572, 24604.7224005, + 24151.7432007, 23715.5274976, 23295.1554155, + 22889.7733832, 22498.5882546, 22120.8620455, + 21755.9072116, 21403.082403, 21061.7886423, + 20731.4658758, 20411.5898558, 20101.6693198, + 19801.2434311, 19227.1706446, 18686.2100916, + 18175.5584758, 17692.7212135, 17235.4710025, + 16801.8128973, 16389.9547259, 15998.2819199, + 15625.3360073, 15269.7961595, 14930.463299, + 14606.2463622, 14296.1503821, 13999.2661181, + 13714.7610004, 13441.871201, 13179.8946694, + 12928.184999, 12686.1460114, 12453.2269616, + 12228.9182827, 12012.7478009, 11804.2773608, + 11603.0998103, 11408.8363005, 11221.1338643, + 11039.6632386, 10864.1169034, 10694.2073132, + 10529.6652976, 10370.2386141, 10215.690635, + 9920.35530902, 9642.03589933, 9379.29279296, + 9130.84483975, 8895.54809344, 8672.3778898, + 8460.41366569, 8258.82604172, 8066.86578413, + 7883.85433402, 7709.17565017, 7542.26915762, + 7382.6236306, 7229.77186868, 7083.28604825, + 6942.7736517, 6807.8738919, 6678.25456313, + 6553.60926028, 6433.65491683, 6318.12961989, + 6206.79066653, 6099.41283073, 5995.78681498, + 5895.71786375, 5799.02451956, 5705.53750473, + 5615.09871424, 5527.56030707, 5442.78388486, + 5360.63974837, 5281.00622313, 5128.82081305, + 4985.39281878, 4849.98187786, 4721.92907957, + 4600.64604199, 4485.60570297, 4376.33451913, + 4272.40582769, 4173.43417369, 4079.07044241, + 3988.99766684, 3902.92740311, 3820.59658617, + 3741.76479301, 3666.21185297, 3593.73575486, + 3524.1508087, 3457.28602662, 3392.98369304, + 3331.09809869, 3271.49441705, 3214.04770487, + 3158.64201089, 3105.16957952, 3053.53013775, + 3003.63025539, 2955.38276983, 2908.70626808, + 2863.52461931, 2819.76655239, 2777.36527337, + 2736.25811858, 2657.69431628, 2583.6451563, + 2513.72928085, 2447.60726343, 2384.97598811, + 2325.56391052, 2269.1270432, 2215.44553905, + 2164.32077155, 2115.57282931, 2069.03835784, + 2024.56869368, 1982.02824566, 1941.29308582, + 1902.24971907, 1864.79400552, 1828.83021394, + 1794.27018797, 1761.03260977, 1729.04234809, + 1698.22987957, 1668.53077394, 1639.88523494, + 1612.23769017, 1585.53642374, 1559.73324667, + 1534.78320059, 1510.64429085, 1487.27724571, + 1464.64529866, 1442.7139913, 1421.45099465, + 1380.81030481, 1342.50136932, 1306.32740443, + 1272.1132493, 1239.70246899, 1208.95491167, + 1179.74463906, 1151.9581651, 1125.49295061, + 1100.25611146, 1076.16330573, 1053.13777154, + 1031.10949225, 1010.01446977, 989.794089986, + 970.394566925, 951.766454485, 933.864216342, + 916.645846088, 900.072530873, 884.108352851, + 868.720023553, 853.876647032, 839.549508182, + 825.711883191, 812.33886945, 799.407232626, + 786.895268923, 774.782680783, 763.050464528, + 751.680808624, 740.657001406, 719.585090388, + 699.720033366, 680.960086838, 663.214678935, + 646.402913465, 630.452308433, 615.297727189, + 600.880468722, 587.147490089, 574.050739088, + 561.546579359, 549.59529327, 538.160650604, + 527.209533055, 516.711606313, 506.639032813, + 496.96621939, 487.669594983, 478.727414292, + 470.119583902, 461.827507957, 453.833950828, + 446.122914658, 438.679529921, 431.489957406, + 424.541300267, 417.821524944, 411.319389924, + 405.024381463, 398.926655468, 393.01698488, + 387.286711944, 376.332318284, 366.004045462, + 356.249171211, 347.020757519, 338.276876563, + 329.979957895, 322.096235284, 314.59527586, + 307.449577629, 300.634224017, 294.126586238, + 287.906065913, 281.95387174, 276.252825046, + 270.787189968, 265.542524683, 260.50555071, + 255.664037759, 251.006702025, 246.523116109, + 242.203629065, 238.039295241, 234.021810832, + 230.143457166, 226.397049911, 222.775893491, + 219.273740104, 215.884752796, 212.60347214, + 209.424786113, 206.343902815, 203.356325724, + 197.644448118, 192.25828345, 187.17044241, + 182.356537811, 177.794783117, 173.465653828, + 169.351600521, 165.436804568, 161.706969302, + 158.149140755, 154.751553204, 151.503495587, + 148.395195583, 145.417718676, 142.562879997, + 139.823167083, 137.191672013, 134.662031621, + 132.228374673, 129.885275086, 127.627710402, + 125.451024827, 123.350896269, 121.323306878, + 119.364516656, 117.471039772, 115.639623265, + 113.867227861, 112.151010651, 110.488309437, + 108.876628554, 107.313626007, 104.324987222, + 101.506311917, 98.8433301246, 96.3233343285, + 93.9349706793, 91.6680628859, 89.5134629529, + 87.4629241036, 85.5089921298, 83.6449121192, + 81.8645480786, 80.1623134152, 78.5331106002, + 76.9722786296, 75.4755471284, 74.0389961376, + 72.6590207791, 71.3323001202, 70.0557696658, + 68.8265969947, 67.6421601273, 66.5000282736, + 65.3979446612, 64.3338111858, 63.3056746605, + 62.3117144747, 61.3502314957, 60.4196380687, + 59.5184489908, 58.6452733506, 57.7988071362, + 56.9778265301, 55.4077918373, 53.9267643608, + 52.5272846644, 51.2027090519, 49.9471006653, + 48.7551376125, 47.622035089, 46.5434790675, + 45.5155695954, 44.5347721114, 43.5978754878, + 42.7019557373, 41.8443445089, 41.0226016526, + 40.2344912502, 39.4779606118, 38.751121818, + 38.0522354538, 37.3796962368, 36.7320202863, + 36.1078338186, 35.5058630854, 34.9249253981, + 34.3639211041, 33.8218263982, 33.2976868701, + 32.7906117014, 32.2997684362, 31.8243782605, + 31.3637117346, 30.917084926, 30.4838559023, + 29.6552146411, 28.8733782988, 28.134432563, + 27.4348905633, 26.7716358691, 26.1418743927, + 25.5430936131, 24.9730278502, 24.4296285677, + 23.9110388709, 23.4155715259, 22.9416899422, + 22.4879916639, 22.0531939906, 21.6361214127, + 21.2356946011, 20.8509207292, 20.4808849434, + 20.1247428261, 19.7817137183, 19.4510747894, + 19.132155759, 18.824334187, 18.5270312637, + 18.2397080369, 17.9618620255, 17.6930241733, + 17.4327561035, 17.1806476409, 16.9363145704, + 16.6993966065, 16.4695555516, 16.0298519219, + 15.6148798725, 15.2225761964, 14.8511026109, + 14.4988157995, 14.1642421305, 13.8460562183, + 13.5430626642, 13.2541804371, 12.97842946, + 12.7149190454, 12.4628378888, 12.2214453808, + 11.9900640388, 11.7680728923, 11.5549016866, + 11.3500257858, 11.1529616813, 10.9632630215, + 10.7805170944, 10.6043417028, 10.4343823832, + 10.2703099236, 10.1118181445, 9.95862191002, + 9.81045534239, 9.6670702159, 9.52823450908, + 9.3937310977, 9.26335657253, 9.13692016828, + 9.01424279167, 8.77950188724, 8.5579029016, + 8.34835265336, 8.14987690272, 7.96160453251, + 7.78275419548, 7.61262298955, 7.45057681007, + 7.29604209573, 7.14849873828, 7.00747396878, + 6.87253706654, 6.74329476426, 6.6193872446, + 6.50048464099, 6.38628396998, 6.27650643422, + 6.17089504471, 6.06921251895, 5.97123941835, + 5.87677249363, 5.78562321153, 5.69761644002, + 5.61258927241, 5.53038997362, 5.45087703381, + 5.37391831699, 5.29939029358, 5.22717734731, + 5.15717114836, 5.08927008528, 5.02337874941, + 4.89727186893, 4.77819450111, 4.66556389779, + 4.5588605707, 4.45761989234, 4.36142500459, + 4.26990080294, 4.18270881023, 4.09954278998, + 4.02012497734, 3.9442028284, 3.87154620636, + 3.8019449374, 3.73520668068, 3.67115506623, + 3.60962806223, 3.5504765392, 3.49356300388, + 3.43876047989, 3.38595151559, 3.33502730255, + 3.28588689046, 3.2384364864, 3.19258882806, + 3.14826262191, 3.10538203853, 3.06387625858, + 3.0236790634, 2.98472846526, 2.9469663728, + 2.91033828793, 2.8747930306, 2.8067613898, + 2.74251940505, 2.68175424311, 2.62418694186, + 2.56956792209, 2.51767319702, 2.46830115574, + 2.42126982168, 2.37641450585, 2.33358579, + 2.29264778675, 2.2534766331, 2.21595918157, + 2.17999185932, 2.14547967046, 2.11233532111, + 2.08047844974, 2.0498349484, 2.02033636247, + 1.99191935846, 1.9645252511, 1.93809958206, + 1.91259174386, 1.8879546434, 1.86414440028, + 1.84112007579, 1.81884342903, 1.79727869694, + 1.77639239563, 1.75615314058, 1.73653148369, + 1.71749976531, 1.68110365251, 1.64677447223, + 1.61434304574, 1.58365847132, 1.55458570812, + 1.5270035349, 1.50080281743, 1.47588503118, + 1.45216099646, 1.42954979098, 1.40797781157, + 1.38737796141, 1.36768894386, 1.34885464657, + 1.33082360294, 1.31354851955, 1.2969858605, + 1.28109548066, 1.2658403013, 1.25118602242, + 1.23710086713, 1.22355535382, 1.21052209274, + 1.19797560406, 1.18589215458, 1.17424961117, + 1.16302730872, 1.15220593111, 1.14176740369, + 1.1316947959, 1.12197223308, 1.11258481634, + 1.09476027388, 1.07811888208, 1.06256992542, + 1.04803270312, 1.03443522136, 1.02171308882, + 1.00980857969, 0.998669835485, 0.988250182301, + 0.978507544678, 0.96940394074, 0.960905045915, + 0.952979814867, 0.945600153008, 0.938740630449, + 0.932378232401, 0.926492141047, 0.921063544663, + 0.916075470469, 0.911512638216, 0.907361331987, + 0.903609288065, 0.900245597058, 0.897260618748, + 0.894645908353, 0.892394153106, 0.890499118227, + 0.888955601518, 0.887759395947, 0.886907259694, + 0.886396893265, 0 +}; + + int n; + lebool negatif; + Uvalue uval, wval; + double v, x; + + util_Assert (u >= 0.0, "finv_Normal2: u < 0"); + util_Assert (u <= 1.0, "finv_Normal2: u > 1"); + + if (u >= 1.0) { + util_Warning (1, "finv_Normal2: u = 1"); + return fdist_XBIG; + } + if (u <= 0.0) { + util_Warning (1, "finv_Normal2: u = 0"); + return -fdist_XBIG; + } + if (u < 0.5) { + negatif = TRUE; + uval.u = 2.0*u; + } else { + negatif = FALSE; + uval.u = 2.0*(1.0 - u); + } + wval.i = uval.i & 2147221504; + n = (wval.i >> 18) - 3040; + /* util_Assert (n <= 1024, "n >= 1024"); */ + if (n < 0) { + if (negatif) { + util_Warning (1, "finv_Normal2: u --> 0"); + return -fdist_XBIG; + } else { + util_Warning (1, "finv_Normal2: u --> 1"); + return fdist_XBIG; + } + } + v = (uval.u - wval.u) * B[n]; + x = A[n] - v * (1.414214 - v * (A[n] - 0.4714045 * (1.0 + + 2.0 * A[n] * A[n]) * v)); + if (negatif) + return -x; + else + return x; +} + + +/*=========================================================================*/ + +double finv_LogNormal (double mu, double sigma, double u) +{ + double t, v; + util_Assert (sigma > 0.0, "finv_LogNormal: sigma <= 0"); + util_Assert (u >= 0.0 && u <= 1.0, "finv_LogNormal: u not in [0, 1]"); + if (DBL_EPSILON >= 1.0 - u) { + util_Warning (1, "finv_LogNormal: u --> 1"); + return fdist_XINF; + } + if (u <= 0.0) + return 0.0; + t = finv_Normal1 (u); + v = mu + sigma * t; + if ((t >= fdist_XBIGM) || (v >= DBL_MAX_EXP * num_Ln2)) { + util_Warning (1, "finv_LogNormal: u --> 1"); + return fdist_XINF; + } + if ((t <= -fdist_XBIGM) || (v <= -DBL_MAX_EXP * num_Ln2)) { + util_Warning (1, "finv_LogNormal: u --> 0"); + return 0.0; + } + return exp (mu + sigma * t); +} + + +/*=========================================================================*/ + +double finv_JohnsonSB (double alpha, double beta, double a, double b, + double u) +{ + double v, t; + util_Assert (beta > 0.0, "finv_JohnsonSB: beta <= 0"); + util_Assert (b > a, "finv_JohnsonSB: b <= a"); + util_Assert (u >= 0.0 && u <= 1.0, "finv_JohnsonSB: u not in [0, 1]"); + + if (u >= 1.0) /* if u == 1, in fact */ + return b; + if (u <= 0.0) /* if u == 0, in fact */ + return a; + + t = finv_Normal1 (u); + v = (t - alpha) / beta; + if ((t >= fdist_XBIGM) || (v >= DBL_MAX_EXP * num_Ln2)) { + util_Warning (1, "finv_JohnsonSB: u --> 1"); + return b; + } + if ((t <= -fdist_XBIGM) || (v <= -DBL_MAX_EXP * num_Ln2)) { + util_Warning (1, "finv_JohnsonSB: u --> 0"); + return a; + } + v = exp (v); + return (a + b * v) / (1 + v); +} + + +/*=========================================================================*/ + +double finv_JohnsonSU (double alpha, double beta, double u) +{ + double t, v; + util_Assert (beta > 0.0, "finv_JohnsonSU: beta <= 0"); + util_Assert (u >= 0.0 && u <= 1.0, "finv_JohnsonSU: u not in [0, 1]"); + if (u >= 1.0) { + util_Warning (1, "finv_JohnsonSU: u = 1"); + return fdist_XINF; + } + if (u <= 0.0) { + util_Warning (1, "finv_JohnsonSU: u = 0"); + return -fdist_XINF; + } + + t = finv_Normal1 (u); + if (t >= fdist_XBIGM) { + util_Warning (1, "finv_JohnsonSU: u --> 1"); + return fdist_XINF; + } + if (t <= -fdist_XBIGM) { + util_Warning (1, "finv_JohnsonSU: u --> 0"); + return -fdist_XINF; + } + + v = (t - alpha) / beta; + if (v >= num_Ln2 * DBL_MAX_EXP) { + util_Warning (1, "finv_JohnsonSU: v > Ln 2 * DBL_MAX_EXP"); + return fdist_XINF; + } + if (v <= num_Ln2 * DBL_MIN_EXP) { + util_Warning (1, "finv_JohnsonSU: v < Ln 2 * DBL_MIN_EXP"); + return -fdist_XINF; + } + return sinh (v); +} + + +/**************************************************************************/ + +double finv_ChiSquare1 (long k, double u) +/* + * Returns an approximation of the inverse of Chi square cdf + * with k degrees of freedom. + * As in Figure L.24 of P.Bratley, B.L.Fox, and L.E.Schrage. + * A Guide to Simulation Springer-Verlag, + * New York, second edition, 1987. + */ +{ + const double sqp5 = 0.70710678118654752440; + const double dwarf = 0.1e-15; + double Z, arg, zsq, ch, sqdf; + + util_Assert (u >= 0.0 && u <= 1.0, "finv_ChiSquare1: u not in [0, 1]"); + if (u <= 0.0) + return 0.0; + if (u >= 1.0) { + util_Warning (1, "finv_ChiSquare1: u = 1"); + return k * fdist_XBIG; + } + if (k == 1) { + Z = finv_Normal1 ((1.0 + u) / 2); + return (Z * Z); + } else { + if (k == 2) { + arg = 1.0 - u; + if (arg < dwarf) + arg = dwarf; + return (-log (arg) * 2.0); + } else { + if (u > dwarf) { + Z = finv_Normal1 (u); + sqdf = sqrt ((double) k); + zsq = Z * Z; + ch = -(((3753.0 * zsq + 4353.0) * zsq - 289517.0) * zsq - + 289717.0) * Z * sqp5 / 9185400; + ch = ch / sqdf + (((12.0 * zsq - 243.0) * zsq - 923.0) * zsq + + 1472.0) / 25515.0; + ch = ch / sqdf + ((9.0 * zsq + 256.0) * zsq - 433.0) * Z * sqp5 / + 4860; + ch = ch / sqdf - ((6.0 * zsq + 14.0) * zsq - 32.0) / 405.0; + ch = ch / sqdf + (zsq - 7.0) * Z * sqp5 / 9; + ch = ch / sqdf + 2.0 * (zsq - 1.0) / 3.0; + ch = ch / sqdf + Z / sqp5; + return (k * (ch / sqdf + 1.0)); + } else + return 0.0; + } + } +} + + +/**************************************************************************/ + +double finv_ChiSquare2 (long k, double u) +/* + * Returns an approximation of the inverse of Chi square cdf + * with k degrees of freedom. + * As in Figure L.23 of P.Bratley, B.L.Fox, and L.E.Schrage. + * A Guide to Simulation Springer-Verlag, + * New York, second edition, 1987. + */ +{ + const double E = 0.5e-5; /* Precision of this approximation */ + const double AA = 0.6931471805; + double A, XX, X, C, G, CH, Q, P1, P2, T, B, S1, S2, S3, S4, S5, S6; + + util_Assert (u >= 0.0 && u <= 1.0, "finv_ChiSquare2: u not in [0, 1]"); + if (k < 0 || u <= 0.000002) + return 0.0; + if (u >= 1.0) { + util_Warning (1, "finv_ChiSquare2: u = 1"); + return k * fdist_XBIG; + } + if (u >= 0.999998) + return (k + 4.0 * sqrt (2.0 * k)); + + G = num2_LnGamma (k / 2.0); + XX = 0.5 * k; + C = XX - 1.0; + + if (k >= -1.24 * log (u)) { + if (k <= 0.32) { + CH = 0.4; + A = num2_log1p (-u); + Q = CH; + P1 = 1.0 + CH * (4.67 + CH); + P2 = CH * (6.73 + CH * (6.66 + CH)); + T = -0.5 + (4.67 + 2.0 * CH) / P1 - (6.73 + + CH * (13.32 + 3.0 * CH)) / P2; + CH = CH - (1.0 - exp (A + G + 0.5 * CH + C * AA) * P2 / P1) / T; + while (fabs (Q / CH - 1.0) - 0.01 > 0) { + Q = CH; + P1 = 1.0 + CH * (4.67 + CH); + P2 = CH * (6.73 + CH * (6.66 + CH)); + T = -0.5 + (4.67 + 2.0 * CH) / P1 - (6.73 + CH * (13.32 + + 3.0 * CH)) / P2; + CH = CH - (1.0 - exp (A + G + 0.5 * CH + C * AA) * P2 / P1) / T; + } + } else { + X = finv_Normal1 (u); + P1 = 0.222222 / k; + CH = k * pow ((X * sqrt (P1) + 1.0 - P1), 3.0); + if (CH > 2.2 * k + 6.0) + CH = -2.0 * (num2_log1p (-u) - C * log (0.5 * CH) + G); + } + } else { + CH = pow ((u * XX * exp (G + XX * AA)), (1.0 / XX)); + if (CH - E < 0) + return CH; + } + + Q = CH; + P1 = 0.5 * CH; + P2 = u - fdist_Gamma (XX, 5, P1); + if (fdist_Gamma (XX, 5, P1) == -1.0) + return -1.0; + + T = P2 * exp (XX * AA + G + P1 - C * log (CH)); + B = T / CH; + A = 0.5 * T - B * C; + S1 = (210.0 + A * (140.0 + + A * (105.0 + A * (84.0 + A * (70.0 + 60.0 * A))))) / 420.0; + S2 = (420.0 + A * (735.0 + A * (966.0 + A * (1141.0 + 1278.0 * A)))) + / 2520.0; + S3 = (210.0 + A * (462.0 + A * (707.0 + 932.0 * A))) / 2520.0; + S4 = (252.0 + A * (672.0 + 1182.0 * A) + + C * (294.0 + A * (889.0 + 1740.0 * A))) / 5040.0; + S5 = (84.0 + 264.0 * A + C * (175.0 + 606.0 * A)) / 2520.0; + S6 = (120.0 + C * (346.0 + 127.0 * C)) / 5040.0; + CH = CH + T * (1.0 + 0.5 * T * S1 - B * C * (S1 - B * (S2 - + B * (S3 - B * (S4 - B * (S5 - B * S6)))))); + + while (fabs (Q / CH - 1.0) > E) { + Q = CH; + P1 = 0.5 * CH; + P2 = u - fdist_Gamma (XX, 5, P1); + if (fdist_Gamma (XX, 5, P1) == -1.0) + return -1.0; + + T = P2 * exp (XX * AA + G + P1 - C * log (CH)); + B = T / CH; + A = 0.5 * T - B * C; + S1 = (210.0 + A * (140.0 + A * (105.0 + A * (84.0 + + A * (70.0 + 60.0 * A))))) / 420.0; + S2 = (420.0 + A * (735.0 + A * (966.0 + A * (1141.0 + + 1278.0 * A)))) / 2520.0; + S3 = (210.0 + A * (462.0 + A * (707.0 + 932.0 * A))) / 2520.0; + S4 = (252.0 + A * (672.0 + 1182.0 * A) + + C * (294.0 + A * (889.0 + 1740.0 * A))) / 5040.0; + S5 = (84.0 + 264.0 * A + C * (175.0 + 606.0 * A)) / 2520.0; + S6 = (120.0 + C * (346.0 + 127.0 * C)) / 5040.0; + CH = CH + T * (1.0 + 0.5 * T * S1 - B * C * (S1 - B * (S2 - + B * (S3 - B * (S4 - B * (S5 - B * S6)))))); + } + + return CH; +} + + +/*=========================================================================*/ + +double finv_Student (long k, double u) +/* + * Returns an approximation of the inverse of a the Student Distribution + * with k degrees of freedom. + * As in Figure L.28 of P.Bratley, B.L.Fox, and L.E.Schrage. + * A Guide to Simulation Springer-Verlag, + * New York, second edition, 1987. + */ +{ + const double dwarf = 1.e-307; + const double piovr2 = 1.5707963268; + double arg, T, vtemp, ux2, p2tail, X, C, Y2, Y; + static double W[5] = { 0 }; + + if (k < 1) + util_Error ("Calling finv_Student with k < 1"); + if (u < 0. || u > 1.) + util_Error ("Calling finv_Student with u < 0 or u > 1"); + + /* For 1 degree of freedom we use a special method */ + /* of Standard Cauchy Inversion */ + if (k == 1) { + arg = num_Pi * (1.0 - u); + if (sin (arg) > dwarf) + return (cos (arg) / sin (arg)); + else + return (cos (arg) / dwarf); + } + + /* There is also a special method for 2 degrees of freedom */ + if (k == 2) { + if (u <= 0.5) + T = 2.0 * u; + else + T = 2.0 * (1.0 - u); + if (T <= dwarf) + T = dwarf; + vtemp = sqrt ((2.0 / (T * (2.0 - T))) - 2.0); + if (u <= 0.5) + return (-vtemp); + else + return (vtemp); + } + + if (u <= dwarf || (1.0 - u) <= dwarf) { + T = 10.0e30; + if (u < 0.5) + return (-T); + else + return (T); + } + + ux2 = u * 2.0; + + if (ux2 < 2.0 - ux2) + p2tail = ux2; + else + p2tail = 2.0 - ux2; + + W[2] = 1.0 / (k - 0.5); + W[1] = 48.0 / (W[2] * W[2]); + W[3] = ((20700.0 * W[2] / W[1] - 98.0) * W[2] - 16.0) * W[2] + 96.36; + W[4] = ((94.5 / (W[1] + W[3]) - 3.0) / W[1] + 1.0) * + sqrt (W[2] * piovr2) * k; + + X = W[4] * p2tail; + C = W[3]; + Y = pow (X, 2.0 / k); + + if (Y <= (0.05 + W[2])) { + Y2 = (k + 6.0) / (k + Y) - 0.089 * W[4] - 0.822; + Y2 = Y2 * (k + 2.0) * 3.0; + Y2 = (1.0 / Y2 + 0.5 / (k + 4.0)) * Y - 1.0; + Y2 = Y2 * (k + 1.0) / (k + 2.0); + Y = Y2 + 1.0 / Y; + } else { + X = finv_Normal1 (p2tail * 0.5); + Y = X * X; + if (k < 5) + C = C + 0.3 * (k - 4.5) * (X + 0.6); + C = (((0.05 * W[4] * X - 5.0) * X - 7.0) * X - 2.0) * X + W[1] + C; + Y = (((((0.4 * Y + 6.3) * Y + 36.0) * Y + 94.5) / C - Y - 3.0) / W[1] + + 1.0) * X; + Y = W[2] * Y * Y; + if (Y <= 0.002) + Y = 0.5 * Y * Y + Y; + else + Y = exp (Y) - 1.0; + } + + T = sqrt (k * Y); + if (u < 0.5) + return (-T); + else + return (T); +} + + +/*=========================================================================*/ +/* Constants for finv_BetaSymmetric */ + +#define EPSSINGLE 1.0e-5 /* Limited Tolerance */ +#define EPSILON 1.0e-15 /* Tolerance double precision */ +#define EPSBETA 1.0e-10 /* < 0.75 sqrt(DBL_EPSILON) */ +#define MAXI 11 /* Max number of Newton's iterations */ +#define MAXIB 50 /* Max number of bisection iterations */ +#define MAXJ 2000 /* Max number of terms in series */ +#define LOG2 0.6931471805599453 /* Ln(2) */ +#define LOG4 1.3862943611198906 /* Ln(4) */ +#define PI_2 1.5707963267948966 /* Pi / 2 */ +#define SQPI_2 0.88622692545275801 /* Sqrt(Pi) / 2 */ +#define ALIM1 100000.0 /* Limiting alpha for normal approx. */ + + + +/*------------------------------------------------------------------------*/ + +static double inverse1 ( + double alpha, /* Shape parameter */ + double bu /* u * Beta(alpha, alpha) */ + ) +/* + * This method is used for alpha < 1 and x close to 0. + */ +{ + int i, j; + double x, xnew; + double poc, sum, term; + + x = pow (bu * alpha, 1.0 / alpha); /* First term of series */ + + /* If T1/T0 is very small, neglect all terms of series except T0 */ + term = alpha * (1.0 - alpha) * x / (1.0 + alpha); + if (term < EPSILON) + return x; + + x = bu * alpha / (1.0 + term); + xnew = pow (x, 1.0 / alpha); /* Starting point of Newton's iterates */ + i = 0; + do { + ++i; + x = xnew; + + /* Compute the series for F(x) */ + poc = 1.0; + sum = 1.0 / alpha; + j = 1; + do { + poc *= x * (j - alpha) / j; + term = poc / (j + alpha); + sum += term; + ++j; + } while ((term > sum * EPSILON) && (j < MAXJ)); + sum *= pow (x, alpha); + + /* Newton's method */ + term = (sum - bu) * pow (x * (1.0 - x), 1.0 - alpha); + xnew = x - term; + + } while ((fabs (term) > EPSILON) && (i <= MAXI)); + + return xnew; +} + + +/*------------------------------------------------------------------------*/ + +static double inverse2 ( + double alpha, /* Shape parameter */ + double w /* (0.5 - u)B/pow(4, 1 - alpha) */ + ) +/* + * This method is used for alpha < 1 and x close to 1/2. + */ +{ + int i, j; + double term, sum, y, ynew, z; + double poc; + + term = (1.0 - alpha) * w * w * 4.0 / 3.0; + /* If T1/T0 is very small, neglect all terms of series except T0 */ + if (term < EPSILON) + return 0.5 - w; + + ynew = w / (1 + term); /* Starting point of Newton's iterates */ + i = 0; + do { + ++i; + y = ynew; + z = 4.0 * y * y; + + /* Compute the series for G(y) */ + poc = sum = 1.0; + j = 1; + do { + poc *= z * (j - alpha) / j; + term = poc / (2 * j + 1); + sum += term; + ++j; + } while ((term > sum * EPSILON) && (j < MAXJ)); + sum *= y; + + /* Newton's method */ + term = (sum - w) * pow (1.0 - z, 1.0 - alpha); + ynew = y - term; + + } while ((fabs (term) > EPSILON) && (i <= MAXI)); + + return 0.5 - ynew; +} + + +/*------------------------------------------------------------------------*/ + +static double bisect ( + double alpha, /* Shape parameter */ + double logBua, /* Ln(alpha * u * Beta(alpha, alpha)) */ + double a, /* x is presumed in [a, b] */ + double b) +/* + * Bisection method to find a solution x. This method is used for alpha > 1 and + * u very close to 0. It will rarely be called. + */ +{ + int i, j; + double z, sum, term; + double x, xprev; + + if (a >= 0.5 || a > b) { + a = 0.0; + b = 0.5; + } + + x = 0.5 * (a + b); + i = 0; + do { + ++i; + z = -x / (1 - x); + + /* Compute the series for F(x) */ + sum = term = 1.0; + j = 1; + do { + term *= z * (j - alpha) / (j + alpha); + sum += term; + ++j; + } while ((fabs (term/sum) > EPSILON) && (j < MAXJ)); + sum *= x; + + /* Bisection method */ + z = logBua - (alpha - 1.0) * log (x * (1.0 - x)); + if (z > log(sum)) + a = x; + else + b = x; + xprev = x; + x = 0.5 * (a + b); + + } while ((fabs(xprev - x) > EPSILON) && (i < MAXIB)); + + return x; +} + + +/*------------------------------------------------------------------------*/ + +static double inverse3 ( + double alpha, /* Shape parameter */ + double logBua /* Ln(alpha * u * Beta(alpha, alpha)) */ + ) +/* + * This method is used for alpha > 1 and x close to 0. + */ +{ + int i, j; + double z, x, w, xnew, sum, term; + double eps = EPSSINGLE; + /* For alpha <= 100000 and u < 1.0/(2.5 + 2.25*sqrt(alpha)), X0 is always + to the right of the solution, so Newton is certain to converge. */ + const double X0 = 0.497; + + /* Compute starting point of Newton's iterates */ + w = logBua / alpha; + x = exp (w); + term = (num2_log1p(-x) + logBua) / alpha; + z = exp (term); + if (z >= 0.25) + xnew = X0; + else if (z > 1.0e-6) + xnew = (1.0 - sqrt(1.0 - 4.0*z)) / 2.0; + else + xnew = z; + + i = 0; + do { + ++i; + if (xnew >= 0.5) + xnew = X0; + x = xnew; + + w = logBua - (alpha - 1.0) * log (x * (1.0 - x)); + if (fabs (w) >= DBL_MAX_EXP * LOG2) { + xnew = X0; + continue; + } + w = exp (w); + z = -x / (1 - x); + + /* Compute the series for F(x) */ + sum = term = 1.0; + j = 1; + do { + term *= z * (j - alpha) / (j + alpha); + sum += term; + ++j; + } while ((fabs (term/sum) > eps) && (j < MAXJ)); + sum *= x; + + /* Newton's method */ + term = (sum - w) / alpha; + xnew = x - term; + if (fabs(term) < 32.0*EPSSINGLE) + eps = EPSILON; + + } while ((fabs (xnew - x) > EPSILON) && (fabs (xnew - x) > sum * EPSILON) && + (i <= MAXI)); + + /* If Newton has not converged with enough precision, call bisection + method. It is very slow, but will be called very rarely. */ + if (i >= MAXI && fabs (xnew - x) > 10.0 * EPSILON) + return bisect (alpha, logBua, 0.0, 0.5); + return xnew; +} + + +/*------------------------------------------------------------------------*/ + +static double inverse4 ( + double alpha, /* Shape parameter */ + double logBva /* Ln(B) + Ln(1/2 - u) + (alpha - 1)*Ln(4) */ + ) +/* + * This method is used for alpha > 1 and x close to 1/2. + */ +{ + int i, j; + double term, sum, y, ynew, z; + double eps = EPSSINGLE; + + ynew = exp (logBva); /* Starting point of Newton's iterates */ + + i = 0; + do { + ++i; + y = ynew; + + /* Compute the series for G(y) */ + z = 4.0 * y * y; + term = sum = 1.0; + j = 1; + do { + term *= z * (j + alpha - 0.5) / (0.5 + j); + sum += term; + ++j; + } while ((term > sum * eps) && (j < MAXJ)); + sum *= y * (1.0 - z); + + /* Newton's method */ + term = sum - exp (logBva - (alpha - 1.0) * num2_log1p (-z)); + ynew = y - term; + if (fabs(term) < 32.0*EPSSINGLE) + eps = EPSILON; + + } while ((fabs (ynew - y) > EPSILON) && (fabs (ynew - y) > sum*EPSILON) + && (i <= MAXI)); + + return 0.5 - ynew; +} + + +/*-------------------------------------------------------------------------*/ + +static double PeizerInverse (double alpha, double u) +{ + /* Inverse of the normal approximation of Peizer and Pratt */ + double t1, t3, xprev; + const double C2 = alpha - 1.0 / 3.0 + 0.025 / alpha; + const double z = finv_Normal1 (u); + double x = 0.5; + double y = 1.0 - x; + int i = 0; + + do { + i++; + t1 = (2.0 * alpha - 5.0 / 6.0) * x * y; + t3 = 1.0 - y * fdist_belog (2.0 * x) - x * fdist_belog (2.0 * y); + xprev = x; + x = 0.5 + 0.5 * z * sqrt(t1 / t3) / C2; + y = 1.0 - x; + } while (i <= MAXI && fabs (x - xprev) > EPSBETA); + + return x; +} + + +/*------------------------------------------------------------------------*/ + +double finv_BetaSymmetric (double alpha, double u) +/* + * Compute the inverse of the symmetrical beta distribution. + * Returns a negative value on error, otherwise returns x in [0, 1]. + */ +{ + double temp, x, y0; + int isUpper; /* True if u > 0.5 */ + double B; /* Beta(alpha, alpha) */ + double C; /* 4^(alpha-1) * Beta(alpha, alpha) */ + double logB; /* Ln(Beta(alpha, alpha)) */ + double logC; /* Ln(4^(alpha-1)*Beta(alpha, alpha)) */ + double logBua; /* Ln(alpha * u * Beta(alpha, alpha)) */ + double logBva; /* Ln(4^(alpha-1)*Beta(alpha,alpha)*(0.5 - u)*/ + + util_Assert (alpha > 0.0, "finv_BetaSymmetric: p <= 0\n"); + util_Assert (u >= 0.0 && u <= 1.0, + "finv_BetaSymmetric: u is not in [0, 1]\n"); + + if (u == 0.0) + return 0.0; + if (u == 1.0) + return 1.0; + if (u == 0.5) + return 0.5; + if (alpha == 1.0) + return u; /* alpha = 1 is the uniform law */ + if (alpha == 0.5) { /* alpha = 1/2 is the arcsin law */ + temp = sin (u * PI_2); + return temp * temp; + } + + if (alpha > ALIM1) + return PeizerInverse (alpha, u); + + if (u > 0.5) { + u = 1.0 - u; + isUpper = 1; + } else + isUpper = 0; + + fdist_CalcB4 (alpha, &B, &logB, &C, &logC); + + if (alpha <= 1.0) { + /* First term of integrated series around 1/2 */ + y0 = C * (0.5 - u); + if (y0 > 0.25) + x = inverse1 (alpha, B * u); + else + x = inverse2 (alpha, y0); + + } else { + if (u < 1.0 / (2.5 + 2.25*sqrt(alpha))) { + logBua = logB + log (u * alpha); + x = inverse3 (alpha, logBua); + } else { + logBva = logC - LOG2 + num2_log1p (-2.0*u); + x = inverse4 (alpha, logBva); + } + } + + if (isUpper) + return 1.0 - x - DBL_EPSILON; + else + return x; +} + + +/*=========================================================================*/ + +long finv_Geometric (double p, double u) +{ + static double pold = -1.0; + static double v = 1.0; + util_Assert (p >= 0.0 && p <= 1.0, "finv_Geometric: p not in [0, 1]"); + util_Assert (u >= 0.0 && u <= 1.0, "finv_Geometric: u not in [0, 1]"); + if (p >= 1.0) + return 0; + if (u <= 0.0) + return 0; + if (u >= 1.0 || p <= 0.0) + return INT_MAX; + if (pold != p) { + pold = p; + v = num2_log1p (-p); + } + return (long) (num2_log1p (-u) / v); +} + + +/*=========================================================================*/ + +double finv_GenericC (wdist_CFUNC F, double par[], double U, int prec, + int Detail) +{ + const int MaxIter = 100; /* Maximum number of iterations */ + const double Epsilon = EpsArray[prec]; /* Absolute precision */ + double x, y = 1.0; + double yb, ya, xb, xa; + int i; + int fini; + + util_Assert (U >= 0.0 && U <= 1.0, "finv_GenericC: U not in [0, 1]"); + util_Assert (prec <= DBL_DIG, "finv_GenericC: d too large"); + util_Assert (prec > 0, "finv_GenericC: d <= 0"); + if (Detail > 0) { + printf ("---------------------------------------------------------"); + printf ("\n U = %10.8f\n", U); + } + if (U <= 0.0) { + x = -DBL_MAX; + if (Detail > 0) { + printf ("\n x y\n"); + printf ("%17.2g %17.*f\n", x, prec, U); + } + return x; + } + if (U >= 1.0) { + x = DBL_MAX; + if (Detail > 0) { + printf ("\n x y\n"); + printf ("%17.2g %17.*f\n", x, prec, U); + } + return x; + } + + xb = 8.0; /* tentative upper limit */ + xa = -8.0; /* tentative lower limit */ + yb = F (par, xb); + ya = F (par, xa); + + util_Assert (yb >= ya, "finv_GenericC: F is decreasing"); + + /* make sure that unknown x is inside [xa, xb] */ + while (yb < U) { + xa = xb; + ya = yb; + xb *= 2.0; + yb = F (par, xb); + } + while (ya > U) { + xb = xa; + yb = ya; + xa *= 2.0; + ya = F (par, xa); + } + + yb -= U; + ya -= U; + + if (Detail > 0) { + printf ("\niter xa xb F - u\n"); + } + fini = 0; + i = 0; + while (!fini) { + if (Detail > 0) { + printf ("%3d %18.*g %18.*g %14.4g\n", i, prec, xa, prec, xb, y); + } + x = (xa + xb) / 2.0; + y = F (par, x) - U; + if ((fabs (y) <= Epsilon) || + (fabs ((xb - xa)/(x + DBL_EPSILON)) <= Epsilon)) { + fini = 1; + if (Detail > 0) { + printf ("\n x U\n"); + printf ("%20.*g %18.*g\n", prec, x, prec, y + U); + } + } else if (y * ya < 0.0) { + xb = x; + } else + xa = x; + ++i; + if (i > MaxIter) { + printf + ("\n******* finv_GenericC: SEARCH DOES NOT SEEM TO CONVERGE\n"); + fini = 1; + } + } + return x; +} + + +/*=========================================================================*/ + +long finv_GenericD1 (fmass_INFO W, double u) +{ + long i, j, k; + double *F; + + util_Error ("finv_GenericD1 is not finished."); + util_Assert (W != NULL, "finv_GenericD1: fmass_INFO is NULL pointer"); + util_Assert (u >= 0.0 && u <= 1.0, "finv_GenericD1: u not in [0, 1]"); + + F = W->cdf; + + /* Remember: the upper part of cdf contains the complementary distribu- + tion for W->smed < s <= W->smax, and the lower part of cdf the + distribution for W->smin <= s <= W->smed */ + + if (u <= F[W->smed - W->smin]) { + /* In the lower part of cfd */ + if (u <= F[0]) + return W->smin; + i = 0; + j = W->smed - W->smin; + while (i < j) { + k = (i + j) / 2; + if (u > F[k]) + i = k + 1; + else + j = k; + } + + } else { + /* In the upper part of cdf */ + u = 1 - u; + if (u < W->cdf[W->smax - W->smin]) + return W->smax; + + i = W->smed - W->smin + 1; + j = W->smax - W->smin; + while (i < j) { + k = (i + j) / 2; + if (u < F[k]) + i = k + 1; + else + j = k; + } + } + + return i + W->smin; +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/probdist/finv.tex b/TESTU01/TestU01-1.2.3/probdist/finv.tex new file mode 100644 index 0000000..a76b277 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/finv.tex @@ -0,0 +1,323 @@ +\defmodule {finv} + +Here one finds procedures to compute or approximate the +inverse of certain distribution functions. +Each procedure computes $F^{-1}(u) = \inf\{x\in\mathbb{R} : F(x)\ge u\}$, +where $0\le u\le 1$ and $F$ +is the distribution function of a specific type of random variable. +These procedures can be used, among other things, to generate +the corresponding random variables by inversion, by passing a +$U(0,1)$ random variate as the value of $u$. + +Several distributions are only implemented in standardized form here, +i.e., with the location parameter set to 0 and the scale parameter +set to 1. To obtain the inverse for the distribution shifted +by $x_0$ and rescaled by a factor $c$, it suffices to multiply the +returned value by $c$ and add $x_0$. + +\bigskip\hrule\medskip +\code\hide +/* finv.h for ANSI C */ + +#ifndef FINV_H +#define FINV_H +\endhide +#include "gdef.h" /* From the library mylib */ +#include "fmass.h" +#include "fdist.h" +#include "wdist.h" +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Continuous distributions} + +\code + +double finv_Expon (double u); +\endcode + \tab + Returns the inverse of the standard exponential distribution, +$$ + F^{-1}(u) = -\ln (1-u), \qquad 0 \le u \le 1. +$$ + \endtab +\code + +double finv_Weibull (double alpha, double u); +\endcode + \tab + Returns the inverse of the standard Weibull distribution, +$$ + F^{-1}(u) = \left(-\ln (1-u) \right)^{1/\alpha}, \qquad 0 \le u \le 1. +$$ + Restriction: $\alpha > 0$. + \endtab +\code + + +double finv_ExtremeValue (double u); +\endcode + \tab + Returns the inverse of the standard extreme value distribution, +$$ + F^{-1}(u) = -\ln (-\ln (u)), \qquad 0 \le u \le 1. +$$ + \endtab +\code + +double finv_Logistic (double u); +\endcode + \tab + Returns the inverse of the standard logistic distribution, +$$ + F^{-1}(u) = \ln \left(\frac{u}{1-u}\right), \qquad 0 \le u \le 1. +$$ + \endtab +\code + +double finv_Pareto (double c, double u); +\endcode + \tab + Returns the inverse of the standard Pareto distribution, +$$ + F^{-1}(u) = \left(\frac 1 {1 - u}\right)^{1/c}, + \qquad 0 \le u \le 1. +$$ + Restriction: $c > 0$. + \endtab +\code + + +double finv_Normal1 (double u); +\endcode + \tab + Returns an approximation of $\Phi^{-1}(u)$, + where $\Phi$ is the standard normal distribution function, + with mean 0 and variance 1. + Uses rational Chebyshev approximations giving at least 15 decimal + digits of precision over most of the range \cite{tBLA76a}. + Far in the lower tail ($u < 10 ^{-122}$), the precision decreases slowly + until for $u < 10 ^{-308}$, the function gives only 11 decimal + digits of precision. + \endtab +\code + + +double finv_Normal2 (double u); +\endcode + \tab + Returns an approximation of $\Phi^{-1}(u)$, + where $\Phi$ is the standard normal distribution function, with mean 0 and + variance 1. Uses Marsaglia's et al \cite{rMAR94b} method + with tables lookup. The method works provided that + the processor respects the IEEE-754 floating-point standard. + Returns 6 decimal digits of precision. This function is twice as fast + as {\tt finv\_Normal1}. + \endtab +\hide\code + + +double finv_Normal3 (double u); +\endcode + \tab + Returns an approximation of $\Phi^{-1}(u)$, + where $\Phi$ is the standard normal distribution function, + with mean 0 and variance 1. + Uses a rational approximation giving at least 7 decimal digits of + precision when $10^{-20} < u < 1 - 10^{-20}$ + (see \cite{sBRA87a,tKEN80a}). This method is slow. + \endtab +\endhide\code + + +double finv_LogNormal (double mu, double sigma, double u); +\endcode + \tab + Returns the inverse of the lognormal distribution, +$$ + F^{-1}(u) = e^{\mu + \sigma\Phi^{-1} (u)}, + \qquad 0 \le u \le 1. +$$ + Restriction: $\sigma > 0$. + \endtab +\code + + +double finv_JohnsonSB (double alpha, double beta, double a, double b, + double u); +\endcode + \tab + Returns the inverse of the Johnson JSB distribution, +$$ + F^{-1}(u) = \frac {a + b\,v}{1 + v}, +$$ + where +$$ + v = \exp \left({\frac{\Phi^{-1}(u) - \alpha}{\beta}}\right), + \qquad 0 \le u \le 1. +$$ + and $\Phi^{-1}$ is the inverse of the standard normal distribution. + Restrictions: $\beta>0$ and $a < x < b$. + \endtab +\code + + +double finv_JohnsonSU (double alpha, double beta, double u); +\endcode + \tab + Returns the inverse of the Johnson JSU distribution, +$$ + F^{-1}(u) = \frac {v - 1/v}{2} +$$ + where +$$ + v = \exp \left({\frac{\Phi^{-1}(u) - \alpha}{\beta}}\right), + \qquad 0 \le u \le 1. +$$ +and $\Phi^{-1}$ is the inverse of the standard normal distribution. +Restriction: $\beta>0$. + \endtab +\code + + +double finv_ChiSquare1 (long k, double u); +\endcode + \tab + Returns a quick and dirty approximation of $F^{-1}(u)$, + where $F$ is the chi-square distribution with $k$ degrees of freedom. + Uses the approximation given in Figure L.24 of \cite{sBRA87a}. + \endtab +\code + + +double finv_ChiSquare2 (long k, double u); +\endcode + \tab + Returns an approximation of $F^{-1}(u)$, where $F$ is the + chi-square distribution with $k$ degrees of freedom. + Uses the approximation given in \cite{tBES75a} + and in Figure L.23 of \cite{sBRA87a}. This function is up to + 20 times slower than {\tt finv\_ChiSquare1}. + \endtab +\code + + +double finv_Student (long n, double u); +\endcode + \tab + Returns an approximation of $F^{-1}(u)$, where $F$ is the + {\em Student-$t$\/} distribution function with $n$ degrees of freedom. + Uses an approximation giving at least + 5 decimal digits of precision when $n \ge 8$ or $n\le 2$, and + 3 decimal digits of precision when $3\le n \le 7$ + (see \cite{tHIL70a} and Figure L.28 of \cite{sBRA87a}). + \endtab +\code + + +double finv_BetaSymmetric (double p, double u); +\endcode + \tab + Returns a special approximation of $F^{-1}(u)$, where $F(x)$ is the + symmetric {\it beta} distribution with shape parameter $p = q$ + as defined in (\ref{eq:Fbeta}). Uses four different hypergeometric series + (for the four cases $x$ close to 0 and $p \le 1$, + $x$ close to 0 and $p > 1$, $x$ close to 1/2 and $p \le 1$, + and $x$ close to 1/2 and $p > 1$) + to compute the distribution $u = F(x)$, + which are then solved by Newton's method for the solution of equations. + For $p > 100000$, uses a normal approximation given in \cite{tPEI68a}. + Restrictions: $p > 0$ and $0 \le u \le 1$. + \endtab +\code + + +double finv_GenericC (wdist_CFUNC F, double par[], double u, int d, + int detail); +\endcode + \tab + Uses binary search to find the inverse of a generic continuous + distribution function $F$, evaluated at $u$. + The parameters of $F$ (if any) are passed in the array {\tt par}. + The returned value has $d$ decimal digits of precision. + If {\tt detail > 0}, the procedure will print detailed information + about the inversion process. + Restrictions: $0 \le u \le 1$ and $d>0$. + \endtab + +\newpage +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Discrete distributions} +\hide +\code + +long finv_GenericD1 (fmass_INFO W, double u); +\endcode + \tab +This function is not finished. Must check that it works for all cases +and also eliminate some ugliness. + Uses binary search to find the inverse of a generic discrete + distribution function evaluated at $u$, and whose values have been + precomputed and are kept inside the structure $W$. + The procedure returns an approximation of $F^{-1}(u)$. \\ + Restriction: $0 \le u \le 1$. + \endtab +\code + +#if 0 +long finv_GenericD2 (wdist_DFUNC F, fmass_INFO W, double u); +#endif +\endcode + \tab + Uses binary search to find the inverse of a generic discrete + distribution function $F$, evaluated at $u$. + The parameters of $F$ (if any) are passed in the structure {\tt W}. + The procedure assumes that the variable {\tt F} + contains the distribution function $F$ and returns an approximation + of $F^{-1}(u)$. \\ + \hpierre{Je ne vois pas trop \`a quoi inverser $\bar F$ peut bien servir. + En tous cas, il faut faire bien attention comment on d\'efinit + l'inverse dans ce cas. } + \hrichard {J'ai enlev\'e le parametre comp} + Restriction: $0 \le u \le 1$. + \endtab +\endhide +\code + + +long finv_Geometric (double p, double u); +\endcode + \tab Returns the inverse of the geometric distribution, +$$ + F^{-1}(u) = \left\lfloor \frac{\ln (1 - u)}{\ln (1 - p)}\right\rfloor, + \qquad 0 \le u \le 1. +$$ + Restriction: $0 \le p \le 1$. + \endtab +\code + +\hide +#if 0 +long finv_Poisson2 (fmass_INFO W, double u); +\endcode + \tab Returns the inverse of the Poisson distribution function, + using the structure {\tt W}, which must have been created previously + by calling {\tt fmass\_CreatePoisson} with the desired $\lambda$. + Uses binary search. + \endtab +\code + + +long finv_Binomial2 (fmass_INFO W, double u); +\endcode + \tab Returns the inverse of the binomial distribution function, + from the structure {\tt W}, which must have been created previously + by calling {\tt fmass\_CreateBinomial} with the desired $n$ and $p$. + Uses binary search. + \endtab +\code + +#endif +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/probdist/fmass.c b/TESTU01/TestU01-1.2.3/probdist/fmass.c new file mode 100644 index 0000000..207825f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/fmass.c @@ -0,0 +1,780 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: fmass.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "fmass.h" + +#include "util.h" +#include "num.h" +#include "num2.h" + +#include +#include +#include +#include + + +#define TRACE1(N) printf ("********* " #N " = %d\n", N); +#define TRACE2(x) printf ("********* " #x " = %g\n", x); + + +double fmass_Epsilon = 1.0e-16; + +/* When we precompute probability terms until terms are smaller than + fmass_Epsilon, the last few terms will not be very precise. Instead we + add terms as small as fmass_Epsilon * EPS_EXTRA to get a few correct digits + at the tails of the precomputed distributions. */ +static const double EPS_EXTRA = 1 / 100.0; + +double fmass_MaxLambdaPoisson = 100000.0; + +double fmass_MaxnBinomial = 100000.0; + +double fmass_MaxnNegaBin = 100000.0; + + + + +/*=========================================================================*/ + +double fmass_PoissonTerm1 (double lam, long s) +{ + const double lamlim = 20.0; + double y; + double x = s; + double Res; + + if (s < 0) + return 0.0; + + if ((lam < lamlim) && (x < 2.0 * lamlim)) { + Res = exp (-lam) * pow (lam, x) / num2_Factorial (s); + + } else { + y = x * log (lam) - num2_LnGamma (x + 1.0) - lam; + Res = exp (y); + } + + return Res; +} + +/*=========================================================================*/ + +fmass_INFO fmass_CreatePoisson (double lam) +{ + double epsilon; + long i, mid, Nmax; + long imin, imax; + double sum; + fmass_INFO W; + double *P; /* Poisson probability terms */ + double *F; /* Poisson cumulative probabilities */ + + util_Assert (lam >= 0.0, "fmass_CreatePoisson: lambda < 0"); + W = (fmass_INFO) util_Malloc (sizeof (struct fmass_INFO_T)); + W->paramI = NULL; + W->paramR = (double *) util_Malloc (sizeof (double)); + W->paramR[0] = lam; + + /* For lam > fmass_MaxLambdaPoisson, we do not use pre-computed arrays */ + if (lam > fmass_MaxLambdaPoisson) { + W->pdf = NULL; + W->cdf = NULL; + return W; + } + + /* In theory, the Poisson distribution has an infinite range. But */ + /* for i > Nmax, probabilities should be extremely small. */ + Nmax = (long) (lam + 16 * (2 + sqrt (lam))); + P = (double *) util_Calloc ((size_t) (1 + Nmax), sizeof (double)); + F = (double *) util_Calloc ((size_t) (1 + Nmax), sizeof (double)); + + mid = (long) lam; + epsilon = EPS_EXTRA * fmass_Epsilon / fmass_PoissonTerm1 (lam, mid); + /* For large lam, fmass_PoissonTerm1 will lose a few digits of precision */ + /* We shall normalize by explicitly summing all terms >= epsilon */ + sum = P[mid] = 1.0; + + /* Start from the maximum and compute terms > epsilon on each side. */ + i = mid; + while (i > 0 && P[i] > epsilon) { + P[i - 1] = P[i] * i / lam; + i--; + sum += P[i]; + } + W->smin = imin = i; + + i = mid; + while (P[i] > epsilon) { + P[i + 1] = P[i] * lam / (i + 1); + i++; + sum += P[i]; + if (i >= Nmax - 1) { + Nmax *= 2; + P = (double *) util_Realloc (P, (1 + Nmax) * sizeof (double)); + F = (double *) util_Realloc (F, (1 + Nmax) * sizeof (double)); + /* util_Warning (TRUE, "fmass_CreatePoisson: Calling Realloc"); */ + } + } + W->smax = imax = i; + + /* Renormalize the sum of probabilities to 1 */ + for (i = imin; i <= imax; i++) { + P[i] /= sum; + } + + /* Compute the cumulative probabilities until F >= 0.5, and keep them in + the lower part of array, i.e. F[s] contains all P[i] for i <= s */ + F[imin] = P[imin]; + i = imin; + while (i < imax && F[i] < 0.5) { + i++; + F[i] = P[i] + F[i - 1]; + } + /* This is the boundary between F and 1 - F in the CDF */ + W->smed = i; + + /* Compute the cumulative probabilities of the complementary distribution + and keep them in the upper part of the array. i.e. F[s] contains all + P[i] for i >= s */ + F[imax] = P[imax]; + i = imax - 1; + while (i > W->smed) { + F[i] = P[i] + F[i + 1]; + i--; + }; + + /* Reset imin because we lose too much precision for a few terms near + imin when we stop adding terms < epsilon. */ + i = imin; + while (i < W->smed && F[i] < fmass_Epsilon) + i++; + W->smin = imin = i; + + /* Same thing with imax */ + i = imax; + while (i > W->smed && F[i] < fmass_Epsilon) + i--; + W->smax = imax = i; + + W->pdf = (double *) util_Calloc ((size_t) (imax + 1 - imin), sizeof (double)); + W->cdf = (double *) util_Calloc ((size_t) (imax + 1 - imin), sizeof (double)); + for (i = imin; i <= imax; i++) { + W->pdf[i - imin] = P[i]; + W->cdf[i - imin] = F[i]; + } + util_Free (P); + util_Free (F); + return W; +} + +/*-------------------------------------------------------------------------*/ + +double fmass_PoissonTerm2 (fmass_INFO W, long s) +{ + double lam; + + util_Assert (W != NULL, + "fmass_PoissonTerm2: fmass_INFO is NULL pointer"); + lam = W->paramR[0]; + if (s < 0) + return 0.0; + if (W->pdf == NULL) + return fmass_PoissonTerm1 (lam, s); + if (s > W->smax || s < W->smin) + return fmass_PoissonTerm1 (lam, s); + return W->pdf[s - W->smin]; +} + +/*-------------------------------------------------------------------------*/ + +void fmass_DeletePoisson (fmass_INFO W) +{ + if (W == NULL) + return; + util_Free (W->paramR); + util_Free (W->pdf); + util_Free (W->cdf); + util_Free (W); +} + + +/*=========================================================================*/ + +double fmass_BinomialTerm1 (long n, double p, double q, long s) +{ + const long slim = 30; /* To avoid overflow */ + const double maxexp = (DBL_MAX_EXP - 1) * num_Ln2; /* To avoid overflow */ + const double minexp = (DBL_MIN_EXP - 1) * num_Ln2; /* To avoid underflow */ + int signe = 1; + double Res; + + util_Assert (n >= 0, "fmass_BinomialTerm1: n < 0"); + if (0 == n) + return 1.0; + if (s < 0 || s > n) + return 0.0; + + /* Combination(n, s) are symmetric between s and n-s */ + if (s > n / 2) { + s = n - s; + Res = p; + p = q; + q = Res; + } + + if (p < 0.0) { + p = -p; + if (s & 1) + signe *= -1; /* odd s */ + } + if (q < 0.0) { + q = -q; + if ((n - s) & 1) + signe *= -1; /* odd n - s */ + } + + if (n <= slim) { + Res = pow (p, (double) s) * num2_Combination (n, s) * pow (q, + (double) (n - s)); + return signe * Res; + + } else { + /* This could be calculated with more precision as there is some + cancellation because of subtraction of the large LnFactorial: the + last few digits can be lost. But we need the function lgammal in + long double precision. Another possibility would be to use an + asymptotic expansion for the binomial coefficient. */ + Res = s * log (p) + (n - s) * log (q) + num2_LnFactorial (n) + - num2_LnFactorial (n - s) - num2_LnFactorial (s); + util_Assert (Res < maxexp, "fmass_BinomialTerm1: term overflow"); + + if (Res < minexp) + return 0.0; + + return signe * exp (Res); + } +} + + +/*=========================================================================*/ + +double fmass_BinomialTerm4 (long n, double p, double p2, long s) +{ + const long slim = 30; /* To avoid overflow */ + const double maxexp = (DBL_MAX_EXP - 1) * num_Ln2; /* To avoid overflow */ + const double minexp = (DBL_MIN_EXP - 1) * num_Ln2; /* To avoid underflow */ + double Res; + + util_Assert (p >= 0.0 && p <= 1.0, "fmass_BinomialTerm4: p not in [0, 1]"); + util_Assert (p2 >= 0.0 && p2 <= 1.0, "fmass_BinomialTerm4: p2 not in [0, 1]"); + util_Assert (n >= 0, "fmass_BinomialTerm4: n < 0"); + if (0 == n) + return 1.0; + if (s < 0 || s > n) + return 0.0; + + if (n <= slim) { + if (p2 > 1.0e-1) { + Res = pow (p, (double) s) * num2_Combination (n, s) * pow (1.0 - p2, + (double) (n - s)); + } else { + double temp = (n - s)*num2_log1p (-p2); + Res = pow (p, (double) s) * num2_Combination (n, s) * exp(temp); + } + return Res; + + } else { + /* This could be calculated with more precision as there is some + cancellation because of subtraction of the large LnFactorial: the + last few digits can be lost. But we need the function lgammal in + long double precision. Another possibility would be to use an + asymptotic expansion for the binomial coefficient. */ + Res = s * log (p) + (n - s) * num2_log1p(-p2) + num2_LnFactorial (n) + - num2_LnFactorial (n - s) - num2_LnFactorial (s); + util_Assert (Res < maxexp, "fmass_BinomialTerm4: term overflow"); + + if (Res < minexp) + return 0.0; + + return exp (Res); + } +} + + +/*=========================================================================*/ + +double fmass_BinomialTerm3 (long n, double p, long s) +{ + const long slim = 50; /* To avoid overflow */ + const double maxexp = (DBL_MAX_EXP - 1) * num_Ln2; /* To avoid overflow */ + const double minexp = (DBL_MIN_EXP - 1) * num_Ln2; /* To avoid underflow */ + int signe = 1; + double Res; + double q = 1.0 - p; + + /* util_Assert (p >= 0.0 && p <= 1.0, "fmass_BinomialTerm3: p not in [0, + 1]"); */ + util_Assert (n >= 0, "fmass_BinomialTerm3: n < 0"); + if (0 == n) + return 1.0; + if (s < 0 || s > n) + return 0.0; + + /* Combination(n, s) are symmetric between s and n-s */ + if (s > n / 2) { + s = n - s; + Res = p; + p = q; + q = Res; + } + + if (p < 0.0) { + p = -p; + if (s & 1) + signe *= -1; /* odd s */ + } + if (q < 0.0) { + q = -q; + if ((n - s) & 1) + signe *= -1; /* odd n - s */ + } + + if (n <= slim) { + if (p > 1.0e-1) { + Res = pow (p, (double) s) * num2_Combination (n, s) * pow (q, + (double) (n - s)); + } else { + double temp = (n - s)*num2_log1p (-p); + Res = pow (p, (double) s) * num2_Combination (n, s) * exp(temp); + } + return signe * Res; + + } else { + /* This could be calculated with more precision as there is some + cancellation because of subtraction of the large LnFactorial: the + last few digits can be lost. But we need the function lgammal in + long double precision. Another possibility would be to use an + asymptotic expansion for the binomial coefficient. */ + Res = s * log (p) + (n - s) * num2_log1p (-p) + num2_LnFactorial (n) + - num2_LnFactorial (n - s) - num2_LnFactorial (s); + util_Assert (Res < maxexp, "fmass_BinomialTerm3: term overflow"); + + if (Res < minexp) + return 0.0; + + return signe * exp (Res); + } +} + + +/*=========================================================================*/ + +fmass_INFO fmass_CreateBinomial (long n, double p, double q) +{ +/* + * Compute all probability terms of the binomial distribution; start near + * the mean, and calculate probabilities on each side until they become + * smaller than epsilon, then stop there. + * However, this is more general than the binomial probability distribu- + * tion as this will compute the binomial terms when p + q != 1, and + * even when p or q are negative. However in this case, the cumulative + * terms are meaningless and are not computed. + */ + const double epsilon = fmass_Epsilon * EPS_EXTRA; + long i, mid; + long imin, imax; + double z = 0; + fmass_INFO W; + double *P; /* Binomial "probability" terms */ + double *F; /* Binomial cumulative "probabilities" */ + + util_Assert (n > 0, "fmass_CreateBinomial: n <= 0"); + + W = (fmass_INFO) util_Malloc (sizeof (struct fmass_INFO_T)); + W->paramI = (long *) util_Malloc (sizeof (long)); + W->paramR = (double *) util_Calloc ((size_t) 2, sizeof (double)); + W->paramI[0] = n; + W->paramR[0] = p; + W->paramR[1] = q; + + /* For n > fmass_MaxnBinomial, we shall not use pre-computed arrays */ + if (n > fmass_MaxnBinomial) { + W->pdf = NULL; + W->cdf = NULL; + return W; + } + + P = (double *) util_Calloc ((size_t) (1 + n), sizeof (double)); + F = (double *) util_Calloc ((size_t) (1 + n), sizeof (double)); + + /* the maximum term in absolute value */ + mid = (long) ((n + 1) * fabs (p) / (fabs (p) + fabs (q))); + if (mid > n) + mid = n; + P[mid] = fmass_BinomialTerm1 (n, p, q, mid); + + if (fabs(p) > 0.0) { + z = q / p; + } else { + z = 0.0; + util_Warning (1, "fmass_CreateBinomial: q / p = infinite"); + } + i = mid; + while (i > 0 && fabs (P[i]) > epsilon) { + P[i - 1] = P[i] * z * i / (n - i + 1); + i--; + } + imin = i; + + if (fabs(q) > 0.0) { + z = p / q; + } else { + z = 0.0; + util_Warning (1, "fmass_CreateBinomial: p / q = infinite"); + } + i = mid; + while (i < n && fabs (P[i]) > epsilon) { + P[i + 1] = P[i] * z * (n - i) / (i + 1); + i++; + } + imax = i; + + /* Here, we assume that we are dealing with a probability distribution. */ + /* Compute the cumulative probabilities for F and keep them in the */ + /* lower part of CDF. */ + F[imin] = P[imin]; + i = imin; + while (i < n && F[i] < 0.5) { + i++; + F[i] = F[i - 1] + P[i]; + } + + /* This is the boundary between F (i <= smed) and 1 - F (i > smed) in */ + /* the array CDF */ + W->smed = i; + + /* Compute the cumulative probabilities of the complementary */ + /* distribution and keep them in the upper part of the array */ + F[imax] = P[imax]; + i = imax - 1; + while (i > W->smed) { + F[i] = P[i] + F[i + 1]; + i--; + } + + /* Reset imin because we lose too much precision for a few terms near + imin when we stop adding terms < epsilon. */ + i = imin; + while (i < W->smed && F[i] < fmass_Epsilon) + i++; + W->smin = imin = i; + + /* Same thing with imax */ + i = imax; + while (i > W->smed && F[i] < fmass_Epsilon) + i--; + W->smax = imax = i; + + W->pdf = (double *) util_Calloc ((size_t) (imax + 1 - imin), sizeof (double)); + W->cdf = (double *) util_Calloc ((size_t) (imax + 1 - imin), sizeof (double)); + for (i = imin; i <= imax; i++) { + W->pdf[i - imin] = P[i]; + W->cdf[i - imin] = F[i]; + } + util_Free (P); + util_Free (F); + + return W; +} + +/*-------------------------------------------------------------------------*/ + +double fmass_BinomialTerm2 (fmass_INFO W, long s) +{ + long n; + double p, q; + + util_Assert (W != NULL, + "fmass_BinomialTerm2: fmass_INFO is NULL pointer"); + n = W->paramI[0]; + if (0 == n) + return 1.0; + if (s < 0 || s > n) + return 0.0; + p = W->paramR[0]; + if (p == 0.0) { + if (s > 0) + return 0.0; + else + return 1.0; + } + q = W->paramR[1]; + if (q == 0.0) { + if (s < n) + return 0.0; + else + return 1.0; + } + if (W->pdf == NULL) + return fmass_BinomialTerm1 (n, p, q, s); + + if (s > W->smax || s < W->smin) + return fmass_BinomialTerm1 (n, p, q, s); + + return W->pdf[s - W->smin]; +} + +/*-------------------------------------------------------------------------*/ + +void fmass_DeleteBinomial (fmass_INFO W) +{ + if (W == NULL) + return; + util_Free (W->paramI); + util_Free (W->paramR); + util_Free (W->pdf); + util_Free (W->cdf); + util_Free (W); +} + + +/*=========================================================================*/ + +double fmass_NegaBinTerm1 (long n, double p, long s) +{ + const long slim = 15; /* To avoid overflow */ + const double maxexp = (DBL_MAX_EXP - 1) * num_Ln2; /* To avoid overflow */ + const double minexp = (DBL_MIN_EXP - 1) * num_Ln2; /* To avoid underflow */ + double y; + + util_Assert (p >= 0.0 && p <= 1.0, + "fmass_NegaBinTerm1: p not in [0, 1]"); + util_Assert (n > 0, "fmass_NegaBinTerm1: n < 1"); + if (s < 0) + return 0.0; + if (p >= 1.0) { /* In fact, p == 1 */ + if (0 == s) + return 1.0; + else + return 0.0; + } + if (p <= 0.0) /* In fact, p == 0 */ + return 0.0; + + if (s <= slim || n <= slim) { + y = pow (p, (double) n) * num2_Combination (n + s - 1, s) * + pow (1.0 - p, (double) s); + return y; + + } else { + y = s * num2_log1p (-p) + n * log (p) + num2_LnFactorial (n + s - 1) + - num2_LnFactorial (n - 1) - num2_LnFactorial (s); + util_Assert (y < maxexp, "fmass_NegaBinTerm1: term overflow"); + if (y <= minexp) + return 0.0; + else + return exp (y); + } +} + + +/*=========================================================================*/ + +fmass_INFO fmass_CreateNegaBin (long n, double p) +/* + * Compute all probability terms of the negative binomial distribution; + * start at the mode, and calculate probabilities on each side until they + * become smaller than epsilon. Set all others to 0. + */ +{ + double epsilon; + long i, mode, Nmax; + long imin, imax; + double sum; + fmass_INFO W; + double *P; /* Negative Binomial mass probabilities */ + double *F; /* Negative Binomial cumulative + probabilities */ + + util_Assert (p >= 0.0 && p <= 1.0, + "fmass_CreateNegaBin: p not in [0, 1]"); + util_Assert (n > 0, "fmass_CreateNegaBin: n < 1"); + + W = (fmass_INFO) util_Malloc (sizeof (struct fmass_INFO_T)); + W->paramI = (long *) util_Malloc (sizeof (long)); + W->paramR = (double *) util_Malloc (sizeof (double)); + W->paramI[0] = n; + W->paramR[0] = p; + + /* Compute the mode (at the maximum term) */ + mode = (long) (1 + (n * (1.0 - p) - 1.0) / p); + + /* For mode > fmass_MaxnNegaBin, we shall not use pre-computed arrays. + mode < 0 should be impossible, unless overflow of long occur, in + which case mode will be = LONG_MIN. */ + if (mode < 0 || mode > fmass_MaxnNegaBin) { + W->pdf = NULL; + W->cdf = NULL; + return W; + } + + /* In theory, the negative binomial distribution has an infinite range. */ + /* But for i > Nmax, probabilities should be extremely small. */ + /* Nmax = Mean + 16 * Standard deviation. */ + Nmax = (long) (n * (1.0 - p) / p + 16 * sqrt (n * (1.0 - p) / (p * p))); + if (Nmax < 32) + Nmax = 32; + P = (double *) util_Calloc ((size_t) (1 + Nmax), sizeof (double)); + F = (double *) util_Calloc ((size_t) (1 + Nmax), sizeof (double)); + + epsilon = fmass_Epsilon * EPS_EXTRA / fmass_NegaBinTerm1 (n, p, mode); + + /* We shall normalize by explicitly summing all terms >= epsilon */ + sum = P[mode] = 1.0; + + /* Start from the maximum and compute terms > epsilon on each side. */ + i = mode; + while (i > 0 && P[i] >= epsilon) { + P[i - 1] = P[i] * i / ((1.0 - p) * (n + i - 1)); + i--; + sum += P[i]; + } + imin = i; + + i = mode; + while (P[i] >= epsilon) { + P[i + 1] = P[i] * (1.0 - p) * (n + i) / (i + 1); + i++; + sum += P[i]; + if (i == Nmax - 1) { + Nmax *= 2; + P = (double *) util_Realloc (P, (1 + Nmax) * sizeof (double)); + F = (double *) util_Realloc (F, (1 + Nmax) * sizeof (double)); + /* util_Warning (TRUE, "fmass_CreateNegaBin: Calling Realloc"); */ + } + } + imax = i; + + /* Renormalize the sum of probabilities to 1 */ + for (i = imin; i <= imax; i++) { + P[i] /= sum; + } + + /* Compute the cumulative probabilities for F and keep them in the */ + /* lower part of CDF. */ + F[imin] = P[imin]; + i = imin; + while (i < imax && F[i] < 0.5) { + i++; + F[i] = F[i - 1] + P[i]; + } + + /* This is the boundary between F (i <= smed) and 1 - F (i > smed) in */ + /* the array CDF */ + W->smed = i; + + /* Compute the cumulative probabilities of the complementary */ + /* distribution 1 - F and keep them in the upper part of the array */ + F[imax] = P[imax]; + i = imax - 1; + while (i > W->smed) { + F[i] = P[i] + F[i + 1]; + i--; + } + + /* Reset imin because we lose too much precision for a few terms near + imin when we stop adding terms < epsilon. */ + i = imin; + while (i < W->smed && F[i] < fmass_Epsilon) + i++; + W->smin = imin = i; + + /* Same thing with imax */ + i = imax; + while (i > W->smed && F[i] < fmass_Epsilon) + i--; + W->smax = imax = i; + + W->pdf = (double *) util_Calloc ((size_t) (imax + 1 - imin), sizeof (double)); + W->cdf = (double *) util_Calloc ((size_t) (imax + 1 - imin), sizeof (double)); + for (i = imin; i <= imax; i++) { + W->pdf[i - imin] = P[i]; + W->cdf[i - imin] = F[i]; + } + util_Free (P); + util_Free (F); + + return W; +} + +/*-------------------------------------------------------------------------*/ + +double fmass_NegaBinTerm2 (fmass_INFO W, long s) +{ + double p; + long n; + + util_Assert (W != NULL, + "fmass_NegaBinTerm2: fmass_INFO is NULL pointer"); + if (s < 0) + return 0.0; + n = W->paramI[0]; + p = W->paramR[0]; + if (p == 0.0) + return 0.0; + if (p == 1.0) { + if (s > 0) + return 0.0; + else + return 1.0; + } + + if (W->pdf == NULL) + return fmass_NegaBinTerm1 (n, p, s); + + if (s > W->smax || s < W->smin) + return fmass_NegaBinTerm1 (n, p, s); + + return W->pdf[s - W->smin]; +} + +/*-------------------------------------------------------------------------*/ + +void fmass_DeleteNegaBin (fmass_INFO W) +{ + if (W == NULL) + return; + util_Free (W->paramI); + util_Free (W->paramR); + util_Free (W->pdf); + util_Free (W->cdf); + util_Free (W); +} diff --git a/TESTU01/TestU01-1.2.3/probdist/fmass.tex b/TESTU01/TestU01-1.2.3/probdist/fmass.tex new file mode 100644 index 0000000..8593e03 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/fmass.tex @@ -0,0 +1,347 @@ +\defmodule {fmass} + +This module provides functions for computing the probability terms +(or mass function) for some standard discrete distributions. + +For certain distributions (e.g., the Poisson, binomial, and negative +binomial), one can either recompute a probability term each time +it is needed, or precompute tables that contain the probability terms +and the distribution function, and then use these tables whenever a +value is needed. The latter trades memory for speed and is recommended +especially if the distribution function has to be computed several times +for the same parameter(s). +We describe how this works for the Poisson distribution. +Things work similarly for the other distributions. + +To compute a single Poisson probability from scratch, simply use + {\tt fmass\_PoissonTerm1}. +To precompute tables, one must first call {\tt fmass\_CreatePoisson} +with the desired parameter value $\lambda$ of the Poisson distribution. +This will precompute and store the non-negligible probability terms +$f(s)$ (those that exceed {\tt fmass\_Epsilon}) in a table, +and the cumulative distribution function +\[ + F(x) = \sum_{s=0}^x f(s) +\] +for the corresponding values of $x$ in a second table. +In fact, that second table will contain $F(x)$ when $F(x) \le 1/2$ +and $1-F(x)$ when $F(x) > 1/2$. +These tables are kept in a structure of type {\tt fmass\_INFO} +which can be deleted by calling {\tt fmass\_DeletePoisson}. +\hpierre {Pourquoi pas un seul {\tt fmass\_DeleteInfo} ?} +Any value of the mass, distribution, complementary distribution, +or inverse distribution function +\hrichard {Je n'ai pas programm\'e les distributions inverses discr\`etes} + can be obtained from this structure +by calling {\tt fmass\_Poisson2}, {\tt fdist\_Poisson2}, +{\tt fbar\_Poisson2}, or {\tt finv\_Poisson2}, respectively. +As a rule of thumb, creating tables and using {\tt fdist\_Poisson2} +is faster than just using {\tt fdist\_Poisson1} as soon as two or three +calls are made to this function, unless $\lambda$ is large. +(If $\lambda$ is very large, +\ifdetailed %%% +i.e., exceeds {\tt fmass\_MaxLambdaPoisson}, +\fi %%% +the tables are not created +because they would take too much space, and the functions with suffix +{\tt \_Poisson2} automatically call those with suffix {\tt \_Poisson1} +instead.) + + +\code\hide +/* fmass.h for ANSI C */ +#ifndef FMASS_H +#define FMASS_H +\endhide\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Types} +\code + +struct fmass_INFO_T; +\hide +/* + For better precision in the tails, we keep the cumulative probabilities + (F) in cdf[s] for s <= smed (i.e. cdf[s] is the sum off all the probabi- + lities pdf[i] for i <= s), + and the complementary cumulative probabilities (1 - F) in cdf[s] for + s > smed (i.e. cdf[s] is the sum off all the probabilities pdf[i] + for i >= s). +*/ +struct fmass_INFO_T { + double *cdf; /* cumulative probabilities */ + double *pdf; /* probability terms or mass distribution */ + double *paramR; /* real parameters of the distribution */ + long *paramI; /* integer parameters of the distribution */ + long smin; /* pdf[s] = 0 for s < smin */ + long smax; /* pdf[s] = 0 for s > smax */ + long smed; /* cdf[s] = F(s) for s <= smed, and + cdf[s] = bar_F(s) for s > smed */ +}; +\endhide +typedef struct fmass_INFO_T *fmass_INFO; +\endcode + \tab Type of structure used to store precomputed discrete distributions. + \endtab + +\newpage +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\ifdetailed %%%%%%% +\guisec{Environment variables} + +\code + +extern double fmass_Epsilon; +\endcode + \tab Environment variable that determines what probability terms can + be considered as negligible when building precomputed tables for + probability or mass functions. + Probabilities smaller than {\tt fmass\_Epsilon} are + are not stored in the {\tt fmass\_INFO} structures created by functions + such as {\tt fmass\_CreatePoisson}, etc., but will be computed directly + each time they are needed (which should be seldom). + The default value is set to $10^{-16}$. + \endtab +\code + +extern double fmass_MaxLambdaPoisson; /* = 100000 */ + +extern double fmass_MaxnBinomial; /* = 100000 */ + +extern double fmass_MaxnNegaBin; /* = 100000 */ +\endcode + \tab The parameter value above which the tables are {\em not\/} + constructed and stored in the {\tt fmass\_INFO} when calling + functions of type {\tt fmass\_Create...}, for each type of distribution. + The default values are given to the right of each variable. + If this value is exceeded, then the tables are not computed and + any call to a function using that structure is converted automatically + and transparently into a call to the corresponding function that + recomputes everything from scratch + (e.g., a call to {\tt fdist\_Poisson2} is converted into + a call to {\tt fdist\_Poisson1}). +\hrichard{Je pr\'ef\`ererais \'eliminer ces 3 variables parce qu'elles + rendent la compr\'ehension plus difficile et vont provoquer + de l'anxi\'et\'e chez la majorit\'e des utilisateurs.} +\hpierre{Anxiete? Je ne vois pas pourquoi. + Et puis ceci n'apparait que dans la version ``detailed''. + Par contre, on pourrait peut-etre remplacer les 3 variables par + une seule? Meme chose pour les Epsilon. } + \endtab +\fi %%%%% detailed + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The Poisson distribution} +\code + +double fmass_PoissonTerm1 (double lambda, long s); +\endcode + \tab Computes and returns the value of the Poisson probability + \eq + f(s) = \frac{e^{-{\lambda}} {\lambda}^s}{s!} \eqlabel{eq:fmass-poisson} + \endeq + for $\lambda = {\tt lambda}$. + If one has to call this function several times with the same $\lambda$, + where $\lambda$ is not too large, then it is more efficient to use + {\tt fmass\_PoissonTerm2}. + Restriction: $\lambda > 0$. + \endtab +\code + + +fmass_INFO fmass_CreatePoisson (double lambda); +\endcode + \tab Creates and returns a structure that contains + the mass and distribution functions for the Poisson + distribution with parameter {\tt lambda $= \lambda$}, which are + computed and stored in dynamic arrays inside that structure. + Such a structure is needed for calling {\tt fmass\_PoissonTerm2}, + {\tt fdist\_Poisson2}, {\tt fbar\_Poisson2}, or {\tt finv\_Poisson2}. + It can be deleted by calling the procedure {\tt fmass\_DeletePoisson}. + \ifdetailed %%%% + Only probability terms larger than {\tt fmass\_Epsilon} + are kept in the arrays. The other terms are recomputed directly each time + they are needed. + \fi %%%% detailed + Restriction: $\lambda > 0$. + \endtab +\code + + +void fmass_DeletePoisson (fmass_INFO W); +\endcode + \tab Deletes the structure {\tt W} created previously + by {\tt fmass\_CreatePoisson}. + \endtab +\code + + +double fmass_PoissonTerm2 (fmass_INFO W, long s); +\endcode + \tab Returns the Poisson probability (\ref{eq:fmass-poisson}) + % $f(s) = {e^{-{\lambda}}{\lambda}^s}/s!$ + from the structure {\tt W}, which must have been created previously + by calling {\tt fmass\_CreatePoisson} with the desired $\lambda$. + \endtab + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The binomial distribution} +\code + + +double fmass_BinomialTerm3 (long n, double p, long s); +\endcode + \tab Computes and returns the binomial term + \eq + f(s) = {n \choose s} p^s (1 - p)^{n-s} = + \frac {n!}{s!(n-s)!}\; p^s (1 - p)^{n-s}, \eqlabel{eq:fmass-binom3} + \endeq + where $p$ is an arbitrary real number. + In the case where $0 \le p \le 1$, the returned + value is a probability term for the binomial distribution. + Restriction: $0\le s\le n$. + \hpierre{Il serait peut-etre utile d'avoir aussi une version + avec seulement $n$ et $p$, pour le cas (fr\'equent) o\`u $p$ est + tr\'es proche de 0?} + \endtab +\code + + +double fmass_BinomialTerm1 (long n, double p, double q, long s); +\endcode + \tab Computes and returns the binomial term + \eq + f(s) = {n \choose s} p^s q^{n-s} = + \frac {n!}{s!(n-s)!}\; p^s q^{n-s}, \eqlabel{eq:fmass-binom} + \endeq + where $p$ and $q$ are arbitrary real numbers. + In the case where $0 \le p \le 1$ and $q = 1-p$, the returned + value is a probability term for the binomial distribution. + Restriction: $0\le s\le n$. + \hpierre{Il serait peut-etre utile d'avoir aussi une version + avec seulement $n$ et $p$, pour le cas (fr\'equent) o\`u $p$ est + tr\'es proche de 0?} + \endtab +\code + + +double fmass_BinomialTerm4 (long n, double p, double p2, long s); +\endcode + \tab Computes and returns the binomial term + \eq + f(s) = {n \choose s} p^s (1 - p_2)^{n-s} = + \frac {n!}{s!(n-s)!}\; p^s (1 - p_2)^{n-s}, \eqlabel{eq:fmass-binom11} + \endeq + where $p$ and $p_2$ are real numbers in $[0, 1]$. + In the case where $p_2 = p$, the returned + value is a probability term for the binomial distribution. If + $p_2$ is small, this function is more precise than + {\tt fmass\_BinomialTerm1}. + Restriction: $0\le s\le n$. + \endtab +\code + + +fmass_INFO fmass_CreateBinomial (long n, double p, double q); +\endcode + \tab Creates and returns a structure that contains binomial terms + (\ref{eq:fmass-binom}) for $0\le s\le n$, and the corresponding + cumulative function. If $0\le p = 1-q\le 1$, these are the probabilities + and the distribution function of a binomial random variable. + The values are computed and stored in dynamic arrays. + Such a structure is needed for calling {\tt fmass\_BinomialTerm2}, + {\tt fdist\_Binomial2}, {\tt fbar\_Binomial2}, or {\tt finv\_Binomial2}. + It can be deleted by calling {\tt fmass\_DeleteBinomial}. + This function is more general than the binomial probability distribution + as it computes the binomial terms when $p + q \not= 1$, and + even when $p$ or $q$ are negative. However in this case, the cumulative + terms will be meaningless and only the mass terms {\tt fmass\_BinomialTerm2} + are computed. + \ifdetailed %%% + Only the terms larger than {\tt fmass\_Epsilon} in absolute value are kept + in the arrays. The other terms are recomputed directly each time + they are needed. + \fi %%% detailed + \endtab +\code + + +void fmass_DeleteBinomial (fmass_INFO W); +\endcode + \tab Deletes the structure {\tt W} created previously + by {\tt fmass\_CreateBinomial}. + \endtab +\code + + +double fmass_BinomialTerm2 (fmass_INFO W, long s); +\endcode + \tab Returns the value of the binomial term (\ref{eq:fmass-binom}) + from the structure {\tt W}, which must have been created previously + by {\tt fmass\_CreateBinomial} with the desired parameters. + \endtab + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The negative binomial distribution} + +\code + +double fmass_NegaBinTerm1 (long n, double p, long s); +\endcode + \tab + Computes and returns the value of the negative binomial + probability term + \eq + f(s) = {n + s - 1 \choose s} p^n (1 - p)^{s}, + \eqlabel{eq:fmass-negbin} + \endeq + which can be interpreted as the probability of having $s$ failures + before the $n$th success in a sequence of independent Bernoulli trials + with success probability $p$. + \ifdetailed %%% + When one needs many such $f(s)$ with the same $n$ and $p$, and $n$ is + not too large, it is more efficient to use + {\tt fmass\_NegaBinTerm2} instead. + \fi %%% detailed + Restrictions: $n > 0$, $0\le p\le 1$, and $s\ge 0$. + \endtab +\code + + +fmass_INFO fmass_CreateNegaBin (long n, double p); +\endcode + \tab Creates and returns a structure that contains the probability + terms (\ref{eq:fmass-negbin}) and the distribution functions for + the negative binomial distribution with parameter $n$ and $p$. + Such a structure is needed for calling {\tt fmass\_NegaBinTerm2}, + {\tt fdist\_NegaBin2}, {\tt fbar\_NegaBin2}, or {\tt finv\_NegaBin2}. + It can be deleted by calling {\tt fmass\_DeleteNegaBin}. + \ifdetailed %%% + Only probability terms larger than {\tt fmass\_Epsilon} + are kept in the arrays. The other terms are recomputed directly each time + they are needed. + \fi %%% detailed + Restrictions: $0\le p\le 1$ and $n > 0$. + \endtab +\code + + +void fmass_DeleteNegaBin (fmass_INFO W); +\endcode + \tab Deletes the structure {\tt W} created previously + by {\tt fmass\_CreateNegaBin}. + \endtab +\code + + +double fmass_NegaBinTerm2 (fmass_INFO W, long s); +\endcode + \tab Returns the negative binomial probability (\ref{eq:fmass-negbin}) + from the structure {\tt W}, which must have been created previously + by calling {\tt fmass\_CreateNegaBin} with the desired parameters. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/probdist/gofs.c b/TESTU01/TestU01-1.2.3/probdist/gofs.c new file mode 100644 index 0000000..e0d7985 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/gofs.c @@ -0,0 +1,578 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: gofs.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "tables.h" +#include "num.h" +#include "num2.h" + +#include "gofs.h" +#include "fdist.h" +#include "wdist.h" + +#include +#include +#include + + +#define TRACE0(x) printf ("*** " #x " "); +#define TRACE1(N, form) printf ("*** " #N " = %"#form " ", N); + + + +/*---------------------------- extern variables ---------------------------*/ + +double gofs_MinExpected = 10.0; + +double gofs_EpsilonAD = DBL_EPSILON / 2.0; + + + +/*---------------------------- module variables ---------------------------*/ + +/* Used in discontinuous distributions */ +static double EpsilonD = 1.0E-15; + + + + + + +/*-------------------------------- functions ------------------------------*/ + + +void gofs_ContUnifTransform (double V[], long N, wdist_CFUNC F, + double par[], double U[]) +{ + long i; + for (i = 1; i <= N; i++) + U[i] = F (par, V[i]); +} + +/*-------------------------------------------------------------------------*/ + +void gofs_DiscUnifTransform (double V[], long N, wdist_DFUNC F, + fmass_INFO W, double U[]) +{ + long i; + for (i = 1; i <= N; i++) + U[i] = F (W, (long) V[i]); +} + +/*-------------------------------------------------------------------------*/ + +void gofs_DiffD (double U[], double D[], long N1, long N2, + double a, double b) +{ + long i; + D[N1 - 1] = U[N1] - a; + for (i = N1; i < N2; i++) + D[i] = U[i + 1] - U[i]; + D[N2] = b - U[N2]; +} + +/*-------------------------------------------------------------------------*/ +#ifdef USE_LONGLONG + +void gofs_DiffLL (longlong U[], longlong D[], long N1, long N2, + longlong a, longlong b) +{ + long i; + D[N1 - 1] = U[N1] - a; + for (i = N1; i < N2; i++) + D[i] = U[i + 1] - U[i]; + D[N2] = b - U[N2]; +} + +/*-------------------------------------------------------------------------*/ + +void gofs_DiffULL (ulonglong U[], ulonglong D[], long N1, long N2, + ulonglong a, ulonglong b) +{ + long i; + D[N1 - 1] = U[N1] - a; + for (i = N1; i < N2; i++) + D[i] = U[i + 1] - U[i]; + D[N2] = b - U[N2]; +} + +#endif +/*-------------------------------------------------------------------------*/ + +void gofs_DiffL (long U[], long D[], long N1, long N2, long a, long b) +{ + long i; + D[N1 - 1] = U[N1] - a; + for (i = N1; i < N2; i++) + D[i] = U[i + 1] - U[i]; + D[N2] = b - U[N2]; +} + +/*-------------------------------------------------------------------------*/ + +void gofs_IterateSpacings (double V[], double S[], long N) +{ + long i; + tables_QuickSortD (S, 0, N); + for (i = 0; i < N; i++) + S[N - i] = (i + 1) * (S[N - i] - S[N - i - 1]); + S[0] = (N + 1) * S[0]; + V[1] = S[0]; + for (i = 2; i <= N; i++) + V[i] = V[i - 1] + S[i - 1]; +} + +/*-------------------------------------------------------------------------*/ + +void gofs_PowerRatios (double U[], long N) +{ + long i; + /* Assumes that the U[i] are already sorted in increasing order. */ + for (i = 1; i < N; i++) { + if (U[i + 1] == 0.0 || U[i + 1] == -0.0) { + /* util_Warning (1, "gofs_PowerRatios: 0 divisor"); */ + U[i] = 1.0; + } else + U[i] = pow (U[i] / U[i + 1], (double) i); + } + U[N] = pow (U[N], (double) N); + tables_QuickSortD (U, 1, N); +} + +/*-------------------------------------------------------------------------*/ + +void gofs_MergeClasses (double NbExp[], long Loc[], + long *smin, long *smax, long *NbClasses) +{ + long s0, j, s; + double somme; + + *NbClasses = 0; + s = *smin; + while (s <= *smax) { + /* Merge classes to ensure that the number expected in each class is + >= gofs_MinExpected. */ + if (NbExp[s] < gofs_MinExpected) { + s0 = s; + somme = NbExp[s]; + while (somme < gofs_MinExpected && s < *smax) { + NbExp[s] = 0.0; + ++s; + somme += NbExp[s]; + } + NbExp[s] = somme; + for (j = s0; j <= s; j++) + Loc[j] = s; + } else { + Loc[s] = s; + } + ++*NbClasses; + ++s; + } + *smin = Loc[*smin]; + + /* Special case: the last class, if NbExp < MinExpected */ + if (NbExp[*smax] < gofs_MinExpected) { + if (s0 > *smin) + --s0; + NbExp[s0] += NbExp[*smax]; + NbExp[*smax] = 0.0; + --*NbClasses; + for (j = s0 + 1; j <= *smax; j++) + Loc[j] = s0; + *smax = s0; + } + util_Warning (*NbClasses < 2, "gofs_MergeClasses: NumClasses < 2.\n" + " The chi-square test is not done."); + /* + util_Assert (*NbClasses > 1, "gofs_MergeClasses: NumClasses < 2"); + */ +} + + +/*-------------------------------------------------------------------------*/ + +void gofs_WriteClasses (double NbExp[], long Loc[], + long smin, long smax, long NbClasses) +{ + /* Writes the groupings of cells before or after a merging that has */ + /* been done by a previous call to gofs_MergeClasses. */ + long s, s0; + double somme; + const double epsilon = 5.0E-16; + + /* Before merging classes or cells */ + if (NbClasses <= 0) { + somme = 0.0; + printf ("-----------------------------------------------\n" + "Expected numbers per class before merging:\n\n" + "Class s NumExpected[s]\n"); + + /* Don't print classes for which the expected number < epsilon */ + /* Instead reset smin */ + s = smin; + while (NbExp[s] < epsilon) + s++; + if (s > smin) { + smin = s; + s--; + printf ("<= %3ld", s); + num_WriteD (NbExp[s], 18, 4, 4); + printf ("\n"); + } + /* Reset smax also */ + s0 = s = smax; + while (NbExp[s] < epsilon) + s--; + if (s < smax) + smax = s; + + /* Now print the classes with their expected numbers */ + for (s = smin; s <= smax; s++) { + somme += NbExp[s]; + printf ("%6ld", s); + num_WriteD (NbExp[s], 20, 4, 4); + printf ("\n"); + } + + if (s0 > smax) { + s = smax + 1; + printf (">= %3ld", s); + num_WriteD (NbExp[s], 18, 4, 4); + printf ("\n"); + } + + printf ("\n"); + printf ("Total No. Expected = %18.2f\n\n", somme); + return; + } + + /* NbClasses > 0: After merging classes */ + printf ("-----------------------------------------------\n" + "Expected numbers per class after merging:\n" + "Number of classes: %4ld\n\n", NbClasses); + printf ("Class s NumExpected[s]\n"); + + somme = 0.0; + for (s = smin; s <= smax; s++) { + if (Loc[s] == s) { + somme += NbExp[s]; + printf ("%4ld %18.4f\n", s, NbExp[s]); + } + } + printf ("\nTotal NumExpected = %18.2f\n\n", somme); + printf ("The groupings :\n Class s Loc[s]\n"); + for (s = smin; s <= smax; s++) { + if (s == smin) + printf ("<= "); + else if (s == smax) + printf (">= "); + else + printf (" "); + printf ("%4ld %12ld\n", s, Loc[s]); + } + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +/*******************************\ + + Computing EDF test statistics + +\*******************************/ + + +double gofs_Chi2 (double NbExp[], long Count[], long smin, long smax) +{ + double Diff, Khi; + long s; + + Khi = 0.0; + for (s = smin; s <= smax; s++) { + if (NbExp[s] <= 0.0) { + util_Assert (Count[s] == 0, + "gofs_Chi2: NbExp[s] = 0 and Count[s] > 0"); + } else { + Diff = Count[s] - NbExp[s]; + Khi += Diff * Diff / NbExp[s]; + } + } + return Khi; +} + +/*-------------------------------------------------------------------------*/ + +double gofs_Chi2Equal (double NbExp, long Count[], long smin, long smax) +{ + double Diff, Khi; + long s; + Khi = 0.0; + for (s = smin; s <= smax; s++) { + Diff = Count[s] - NbExp; + Khi += Diff * Diff; + } + return Khi / NbExp; +} + +/*-------------------------------------------------------------------------*/ + +long gofs_Scan (double U[], long N, double d) +{ + long m, j = 1, i = 0; + double High; + + High = 0.0; + m = 1; + while (j < N && High < 1.0) { + ++i; + /* Low = U[i]; */ + High = U[i] + d; + while (j <= N && U[j] < High) + ++j; + /* j is now the index of the first obs. to the right of High. */ + if (j - i > m) + m = j - i; + } + /* p-value = fbar_Scan (N, d, m); */ + return m; +} + +/*-------------------------------------------------------------------------*/ + +double gofs_CramerMises (double U[], long N) +{ + long i; + double W, W2; + + if (N <= 0) { + util_Warning (TRUE, "gofs_CramerMises: N <= 0"); + return 0.0; + } + + W2 = 1.0 / (12 * N); + for (i = 1; i <= N; i++) { + W = U[i] - (i - 0.5) / N; + W2 += W * W; + } + return W2; + /* p-value = fbar_CramerMises (N, W2); */ +} + +/*-------------------------------------------------------------------------*/ + +double gofs_WatsonG (double U[], long N) +{ + long i; + double SumZ; + double D2; + double DP, G; + double UnSurN = 1.0 / N; + + if (N <= 0) { + util_Warning (TRUE, "gofs_WatsonG: N <= 0"); + return 0.0; + } + + /* degenerate case N = 1 */ + if (N == 1) + return 0.0; + + /* We assume that U is already sorted. */ + DP = SumZ = 0.0; + for (i = 1; i <= N; i++) { + D2 = i * UnSurN - U[i]; + if (D2 > DP) + DP = D2; + SumZ += U[i]; + } + SumZ = SumZ * UnSurN - 0.5; + G = sqrt ((double) N) * (DP + SumZ); + return G; + /* p-value = fbar_WatsonG (N, G); */ +} + +/*-------------------------------------------------------------------------*/ + +double gofs_WatsonU (double U[], long N) +{ + long i; + double SumZ, W, W2, U2; + + if (N <= 0) { + util_Warning (TRUE, "gofs_WatsonU: N <= 0"); + return 0.0; + } + + /* degenerate case N = 1 */ + if (N == 1) { + return 1.0 / 12.0; + } + + SumZ = 0.0; + W2 = 1.0 / (12 * N); + for (i = 1; i <= N; i++) { + SumZ += U[i]; + W = U[i] - (i - 0.5) / N; + W2 += W * W; + } + SumZ = SumZ / N - 0.5; + U2 = W2 - SumZ * SumZ * N; + return U2; + /* p-value = fbar_WatsonU (N, U2); */ +} + +/*-------------------------------------------------------------------------*/ + +double gofs_AndersonDarling (double V[], long N) +{ + long i; + double U1; + double U, A2; + + if (N <= 0) { + util_Warning (TRUE, "gofs_AndersonDarling: N <= 0"); + return 0.0; + } + + A2 = 0.0; + for (i = 1; i <= N; i++) { + U1 = U = V[i]; + if (U <= gofs_EpsilonAD) { + U1 = U = gofs_EpsilonAD; + } else if (U >= 1 - gofs_EpsilonAD) + U1 = 1.0 - gofs_EpsilonAD; + A2 += (2 * i - 1) * log (U) + (1 + 2 * (N - i)) * num2_log1p (-U1); + } + A2 = -N - A2 / N; + return A2; + /* p-value = fbar_AndersonDarling (N, A2); */ +} + +/*-------------------------------------------------------------------------*/ + +void gofs_KSJumpOne (double U[], long N, double a, double *DP, double *DM) + /* Statistics KS+ and KS-. Case with 1 jump at a, near the lower tail of + the distribution. */ +{ + long j, i; + double D2, D1, UnSurN; + + if (N <= 0) { + *DP = *DM = 0.0; + util_Warning (TRUE, "gofs_KSJumpOne: N <= 0"); + return; + } + + *DP = 0.0; + *DM = 0.0; + UnSurN = 1.0 / N; + j = 1; + while (j < N && U[j] <= a + EpsilonD) + ++j; + for (i = j - 1; i <= N; i++) { + if (i >= 1) { + D1 = i * UnSurN - U[i]; + if (D1 > *DP) + *DP = D1; + } + if (i >= j) { + D2 = U[i] - (i - 1) * UnSurN; + if (D2 > *DM) + *DM = D2; + } + } +} + +/*-------------------------------------------------------------------------*/ + +void gofs_KS (double U[], long N, double *DP, double *DM, double *D) +{ + if (N <= 0) { + *DP = *DM = *D = 0.0; + util_Warning (TRUE, "gofs_KS: N <= 0"); + return; + } + + gofs_KSJumpOne (U, N, 0.0, DP, DM); + if (*DM > *DP) + *D = *DM; + else + *D = *DP; + /* pp = fbar_KSPlus (N, *DP); + pm = fbar_KSPlus (N, *DM); + p = fbar_KS (N, *D); */ +} + +/*-------------------------------------------------------------------------*/ +#if 0 + +void gofs_KSJumpsMany (double X[], int N, wdist_CFUNC F, double W[], + double *DP, double *DM, int Detail) +{ + int i; + double y, UnSurN, D; + + if (N <= 0) { + *DP = *DM = 0.0; + util_Warning (TRUE, "gofs_KSJumpsMany: N <= 0"); + return; + } + + util_Assert (N > 0, "gofs_KSJumpsMany: N <= 0"); + UnSurN = 1.0 / N; + *DP = 0.0; + *DM = 0.0; + + if (Detail > 0) { + printf ("-----------------------------------------------\n" + "Values of the distribution F(x+0) :\n\n"); + } + /* Assume that the X[i] are already sorted */ + for (i = 1; i <= N; i++) { + /* Compute KS+ */ + y = F (W, X[i]); + D = i * UnSurN - y; + if (D > *DP) + *DP = D; + if (Detail > 0) { + printf ("%14.6f %14.6f\n", X[i], y); + } + /* Compute KS- */ + y = F (W, X[i] - EpsilonD); + D = y - (i - 1) * UnSurN; + if (D > *DM) + *DM = D; + } + if (Detail > 0) + printf ("\n\n"); +} +#endif diff --git a/TESTU01/TestU01-1.2.3/probdist/gofs.tex b/TESTU01/TestU01-1.2.3/probdist/gofs.tex new file mode 100644 index 0000000..eb3d447 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/gofs.tex @@ -0,0 +1,446 @@ +\defmodule {gofs} + +This module provides tools for computing goodness-of-fit test statistics +for testing the hypothesis $\cH_0$ that a sample of $N$ observations +$V_1,\dots,V_N$ comes from a given univariate probability +distribution $F$. +These test statistics generally measure, in different ways, the +distance between $F$ and the {\em empirical distribution function\/} +(EDF) $\hat F_N$ of $V_1,\dots,V_N$. +They are also called EDF test statistics. +The observations $V_i$ are usually transformed into $U_i = F(V_i)$, +which always satisfy $0\le U_i\le 1$, and which +follow the $U(0,1)$ distribution under $\cH_0$. +These observations are also usually sorted. +Here, $U_{(1)}, \dots, U_{(N)}$ stand for $N$ observations +$U_1,\dots,U_N$ sorted by increasing order, where $0\le U_i\le 1$. + +Procedures for applying certain types of transformations to the +observations $V_i$ or $U_i$ are also provided. +This includes the transformation $U_i = F(V_i)$, as well as +the power ratio and iterated spacing transformations \cite{tSTE86a}. + + +\bigskip\hrule\medskip +\code\hide +/* gofs.h for ANSI C */ +#ifndef GOFS_H +#define GOFS_H +\endhide +#include "bitset.h" /* From the library mylib */ +#include "fmass.h" +#include "fdist.h" +#include "wdist.h" +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Environment variables} + +\code + + +extern double gofs_MinExpected; +\endcode + \tab Used for the chi-square tests. + When a chi-square test statistic is computed, the expected number + of observations in each class should be large enough if we want + the chi-square test statistic to follow approximately the + chi-square distribution. Larger expected numbers are usually + required when these numbers differ between classes \cite{tREA88a}. + The function {\tt gofs\_MergeClasses} can be used to regroup classes + in order to make sure that the expected number in each class is + at least {\tt gofs\_MinExpected}. + The default value of this variable is 10.0. +\iffalse %%% + This is for testu01: + For some tests, the software will merge + classes in such a way that this is always so. For others, an error + message will be printed if this not the case (see the {\it restrictions} + that apply for the different tests). +\fi %% + \hpierre {Et si on mettait cette variable en param\`etre \`a + {\tt MergeClasses} \`a la place? Peser le pour et le contre. + En fait, dans plusieurs situations, la valeur 10.0 est beaucoup + trop \'elev\'ee. } + \hrichard {Cette variable est vraiment d'environnement. Depuis des + ann\'ees, on ne l'a jamais vari\'e. Et les fonctions qui l'utilisent + sont appel\'ees des douzaines de fois partout. Ce type de variables + devrait demeurer environnement.} + \endtab +\ifdetailed %%%% +\code + + +extern double gofs_EpsilonAD; +\endcode + \tab When computing the Anderson-Darling statistic $A_N^2$, + all observations $U_i$ are projected to the interval + $[\epsilon,\,1-\epsilon]$ for some $\epsilon > 0$, in order to + avoid numerical overflow when taking the logarithm of $U_i$ or + $1-U_i$. This variable gives the value of $\epsilon$; + its default value is {\tt DBL\_EPSILON/2.0}. + {\tt DBL\_EPSILON} (from {\tt float.h}) is usually $2^{-52}$. + \hpierre {Autre choix possible: cacher cela dans le .c. + Mais il ne semble pas y avoir d'avantage \`a faire cela, + tandis que le laisser ici peut permettre aux ``experts'' de faire + \'eventuellement des exp\'eriences avec le choix de $\epsilon$. } + \endtab +\fi %%%% detailed + +\hrichard {Il faut mettre ``{\tt extern}'' parce que sinon + il y aurait autant d'instances de cette variable que d'inclusions + de ce fichier *.h dans le programme, ce qui provoquerait une erreur + avec plusieurs compilateurs. + Parmi toutes les conventions des diff\'erents compilateurs pour les + variables externes, celle-ci est la plus propre et est compatible + ANSI C. Parmi les 5 conventions utilis\'ees couramment, c'est celle + recommand\'ee par Harbison+Steele p. 94.} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Transforming the observations} + +\code + +void gofs_ContUnifTransform (double V[], long N, wdist_CFUNC F, + double par[], double U[]); +\endcode +\tab Applies the transformation $U_i = F(V_i)$ to the values in + {\tt V[1..N]}, where $F$ is a {\em continuous\/} distribution function + given by {\tt F} and with parameters in {\tt par}, + and puts the result in {\tt U[1..N]}. + If {\tt V} contains random variables from the distribution function + {\tt F}, then {\tt U} will contain uniform random variables over $(0,1)$. +\endtab +\code + + +void gofs_DiscUnifTransform (double V[], long N, wdist_DFUNC F, + fmass_INFO W, double U[]); +\endcode +\tab Applies the transformation $U_i = F(V_i)$ to the values in + {\tt V[1..N]}, where $F$ is a {\em discrete\/} distribution function + specified by {\tt F} and the previously-created structure {\tt W}, + and puts the result in {\tt U[1..N]}. + Note: If {\tt V[1..N]} are the values of random variables with + distribution function {\tt F}, then {\tt U[1..N]} will contain + the values of {\em discrete\/} random variables distributed over the + set of values taken by {\tt F}, + not uniform random variables over $(0,1)$. +\hrichard {Devrait probablement \^etre \'elimin\'e. Utilis\'e 1 fois dans + smultin, mais pourrait \^etre remplac\'e.} +\hpierre {Tu as probablement raison.} +\endtab +\code + + +void gofs_DiffD (double U[], double D[], long N1, long N2, + double a, double b); +\endcode + \tab Assumes that the real-valued observations {\tt U[N1..N2]} + are already sorted in increasing order and computes the differences + between the successive observations. + The difference {\tt U[i+1] - U[i]} is put in {\tt D[i]} for + {\tt N1 <= i < N2}, whereas {\tt U[N1] - a} is put into {\tt D[N1-1]} + and {\tt b - U[N2]} is put into {\tt D[N2]}. + The sizes of the arrays {\tt U} and {\tt D} must be at least {\tt N2+1}. +\hpierre {ATTENTION: J'ai chang\'e cette proc\'edure et la suivante + pour les rendre plus g\'en\'erales et surtout plus {\em semblables}. + Un appel \`a l'ancien {\tt DiffD (U, D, N)} doit se traduire par + {\tt DiffD (U, D, 1, N, 0.0, 1.0)}, tandis qu'un appel + \`a l'ancien {\tt DiffL (U, D, N1, N2, L)} doit se traduire par + {\tt DiffD (U, D, N1, N2, 0, L+U[N1])}. } + \endtab +\code + + +void gofs_DiffL (long U[], long D[], long N1, long N2, long a, long b); + +#ifdef USE_LONGLONG +void gofs_DiffLL (longlong U[], longlong D[], long N1, long N2, + longlong a, longlong b); +void gofs_DiffULL (ulonglong U[], ulonglong D[], long N1, long N2, + ulonglong a, ulonglong b); +#endif +\endcode + \tab Same as {\tt gofs\_DiffD}, but for integer-valued observations. + \endtab +\code + + +void gofs_IterateSpacings (double V[], double S[], long N); +\endcode + \tab Applies one iteration of the {\em iterated spacings\/} + transformation \cite{rKNU98a,tSTE86a}. + Assumes that {\tt S[0...N]} contains the {\em spacings\/} + between $N$ real numbers $U_1,\dots,U_N$ in the interval $[0,1]$. + These spacings are defined by + $$ S_i = U_{(i+1)} - U_{(i)}, \qquad 0\le i\le N, $$ + where $U_{(0)}=0$, $U_{(N+1)}=1$, and + $U_{(1)},\dots,U_{(N)}$, are the $U_i$ sorted in increasing order. +% These $U_i$ do not need to be in the array {\tt V}. + These spacings may have been obtained by calling {\tt gofs\_DiffD}. + This procedure transforms the spacings into new + spacings, by a variant of the method described + in section 11 of \cite {rMAR85a} and also by Stephens \cite{tSTE86a}: +% See also Knuth (1998), 3th edition. + it sorts $S_0,\dots,S_N$ to obtain + $S_{(0)} \le S_{(1)} \le S_{(2)} \le \cdots \le S_{(N)}$, + computes the weighted differences + \begin {eqnarray*} + S_{0} &=& (N+1) S_{(0)}, \\ + S_{1} &=& N (S_{(1)}-S_{(0)}), \\ + S_{2} &=& (N-1) (S_{(2)}-S_{(1)}),\\ + & \vdots& \\ + S_{N} &=& S_{(N)}-S_{(N-1)}, + \end {eqnarray*} + and computes $V_i = S_0 + S_1 + \cdots + S_{i-1}$ for $1\le i\le N$. + It then returns $S_0,\dots,S_N$ in {\tt S[0..N]} and + $V_1,\dots,V_N$ in {\tt V[1..N]}. + + Under the assumption that the $U_i$ are i.i.d.\ $U(0,1)$, the new + $S_i$ can be considered as a new set of spacings having the same + distribution as the original spacings, and the $V_i$ are a new sample + of i.i.d.\ $U(0,1)$ random variables, sorted by increasing order. + + This transformation is useful to detect {\em clustering\/} in a data + set: A pair of observations that are close to each other is transformed + into an observation close to zero. A data set with unusually clustered + observations is thus transformed to a data set with an + accumulation of observations near zero, which is easily detected by + the Anderson-Darling GOF test. + \hrichard {Utilis\'e dans \tt snpair} + \endtab +\code + + +void gofs_PowerRatios (double U[], long N); +\endcode + \tab Applies the {\em power ratios\/} transformation $W$ described + in section 8.4 of Stephens \cite{tSTE86a}. + Assume that {\tt U[1...N]} contains $N$ real numbers + $U_{(1)},\dots,U_{(N)}$ from the interval $[0,1]$, + already sorted in increasing order, and computes the transformations: + $$ U'_i = (U_{(i)} / U_{(i+1)})^i, \qquad i=1,\dots,N,$$ + with $U_{(N+1)} = 1$. + These $U'_i$ are sorted in increasing order and put back in + {\tt U[1...N]}. + If the $U_{(i)}$ are i.i.d.\ $U(0,1)$ sorted by increasing order, + then the $U'_i$ are also i.i.d.\ $U(0,1)$. + + This transformation is useful to detect clustering, as explained in + {\tt gofs\_IterateSpacings}, except that here a pair of + observations close to each other is transformed + into an observation close to 1. + An accumulation of observations near 1 is also easily detected by + the Anderson-Darling GOF test. + \hrichard {Utilis\'e dans \tt snpair} + \endtab +\code + + +void gofs_MergeClasses (double NbExp[], long Loc[], + long *smin, long *smax, long *NbClasses); +\endcode + \tab This function is convenient for regrouping classes before + applying a chi-square test, + in the case where the expected number of observations in some of + the classes may be too small. + It merges classes of observations so that the expected + number of observations in each class is at least + {\tt gofs\_MinExpected}. Initially, the expected numbers in each class + are in {\tt NbExp[*smin...*smax]}. + When the function returns, if ${\tt Loc}[s] = j$, this means that class + $s$ has been merged with class $j$. + In this case, all observations that previously belonged to class $s$ + are redirected to class $j$, + % i.e. considered as if they belong to class $j$, + and {\tt NbExp$[s]$} has been added to {\tt NbExp$[j]$} + and then set to zero. + {\tt NbClasses} gives the final number of classes, + {\tt smin} contains the new index of the lowest class, + and {\tt smax} the new index of the highest class. + \endtab +\code + + +void gofs_WriteClasses (double NbExp[], long Loc[], + long smin, long smax, long NbClasses); +\endcode + \tab Prints the classes before or after their regrouping by + {\tt gofs\_MergeClasses}. + The parameters are the same as for the latter function. + If {\tt NbClasses > 0}, assumes that {\tt gofs\_MergeClasses} + has already been called to regroup classes +% (otherwise {\tt Loc} will be undefined!)} + and prints the classes after the regrouping. + If {\tt NbClasses <= 0}, prints only the classes before any regrouping. + \endtab + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Computing EDF test statistics} + +\code + +double gofs_Chi2 (double NbExp[], long Count[], long smin, long smax); +\endcode +\tab Computes and returns the chi-square statistic for the + observations $o_i$ in {\tt Count[smin...smax]}, for which the + corresponding expected values $e_i$ are in {\tt NbExp[smin...smax]}. + Assuming that $i$ goes from 1 to $k$, where $k =$ {\tt smax-smin+1} + is the number of classes, the chi-square statistic is defined as + \eq + X^2 = \sum_{i=1}^k \frac{(o_i - e_i)^2}{e_i}. \eqlabel{eq:chi-square} + \endeq + Under the hypothesis that the $e_i$ are the correct expectations and + if these $e_i$ are large enough, $X^2$ follows approximately the + chi-square distribution with $k-1$ degrees of freedom. + If some of the $e_i$ are too small, one can use {\tt gofs\_MergeClasses} + to regroup classes. +\endtab +\code + + +double gofs_Chi2Equal (double NbExp, long Count[], long smin, long smax); +\endcode +\tab Similar to {\tt gofs\_Chi2}, except that the expected + number of observations per class is assumed to be the same for + all classes, and equal to {\tt NbExp}. +\endtab +\code + + +long gofs_Scan (double U[], long N, double d); +\endcode + \tab Computes and returns the scan statistic $S_N(d)$, + defined in (\ref{eq:scan}). + The $N$ observations in the array {\tt U[1..N]} must be real numbers + in the interval $[0,1]$, sorted in increasing order. + (See {\tt fbar\_Scan} for the distribution function of $S_N(d)$). + \endtab +\code + + +double gofs_CramerMises (double U[], long N); +\endcode + \tab Computes and returns the Cram\'er-von Mises statistic $W_N^2$ + (see \cite{tDUR73a,tSTE70a,tSTE86b}), defined by + \begin {equation} + W_N^2 = {1\over 12N} + + \sum_{j=1}^N \left(U_{(j)} - {(j-0.5) \over N}\right)^2, + \eqlabel {eq:CraMis} + \end {equation} + assuming that {\tt U[1...N]} contains $U_{(1)},\dots,U_{(N)}$ + sorted in increasing order. + \endtab +\code + + +double gofs_WatsonG (double U[], long N); +\endcode + \tab Computes and returns the Watson statistic $G_N$ + (see \cite{tWAT76a,tDAR83a}), defined by + \begin {eqnarray} + G_N &=& \sqrt{N} \max_{\rule{0pt}{7pt} 1\le j \le N} \left\{ j/N - + U_{(j)} + \overline U_N - 1/2 \right\} + \eqlabel {eq:WatsonG} \\[6pt] + &=& \sqrt{N}\left (D_N^+ + \overline U_N - 1/2\right), \nonumber + \end {eqnarray} + where $\overline U_N$ is the average of the observations $U_{(j)}$, + assuming that {\tt U[1...N]} contains the sorted $U_{(1)},\dots,U_{(N)}$. + \endtab +\code + + +double gofs_WatsonU (double U[], long N); +\endcode + \tab Computes and returns the Watson statistic $U_N^2$ + (see \cite{tDUR73a,tSTE70a,tSTE86b}), defined by + \begin {eqnarray} + W_N^2 &=& {1\over 12N} + + \sum_{j=1}^N \left\{U_{(j)} - {(j- 0.5)\over N}\right\}^2, \\ + U_N^2 &=& W_N^2 - N\left (\overline U_N - 1/2\right)^2. + \eqlabel {eq:WatsonU} + \end {eqnarray} + where $\overline U_N$ is the average of the observations $U_{(j)}$, + assuming that {\tt U[1...N]} contains the sorted $U_{(1)},\dots,U_{(N)}$. + \endtab +\code + + +double gofs_AndersonDarling (double U[], long N); +\endcode + \tab Computes and returns the Anderson-Darling statistic $A_N^2$ + (see \cite{tLEW61a,tSTE86b,tAND52a}), defined by + \begin {eqnarray*} + A_N^2 &=& -N -{1\over N} \sum_{j=1}^N \left\{ (2j-1)\ln(U_{(j)}) + + (2N+1-2j) \ln(1-U_{(j)}) \right\}, \eqlabel {eq:Andar} + \end {eqnarray*} + assuming that {\tt U[1...N]} contains $U_{(1)},\dots,U_{(N)}$. + \ifdetailed %%%% + This function uses the environment variable {\tt gofs\_EpsilonAD}. + \fi %%%% detailed + \endtab +\code + + +void gofs_KS (double U[], long N, double *DP, double *DM, double *D); +\endcode +\tab Computes the Kolmogorov-Smirnov (KS) test statistics + $D_N^+$, $D_N^-$, and $D_N$, defined by + \begin {eqnarray} + D_N^+ &=& \max_{1\le j\le N} \left(j/N - U_{(j)}\right), + \eqlabel{eq:DNp} \\ + D_N^- &=& \max_{1\le j\le N} \left(U_{(j)} - (j-1)/N\right), + \eqlabel{eq:DNm} \\ + D_N &=& \max\ (D_N^+, D_N^-). \eqlabel{eq:DN} + \end {eqnarray} + and return their values in {\tt DP, DM}, and {\tt D}, respectively. + These statistics compare the empirical distribution of + $U_{(1)},\dots,U_{(N)}$, which are assumed to be in {\tt U[1...N]}, + with the uniform distribution. +\hrichard {Pourquoi avoir enlev\'e les calculs des EDF de ce fichier et + l'avoir mis dans gofw? On calcule d\'ej\`a toutes les stats EDF + explicitement.} +\hpierre {Simplement pour \'eviter d'introduire {\tt TestType}, + {\tt TestArray}, etc. dans ce module, et pouvoir tout cacher + cela ensemble \`a la fin de {\tt gofw}. Ces choses sont commodes + pour Testu01, mais trop sp\'ecialis\'ees et pas trop int\'eressantes + pour la plupart des gens. } +\endtab +\code + + +void gofs_KSJumpOne (double U[], long N, double a, double *DP, double *DM); +\endcode +\tab Compute the KS statistics $D_N^+(a)$ and $D_N^-(a)$ defined in the + description of the function +{\tt fdist\_KSPlusJumpOne}, assuming that $F$ is the + uniform distribution over $[0,1]$ and that + $U_{(1)},\dots,U_{(N)}$ are in {\tt U[1...N]}. + Returns the values in {\tt DP} and {\tt DM}. + \endtab +\hide%%%%% + +\code +#if 0 +void gofs_KSJumpsMany (double X[], int N, wdist_CFUNC F, double W[], + double *DP, double *DM, int Detail); +#endif +\endcode +\tab We assume that $X[1...N]$ is already sorted and contains the + $N$ empirical observations. We obtain the values of the distribution + $U = F(W, X[i])$ where $F$ is the theoretical + distribution which may be discontinuous, and $W$ are the parameters + of $F$. If {\tt Detail} $> 0$, the computed values of the + distribution will be printed. + Returns the values of the KS statistics in {\tt DP} and {\tt DM}. + \endtab +\endhide%%%%%%%%%%%%%% + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/probdist/gofw.c b/TESTU01/TestU01-1.2.3/probdist/gofw.c new file mode 100644 index 0000000..702f26c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/gofw.c @@ -0,0 +1,709 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: gofw.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "gofw.h" +#include "gofs.h" +#include "fdist.h" +#include "wdist.h" +#include "fbar.h" + +#include "util.h" +#include "num.h" +#include "tables.h" +#include "mystr.h" +#include "bitset.h" + +#include +#include +#include +#include + + + + +/*---------------------------- extern variables ----------------------------*/ + +gofw_GraphType gofw_GraphSoft = gofw_Gnuplot; + +double gofw_Suspectp = 0.001; + +double gofw_Epsilonp = 1.0E-300; +double gofw_Epsilonp1 = 1.0E-15; + +char *gofw_TestNames[gofw_NTestTypes] = { + "KSPlus", "KSMinus", "KS", "Anderson-Darling", + "Cramer-vonMises", "Watson G", "Watson U", + "Mean", "Variance", "Correlation", "Sum" +}; + +bitset_BitSet gofw_ActiveTests = (bitset_BitSet) 0 | + (1U << gofw_KSP) | (1U << gofw_KSM) | (1U << gofw_AD); + + + +/*---------------------------- module variables ----------------------------*/ + +#define LEN1 100 +#define LEN2 10 + +static char desc[LEN1]; +static char str[LEN2]; + + + + +/*--------------------------------------------------------------------------*/ + +static void printMath2 (FILE * f, double x, double y) +{ + /* Writes the pair (x, y) in file f, in a format understood */ + /* by Mathematica */ + char S[41]; + + fprintf (f, " { "); + if ((x != 0.0) && (x < 0.1 || x > 1.0)) { + sprintf (S, "%16.7E", x); + mystr_Subst (S, "E", "*10^("); + strcat (S, ")"); + } else { + sprintf (S, "%16.8g", x); + } + fprintf (f, S); + fprintf (f, ", "); + + if (y != 0.0 && (y < 0.1 || y > 1.0)) { + sprintf (S, "%16.7E", y); + mystr_Subst (S, "E", "*10^("); + strcat (S, ")"); + } else { + sprintf (S, "%16.8g", y); + } + fprintf (f, S); + fprintf (f, " }"); +} + +/*--------------------------------------------------------------------------*/ + +void gofw_GraphDistUnif (FILE * f, double U[], long N, char Desc[]) +{ + long i; + double UnSurN = 1.0 / N; + if (f == NULL) + f = stdout; + + switch (gofw_GraphSoft) { + + case gofw_Gnuplot: + fprintf (f, "#----------------------------------\n"); + fprintf (f, "# %-70s\n\n", Desc); + fprintf (f, "%16.8g %16.8g\n", 0.0, 0.0); + for (i = 1; i <= N; i++) + fprintf (f, "%16.8g %16.8g\n", U[i], i * UnSurN); + fprintf (f, "%16.8g %16.8g\n\n", 1.0, 1.0); + break; + + case gofw_Mathematica: + fprintf (f, "(*----------------------------------*)\n"); + fprintf (f, "(* %-70s\n *)\n\npoints = { \n", Desc); + printMath2 (f, 0.0, 0.0); + fprintf (f, ",\n"); + for (i = 1; i <= N; i++) { + printMath2 (f, U[i], i * UnSurN); + fprintf (f, ",\n"); + } + printMath2 (f, 1.0, 1.0); + fprintf (f, "\n}\n\n"); + break; + + default: + util_Error ("gofw_GraphDistUnif: gofw_GraphSoft unknown"); + break; + } +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_GraphFunc (FILE *f, wdist_CFUNC F, double par[], double a, + double b, int M, int mono, char Desc[]) +{ + int i; + double yprec, y, x, h; + if (f == NULL) + f = stdout; + + switch (gofw_GraphSoft) { + + /* Il y a trop de repetition de code ici. */ + case gofw_Gnuplot: + fprintf (f, "#----------------------------------\n"); + fprintf (f, "# %-70s\n\n", Desc); + h = (b - a) / M; + if (mono == 1) + yprec = -DBL_MAX; + else if (mono == -1) + yprec = DBL_MAX; + else + yprec = 0.0; + for (i = 0; i <= M; i++) { + x = a + i * h; + y = F (par, x); + fprintf (f, "%16.8g %16.8g", x, y); + switch (mono) { + case 1: + if (y < yprec) + fprintf (f, " # DECREASING"); + break; + case -1: + if (y > yprec) + fprintf (f, " # INCREASING"); + break; + default: + break; + } + fprintf (f, "\n"); + yprec = y; + } + fprintf (f, "\n"); + break; + + case gofw_Mathematica: + fprintf (f, "(*----------------------------------*)\n"); + fprintf (f, "(* %-70s\n *)\n\npoints = { \n", Desc); + h = (b - a) / M; + if (mono == 1) + yprec = -DBL_MAX; + else if (mono == -1) + yprec = DBL_MAX; + else + yprec = 0.0; + for (i = 0; i <= M; i++) { + x = a + i * h; + y = F (par, x); + printMath2 (f, x, y); + if (i < M) + fprintf (f, ","); + + switch (mono) { + case 1: + if (y < yprec) + fprintf (f, " (* DECREASING *)"); + break; + case -1: + if (y > yprec) + fprintf (f, " (* INCREASING *)"); + break; + default: + break; + } + fprintf (f, "\n"); + yprec = y; + } + fprintf (f, "}\n\n"); + break; + + default: + util_Error ("gofw_GraphFunc: gofw_GraphSoft unknown"); + break; + } +} + + +/*--------------------------------------------------------------------------*/ + +double gofw_pDisc (double pLeft, double pRight) +{ + double p; + + if (pRight < pLeft) + p = pRight; + else if (pLeft > 0.5) + p = 0.5; + else + p = 1.0 - pLeft; + /* Note: si p est tres proche de 1, on perd toute la precision ici! */ + /* Note2: je ne pense pas que cela puisse se produire a cause des if (RS) + */ + return p; +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_Writep0 (double p) + /* Prints the significance level of a test, without a descriptor */ +{ + if ((p >= 0.01) && (p <= 0.99)) + num_WriteD (p, 8, 2, 1); + else if (p < gofw_Epsilonp) + printf (" eps "); + else if (p < 0.01) + num_WriteD (p, 8, 2, 2); + else if (p >= 1.0 - gofw_Epsilonp1) + printf (" 1 - eps1"); + else if (p < 1.0 - 1.0e-4) + printf (" %.4f", p); + else { + printf (" 1 - "); + num_WriteD (1.0 - p, 7, 2, 2); + } +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_Writep1 (double p) + /* Prints the significance level of a test, with a descriptor. */ +{ +/* printf ("Significance level of test :"); */ + printf ("p-value of test :"); + gofw_Writep0 (p); + if (p < gofw_Suspectp || p > 1.0 - gofw_Suspectp) { + printf (" *****"); + } + printf ("\n\n"); +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_Writep2 (double x, double p) + /* Prints the statistic x and its significance level p. */ +{ + if ((x < 1.0e5 && x >= 0.1) || (x > -1.0e4 && x <= -0.1)) + num_WriteD (x, 8, 2, 1); + else if ((x < 0.1 && x >= 0.01) || (x > -0.1 && x <= -0.01)) + num_WriteD (x, 8, 3, 2); + else + num_WriteD (x, 8, 3, 3); + printf ("\n"); + gofw_Writep1 (p); +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_WriteKS0 (long N, double DP, double DM, double D) + /* Prints the results of a Kolmogorov-Smirnov test */ +{ + printf ("\n\nKolmogorov-Smirnov+ statistic = D+ :"); + gofw_Writep2 (DP, fbar_KSPlus (N, DP)); + printf ("Kolmogorov-Smirnov- statistic = D- :"); + gofw_Writep2 (DM, fbar_KSPlus (N, DM)); + printf ("Kolmogorov-Smirnov statistic = D :"); + gofw_Writep2 (D, fbar_KS1 (N, D)); + printf ("\n\n"); +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_WriteKS1 (double V[], long N, wdist_CFUNC F, double par[]) +{ + double *U; + double D, DM, DP; + + U = (double *) util_Calloc ((size_t) N + 1, sizeof (double)); + gofs_ContUnifTransform (V, N, F, par, U); + tables_QuickSortD (U, 1, N); + gofs_KS (U, N, &DP, &DM, &D); + gofw_WriteKS0 (N, DP, DM, D); + util_Free (U); +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_WriteKSJumpOne0 (long N, double a, double DP) +{ + double d; + + printf ("\nKolmogorov-Smirnov+ statistic = D+ :%8.2g\n", DP); + d = 1.0 - fdist_KSPlusJumpOne (N, a, DP); + gofw_Writep1 (d); + printf ("\n"); +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_WriteKSJumpOne1 (double V[], long N, wdist_CFUNC F, double par[], + double a) +{ + double *U; + double DP, DM; + + U = (double *)util_Calloc ((size_t) N + 1, sizeof (double)); + gofs_ContUnifTransform (V, N, F, par, U); + tables_QuickSortD (U, 1, N); + gofs_KSJumpOne (U, N, a, &DP, &DM); + gofw_WriteKSJumpOne0 (N, a, DP); + util_Free (U); +} + + +/*--------------------------------------------------------------------------*/ + +#if 0 + +void gofw_KSJumpsMany0 (double DP, double DM, fdist_FUNC_JUMPS * H) +{ + double d; + + printf ("\nKolmogorov-Smirnov+ statistic = D+ :%8.2g\n", DP); + d = 1.0 - fdist_KSPlusJumpsMany (H, DP); + gofw_Desc1 (d); + + printf ("\nKolmogorov-Smirnov- statistic = D- :%8.2g\n", DM); + d = 1.0 - fdist_KSMinusJumpsMany (H, DM); + gofw_Desc1 (d); + printf ("\n"); +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_KSJumpsMany2 (statcoll_Collector *S, fdist_FUNC_JUMPS *H, + int Detail) +{ + double DM, DP; + double *X; + wdist_CFUNC F = H->F; + double *W = H->par; + + /* The implementation of fdist_KSPlusJumpsMany and fdist_KSMinusJumpsMany + works only for NObs <= 64: instability for larger NObs. */ + if (S->NObs > 64) { + printf ("\nKolmogorov-Smirnov, sample too large\n\n\n" + "------------------------------------------\n"); + return; + } + + X = (double *) util_Calloc (1 + (size_t) S->NObs, sizeof (double)); + tables_CopyTabD (S->St, X, 1, S->NObs); + tables_QuickSortD (X, 1, S->NObs); + statcalc_KSJumpsMany (X, S->NObs, F, W, &DP, &DM, Detail); + gofw_KSJumpsMany0 (DP, DM, H); + util_Free (X); + printf ("\n"); +} + +#endif +/*--------------------------------------------------------------------------*/ + +void gofw_InitTestArray (gofw_TestArray A, double x) +{ + int i; + for (i = 0; i < gofw_NTestTypes; i++) + A[i] = x; +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_Tests0 (double U[], long N, gofw_TestArray sVal) +{ + long i; + double A2 = 0.0, W2, DM = 0.0, DP = 0.0, W; + double U1, Ui, D2, D1; + double SumZ; + double UnSurN; + + util_Assert (N > 0, "gofw_Tests0: N <= 0"); + + /* We assume that U is already sorted. */ + if (N == 1) { + sVal[gofw_KSP] = 1.0 - U[1]; + sVal[gofw_Mean] = U[1]; + return; + } + UnSurN = 1.0 / N; + W2 = UnSurN / 12.0; + SumZ = 0.0; + for (i = 1; i <= N; i++) { + /* Statistics KS */ + D1 = U[i] - (i - 1) * UnSurN; + D2 = i * UnSurN - U[i]; + if (D1 > DM) + DM = D1; + if (D2 > DP) + DP = D2; + /* Watson U and G */ + SumZ += U[i]; + W = U[i] - (i - 0.5) * UnSurN; + W2 += W * W; + /* Anderson-Darling */ + Ui = U[i]; + U1 = 1.0 - Ui; + if (Ui < gofs_EpsilonAD) + Ui = gofs_EpsilonAD; + else if (U1 < gofs_EpsilonAD) + U1 = gofs_EpsilonAD; + A2 += (2 * i - 1) * log (Ui) + (1 + 2 * (N - i)) * log (U1); + } + if (DM > DP) + sVal[gofw_KS] = DM; + else + sVal[gofw_KS] = DP; + sVal[gofw_KSM] = DM; + sVal[gofw_KSP] = DP; + SumZ = SumZ * UnSurN - 0.5; + sVal[gofw_CM] = W2; + sVal[gofw_WG] = sqrt ((double) N) * (DP + SumZ); + sVal[gofw_WU] = W2 - SumZ * SumZ * N; + sVal[gofw_AD] = -N - A2 * UnSurN; +/* sVal[gofw_Mean] = SumZ + 0.5; */ /* Nouveau ... */ +} + +/*-------------------------------------------------------------------------*/ + +void gofw_Tests1 (double V[], long N, wdist_CFUNC F, double par[], + gofw_TestArray sVal) +{ + double *U; + util_Assert (N > 0, "gofw_Tests1: N <= 0"); + U = (double *) util_Calloc ((size_t) N + 1, sizeof (double)); + gofs_ContUnifTransform (V, N, F, par, U); + tables_QuickSortD (U, 1, N); + gofw_Tests0 (U, N, sVal); + if (N == 1) + sVal[gofw_Mean] = V[1]; /* On veut V[1], pas U[1] */ + util_Free (U); +} + +/*-------------------------------------------------------------------------*/ + +void gofw_ActiveTests0 (double U[], long N, + gofw_TestArray sVal, gofw_TestArray pVal) +{ + util_Assert (N > 0, "gofw_ActiveTests0: N <= 0"); + if (N == 1) { + sVal[gofw_Mean] = U[1]; + pVal[gofw_Mean] = 1.0 - U[1]; + sVal[gofw_KSP] = 1.0 - U[1]; + pVal[gofw_KSP] = 1.0 - U[1]; + pVal[gofw_AD] = -1.0; /* My bug detector */ + return; + } + /* We assume that U is already sorted. */ + gofw_Tests0 (U, N, sVal); + + if (bitset_TestBit (gofw_ActiveTests, gofw_KSP)) + pVal[gofw_KSP] = fbar_KSPlus (N, sVal[gofw_KSP]); + + if (bitset_TestBit (gofw_ActiveTests, gofw_KSM)) + pVal[gofw_KSM] = fbar_KSPlus (N, sVal[gofw_KSM]); + + if (bitset_TestBit (gofw_ActiveTests, gofw_KS)) + pVal[gofw_KS] = fbar_KS1 (N, sVal[gofw_KS]); + + if (bitset_TestBit (gofw_ActiveTests, gofw_AD)) + pVal[gofw_AD] = fbar_AndersonDarling (N, sVal[gofw_AD]); + + if (bitset_TestBit (gofw_ActiveTests, gofw_CM)) + pVal[gofw_CM] = fbar_CramerMises (N, sVal[gofw_CM]); + + if (bitset_TestBit (gofw_ActiveTests, gofw_WG)) + pVal[gofw_WG] = fbar_WatsonG (N, sVal[gofw_WG]); + + if (bitset_TestBit (gofw_ActiveTests, gofw_WU)) + pVal[gofw_WU] = fbar_WatsonU (N, sVal[gofw_WU]); +} + +/*-------------------------------------------------------------------------*/ + +void gofw_ActiveTests1 (double V[], long N, wdist_CFUNC F, double par[], + gofw_TestArray sVal, gofw_TestArray pVal) +{ + double *U; + util_Assert (N > 0, "gofw_ActiveTests1: N <= 0"); + U = (double *) util_Calloc ((size_t) N + 1, sizeof (double)); + gofs_ContUnifTransform (V, N, F, par, U); + tables_QuickSortD (U, 1, N); + gofw_ActiveTests0 (U, N, sVal, pVal); + if (N == 1) + sVal[gofw_Mean] = V[1]; + util_Free (U); +} + +/*-------------------------------------------------------------------------*/ + +void gofw_ActiveTests2 (double V[], double U[], long N, wdist_CFUNC F, + double par[], gofw_TestArray sVal, gofw_TestArray pVal) +{ + util_Assert (N > 0, "gofw_ActiveTests1: N <= 0"); + tables_QuickSortD (V, 1, N); + gofs_ContUnifTransform (V, N, F, par, U); + gofw_ActiveTests0 (U, N, sVal, pVal); + if (N == 1) + sVal[gofw_Mean] = V[1]; +} + +/*-------------------------------------------------------------------------*/ + +void gofw_WriteActiveTests0 (long N, gofw_TestArray sVal, + gofw_TestArray pVal) +{ + if (N == 1) { + gofw_Writep1 (pVal[gofw_KSP]); + return; + } + printf ("\n"); + if (bitset_TestBit (gofw_ActiveTests, gofw_KSP)) { + printf ("Kolmogorov-Smirnov+ statistic = D+ :"); + gofw_Writep2 (sVal[gofw_KSP], pVal[gofw_KSP]); + } + if (bitset_TestBit (gofw_ActiveTests, gofw_KSM)) { + printf ("Kolmogorov-Smirnov- statistic = D- :"); + gofw_Writep2 (sVal[gofw_KSM], pVal[gofw_KSM]); + } + if (bitset_TestBit (gofw_ActiveTests, gofw_KS)) { + printf ("Kolmogorov-Smirnov statistic = D :"); + gofw_Writep2 (sVal[gofw_KS], pVal[gofw_KS]); + } + if (bitset_TestBit (gofw_ActiveTests, gofw_AD)) { + printf ("Anderson-Darling statistic = A2 :"); + gofw_Writep2 (sVal[gofw_AD], pVal[gofw_AD]); + } + if (bitset_TestBit (gofw_ActiveTests, gofw_CM)) { + printf ("Cramer-von Mises statistic = W2 :"); + gofw_Writep2 (sVal[gofw_CM], pVal[gofw_CM]); + } + if (bitset_TestBit (gofw_ActiveTests, gofw_WG)) { + printf ("Watson statistic = G :"); + gofw_Writep2 (sVal[gofw_WG], pVal[gofw_WG]); + } + if (bitset_TestBit (gofw_ActiveTests, gofw_WU)) { + printf ("Watson statistic = U2 :"); + gofw_Writep2 (sVal[gofw_WU], pVal[gofw_WU]); + } +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_WriteActiveTests1 (double V[], long N, wdist_CFUNC F, double par[]) +{ + gofw_TestArray sv, pv; + + gofw_ActiveTests1 (V, N, F, par, sv, pv); + gofw_WriteActiveTests0 (N, sv, pv); +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_WriteActiveTests2 (long N, gofw_TestArray sVal, + gofw_TestArray pVal, char S[]) +{ + printf ("\n-----------------------------------------------\n"); + if (N == 1) { + printf (S); + gofw_Writep2 (sVal[gofw_Mean], pVal[gofw_Mean]); + } else { + gofw_WriteActiveTests0 (N, sVal, pVal); + } +} + + +/*--------------------------------------------------------------------------*/ + +void gofw_IterSpacingsTests0 (double U[], long N, int k, + lebool printval, lebool graph, FILE * f) + /* Assumes that U is sorted. */ +{ + int j; + long i; + double *S, *UU; + gofw_TestArray sVal, pVal; + + UU = (double *) util_Calloc (1 + (size_t) N, sizeof (double)); + S = (double *) util_Calloc (1 + (size_t) N, sizeof (double)); + printf ("\n"); + for (i = 1; i <= N; i++) + UU[i] = U[i]; /* UU is a copy of U */ + for (j = 1; j <= k; j++) { + printf ("-----------------------------------\n" + "EDF Tests after \"gofw_IterateSpacings\", level :%2d\n", j); + gofs_DiffD (UU, S, 1, N, 0.0, 1.0); + gofs_IterateSpacings (UU, S, N); + tables_QuickSortD (UU, 1, N); + gofw_ActiveTests0 (UU, N, sVal, pVal); + gofw_WriteActiveTests0 (N, sVal, pVal); + strncpy (desc, "Values of Uniforms after IterateSpacings, level ", + (size_t) LEN1); + sprintf (str, "%2d", j); + strncat (desc, str, (size_t) LEN2); + if (printval > 0) + tables_WriteTabD (UU, 1, N, 5, 15, 6, 6, desc); + if (graph > 0) + gofw_GraphDistUnif (f, UU, N, desc); + } + util_Free (UU); + util_Free (S); +} + + +/*--------------------------------------------------------------------------*/ + + +void gofw_IterPowRatioTests0 (double U[], long N, int k, + lebool printval, lebool graph, FILE * f) +{ + int i; + long j; + double *UU; + gofw_TestArray sVal, pVal; + + UU = (double *) util_Calloc (1 + (size_t) N, sizeof (double)); + printf ("\n"); + for (j = 1; j <= N; j++) + UU[j] = U[j]; + for (i = 1; i <= k; i++) { + gofs_PowerRatios (UU, N); + printf ("-----------------------------------\n" + "EDF Tests after \"gofw_PowerRatios\", level :%2d\n", i); + tables_QuickSortD (UU, 1, N); + gofw_ActiveTests0 (UU, N, sVal, pVal); + gofw_WriteActiveTests0 (N, sVal, pVal); + strncpy (desc, "Values of Uniforms after PowerRatios, level ", + (size_t) LEN1); + sprintf (str, "%2d", i); + strncat (desc, str, (size_t) LEN2); + if (printval > 0) + tables_WriteTabD (UU, 1, N, 5, 15, 6, 6, desc); + if (graph > 0) + gofw_GraphDistUnif (f, UU, N, desc); + } + util_Free (UU); +} + +/*--------------------------------------------------------------------------*/ diff --git a/TESTU01/TestU01-1.2.3/probdist/gofw.tex b/TESTU01/TestU01-1.2.3/probdist/gofw.tex new file mode 100644 index 0000000..0cddbda --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/gofw.tex @@ -0,0 +1,539 @@ +\defmodule {gofw} + +This module contains functions used to print results of GOF +test statistics (see module {\tt gofs}), or to apply a series of tests +simultaneously and print the results. +Strictly speaking, applying several tests simultaneously makes the +$p$-values ``invalid'' in the sense that the probability of having +{\em at least one\/} $p$-value less than 0.01, say, is larger than 0.01. +One must therefore be careful with the interpretation of these +$p$-values (one could use, e.g., the Bonferroni inequality \cite{sLAW00a}). +Applying simultaneous tests is convenient in some situations, such as in +screening experiments for detecting statistical deficiencies +in random number generators. In that context, rejection of the null +hypothesis typically occurs with extremely small $p$-values (e.g., less +than $10^{-15}$), and the interpretation is quite obvious in this case. + +% Expliquer rapidement l'histoire des {\em ActiveTests}. +% (voir plus loin). + +The module also provides tools to plot an empirical or +theoretical distribution function, by creating a data file that +contains a graphic plot in a format compatible with the software +specified by the environment variable {\tt gofw\_GraphSoft}. + + +\bigskip\hrule\medskip +\code\hide +/* gofw.h for ANSI C */ +#ifndef GOFW_H +#define GOFW_H +\endhide +#include "gdef.h" /* From the library mylib */ +#include "bitset.h" /* From the library mylib */ +#include "fdist.h" +#include "wdist.h" +#include +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Plotting distribution functions} + +\code + +typedef enum { + gofw_Gnuplot, + gofw_Mathematica + } gofw_GraphType; +\endcode + \tab Data file formats used for plotting functions or creating graphics. + \endtab +\code + + +extern gofw_GraphType gofw_GraphSoft; +\endcode + \tab Environment variable that selects the type of software to be + used for plotting the graphs of functions. + The data files produced by {\tt gofw\_GraphFunc} and + {\tt gofw\_GraphDistUnif} will be in a format suitable + for this selected software. + The default value is {\tt gofw\_Gnuplot}. + To display a graphic in file {\tt f} using {\tt gnuplot}, for example, + one can use the command ``{\tt plot f with steps, x with lines}'' + in {\tt gnuplot}. + \endtab +\code + + +void gofw_GraphFunc (FILE *f, wdist_CFUNC F, double par[], double a, + double b, int m, int mono, char Desc[]); +\endcode + \tab + Prints data to plot the graph of function $F$ over the interval $[a,b]$, + in file {\tt f}. It is assumed that the parameters of $F$ are in + {\tt par}, so that {\tt F(par, x)} returns the value of $F$ at $x$, + and that $F$ is either non-decreasing or non-increasing. + If {\tt mono} = 1, the procedure will verify that $F$ is non-decreasing; + if {\tt mono} = $-1$, it will verify that $F$ is non-increasing. + (This is useful to verify if $F$ is effectively a sensible + approximation to a distribution function or its complementary + in the given interval.) + The string {\tt Desc} should give a short caption for the graphic plot. + The procedure computes the $m+1$ points $(x_i,\, F(x_i))$, + where $x_i = a + i(b-a)/m$ for $i=0,1,\ldots,m$, and writes these points + to file {\tt f} in a format suitable for the + software specified by {\tt gofw\_GraphSoft}. + If {\tt f = NULL}, the results are sent to the standard output. + \endtab +\code + + +void gofw_GraphDistUnif (FILE *f, double U[], long N, char Desc[]); +\endcode + \tab Prints data in file {\tt f} to plot the empirical distribution of + $U_{(1)},\dots,U_{(N)}$, which are assumed to be in {\tt U[1...N]}, + and to compare it with the uniform distribution. + The two endpoints $(0, 0)$ and $(1, 1)$ are always printed. + The string {\tt Desc} should give a short caption for the graphic plot. + The data is printed in a format suitable for the + software specified by {\tt gofw\_GraphSoft}. + If {\tt f = NULL}, the results are sent to the standard output. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Computing and printing $p$-values for EDF test statistics} + +\code + +extern double gofw_Epsilonp; +extern double gofw_Epsilonp1; +\endcode + \tab Environment variables used in {\tt gofw\_Writep0} to determine + which $p$-values are too close to 0 or 1 to be printed explicitly. + If {\tt gofw\_Epsilonp} $= \epsilon$ and + {\tt gofw\_Epsilonp1} $= \epsilon_1$, then any $p$-value + (sometimes also called significance level) less than $\epsilon$ or larger than + $1-\epsilon_1$ is {\em not\/} written explicitly; + the program simply writes ``{\tt eps}'' ($p$-values close to 0) + or ``{\tt 1 - eps1}'' ($p$-values close to 1). + The default values are {\tt gofw\_Epsilonp} $ =10^{-300}$ and + {\tt gofw\_Epsilonp1} $= 10^{-15}$. + The default value of {\tt gofw\_Epsilonp} is slightly bigger than + the minimum normalized positive floating-point number + {\tt DBL\_MIN} = $2.2*10^{-308}$ given in the IEEE floating-point standard, + while {\tt gofw\_Epsilonp1} is slightly bigger than + {\tt DBL\_EPSILON} = $2.2*10^{-16}$, the ``machine $\epsilon$'' + for type {\tt double}. + \hpierre{Nouveau. Utilis\'e seulement dans {\tt gofw\_Writep0}.} + \endtab +\code + + +extern double gofw_Suspectp; +\endcode + \tab Environment variable used in {\tt gofw\_Writep1} to determine + which $p$-values should be marked as suspect when printing test results. + If {\tt gofw\_Suspectp} $= \alpha$, then any $p$-value + less than $\alpha$ or larger than + $1-\alpha$ is considered suspect and is + ``singled out'' by {\tt gofw\_Writep1}. + The default value is 0.001. + \hpierre{Utilis\'e seulement dans {\tt gofw\_Writep1}, mais + on ne veut pas la mettre en parametre car utilise souvent et ne + change presque jamais. } + \endtab +\code + + +double gofw_pDisc (double pL, double pR); +\endcode +\tab Computes a variant of the $p$-value $p$ whenever a test statistic + has a {\em discrete\/} probability distribution. + This $p$-value is defined as follows: + \begin{eqnarray*} + p_L & = & P[Y \le y] \\ + p_R & = & P[Y \ge y] \\[6pt] + p & = & \left\{ \begin{array}{l@{\qquad}l} + p_R, & \mbox{if } p_R < p_L \\[6pt] + 1 - p_L, & \mbox{if } + p_R \ge p_L \mbox{ and } p_L < 0.5 \\[6pt] + 0.5 & \mbox{otherwise.} + \end{array} \right. + \end{eqnarray*} + The function takes $p_L$ and $p_R$ as input and returns $p$. +\endtab +\code + + +void gofw_Writep0 (double p); +\endcode +\tab Prints the $p$-value $p$ of a test, + in the format ``$1-p$'' if $p$ is close to 1, and $p$ otherwise. +% Uses the environment variable {\tt gofw\_Epsilonp} and replaces $p$ +% by $\epsilon$ when it is too small. + \hrichard {Pourquoi ne pas la cacher dans \tt gofw.c?} + \hpierre {Quelqu'un pourrait vouloir utiliser un autre format que + celui de {\tt gofw\_Writep1}. } +\endtab +\code + + +void gofw_Writep1 (double p); +\endcode +\tab Prints the string ``{\tt "p-value of test : }'', + then calls {\tt gofw\_Writep0} to print $p$, and adds + the marker ``{\tt ****}'' if $p$ is considered suspect + (uses the environment variable {\tt gofw\_Suspectp} for this). +\endtab +\code + + +void gofw_Writep2 (double x, double p); +\endcode +\tab Prints {\tt x} on the current output line, then goes to the next line + and calls {\tt gofw\_Writep1 (p)}. + \hpierre {Peut \^etre \`a cacher?} +\endtab +\code + + +void gofw_WriteKS0 (long N, double DP, double DM, double D); +\endcode +\tab Computes the $p$-values of the three Kolmogorov-Smirnov statistics + $D_N^+$, $D_N^-$, and $D_N$, whose values are in {\tt DP, DM, D}, + respectively, assuming a sample of size $N$. + Then prints these statistics and their $p$-values + using {\tt gofw\_Writep2} for each one. + \hrichard {Devrait \^etre \'elimin\'e. Cas particulier de EDF avec les + autres CM, AD, Wat, .... Pourquoi traitement de faveur.} + \hpierre {Je pr\'ef\`ere laisser ceci pour les gens qui ne veulent pas + prendre le temps de comprendre l'id\'ee des ``active tests'', que + j'ai d'ailleurs repouss\'es compl\`etement \`a la fin. + Les tests de KS sont de loin les plus utilis\'es par les gens + pour les lois continues.} +\endtab +\code + + +void gofw_WriteKS1 (double V[], long N, wdist_CFUNC F, double par[]); +\endcode +\tab Computes the KS test statistics to compare the + empirical distribution of the observations in {\tt V[1..N]} + with the theoretical distribution {\tt F}, with parameters in {\tt par}, + then calls {\tt gofw\_KS0} to compute and print the $p$-values. + These tests are valid only if {\tt F} is continuous. +\endtab +\code + + +void gofw_WriteKSJumpOne0 (long N, double a, double DP); +\endcode +\tab Similar to {\tt gofw\_KS0}, but for the KS statistic $D_N^+(a)$ + defined in (\ref{eq:KSPlusJumpOne}). Writes a header, + computes the $p$-value and calls {\tt gofw\_Writep2}. +\endtab +\code + + +void gofw_WriteKSJumpOne1 (double V[], long N, + wdist_CFUNC F, double par[], double a); +\endcode +\tab Similar to {\tt gofw\_WriteKS1}, but for $D_N^+(a)$ + defined in (\ref{eq:KSPlusJumpOne}). + Calls {\tt gofw\_WriteKSJumpOne0}. +\endtab +\iffalse %%%%%%% +\code +#if 0 + +void gofw_KSJumpsMany0 (double DP, double DM, fdist_FUNC_JUMPS *H); +\endcode +\tab + Prints the KS statistics $D^+$ and $D^-$, as defined in the + description of {\tt fdist\_KSPlusJumpsMany} and + {\tt fdist\_KSMinusJumpsMany}, with their $p$-values. + We assume that the values of the statistics are in {\tt DP} and {\tt DM}, + and the discontinuous function {\tt H} is as described in the + above distributions. +\endtab +\code + + +void gofw_KSJumpsMany2 (statcoll_Collector *S, fdist_FUNC_JUMPS *H, + int Detail); + +\endcode +\tab + Compute the Kolmogorov-Smirnov statistics $D^+$ and $D^-$ + from the empirical distribution contained in the collector {\tt S}, + and compare them with the discontinuous theoretical distribution + {\tt H}; then prints these two statistics and their $p$-values. + If {\tt Detail $> 0$}, prints detailed information + about the calculation. +\endtab +\code + +#endif +\endcode + +\fi %%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec {Applying several tests at once and printing results} + +Higher-level tools for applying several EDF goodness-of-fit tests +simultaneously are offered here. +The test types available are listed in {\tt gofw\_TestType}. +The environment variable {\tt gofw\_ActiveTests} specifies which +tests in this list are to be performed when asking for several +simultaneous tests via the functions {\tt gofw\_ActiveTests0}, +{\tt gofw\_WriteActiveTests0}, etc. + + +\code + +typedef enum { + gofw_KSP, /* Kolmogorov-Smirnov+ */ + gofw_KSM, /* Kolmogorov-Smirnov- */ + gofw_KS, /* Kolmogorov-Smirnov */ + gofw_AD, /* Anderson-Darling */ + gofw_CM, /* Cramer-vonMises */ + gofw_WG, /* Watson G */ + gofw_WU, /* Watson U */ + gofw_Mean, /* Mean */ + gofw_Var, /* Variance */ + gofw_Cor, /* Correlation */ + gofw_Sum, /* Sum */ + gofw_NTestTypes /* Total number of test types */ + } gofw_TestType; +\endcode + \tab Types of EDF tests supported by the present modules. + Here, {\tt gofw\_Sum}, {\tt gofw\_Mean}, {\tt gofw\_Var} and {\tt gofw\_Cor} + usually represent tests based on the sum, the mean, the variance of the + observations and on the correlation between pairs of successive observations. + \hpierre {Est-ce utile que garder ces deux-l\`a dans ce type enum?} + \hrichard {N\'ecessaire si l'on veut que les tableaux sVal, pVal, + r\'eservent aussi une place pour ces 2. Sinon, il faudrait introduire + au moins 4 nouvelles variables globales pour chaque module.} +% {\bf Remark:} if {\tt gofw\_TestType} is modified in any way, then the +% variable {\tt gofw\_TestNames} must be updated correspondingly. + \endtab +\code + + +typedef double gofw_TestArray [gofw_NTestTypes]; +\endcode + \tab Array of values, one for each type of EDF test statistic. + Can be used to store the values of these statistics or their + $p$-values, for example. + \endtab +\code + + +extern char *gofw_TestNames [gofw_NTestTypes]; +\endcode + \tab Name of each {\tt gofw\_TestType} test. + Could be used for printing the test results, for example. +% {\bf Remark:} If the type {\tt gofw\_TestType} +% is modified in any way, then {\tt gofw\_TestNames} must be updated +% correspondingly. + \hpierre{Il me semble que cette liste des noms devrait \^etre juste \`a + cot\'e de la liste {\tt gofw\_TestType}. Est-ce OK comme ceci? } + \hrichard {On ne peut pas initialiser les variables extern dans *.h.} + \endtab +\code + + +extern bitset_BitSet gofw_ActiveTests; +\endcode + \tab The set of EDF tests that are to be performed when calling + the procedures {\tt gofw\_ActiveTests0}, {\tt gofw\_WriteActiveTests0}, etc. + By default, this set contains {\tt gofw\_KSP}, {\tt gofw\_KSM}, + and {\tt gofw\_AD}. %, but it can be changed. + Note: {\tt gofw\_Sum}, {\tt gofw\_Mean}, {\tt gofw\_Var} and {\tt gofw\_Cor} are + {\em always excluded\/} from this set of active tests. + \endtab +\code + + +void gofw_InitTestArray (gofw_TestArray A, double x); +\endcode + \tab Sets all elements of array $A$ to $x$. + \endtab +\code + + +void gofw_Tests0 (double U[], long N, gofw_TestArray sVal); +\endcode +\tab Computes all EDF test statistics in {\tt gofw\_TestType} (except + {\tt gofw\_Mean}, {\tt gofw\_Var} {\tt gofw\_Cor} and {\tt gofw\_Sum}) + to compare the empirical + distribution of $U_{(1)},\dots,U_{(N)}$ with the uniform distribution, + assuming that these sorted observations are in {\tt U[1...N]}. + If $N > 1$, returns in {\tt sVal[0..7]} the values of the KS + statistics $D_N^+$, $D_N^-$ and $D_N$, of the Cram\'er-von Mises + statistic $W_N^2$, Watson's $G_N$ and $U_N^2$, Anderson-Darling's + $A_N^2$, and the average of the $U_i$'s, respectively. + If $N = 1$, only puts {\tt U[1]} in {\tt sVal[gofw\_Mean]} + and {\tt 1 - U[1]} in {\tt sVal[gofw\_KSP]}. + Calling this function is more efficient than computing these statistics + separately by calling the corresponding procedures in {\tt gofs}. + \hrichard{\'Eliminer, garder seulement Active. On devrait \'eliminer + les fonctions qui ont une version active, et enlever le mot Active dans + leur nom. Les actives sont d\'etermin\'ees + par une variable d'environnement; donc toujours sous-entendu actives. + Les non-actives ne sont jamais utilis\'ees.} + \hpierre {On ne peut pas les \'eliminer car les {\tt Active...} appellent + celles-ci pour calculer toutes les stats d'un seul coup. + Si on trouve qu'elles genent, on peut les cacher, mais je ne crois pas. + Devrait peut-etre aller dans gofs, mais je l'ai mis + ici pour eviter de definir {\tt gofw\_TestArray} dans gofs. } +\endtab +\code + + +void gofw_Tests1 (double V[], long N, wdist_CFUNC F, double par[], + gofw_TestArray sVal); +\endcode +\tab Similar to {\tt gofw\_Test0}, except that + the observations are in {\tt V[1..N]}, + not necessarily sorted, and that their empirical + distribution is compared with the continuous distribution {\tt F}, + whose parameters (if any) are in {\tt par}. + \hpierre{ Note: if $N > 1$, the value returned in {\tt sVal[gofs\_Mean]} + is the average of the {\tt U[i] = F(par, V[i])}, not + the average of the {\tt V[i]}. } +% The EDF tests (p-values) are valid only if {\tt F} is continuous. + If $N = 1$, only puts {\tt V[1]} in {\tt sVal[gofw\_Mean]} + and {\tt 1 - F(par, V[1])} in {\tt sVal[gofw\_KSP]}. +\endtab +\code + + +void gofw_ActiveTests0 (double U[], long N, + gofw_TestArray sVal, gofw_TestArray pVal); +\endcode +\tab Computes the EDF test statistics by calling + {\tt gofw\_Tests0}, then computes the $p$-values of those + that currently belong to {\tt gofw\_ActiveTests}, +% \{{\tt gofw\_KSP, gofw\_KSM, gofw\_KS0, gofw\_CM, +% gofw\_WG, gofw\_WU, gofw\_AD}\}. + and return these quantities in {\tt sVal} and {\tt pVal}, respectively. + Assumes that $U_{(1)},\dots,U_{(N)}$ are in {\tt U[1...N]} + and that we want to compare their empirical distribution + with the uniform distribution. + If $N = 1$, only puts {\tt U[1]} in {\tt sVal[gofw\_Mean]}, + and {\tt 1 - U[1]} in {\tt sVal[gofw\_KSP], pVal[gofw\_KSP]}, and + {\tt pVal[gofw\_Mean]}. +\endtab +\code + + +void gofw_ActiveTests1 (double V[], long N, wdist_CFUNC F, double par[], + gofw_TestArray sVal, gofw_TestArray pVal); +\endcode +\tab Similar to {\tt gofw\_ActiveTests0}, + except that the observations are in {\tt V[1..N]}, + not necessarily sorted, and that we want to compare their empirical + distribution with the distribution {\tt F}, + whose parameters (if any) are in {\tt par}. + The EDF tests are valid only if {\tt F} is continuous. + If $N = 1$, only puts {\tt V[1]} in {\tt sVal[gofw\_Mean]}, + and {\tt 1 - F(par, V[1])} in {\tt sVal[gofw\_KSP], pVal[gofw\_KSP]}, + and {\tt pVal[gofw\_Mean]}. + \endtab +\code + + +void gofw_ActiveTests2 (double V[], double U[], long N, wdist_CFUNC F, + double par[], gofw_TestArray sVal, + gofw_TestArray pVal); +\endcode +\tab Similar to {\tt gofw\_ActiveTests1}, but first sorts the {\tt V} + and then returns the $U$ computed from +$$ + U[j] = F(\mbox{par}, V[j]), \qquad j=1,\ldots,N +$$ + and sorted. + \hrichard {Utilis\'e dans tous les tests de testu01.} + \endtab +\code + + +void gofw_WriteActiveTests0 (long N, gofw_TestArray sVal, + gofw_TestArray pVal); +\endcode +\tab Writes the $p$-values of the {\em active\/} EDF test statistics, + which are in {\tt gofw\_ActiveTests}. It is assumed that the values + of these statistics and their $p$-values are {\em already computed}, + in {\tt sVal} and {\tt pVal}, and that the sample size is $N$. + These statistics and $p$-values are printed + using {\tt gofw\_Writep2} for each one. + If $N=1$, prints only {\tt pVal[gofw\_KSP]} using {\tt gofw\_Writep1}. + \hrichard{Utilis\'e souvent dans testu01. ..Test1 jamais utilis\'e.} + \hpierre{Je pr\'ef\`ere conserver ...Tests1 quand meme.} +% \{{\tt statcalc\_KSP, statcalc\_KSM, statcalc\_KS, +% statcalc\_WatsonG, statcalc\_WatsonU, statcalc\_CramerMises, +% statcalc\_AndDar}\} and {\tt statcalc\_TestActives} +\endtab +\code + + +void gofw_WriteActiveTests1 (double V[], long N, + wdist_CFUNC F, double par[]); +\endcode +\tab This is equivalent to calling + {\tt gofw\_ActiveTests1 (V, N, F, par, sVal, pVal)} followed by + {\tt gofw\_WriteActiveTests0 (N, sVal, pVal)}. +\endtab +\code + + +void gofw_WriteActiveTests2 (long N, gofw_TestArray sVal, + gofw_TestArray pVal, char Desc[]); +\endcode +\tab If $N=1$, prints the string {\tt Desc} followed by the elements + {\tt gofw\_Mean} of {\tt sVal} and {\tt pVal}. Otherwise calls + {\tt gofw\_WriteActiveTests0 (N, sVal, pVal)}. +\endtab +\code + + +void gofw_IterSpacingsTests0 (double U[], long N, int k, + lebool printval, lebool graph, FILE *f); +\endcode +\tab Repeats the following $k$ times: + Applies the {\tt gofs\_IterateSpacings} transformation to the + $U_{(1)},\dots,U_{(N)}$, assuming that these observations are in + {\tt U[1...N]}, then computes the EDF test statistics and calls + {\tt gofw\_ActiveTests0} after each transformation. + The function returns the {\em original\/} array {\tt U} (the + transformations are applied on a copy of {\tt U}). +% If {\tt gofw\_StatsDetail} $>0$, prints all the values. +% If {\tt gofw\_GraphicsDetail} $>0$, prints to file {\tt f} +% the values appropriate for drawing graphics. + If {\tt printval = TRUE}, prints all the values to the standard output + after each iteration. + If {\tt graph = TRUE}, calls {\tt gofw\_GraphDistUnif} after each iteration + to print to file {\tt f} the data for plotting the distribution + function of the $U_i$. +\endtab +\code + + +void gofw_IterPowRatioTests0 (double U[], long N, int k, + lebool printval, lebool graph, FILE *f); +\endcode +\tab Similar to {\tt gofw\_IterSpacingsTest0}, but with the + {\tt gofs\_PowerRatios} transformation. +\endtab +\code +\hide +#endif +\endhide +\endcode + + diff --git a/TESTU01/TestU01-1.2.3/probdist/guideprobdist.bbl b/TESTU01/TestU01-1.2.3/probdist/guideprobdist.bbl new file mode 100644 index 0000000..677b94d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/guideprobdist.bbl @@ -0,0 +1,246 @@ +\begin{thebibliography}{10} + +\bibitem{tAND95b} +N.~H. Anderson and D.~M. Titterington. +\newblock A comparison of two statistics for detecting clustering in one + dimension. +\newblock {\em Journal of Statistical Computation and Simulation}, 53:103--125, + 1995. + +\bibitem{tAND52a} +T.~W. Anderson and D.~A. Darling. +\newblock Asymptotic theory of certain goodness of fit criteria based on + stochastic processes. +\newblock {\em Annals of Mathematical Statistics}, 23:193--212, 1952. + +\bibitem{tBES75a} +D.~J. Best and D.~E. Roberts. +\newblock Algorithm {AS} 91: The percentage points of the $\chi^{2}$ + distribution. +\newblock {\em Applied Statistics}, 24:385--388, 1975. + +\bibitem{tBAT70a} +G.~P. Bhattacharjee. +\newblock The incomplete gamma integral. +\newblock {\em Applied Statistics}, 19:285--287, 1970. +\newblock AS32. + +\bibitem{tBLA76a} +J.~M. Blair, C.~A. Edwards, and J.~H. Johnson. +\newblock Rational {C}hebyshev approximations for the inverse of the error + function. +\newblock {\em Mathematics of Computation}, 30:827--830, 1976. + +\bibitem{sBRA87a} +P.~Bratley, B.~L. Fox, and L.~E. Schrage. +\newblock {\em A Guide to Simulation}. +\newblock Springer-Verlag, New York, NY, second edition, 1987. + +\bibitem{tBRO07a} +J.~R. Brown and M.~E. Harvey. +\newblock Rational arithmetic \textsc{{M}athematica} functions to evaluate the + one-sided one-sample {K-S} cumulative sample distribution. +\newblock {\em Journal of Statistical Software}, 19(6):1--32, 2007. + +\bibitem{tBRO08a} +J.~R. Brown and M.~E. Harvey. +\newblock Rational arithmetic \textsc{{M}athematica} functions to evaluate the + two-sided one sample {K-S} cumulative sample distribution. +\newblock {\em Journal of Statistical Software}, 26(2):1--40, 2008. + +\bibitem{tDAR60a} +D.~A. Darling. +\newblock On the theorems of {K}olmogorov-{S}mirnov. +\newblock {\em Theory of Probability and Its Applications}, V(4):356--360, + 1960. + +\bibitem{tDAR83a} +D.~A. Darling. +\newblock On the asymptotic distribution of {W}atson's statistic. +\newblock {\em The Annals of Statistics}, 11(4):1263--1266, 1983. + +\bibitem{tDON73a} +T.~G. Donnelly. +\newblock Algorithm 462: Bivariate normal distribution. +\newblock {\em Communications of the ACM}, 16(10):638, 1973. + +\bibitem{tDRE89a} +Z.~Drezner and G.~O. Wesolowsky. +\newblock On the computation of the bivariate normal integral. +\newblock {\em Journal of Statistical Computation and Simulation}, 35:101--107, + 1989. + +\bibitem{tDUR73a} +J.~Durbin. +\newblock {\em Distribution Theory for Tests Based on the Sample Distribution + Function}. +\newblock SIAM CBMS-NSF Regional Conference Series in Applied Mathematics. + SIAM, Philadelphia, PA, 1973. + +\bibitem{tGAU64a} +W.~Gautschi. +\newblock Algorithm 222: Incomplete beta function ratios. +\newblock {\em Communications of the ACM}, 7(3):143--144, 1964. + +\bibitem{tGAU64b} +W.~Gautschi. +\newblock Certification of algorithm 222: Incomplete beta function ratios. +\newblock {\em Communications of the ACM}, 7(3):244, 1964. + +\bibitem{tGEN04a} +A.~Genz. +\newblock Numerical computation of rectangular bivariate and trivariate normal + and $t$ probabilities. +\newblock {\em Statistics and Computing}, 14:151--160, 2004. +\newblock See \url{http://www.math.wsu.edu/faculty/genz/homepage}. + +\bibitem{tGLA89a} +J.~Glaz. +\newblock Approximations and bounds for the distribution of the scan statistic. +\newblock {\em Journal of the American Statistical Association}, 84:560--566, + 1989. + +\bibitem{tHIL70a} +G.~W. Hill. +\newblock Algorithm 395: Student's $t$-distribution. +\newblock {\em Communications of the ACM}, 13:617--619, 1970. + +\bibitem{tJOH95a} +N.~L. Johnson, S.~Kotz, and N.~Balakrishnan. +\newblock {\em Continuous Univariate Distributions}, volume~1. +\newblock Wiley, 2nd edition, 1994. + +\bibitem{tJOH95b} +N.~L. Johnson, S.~Kotz, and N.~Balakrishnan. +\newblock {\em Continuous Univariate Distributions}, volume~2. +\newblock Wiley, 2nd edition, 1995. + +\bibitem{tKEN80a} +W.~J. {Kennedy Jr.} and J.~E. Gentle. +\newblock {\em Statistical Computing}. +\newblock Dekker, New York, NY, 1980. + +\bibitem{tKNO74a} +M.~Knott. +\newblock The distribution of the {C}ram\'er-von {M}ises statistic for small + sample sizes. +\newblock {\em Journal of the Royal Statistical Society B}, 36:430--438, 1974. + +\bibitem{rKNU98a} +D.~E. Knuth. +\newblock {\em The Art of Computer Programming, Volume 2: Seminumerical + Algorithms}. +\newblock Addison-Wesley, Reading, MA, third edition, 1998. + +\bibitem{mLAN73a} +S.~Lang. +\newblock {\em Elliptic functions}. +\newblock Addison-Wesley, Reading, Mass., 1973. + +\bibitem{sLAW00a} +A.~M. Law and W.~D. Kelton. +\newblock {\em Simulation Modeling and Analysis}. +\newblock McGraw-Hill, New York, NY, third edition, 2000. + +\bibitem{tLEW61a} +P.~A.~W. Lewis. +\newblock Distribution of the {A}nderson-{D}arling statistic. +\newblock {\em Annals of Mathematical Statistics}, 32:1118--1124, 1961. + +\bibitem{tMAR78a} +K.~V. Mardia and P.~J. Zemroch. +\newblock {\em Tables of the {F} and Related Distributions with Algorithms}. +\newblock Academic Press, London, 1978. + +\bibitem{rMAR85a} +G.~Marsaglia. +\newblock A current view of random number generators. +\newblock In {\em Computer Science and Statistics, Sixteenth Symposium on the + Interface}, pages 3--10, North-Holland, Amsterdam, 1985. Elsevier Science + Publishers. + +\bibitem{tMAR04a} +G.~Marsaglia and J.~Marsaglia. +\newblock Evaluating the {A}nderson-{D}arling distribution. +\newblock {\em Journal of Statistical Software}, 9(2):1--5, 2004. +\newblock See \url{http://www.jstatsoft.org/v09/i02/}. + +\bibitem{tMAR03a} +G.~Marsaglia, W.~W. Tsang, and J.~Wang. +\newblock Evaluating {K}olmogorov's distribution. +\newblock {\em Journal of Statistical Software}, 8(18):1--4, 2003. +\newblock See \url{http://www.jstatsoft.org/v08/i18/}. + +\bibitem{rMAR94b} +G.~Marsaglia, A.~Zaman, and J.~C.~W. Marsaglia. +\newblock Rapid evaluation of the inverse normal distribution function. +\newblock {\em Statistics and Probability Letters}, 19:259--266, 1994. + +\bibitem{tPEI68a} +D.~B. Peizer and J.~W. Pratt. +\newblock A normal approximation for binomial, {F}, beta, and other common + related tail probabilities. +\newblock {\em Journal of the American Statistical Association}, 63:1416--1456, + 1968. + +\bibitem{tPEL76a} +W.~Pelz and I.~J. Good. +\newblock Approximating the lower tail-areas of the {K}olmogorov-{S}mirnov + one-sample statistic. +\newblock {\em Journal of the Royal Statistical Society, Series B}, + 38(2):152--156, 1976. + +\bibitem{tPOM74a} +J.~Pomeranz. +\newblock Exact cumulative distribution of the {K}olmogorov-{S}mirnov statistic + for small samples (algorithm 487). +\newblock {\em Communications of the ACM}, 17(12):703--704, 1974. + +\bibitem{tREA88a} +T.~R.~C. Read and N.~A.~C. Cressie. +\newblock {\em Goodness-of-Fit Statistics for Discrete Multivariate Data}. +\newblock Springer Series in Statistics. Springer-Verlag, New York, NY, 1988. + +\bibitem{tSCH78a} +J.~L. Schonfelder. +\newblock Chebyshev expansions for the error and related functions. +\newblock {\em Mathematics of Computation}, 32:1232--1240, 1978. + +\bibitem{tSIN88a} +C.~D. Sinclair and B.~D. Spurr. +\newblock Approximations to the distribution function of the + {A}nderson-{D}arling test statistic. +\newblock {\em Journal of the American Statistical Association}, + 83(404):1190--1191, 1988. + +\bibitem{tSTE70a} +M.~A. Stephens. +\newblock Use of the {K}olmogorov-{S}mirnov, {C}ram{\'e}r-{V}on {M}ises and + related statistics without extensive tables. +\newblock {\em Journal of the Royal Statistical Society, Series B}, + 33(1):115--122, 1970. + +\bibitem{tSTE86b} +M.~S. Stephens. +\newblock Tests based on {EDF} statistics. +\newblock In R.~B. D'Agostino and M.~S. Stephens, editors, {\em Goodness-of-Fit + Techniques}. Marcel Dekker, New York and Basel, 1986. + +\bibitem{tSTE86a} +M.~S. Stephens. +\newblock Tests for the uniform distribution. +\newblock In R.~B. D'Agostino and M.~S. Stephens, editors, {\em Goodness-of-Fit + Techniques}, pages 331--366. Marcel Dekker, New York and Basel, 1986. + +\bibitem{tWAL87a} +S.~R. Wallenstein and N.~Neff. +\newblock An approximation for the distribution of the scan statistic. +\newblock {\em Statistics in Medicine}, 6:197--207, 1987. + +\bibitem{tWAT76a} +G.~S. Watson. +\newblock Optimal invariant tests for uniformity. +\newblock In {\em Studies in Probability and Statistics}, pages 121--127. North + Holland, Amsterdam, 1976. + +\end{thebibliography} diff --git a/TESTU01/TestU01-1.2.3/probdist/guideprobdist.pdf b/TESTU01/TestU01-1.2.3/probdist/guideprobdist.pdf new file mode 100644 index 0000000..0c94ff9 Binary files /dev/null and b/TESTU01/TestU01-1.2.3/probdist/guideprobdist.pdf differ diff --git a/TESTU01/TestU01-1.2.3/probdist/guideprobdist.tex b/TESTU01/TestU01-1.2.3/probdist/guideprobdist.tex new file mode 100644 index 0000000..2a5406d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/guideprobdist.tex @@ -0,0 +1,54 @@ +\documentclass[12pt]{article} +\usepackage{url} +\usepackage{amssymb} + +\input ../doc/myarticle.sty + +\newcommand\cH{\mathcal{H}} +\newcommand\guisec[1]{\vspace{20pt} +\noindent\hrulefill\hspace{10pt}{\bf #1}\hspace{10pt}\hrulefill +\vspace{10pt}\nopagebreak} + +\def\pierre#1 {\fbox {\footnote {\ }}\ \footnotetext { From Pierre: #1}} +\def\richard#1 {\fbox {\footnote {\ }}\ \footnotetext { From Richard: #1}} +\def\hpierre#1 {} +\def\hrichard#1 {} + +\newif\ifdetailed\detailedfalse +\newenvironment{detailed}{\protect\ifdetailed }{\protect\fi } +% \detailedtrue % For a more detailed user's guide. + +% \includeonly {wdist} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{document} + +\include {titre} + +\pagenumbering{roman} +\include {copyright} +\addcontentsline{toc}{subsection}{Copyright} +\tableofcontents +\clearpage + +\pagenumbering{arabic} + +\include {fmass} +\include {fdist} +\include {wdist} +\include {fbar} +\include {finv} +\include {gofs} +\include {gofw} +\include {statcoll} +% \appendix + +\bibliographystyle {plain} +\bibliography{stat,random,simul,math} +\end{document} + + + + + + diff --git a/TESTU01/TestU01-1.2.3/probdist/statcoll.c b/TESTU01/TestU01-1.2.3/probdist/statcoll.c new file mode 100644 index 0000000..3f8f079 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/statcoll.c @@ -0,0 +1,219 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: statcoll.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "statcoll.h" + +#include "util.h" +#include "tables.h" + +#include +#include + + +#define MAXLEN 127 /* Max number of chars in Desc field of a + collector */ + + + +/*=========================================================================*/ + +void statcoll_SetDesc (statcoll_Collector * S, const char name[]) +{ + size_t len; + util_Assert (S != NULL, + "statcoll_SetDesc: statcoll_Collector is a NULL pointer"); + if (S->Desc != NULL) + S->Desc = (char *) util_Free (S->Desc); + if (name == NULL) + return; + len = strlen (name); + if (len > MAXLEN) { + len = MAXLEN; + util_Warning (1, "statcoll_Collector->Desc truncated to 127 chars"); + } + S->Desc = (char *) util_Calloc (len + 1, sizeof (char)); + strncpy (S->Desc, name, (size_t) len); + S->Desc[len] = '\0'; +} + + +/*=========================================================================*/ + +statcoll_Collector *statcoll_Create (long N, const char name[]) +{ + statcoll_Collector *S; + + util_Warning (N == 0, + "statcoll_Create: statcoll_Collector created with N = 0"); + S = (statcoll_Collector *) util_Malloc (sizeof (statcoll_Collector)); + /* We create an array V with N+1 elements, but will keep the N + observations in elements [1..N]. */ + S->V = (double *) util_Calloc ((size_t) N + 1, sizeof (double)); + S->Dim = N; + S->NObs = 0; + S->Desc = NULL; + statcoll_SetDesc (S, name); + return S; +} + + +/*=========================================================================*/ + +statcoll_Collector *statcoll_Delete (statcoll_Collector * S) +{ + if (S == NULL) { + util_Warning (S == NULL, + "statcoll_Delete: statcoll_Collector is a NULL pointer"); + return NULL; + } + S->V = (double *) util_Free (S->V); + S->Desc = (char *) util_Free (S->Desc); + util_Free (S); + return NULL; +} + + +/*=========================================================================*/ + +void statcoll_Init (statcoll_Collector * S, long N) +{ + util_Assert (S != NULL, + "statcoll_Init: statcoll_Collector is a NULL pointer"); + if (N > S->Dim) { + S->V = (double *) util_Realloc (S->V, (N + 1) * sizeof (double)); + S->Dim = N; + } + S->NObs = 0; +} + + +/*=========================================================================*/ + +void statcoll_AddObs (statcoll_Collector * S, double x) +{ + util_Assert (S != NULL, + "statcoll_AddObs: statcoll_Collector is a NULL pointer"); + if (S->NObs >= S->Dim) { + if (S->Dim > 0) + S->Dim *= 2; + else + S->Dim = 8; + S->V = (double *) util_Realloc (S->V, (S->Dim + 1) * sizeof (double)); + } + ++S->NObs; + S->V[S->NObs] = x; +} + + +/*=========================================================================*/ + +void statcoll_Write (statcoll_Collector * S, int k, int p1, int p2, int p3) +{ + tables_WriteTabD (S->V, 1, S->NObs, k, p1, p2, p3, S->Desc); +} + + +/*=========================================================================*/ + +double statcoll_Average (statcoll_Collector * S) +{ + long i; + double Sum; + util_Assert (S != NULL, + "statcoll_Average: statcoll_Collector is a NULL pointer"); + Sum = 0.0; + if (S->NObs == 0) { + util_Warning (1, "statcoll_Average: NObs = 0"); + return 1.0; + } + for (i = 1; i <= S->NObs; i++) + Sum += S->V[i]; + return Sum / S->NObs; +} + + +/*=========================================================================*/ + +double statcoll_Variance (statcoll_Collector * S) +{ + long i; + double Av, Sum2, Diff; + util_Assert (S != NULL, + "statcoll_Variance: statcoll_Collector is a NULL pointer"); + util_Assert (S->NObs > 1, "statcoll_Variance: NObs <= 1"); + Av = statcoll_Average (S); + Sum2 = 0.0; + for (i = 1; i <= S->NObs; i++) { + Diff = S->V[i] - Av; + Sum2 += Diff * Diff; + } + return Sum2 / (S->NObs - 1); +} + + +/*=========================================================================*/ + +double statcoll_AutoCovar (statcoll_Collector * S, int k) +{ + long i; + double Av2, Sum2; + util_Assert (S != NULL, + "statcoll_AutoCovar: statcoll_Collector is a NULL pointer"); + util_Assert (k < S->NObs, "statcoll_AutoCovar: k >= NObs"); + Av2 = statcoll_Average (S); + Av2 = Av2 * Av2; + Sum2 = 0.0; + for (i = 1; i <= S->NObs - k; i++) { + Sum2 += S->V[i] * S->V[i + k] - Av2; + } + return Sum2 / (S->NObs - k); +} + + +/*=========================================================================*/ + +double statcoll_Covar (statcoll_Collector * S1, statcoll_Collector * S2) +{ + long i; + double Av1Av2, Sum; + util_Assert (S1 != NULL, + "statcoll_Covar: statcoll_Collector S1 is a NULL pointer"); + util_Assert (S2 != NULL, + "statcoll_Covar: statcoll_Collector S2 is a NULL pointer"); + util_Assert (S1->NObs == S2->NObs, + "statcoll_Covar: S1->NObs != S2->NObs"); + util_Assert (S1->NObs > 1, "statcoll_Covar: NObs <= 1"); + Av1Av2 = statcoll_Average (S1) * statcoll_Average (S2); + Sum = 0.0; + for (i = 1; i <= S1->NObs; i++) { + Sum += S1->V[i] * S2->V[i] - Av1Av2; + } + return Sum / (S1->NObs - 1); +} diff --git a/TESTU01/TestU01-1.2.3/probdist/statcoll.tex b/TESTU01/TestU01-1.2.3/probdist/statcoll.tex new file mode 100644 index 0000000..9589cea --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/statcoll.tex @@ -0,0 +1,171 @@ +\defmodule {statcoll} + +This module contains some basic tools for collecting statistical +observations and computing simple statistics on them. + +\code +\hide +/* statcoll.h for ANSI C */ + +#ifndef STATCOLL_H +#define STATCOLL_H +\endhide +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Collector type} + +\code + +typedef struct { + double *V; + long Dim; + long NObs; + char *Desc; +} statcoll_Collector; +\endcode + \tab A collector of real-valued statistical observations. + The array {\tt V} has dimensions {\tt Dim + 1} (i.e., elements + {\tt V[0]} to {\tt V[Dim]}) and contains {\tt NObs} observations + in {\tt V[1]} to {\tt V[NbObs]}. + \hpierre { + Je crois que le standard en C est plut\^ot de r\'eserver + {\tt V[0..Dim-1]} et d'y mettre les observations, n'est-ce pas? + Il faudra probablement s'y conformer \'eventuellement... + Il doit y avoir une structure semblable dans {\tt gsl}; \`a v\'erifier.} + The element {\tt V[0]} can be used for special purposes. + The character string {\tt Desc} (max.\ 127 characters) contains + the name of the collector (used for printing reports, etc.). + A collector is created by calling + {\tt statcoll\_Create} and destroyed by calling {\tt statcoll\_Delete}. + Observations are added one at a time by calling {\tt statcoll\_AddObs}. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec {Prototypes} + +\code + +statcoll_Collector * statcoll_Create (long N, const char Desc[]); +\endcode + \tab + Creates and returns a collector that can take up to {\tt N} + observations. Initializes its fields {\tt Dim} to {\tt N}, + {\tt NObs} to 0, {\tt Desc} to {\tt Desc}, and allocates + {\tt V[0..Dim]}. + (If {\tt Desc} is too long, the description will be truncated). + This function must be called for each new collector + {\tt statcoll\_Collector}. One may call {\tt statcoll\_Init} later + to reinitialize a collector or to change its dimension. + \endtab +\code + + +statcoll_Collector * statcoll_Delete (statcoll_Collector *S); +\endcode + \tab + Releases the space allocated for arrays {\tt V} and {\tt Desc} + in this collector, then deletes the collector, and returns the + {\tt NULL} pointer. +\endtab +\code + + +void statcoll_Init (statcoll_Collector *S, long N); +\endcode + \tab + Initializes the collector {\tt S} by setting its observations counter + {\tt NObs} to 0. Then ensures that its dimension {\tt Dim} + is at least {\tt N} (enlarges the array {\tt V} if needed). +\endtab +\code + + +void statcoll_SetDesc (statcoll_Collector *S, const char Desc[]); +\endcode + \tab + Set the {\tt Desc} field of collector {\tt S} to {\tt Desc}. +\endtab +\code + + +void statcoll_AddObs (statcoll_Collector *S, double x); +\endcode +\tab Adds an observation of value {\tt x} to the collector {\tt S}. +% One must have called {\tt statcoll\_Create} beforehand. + If the array {\tt V} is already full ({\tt NObs = Dim}), + it will be automatically enlarged ({\tt Dim} will be doubled) + to accomodate the new observations. +\endtab +\code + + +void statcoll_Write (statcoll_Collector *S, int k, int p1, int p2, int p3); +\endcode + \tab + Writes the observations currently in collector {\tt S}, + {\tt k} values per line, with at least {\tt p1} positions per + value, {\tt p2} digits after the decimal point, + and {\tt p3} significant digits. + \endtab +\code + + +double statcoll_Average (statcoll_Collector *S); +\endcode + \tab + Returns the average of the observations currently in collector {\tt S}. + \endtab +\code + + +double statcoll_Variance (statcoll_Collector *S); +\endcode + \tab + Returns the sample variance of the observations currently + in collector {\tt S}, i.e., + \[ + S_n^2 = \frac{1}{N-1} \sum_{i=1}^N (X_i - \bar X_N)^2, + \] + where $X_1,\dots,X_N$ are the $N$ observations and $\bar X_N$ their + average. + \endtab +\code + + +double statcoll_AutoCovar (statcoll_Collector *S, int k); +\endcode + \tab + Returns the sample autocovariance of lag {\tt k} for the + observations currently in collector {\tt S}, i.e., + \[ + \hat\sigma_k = \frac{1}{N-k} \sum_{i=1}^{N-k} (X_i X_{i+k} - \bar X_N^2), + \] + where $X_1,\dots,X_N$ are the $N$ observations and $\bar X_N$ their + average. + \endtab +\code + + +double statcoll_Covar (statcoll_Collector *S1, statcoll_Collector *S2); +\endcode + \tab + Returns the sample covariance between the observations + in collector {\tt S1} and those in collector {\tt S2}, i.e., + \[ + \frac{1}{N-1} \sum_{i=1}^{N} (X_i Y_i - \bar X_N \bar Y_N), + \] + where $X_1,\dots,X_N$ are the $N$ observations in {\tt S1}, + $Y_1,\dots,Y_N$ are the $N$ observations in {\tt S2}, + and $\bar X_N$ and $\bar Y_N$ are their respective averages. + The two collectors must contain the same number of observations. + \endtab +\code +\hide +#endif +\endhide +\endcode + diff --git a/TESTU01/TestU01-1.2.3/probdist/titre.tex b/TESTU01/TestU01-1.2.3/probdist/titre.tex new file mode 100644 index 0000000..065d57c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/titre.tex @@ -0,0 +1,33 @@ +\begin{titlepage} + +\null +\begin {flushright} \it Last update: \today \end {flushright} + +\vfill +\begin{center} + {\Large\bf ProbDist} \\ \ \\ + {\large\bf A Software Library of Probability Distributions\\[6pt] + and Goodness-of-Fit Statistics in {ANSI C}}\\ +\vfill + {\bf Pierre L'Ecuyer and Richard Simard} \\ \ \\ +% has participated to the development of ProbDist.}} +\medskip +D\'epartement d'Informatique et de Recherche Op\'erationnelle \\ +Universit\'e de Montr\'eal \\ +\end{center} +\vfill + +This document describes a set of basic software utilities, +implemented in ANSI C, developed in our simulation laboratory. +It is part of a larger set of tools used for stochastic simulation +and for testing random number generators. +It provides procedures to compute densities, mass functions, +distribution functions and their inverses, and reliability functions, +for various continuous and discrete probability laws. +It also offers a mechanism for collecting observational data and +computing elementary statistics on it, and tools for performing and +reporting different types of univariate goodness-of-fit tests. + +\vfill +\end{titlepage} + diff --git a/TESTU01/TestU01-1.2.3/probdist/wdist.c b/TESTU01/TestU01-1.2.3/probdist/wdist.c new file mode 100644 index 0000000..f933583 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/wdist.c @@ -0,0 +1,55 @@ +/*************************************************************************\ + * + * Package: ProbDist + * File: wdist.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "wdist.h" +#include "fdist.h" + + + +/*=========================================================================*/ + +double wdist_Normal (double Junk[], double x) +{ + return fdist_Normal2 (x); +} + + +double wdist_ChiSquare (double W[], double x) +{ + long N = (long) W[0]; + return fdist_ChiSquare2 (N, 12, x); +} + + +double wdist_Unif (double Junk[], double x) +{ + return fdist_Unif (x); +} + diff --git a/TESTU01/TestU01-1.2.3/probdist/wdist.tex b/TESTU01/TestU01-1.2.3/probdist/wdist.tex new file mode 100644 index 0000000..7371fb4 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/probdist/wdist.tex @@ -0,0 +1,97 @@ +\defmodule {wdist} + +This module provides wrappers functions that are needed +because the parameter of type {\tt wdist\_CFUNC} in {\tt gofw\_ActiveTests1} +and in {\tt gofs\_ContUnifTransform}, for example, is not type-compatible +with the distribution functions provided in {\tt fdist}, since the different +distributions take a different number of arguments. +\hpierre {This looks like a faulty design. + Could we make it compatible? Otherwise, perhaps we should put the + wrappers in {\tt fdist}. In C++, we could do that and give them the + same names as the functions already in {\tt fdist} (using overloading).} + + +%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip\hrule +\code\hide +/* wdist.h for ANSI C */ +#ifndef WDIST_H +#define WDIST_H +\endhide +#include "fmass.h" +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Types} + +\code + +typedef double (*wdist_CFUNC) (double [], double); +\endcode + \tab A generic {\em continuous\/} distribution function with an + arbitrary number of parameters given in the first argument. + The second argument is the point $x$ at which the function is evaluated. + \ifdetailed %%%% + This type is used, among other things, to compute goodness-of-fit + test statistics for arbitrary distributions (see module {\tt gofs} and + {\tt gofw}). + \fi %%% detailed + \endtab +\code + + +typedef double (*wdist_DFUNC) (fmass_INFO, long); +\endcode + \tab A generic {\em discrete\/} distribution function over the set of + integers. + The first argument contains the parameters of the function and + possibly precomputed tables of values of the function. + The second argument is the point $x$ at which the function is evaluated. +\hrichard {Devrait probablement \^etre \'elimin\'e. Utilis\'e 1 fois dans + smultin, mais pourrait \^etre contourn\'e.} +\hpierre {Je pr\'ef\`ere conserver. } + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Wrap-up functions} + +\code + +double wdist_Normal (double Par[], double x); +\endcode +\tab + Wrapper function for the {standard normal} distribution, needed + for compatibility with the type {\tt wdist\_CFUNC} used as a parameter + in certain functions such as {\tt gofw\_ActiveTests1}, etc. + Returns $\Phi(x)$, where $\Phi$ is the standard normal distribution + function, with mean 0 and variance 1. + {\tt Par} is unused. +\endtab +\code + + +double wdist_ChiSquare (double Par[], double x); +\endcode +\tab + Wrapper function for the {chi-square} distribution, similar to + {\tt wdist\_Normal}. + Returns $P[X \le x]$, where $X$ has the chi-square distribution + with $k$ degrees of freedom. The value of $k$ must be in {\tt Par[0]}. +\endtab +\code + + +double wdist_Unif (double Par[], double x); +\endcode +\tab + Wrapper function for the {uniform} distribution. + Returns $x$. {\tt Par} is unused. +\endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/Makefile.am b/TESTU01/TestU01-1.2.3/testu01/Makefile.am new file mode 100644 index 0000000..46173d8 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/Makefile.am @@ -0,0 +1,12 @@ +include $(top_srcdir)/include/Makefile.def + +include_HEADERS = TestU01.h + +lib_LTLIBRARIES = libtestu01.la +libtestu01_la_SOURCES = $(TESTU01SOURCES) +libtestu01_la_LIBADD = $(top_builddir)/probdist/libprobdist.la $(top_builddir)/mylib/libmylib.la +libtestu01_la_LDFLAGS = -no-undefined -version-info 0:1:0 + +EXTRA_DIST = guidetestu01.tex intro.tex title.tex scatfig.tex bintro.tex copyright.tex fintro.tex sintro.tex uintro.tex guidetestu01.bbl + +doc_DATA = guideshorttestu01.pdf guidelongtestu01.pdf diff --git a/TESTU01/TestU01-1.2.3/testu01/Makefile.in b/TESTU01/TestU01-1.2.3/testu01/Makefile.in new file mode 100644 index 0000000..2fa2b3e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/Makefile.in @@ -0,0 +1,624 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(top_srcdir)/include/Makefile.def +subdir = testu01 +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h \ + $(top_builddir)/include/gdefconf.h +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" \ + "$(DESTDIR)$(includedir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +libtestu01_la_DEPENDENCIES = $(top_builddir)/probdist/libprobdist.la \ + $(top_builddir)/mylib/libmylib.la +am__objects_1 = unif01.lo ulcg.lo umrg.lo ucarry.lo utaus.lo ugfsr.lo \ + uinv.lo uquad.lo ucubic.lo ulec.lo utezuka.lo umarsa.lo \ + uweyl.lo uknuth.lo uwu.lo unumrec.lo uvaria.lo usoft.lo \ + ugranger.lo ucrypto.lo ufile.lo udeng.lo utouzin.lo \ + uautomata.lo uxorshift.lo ubrent.lo rijndael-alg-fst.lo \ + tu01_sha1.lo scatter.lo swrite.lo sres.lo smultin.lo sknuth.lo \ + smarsa.lo sstring.lo svaria.lo snpair.lo swalk.lo sentrop.lo \ + sspectral.lo scomp.lo sspacings.lo vectorsF2.lo bbattery.lo \ + ffam.lo fcong.lo ffsr.lo ftab.lo fres.lo fcho.lo fmultin.lo \ + fmarsa.lo fknuth.lo fwalk.lo fstring.lo fspectral.lo fvaria.lo \ + fnpair.lo +am_libtestu01_la_OBJECTS = $(am__objects_1) +libtestu01_la_OBJECTS = $(am_libtestu01_la_OBJECTS) +libtestu01_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libtestu01_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I. -I$(top_builddir)/include@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libtestu01_la_SOURCES) +DIST_SOURCES = $(libtestu01_la_SOURCES) +docDATA_INSTALL = $(INSTALL_DATA) +DATA = $(doc_DATA) +includeHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(include_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = ${prefix}/share/TestU01/doc +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_mathematica = @have_mathematica@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +MYLIB = ${top_srcdir}/mylib +PROBDIST = ${top_srcdir}/probdist +TESTU01 = ${top_srcdir}/testu01 +MYLIBHEADERS = gdef.h addstr.h bitset.h chrono.h mystr.h num.h num2.h tables.h util.h +MYLIBSOURCES = gdef.c addstr.c bitset.c chrono.c mystr.c num.c num2.c tables.c util.c +MYLIBTEX = $(MYLIB)/gdef.tex $(MYLIB)/addstr.tex $(MYLIB)/bitset.tex $(MYLIB)/chrono.tex $(MYLIB)/mystr.tex $(MYLIB)/num.tex $(MYLIB)/num2.tex $(MYLIB)/tables.tex $(MYLIB)/util.tex +PROBDISTHEADERS = fmass.h fdist.h fbar.h finv.h gofs.h gofw.h statcoll.h wdist.h +PROBDISTSOURCES = fmass.c fdist.c fbar.c finv.c gofs.c gofw.c statcoll.c wdist.c +PROBDISTTEX = $(PROBDIST)/fmass.tex $(PROBDIST)/fdist.tex $(PROBDIST)/fbar.tex $(PROBDIST)/finv.tex $(PROBDIST)/gofs.tex $(PROBDIST)/gofw.tex $(PROBDIST)/statcoll.tex $(PROBDIST)/wdist.tex +TESTU01HEADERS = unif01.h ulcg.h umrg.h ucarry.h utaus.h ugfsr.h uinv.h uquad.h ucubic.h ulec.h utezuka.h umarsa.h uweyl.h uknuth.h uwu.h unumrec.h uvaria.h usoft.h ugranger.h ucrypto.h ufile.h udeng.h utouzin.h uautomata.h uxorshift.h ubrent.h rijndael-alg-fst.h tu01_sha1.h scatter.h swrite.h sres.h smultin.h sknuth.h smarsa.h sstring.h svaria.h snpair.h swalk.h sentrop.h sspectral.h scomp.h sspacings.h vectorsF2.h bbattery.h ffam.h fcong.h ffsr.h ftab.h fres.h fcho.h fmultin.h fmarsa.h fknuth.h fwalk.h fstring.h fspectral.h fvaria.h fnpair.h +TESTU01SOURCES = unif01.c ulcg.c umrg.c ucarry.c utaus.c ugfsr.c uinv.c uquad.c ucubic.c ulec.c utezuka.c umarsa.c uweyl.c uknuth.c uwu.c unumrec.c uvaria.c usoft.c ugranger.c ucrypto.c ufile.c udeng.c utouzin.c uautomata.c uxorshift.c ubrent.c rijndael-alg-fst.c tu01_sha1.c scatter.c swrite.c sres.c smultin.c sknuth.c smarsa.c sstring.c svaria.c snpair.c swalk.c sentrop.c sspectral.c scomp.c sspacings.c vectorsF2.c bbattery.c ffam.c fcong.c ffsr.c ftab.c fres.c fcho.c fmultin.c fmarsa.c fknuth.c fwalk.c fstring.c fspectral.c fvaria.c fnpair.c +TESTU01TEX = $(TESTU01)/unif01.tex $(TESTU01)/ulcg.tex \ + $(TESTU01)/umrg.tex $(TESTU01)/ucarry.tex $(TESTU01)/utaus.tex \ + $(TESTU01)/ugfsr.tex $(TESTU01)/uinv.tex $(TESTU01)/uquad.tex \ + $(TESTU01)/ucubic.tex $(TESTU01)/ulec.tex \ + $(TESTU01)/utezuka.tex $(TESTU01)/umarsa.tex \ + $(TESTU01)/uweyl.tex $(TESTU01)/uknuth.tex $(TESTU01)/uwu.tex \ + $(TESTU01)/unumrec.tex $(TESTU01)/uvaria.tex \ + $(TESTU01)/usoft.tex $(TESTU01)/ugranger.tex \ + $(TESTU01)/ucrypto.tex $(TESTU01)/ufile.tex \ + $(TESTU01)/udeng.tex $(TESTU01)/utouzin.tex \ + $(TESTU01)/uautomata.tex $(TESTU01)/uxorshift.tex \ + $(TESTU01)/ubrent.tex $(TESTU01)/rijndael-alg-fst.tex \ + $(TESTU01)/tu01_sha1.tex $(TESTU01)/scatter.tex \ + $(TESTU01)/swrite.tex $(TESTU01)/sres.tex \ + $(TESTU01)/smultin.tex $(TESTU01)/sknuth.tex \ + $(TESTU01)/smarsa.tex $(TESTU01)/sstring.tex \ + $(TESTU01)/svaria.tex $(TESTU01)/snpair.tex \ + $(TESTU01)/swalk.tex $(TESTU01)/sentrop.tex \ + $(TESTU01)/sspectral.tex $(TESTU01)/scomp.tex \ + $(TESTU01)/sspacings.tex $(TESTU01)/vectorsF2.tex \ + $(TESTU01)/bbattery.tex $(TESTU01)/ffam.tex \ + $(TESTU01)/fcong.tex $(TESTU01)/ffsr.tex $(TESTU01)/ftab.tex \ + $(TESTU01)/fres.tex $(TESTU01)/fcho.tex $(TESTU01)/fmultin.tex \ + $(TESTU01)/fmarsa.tex $(TESTU01)/fknuth.tex \ + $(TESTU01)/fwalk.tex $(TESTU01)/fstring.tex \ + $(TESTU01)/fspectral.tex $(TESTU01)/fvaria.tex \ + $(TESTU01)/fnpair.tex +include_HEADERS = TestU01.h +lib_LTLIBRARIES = libtestu01.la +libtestu01_la_SOURCES = $(TESTU01SOURCES) +libtestu01_la_LIBADD = $(top_builddir)/probdist/libprobdist.la $(top_builddir)/mylib/libmylib.la +libtestu01_la_LDFLAGS = -no-undefined -version-info 0:1:0 +EXTRA_DIST = guidetestu01.tex intro.tex title.tex scatfig.tex bintro.tex copyright.tex fintro.tex sintro.tex uintro.tex guidetestu01.bbl +doc_DATA = guideshorttestu01.pdf guidelongtestu01.pdf +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/include/Makefile.def $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu testu01/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu testu01/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libtestu01.la: $(libtestu01_la_OBJECTS) $(libtestu01_la_DEPENDENCIES) + $(libtestu01_la_LINK) -rpath $(libdir) $(libtestu01_la_OBJECTS) $(libtestu01_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bbattery.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fcho.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fcong.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ffam.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ffsr.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fknuth.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmarsa.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmultin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fnpair.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fres.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fspectral.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftab.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fvaria.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fwalk.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rijndael-alg-fst.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scatter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scomp.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sentrop.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sknuth.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smarsa.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smultin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snpair.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sres.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sspacings.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sspectral.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sstring.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/svaria.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/swalk.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/swrite.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tu01_sha1.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uautomata.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ubrent.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ucarry.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ucrypto.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ucubic.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/udeng.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ufile.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugfsr.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugranger.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uinv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uknuth.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ulcg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ulec.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/umarsa.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/umrg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unif01.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unumrec.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uquad.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/usoft.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utaus.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utezuka.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utouzin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uvaria.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uweyl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uwu.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uxorshift.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vectorsF2.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-docDATA: $(doc_DATA) + @$(NORMAL_INSTALL) + test -z "$(docdir)" || $(MKDIR_P) "$(DESTDIR)$(docdir)" + @list='$(doc_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(docDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(docdir)/$$f'"; \ + $(docDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(docdir)/$$f"; \ + done + +uninstall-docDATA: + @$(NORMAL_UNINSTALL) + @list='$(doc_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(docdir)/$$f'"; \ + rm -f "$(DESTDIR)$(docdir)/$$f"; \ + done +install-includeHEADERS: $(include_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)" + @list='$(include_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \ + $(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \ + done + +uninstall-includeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(include_HEADERS)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \ + rm -f "$(DESTDIR)$(includedir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" "$(DESTDIR)$(includedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-docDATA install-includeHEADERS + +install-dvi: install-dvi-am + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-docDATA uninstall-includeHEADERS \ + uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am \ + install-docDATA install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am \ + install-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-docDATA \ + uninstall-includeHEADERS uninstall-libLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/TESTU01/TestU01-1.2.3/testu01/TestU01.h b/TESTU01/TestU01-1.2.3/testu01/TestU01.h new file mode 100644 index 0000000..65cc4b7 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/TestU01.h @@ -0,0 +1,62 @@ +#ifndef TESTU01_H +#define TESTU01_H + +#include "bbattery.h" +#include "fcho.h" +#include "fcong.h" +#include "ffam.h" +#include "ffsr.h" +#include "fknuth.h" +#include "fmarsa.h" +#include "fmultin.h" +#include "fnpair.h" +#include "fres.h" +#include "fspectral.h" +#include "fstring.h" +#include "ftab.h" +#include "fvaria.h" +#include "fwalk.h" +#include "scatter.h" +#include "scomp.h" +#include "sentrop.h" +#include "sknuth.h" +#include "smarsa.h" +#include "smultin.h" +#include "snpair.h" +#include "sres.h" +#include "sspacings.h" +#include "sspectral.h" +#include "sstring.h" +#include "svaria.h" +#include "swalk.h" +#include "swrite.h" +#include "uautomata.h" +#include "ubrent.h" +#include "ucarry.h" +#include "ucrypto.h" +#include "rijndael-alg-fst.h" +#include "tu01_sha1.h" +#include "ucubic.h" +#include "udeng.h" +#include "ufile.h" +#include "ugfsr.h" +#include "ugranger.h" +#include "uinv.h" +#include "uknuth.h" +#include "ulcg.h" +#include "ulec.h" +#include "umarsa.h" +#include "umrg.h" +#include "unif01.h" +#include "unumrec.h" +#include "uquad.h" +#include "usoft.h" +#include "utaus.h" +#include "utezuka.h" +#include "utouzin.h" +#include "uvaria.h" +#include "uweyl.h" +#include "uwu.h" +#include "uxorshift.h" + +#endif diff --git a/TESTU01/TestU01-1.2.3/testu01/bbattery.c b/TESTU01/TestU01-1.2.3/testu01/bbattery.c new file mode 100644 index 0000000..ae65360 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/bbattery.c @@ -0,0 +1,4396 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: bbattery.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "config.h" +#include "bbattery.h" +#include "smultin.h" +#include "sknuth.h" +#include "smarsa.h" +#include "snpair.h" +#include "svaria.h" +#include "sstring.h" +#include "swalk.h" +#include "scomp.h" +#include "sspectral.h" +#include "swrite.h" +#include "sres.h" +#include "unif01.h" +#include "ufile.h" + +#include "gofs.h" +#include "gofw.h" +#include "fdist.h" +#include "fbar.h" +#include "num.h" +#include "chrono.h" + +#include +#include +#include +#include +#include + + + +#define LEN 120 +#define NAMELEN 30 +#define NDIM 200 /* Dimension of extern arrays */ +#define THOUSAND 1000 +#define MILLION (THOUSAND * THOUSAND) +#define BILLION (THOUSAND * MILLION) + +/* The number of tests in each battery */ +#define SMALLCRUSH_NUM 10 +#define CRUSH_NUM 96 +#define BIGCRUSH_NUM 106 +#define RABBIT_NUM 26 +#define ALPHABIT_NUM 9 + + +double bbattery_pVal[1 + NDIM] = { 0 }; +char *bbattery_TestNames[1 + NDIM] = { 0 }; +int bbattery_NTests; + +static char CharTemp[LEN + 1]; + +/* Gives the test number as enumerated in bbattery.tex. Some test applies + more than one test, so the array of p-values does not correspond with + the test number in the doc. */ +static int TestNumber[1 + NDIM] = { 0 }; + + + + +/*-------------------------------- Functions ------------------------------*/ + + +static void GetName (unif01_Gen * gen, char *genName) +{ + char *p; + int len1, len2; + + if (NULL == gen) { + genName[0] = '\0'; + return; + } + + /* Print only the generator name, without the parameters or seeds. */ + /* The parameters start after the first blank; name ends with ':' */ + genName[LEN] = '\0'; + len1 = strcspn (gen->name, ":"); + len1 = util_Min (LEN, len1); + strncpy (genName, gen->name, (size_t) len1); + genName[len1] = '\0'; + /* For Filters or Combined generators */ + p = strstr (&gen->name[1 + len1], "unif01"); + while (p != NULL) { + len1 += 2; + if (len1 >= LEN) + return; + strcat (genName, ", "); + len2 = strcspn (p, " \0"); + len2 = util_Min (LEN - len1, len2); + if (len2 <= 0) + return; + strncat (genName, p, (size_t) len2); + len1 = strlen (genName); + genName[len1] = '\0'; + p += len2; + p = strstr (p, "unif01"); + } +} + + +/*=========================================================================*/ + +static void WritepVal (double p) +/* + * Write a p-value with a nice format. + */ +{ + if (p < gofw_Suspectp) { + gofw_Writep0 (p); + + } else if (p > 1.0 - gofw_Suspectp) { + if (p >= 1.0 - gofw_Epsilonp1) { + printf (" 1 - eps1"); + } else if (p >= 1.0 - 1.0e-4) { + printf (" 1 - "); + num_WriteD (1.0 - p, 7, 2, 2); + /* printf (" 1 - %.2g ", 1.0 - p); */ + } else if (p >= 1.0 - 1.0e-2) + printf (" %.4f ", p); + else + printf (" %.2f", p); + } +} + + +/*=========================================================================*/ + +static void WriteReport ( + char *genName, /* Generator or file name */ + char *batName, /* Battery name */ + int N, /* Max. number of tests */ + double pVal[], /* p-values of the tests */ + chrono_Chrono * Timer, /* Timer */ + lebool Flag, /* = TRUE for a file, FALSE for a gen */ + lebool VersionFlag, /* = TRUE: write the version number */ + double nb /* Number of bits in the random file */ + ) +{ + int j, co; + + printf ("\n========= Summary results of "); + printf ("%s", batName); + printf (" =========\n\n"); + if (VersionFlag) + printf (" Version: %s\n", PACKAGE_STRING); + if (Flag) + printf (" File: "); + else + printf (" Generator: "); + printf ("%s", genName); + if (nb > 0) + printf ("\n Number of bits: %.0f", nb); + co = 0; + /* Some of the tests have not been done: their pVal[j] < 0. */ + for (j = 0; j < N; j++) { + if (pVal[j] >= 0.0) + co++; + } + printf ("\n Number of statistics: %1d\n", co); + printf (" Total CPU time: "); + chrono_Write (Timer, chrono_hms); + + co = 0; + for (j = 0; j < N; j++) { + if (pVal[j] < 0.0) /* That test was not done: pVal = -1 */ + continue; + if ((pVal[j] < gofw_Suspectp) || (pVal[j] > 1.0 - gofw_Suspectp)) { + co++; + break; + } + } + if (co == 0) { + printf ("\n\n All tests were passed\n\n\n\n"); + return; + } + + if (gofw_Suspectp >= 0.01) + printf ("\n The following tests gave p-values outside [%.4g, %.2f]", + gofw_Suspectp, 1.0 - gofw_Suspectp); + else if (gofw_Suspectp >= 0.0001) + printf ("\n The following tests gave p-values outside [%.4g, %.4f]", + gofw_Suspectp, 1.0 - gofw_Suspectp); + else if (gofw_Suspectp >= 0.000001) + printf ("\n The following tests gave p-values outside [%.4g, %.6f]", + gofw_Suspectp, 1.0 - gofw_Suspectp); + else + printf ("\n The following tests gave p-values outside [%.4g, %.14f]", + gofw_Suspectp, 1.0 - gofw_Suspectp); + printf (":\n (eps means a value < %6.1e)", gofw_Epsilonp); + printf (":\n (eps1 means a value < %6.1e)", gofw_Epsilonp1); + printf (":\n\n Test p-value\n"); + printf (" ----------------------------------------------\n"); + + co = 0; + for (j = 0; j < N; j++) { + if (pVal[j] < 0.0) /* That test was not done: pVal = -1 */ + continue; + if ((pVal[j] >= gofw_Suspectp) && (pVal[j] <= 1.0 - gofw_Suspectp)) + continue; /* That test was passed */ + printf (" %2d ", TestNumber[j]); + printf (" %-30s", bbattery_TestNames[j]); + WritepVal (pVal[j]); + printf ("\n"); + co++; + } + + printf (" ----------------------------------------------\n"); + if (co < N - 1) { + printf (" All other tests were passed\n"); + } + printf ("\n\n\n"); +} + + +/*=========================================================================*/ + +static void GetPVal_Walk (long N, swalk_Res * res, int *pj, char *mess, int j2) +/* + * Get the p-values in a swalk_RandomWalk1 test + */ +{ + int j = *pj; + const unsigned int len = 20; + + if (N == 1) { + bbattery_pVal[++j] = res->H[0]->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 H"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->M[0]->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 M"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->J[0]->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 J"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->R[0]->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 R"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->C[0]->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 C"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + } else { + bbattery_pVal[++j] = res->H[0]->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 H"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->M[0]->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 M"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->J[0]->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 J"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->R[0]->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 R"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + + bbattery_pVal[++j] = res->C[0]->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (CharTemp, "RandomWalk1 C"); + strncat (CharTemp, mess, (size_t) len); + strncpy (bbattery_TestNames[j], CharTemp, (size_t) LEN); + } + + *pj = j; +} + + +/*=========================================================================*/ + +static void GetPVal_CPairs (long N, snpair_Res * res, int *pj, char *mess, + int j2) +/* + * Get the p-values in a snpair_ClosePairs test + */ +{ + int j = *pj; + const unsigned int len = 20; + + if (N == 1) { + bbattery_pVal[++j] = res->pVal[snpair_NP]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs NP"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + + bbattery_pVal[++j] = res->pVal[snpair_mNP]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs mNP"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + + } else { + bbattery_pVal[++j] = res->pVal[snpair_NP]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs NP"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + + bbattery_pVal[++j] = res->pVal[snpair_mNP]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs mNP"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + + bbattery_pVal[++j] = res->pVal[snpair_mNP1]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs mNP1"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + + bbattery_pVal[++j] = res->pVal[snpair_mNP2]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs mNP2"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + + bbattery_pVal[++j] = res->pVal[snpair_NJumps]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs NJumps"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + + if (snpair_mNP2S_Flag) { + bbattery_pVal[++j] = res->pVal[snpair_mNP2S]; + TestNumber[j] = j2; + strcpy (CharTemp, "ClosePairs mNP2S"); + strncat (CharTemp, mess, (size_t) len); + strcpy (bbattery_TestNames[j], CharTemp); + } + } + + *pj = j; +} + + +/*=========================================================================*/ + +static void InitBat (void) +/* + * Initializes the battery of tests: sets all p-values to -1. + */ +{ + int j; + static int flag = 0; + for (j = 0; j < NDIM; j++) + bbattery_pVal[j] = -1.0; + if (0 == flag) { + flag++; + for (j = 0; j < NDIM; j++) + bbattery_TestNames[j] = util_Calloc (LEN + 1, sizeof (char)); + } +} + + +/*=========================================================================*/ + +static void SmallCrush (unif01_Gen * gen, char *filename, int Rep[]) +/* + * A small battery of statistical tests for Random Number Generators + * used in simulation. + * Rep[i] gives the number of times that test i will be done. The default + * values are Rep[i] = 1 for all i. + */ +{ + const int r = 0; + int i; + int j = -1; + int j2 = 0; + char genName[LEN + 1] = ""; + chrono_Chrono *Timer; + sres_Poisson *res1; + sres_Chi2 *res2; + sknuth_Res2 *res3; + swalk_Res *res4; + sknuth_Res1 *res5; + sstring_Res *res6; + lebool fileFlag; + + Timer = chrono_Create (); + InitBat (); + if (swrite_Basic) { + printf ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " Starting SmallCrush\n" + " Version: %s\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n", + PACKAGE_STRING); + } + + if (NULL == gen) { + gen = ufile_CreateReadText (filename, 10 * MILLION); + fileFlag = TRUE; + } else + fileFlag = FALSE; + + ++j2; + if (fileFlag) + ufile_InitReadText (); + res1 = sres_CreatePoisson (); + for (i = 0; i < Rep[j2]; ++i) { +#ifdef USE_LONGLONG + smarsa_BirthdaySpacings (gen, res1, 1, 5 * MILLION, r, 1073741824, + 2, 1); +#else + smarsa_BirthdaySpacings (gen, res1, 10, MILLION / 2, r, 67108864, 2, 1); +#endif + bbattery_pVal[++j] = res1->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings"); + } + sres_DeletePoisson (res1); + + if (fileFlag) + ufile_InitReadText (); + ++j2; + res3 = sknuth_CreateRes2 (); + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Collision (gen, res3, 1, 5 * MILLION, 0, 65536, 2); + bbattery_pVal[++j] = res3->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Collision"); + } + sknuth_DeleteRes2 (res3); + + if (fileFlag) + ufile_InitReadText (); + ++j2; + res2 = sres_CreateChi2 (); + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res2, 1, MILLION / 5, 22, 0.0, .00390625); + bbattery_pVal[++j] = res2->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap"); + } + + ++j2; + if (fileFlag) + ufile_InitReadText (); + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res2, 1, 2 * MILLION / 5, 24, 64, 64); + bbattery_pVal[++j] = res2->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker"); + } + + ++j2; + if (fileFlag) + ufile_InitReadText (); + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res2, 1, MILLION / 2, 26, 16); + bbattery_pVal[++j] = res2->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector"); + } + + if (fileFlag) + ufile_InitReadText (); + ++j2; + res5 = sknuth_CreateRes1 (); + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res5, 1, 2 * MILLION, 0, MILLION / 10, 6); + bbattery_pVal[++j] = res5->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft"); + bbattery_pVal[++j] = res5->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD"); + } + sknuth_DeleteRes1 (res5); + + ++j2; + if (fileFlag) + ufile_InitReadText (); + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res2, 1, MILLION / 5, 27, 256, 0.0, 0.125); + bbattery_pVal[++j] = res2->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib"); + } + + ++j2; + if (fileFlag) + ufile_InitReadText (); + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res2, 1, 20 * THOUSAND, 20, 10, 60, 60); + bbattery_pVal[++j] = res2->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank"); + } + sres_DeleteChi2 (res2); + + if (fileFlag) + ufile_InitReadText (); + ++j2; + res6 = sstring_CreateRes (); + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res6, 1, MILLION/2, 20, 10, 300, 0); + bbattery_pVal[++j] = res6->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep"); + } + sstring_DeleteRes (res6); + + if (fileFlag) + ufile_InitReadText (); + ++j2; + util_Assert (j2 <= SMALLCRUSH_NUM, "SmallCrush: j2 > SMALLCRUSH_NUM"); + res4 = swalk_CreateRes (); + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res4, 1, MILLION, r, 30, 150, 150); + GetPVal_Walk (1, res4, &j, "", j2); + } + swalk_DeleteRes (res4); + + bbattery_NTests = ++j; + if (fileFlag) { + WriteReport (filename, "SmallCrush", bbattery_NTests, bbattery_pVal, + Timer, TRUE, TRUE, 0.0); + ufile_DeleteReadBin (gen); + } else { + GetName (gen, genName); + WriteReport (genName, "SmallCrush", bbattery_NTests, bbattery_pVal, + Timer, FALSE, TRUE, 0.0); + } + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void bbattery_SmallCrush (unif01_Gen * gen) +{ + int i; + int Rep[1 + NDIM] = {0}; + for (i = 1; i <= SMALLCRUSH_NUM; ++i) + Rep[i] = 1; + SmallCrush (gen, NULL, Rep); +} + + +/*=========================================================================*/ + +void bbattery_SmallCrushFile (char *filename) +{ + int i; + int Rep[1 + NDIM] = {0}; + for (i = 1; i <= SMALLCRUSH_NUM; ++i) + Rep[i] = 1; + SmallCrush (NULL, filename, Rep); +} + + +/*=========================================================================*/ + +void bbattery_RepeatSmallCrush (unif01_Gen * gen, int Rep[]) +{ + SmallCrush (gen, NULL, Rep); +} + + +/*=========================================================================*/ + +static void Crush (unif01_Gen * gen, int Rep[]) +/* + * A battery of stringent statistical tests for Random Number Generators + * used in simulation. + * Rep[i] gives the number of times that test i will be done. The default + * values are Rep[i] = 1 for all i. + */ +{ + const int s = 30; + const int r = 0; + int i; + chrono_Chrono *Timer; + char genName[LEN + 1] = ""; + int j = -1; + int j2 = 0; + + Timer = chrono_Create (); + InitBat (); + if (swrite_Basic) { + printf ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " Starting Crush\n" + " Version: %s\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n", + PACKAGE_STRING); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_SerialOver (gen, res, 1, 500 * MILLION, 0, 4096, 2); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SerialOver, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_SerialOver (gen, res, 1, 300 * MILLION, 0, 64, 4); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SerialOver, t = 4"); + } + sres_DeleteBasic (res); + } + { + smarsa_Res *res; + res = smarsa_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 0, 1024 * 1024, 2); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 10, 1024 * 1024, 2); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 0, 1024, 4); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 20, 1024, 4); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 0, 32, 8); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 25, 32, 8); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 0, 4, 20); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 20"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, res, 10, 10 * MILLION, 28, 4, 20); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 20"); + } + smarsa_DeleteRes (res); + } + { + sres_Poisson *res; + res = sres_CreatePoisson (); + +#ifdef USE_LONGLONG + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + long d; +#if LONG_MAX <= 2147483647L + d = 1073741824L; + smarsa_BirthdaySpacings (gen, res, 10, 10 * MILLION, 0, d, 2, 1); +#else + d = 2*1073741824L; + smarsa_BirthdaySpacings (gen, res, 5, 20 * MILLION, 0, d, 2, 1); +#endif + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 5, 20 * MILLION, 0, 2097152, 3, + 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 3"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 5, 20 * MILLION, 0, 65536, 4, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 3, 20 * MILLION, 0, 512, 7, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 7"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 3, 20 * MILLION, 7, 512, 7, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 7"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 3, 20 * MILLION, 14, 256, 8, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 3, 20 * MILLION, 22, 256, 8, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 8"); + } + +#else + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 200, 4 * MILLION / 10, 0, + 67108864, 2, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 100, 4 * MILLION / 10, 0, 131072, + 3, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 3"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 200, 4 * MILLION / 10, 0, + 1024 * 8, 4, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 100, 4 * MILLION / 10, 0, 16, 13, + 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 100, 4 * MILLION / 10, 10, 16, + 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 100, 4 * MILLION / 10, 20, 16, + 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 100, 4 * MILLION / 10, 26, 16, + 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } +#endif + + sres_DeletePoisson (res); + } + { + lebool flag = snpair_mNP2S_Flag; + snpair_Res *res; + res = snpair_CreateRes (); + + snpair_mNP2S_Flag = FALSE; + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairs (gen, res, 10, 2 * MILLION, 0, 2, 0, 30); + GetPVal_CPairs (10, res, &j, ", t = 2", j2); + } + + snpair_mNP2S_Flag = TRUE; + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairs (gen, res, 10, 2 * MILLION, 0, 3, 0, 30); + GetPVal_CPairs (10, res, &j, ", t = 3", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairs (gen, res, 5, 2 * MILLION, 0, 7, 0, 30); + GetPVal_CPairs (10, res, &j, ", t = 7", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairsBitMatch (gen, res, 4, 4 * MILLION, 0, 2); + bbattery_pVal[++j] = res->pVal[snpair_BM]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "ClosePairsBitMatch, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairsBitMatch (gen, res, 2, 4 * MILLION, 0, 4); + bbattery_pVal[++j] = res->pVal[snpair_BM]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "ClosePairsBitMatch, t = 4"); + } + snpair_DeleteRes (res); + snpair_mNP2S_Flag = flag; + } + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 40 * MILLION, 0, 16, 16); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, d = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 40 * MILLION, 26, 16, 16); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, d = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 10 * MILLION, 0, 64, 64); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, d = 64"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 10 * MILLION, 24, 64, 64); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, d = 64"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 40 * MILLION, 0, 4); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, d = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 40 * MILLION, 28, 4); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, d = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 10 * MILLION, 0, 16); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, d = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 10 * MILLION, 26, 16); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, d = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, 100 * MILLION, 0, 0.0, 0.125); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, 100 * MILLION, 27, 0.0, 0.125); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 27"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, 5 * MILLION, 0, 0.0, 1.0/256.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, 5 * MILLION, 22, 0.0, 1.0/256.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 22"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Run (gen, res, 1, 500 * MILLION, 0, TRUE); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of U01, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Run (gen, res, 1, 500 * MILLION, 15, FALSE); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of U01, r = 15"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Permutation (gen, res, 1, 50 * MILLION, 0, 10); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Permutation, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Permutation (gen, res, 1, 50 * MILLION, 15, 10); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Permutation, r = 15"); + } + sres_DeleteChi2 (res); + } + { + sknuth_Res2 *res; + res = sknuth_CreateRes2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CollisionPermut (gen, res, 5, 10 * MILLION, 0, 13); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionPermut, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CollisionPermut (gen, res, 5, 10 * MILLION, 15, 13); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionPermut, r = 15"); + } + sknuth_DeleteRes2 (res); + } + { + sknuth_Res1 *res; + res = sknuth_CreateRes1 (); + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 10, 10 * MILLION, 0, MILLION / 10, 5); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 5"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 5"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 5, 10 * MILLION, 0, MILLION / 10, 10); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 10"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 10"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 1, 10 * MILLION, 0, MILLION / 10, 20); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 20"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 20"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 1, 10 * MILLION, 0, MILLION / 10, 30); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 30"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 30"); + } + sknuth_DeleteRes1 (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleProd (gen, res, 1, 10 * MILLION, 0, 10); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleProd, t = 10"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleProd (gen, res, 1, 10 * MILLION, 0, 30); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleProd, t = 30"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleMean (gen, res, 10*MILLION, 20, 0); + bbattery_pVal[++j] = res->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleMean"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleCorr (gen, res, 1, 500 * MILLION, 0, 1); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleCorr"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_AppearanceSpacings (gen, res, 1, 10 * MILLION, 400 * MILLION, + r, 30, 15); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AppearanceSpacings, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_AppearanceSpacings (gen, res, 1, 10 * MILLION, 100 * MILLION, + 20, 10, 15); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AppearanceSpacings, r = 20"); + } + sres_DeleteBasic (res); + } + { + smarsa_Res2 *res2; + sres_Chi2 *res; + res = sres_CreateChi2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 2 * MILLION, 0, 256, 0.0, 0.125); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 2 * MILLION, 8, 256, 0.0, 0.125); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 2 * MILLION, 16, 256, 0.0, 0.125); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 2 * MILLION, 24, 256, 0.0, 0.125); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 24"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SumCollector (gen, res, 1, 20 * MILLION, 0, 10.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SumCollector"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, MILLION, r, s, 2 * s, 2 * s); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 60 x 60"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, MILLION, 20, 10, 2 * s, 2 * s); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 60 x 60"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 50 * THOUSAND, r, s, 10 * s, 10 * s); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 300 x 300"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 50 * THOUSAND, 20, 10, 10 * s, + 10 * s); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 300 x 300"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 2 * THOUSAND, r, s, 40 * s, 40 * s); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 1200 x 1200"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 2 * THOUSAND, 20, 10, 40 * s, 40 * s); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 1200 x 1200"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_Savir2 (gen, res, 1, 20 * MILLION, 0, 1024*1024, 30); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Savir2"); + } + sres_DeleteChi2 (res); + + res2 = smarsa_CreateRes2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_GCD (gen, res2, 1, 100 * MILLION, 0, 30); + bbattery_pVal[++j] = res2->GCD->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "GCD, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_GCD (gen, res2, 1, 40 * MILLION, 10, 20); + bbattery_pVal[++j] = res2->GCD->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "GCD, r = 10"); + } + smarsa_DeleteRes2 (res2); + } + { + swalk_Res *res; + res = swalk_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 50 * MILLION, r, s, 90, 90); + GetPVal_Walk (1, res, &j, " (L = 90)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 10 * MILLION, 20, 10, 90, 90); + GetPVal_Walk (1, res, &j, " (L = 90)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 5 * MILLION, r, s, 1000, 1000); + GetPVal_Walk (1, res, &j, " (L = 1000)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, MILLION, 20, 10, 1000, 1000); + GetPVal_Walk (1, res, &j, " (L = 1000)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, MILLION / 2, r, s, 10000, 10000); + GetPVal_Walk (1, res, &j, " (L = 10000)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, MILLION / 10, 20, 10, 10000, 10000); + GetPVal_Walk (1, res, &j, " (L = 10000)", j2); + } + swalk_DeleteRes (res); + } + { + scomp_Res *res; + res = scomp_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LinearComp (gen, res, 1, 120 * THOUSAND, r, 1); + bbattery_pVal[++j] = res->JumpNum->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 0"); + bbattery_pVal[++j] = res->JumpSize->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LinearComp (gen, res, 1, 120 * THOUSAND, 29, 1); + bbattery_pVal[++j] = res->JumpNum->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 29"); + bbattery_pVal[++j] = res->JumpSize->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 29"); + } + scomp_DeleteRes (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LempelZiv (gen, res, 10, 25, r, s); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LempelZiv"); + } + sres_DeleteBasic (res); + } + { + sspectral_Res *res; + res = sspectral_CreateRes (); + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sspectral_Fourier3 (gen, res, 50 * THOUSAND, 14, r, s); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Fourier3, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sspectral_Fourier3 (gen, res, 50 * THOUSAND, 14, 20, 10); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Fourier3, r = 20"); + } + sspectral_DeleteRes (res); + } + { + sstring_Res2 *res; + res = sstring_CreateRes2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_LongestHeadRun (gen, res, 1, 1000, r, s, 20 + 10 * MILLION); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 0"); + bbattery_pVal[++j] = res->Disc->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_LongestHeadRun (gen, res, 1, 300, 20, 10, 20 + 10 * MILLION); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 20"); + bbattery_pVal[++j] = res->Disc->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 20"); + } + sstring_DeleteRes2 (res); + } + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_PeriodsInStrings (gen, res, 1, 300 * MILLION, r, s); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "PeriodsInStrings, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_PeriodsInStrings (gen, res, 1, 300 * MILLION, 15, 15); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "PeriodsInStrings, r = 15"); + } + sres_DeleteChi2 (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingWeight2 (gen, res, 100, 100 * MILLION, r, s, MILLION); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingWeight2, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingWeight2 (gen, res, 30, 100 * MILLION, 20, 10, MILLION); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingWeight2, r = 20"); + } + sres_DeleteBasic (res); + } + { + sstring_Res *res; + res = sstring_CreateRes (); + /* sstring_HammingCorr will probably be removed: less sensitive than + svaria_HammingIndep */ + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, 1, 500 * MILLION, r, s, s); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 30"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, 1, 50 * MILLION, r, s, 10 * s); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 300"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, 1, 10 * MILLION, r, s, 40 * s); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 1200"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 300 * MILLION, r, s, s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 30"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 100 * MILLION, 20, 10, s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 30"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 30 * MILLION, r, s, 10 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 300"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 10 * MILLION, 20, 10, 10 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 300"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 10 * MILLION, r, s, 40 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 1200"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, MILLION, 20, 10, 40 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 1200"); + } + sstring_DeleteRes (res); + } + { + sstring_Res3 *res; + res = sstring_CreateRes3 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_Run (gen, res, 1, 1 * BILLION, r, s); + bbattery_pVal[++j] = res->NRuns->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 0"); + bbattery_pVal[++j] = res->NBits->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_Run (gen, res, 1, 1 * BILLION, 20, 10); + bbattery_pVal[++j] = res->NRuns->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 20"); + bbattery_pVal[++j] = res->NBits->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 20"); + } + sstring_DeleteRes3 (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 10, 30 + BILLION, r, s, 1); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d = 1"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 5, 1 + BILLION, 20, 10, 1); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d = 1"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 10, 31 + BILLION, r, s, s); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d = 30"); + } + + ++j2; + /* util_Assert (j2 <= CRUSH_NUM, "Crush: j2 > CRUSH_NUM"); */ + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 5, 11 + BILLION, 20, 10, 10); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d = 10"); + } + sres_DeleteBasic (res); + } + + bbattery_NTests = ++j; + GetName (gen, genName); + WriteReport (genName, "Crush", bbattery_NTests, + bbattery_pVal, Timer, FALSE, TRUE, 0.0); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void bbattery_Crush (unif01_Gen * gen) +{ + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= CRUSH_NUM; ++i) + Rep[i] = 1; + Crush (gen, Rep); +} + + +/*=========================================================================*/ + +void bbattery_RepeatCrush (unif01_Gen * gen, int Rep[]) +{ + Crush (gen, Rep); +} + + +/*=========================================================================*/ + +static void BigCrush (unif01_Gen * gen, int Rep[]) +/* + * A battery of very stringent statistical tests for Random Number Generators + * used in simulation. + * Rep[i] gives the number of times that test i will be done. The default + * values are Rep[i] = 1 for all i. + */ +{ + const int s = 30; + const int r = 0; + int i; + chrono_Chrono *Timer; + char genName[LEN + 1] = ""; + int j = -1; + int j2 = 0; + + Timer = chrono_Create (); + InitBat (); + if (swrite_Basic) { + printf ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " Starting BigCrush\n" + " Version: %s\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n", + PACKAGE_STRING); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_SerialOver (gen, res, 1, BILLION, 0, 256, 3); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SerialOver, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_SerialOver (gen, res, 1, BILLION, 22, 256, 3); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SerialOver, r = 22"); + } + sres_DeleteBasic (res); + } + { + smarsa_Res *resm; + resm = smarsa_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 0, 1024*1024*2, 2); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 9, 1024*1024*2, 2); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 0, 1024*16, 3); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 3"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 16, 1024*16, 3); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 3"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 0, 64, 7); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 7"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 24, 64, 7); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 7"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 0, 8, 14); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 14"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 27, 8, 14); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 14"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 0, 4, 21); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 21"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_CollisionOver (gen, resm, 30, 20 * MILLION, 28, 4, 21); + bbattery_pVal[++j] = resm->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionOver, t = 21"); + } + smarsa_DeleteRes (resm); + } + { + sres_Poisson *res; + res = sres_CreatePoisson (); +#ifdef USE_LONGLONG + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + long d; +#if LONG_MAX <= 2147483647L + d = 1073741824L; + smarsa_BirthdaySpacings (gen, res, 250, 4 * MILLION, 0, d, 2, 1); +#else + d = 2147483648L; + smarsa_BirthdaySpacings (gen, res, 100, 10 * MILLION, 0, d, 2, 1); +#endif + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 20 * MILLION, 0, 2097152, 3, + 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 3"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 30 * MILLION, 14, 65536, 4, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 20 * MILLION, 0, 512, 7, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 7"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 20 * MILLION, 7, 512, 7, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 7"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 30 * MILLION, 14, 256, 8, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 30 * MILLION, 22, 256, 8, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 30 * MILLION, 0, 16, 16, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 20, 30 * MILLION, 26, 16, 16, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 16"); + } + +#else + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 0, + 67108864, 2, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 0, + 1024 * 8, 4, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 16, + 1024 * 8, 4, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 4"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 0, 16, + 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 5, 16, + 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 10, + 16, 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 15, + 16, 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 20, + 16, 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_BirthdaySpacings (gen, res, 10 * THOUSAND, MILLION / 10, 26, + 16, 13, 1); + bbattery_pVal[++j] = res->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings, t = 13"); + } +#endif + sres_DeletePoisson (res); + } + { + lebool flag = snpair_mNP2S_Flag; + snpair_Res *res; + res = snpair_CreateRes (); + + snpair_mNP2S_Flag = TRUE; + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairs (gen, res, 30, 6 * MILLION, 0, 3, 0, 30); + GetPVal_CPairs (40, res, &j, ", t = 3", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairs (gen, res, 20, 4 * MILLION, 0, 5, 0, 30); + GetPVal_CPairs (40, res, &j, ", t = 5", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairs (gen, res, 10, 3 * MILLION, 0, 9, 0, 30); + GetPVal_CPairs (20, res, &j, ", t = 9", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairs (gen, res, 5, 2*MILLION, 0, 16, 0, 30); + GetPVal_CPairs (10, res, &j, ", t = 16", j2); + } + snpair_DeleteRes (res); + snpair_mNP2S_Flag =flag; + } + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 400 * MILLION, 0, 8, 8); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 400 * MILLION, 27, 8, 8); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, r = 27"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 100 * MILLION, 0, 32, 32); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_SimpPoker (gen, res, 1, 100 * MILLION, 25, 32, 32); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SimpPoker, r = 25"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 200 * MILLION, 0, 8); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 200 * MILLION, 10, 8); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, r = 10"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 200 * MILLION, 20, 8); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, r = 20"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CouponCollector (gen, res, 1, 200 * MILLION, 27, 8); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CouponCollector, r = 27"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, BILLION/2, 0, 0.0, 1.0/16.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, 300*MILLION, 25, 0.0, 1.0/32.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 25"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, BILLION/10, 0, 0.0, 1.0/128.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Gap (gen, res, 1, 10*MILLION, 20, 0.0, 1.0/1024.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Gap, r = 20"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Run (gen, res, 5, BILLION, 0, FALSE); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Run (gen, res, 10, BILLION, 15, TRUE); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run, r = 15"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Permutation (gen, res, 1, BILLION, 5, 3); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Permutation, t = 3" ); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Permutation (gen, res, 1, BILLION, 5, 5); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Permutation, t = 5"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Permutation (gen, res, 1, BILLION/2, 5, 7); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Permutation, t = 7"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_Permutation (gen, res, 1, BILLION/2, 10, 10); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Permutation, t = 10"); + } + sres_DeleteChi2 (res); + } + { + sknuth_Res2 *res; + res = sknuth_CreateRes2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CollisionPermut (gen, res, 20, 20 * MILLION, 0, 14); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionPermut, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_CollisionPermut (gen, res, 20, 20 * MILLION, 10, 14); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "CollisionPermut, r = 10"); + } + sknuth_DeleteRes2 (res); + } + { + sknuth_Res1 *res; + res = sknuth_CreateRes1 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 40, 10 * MILLION, 0, MILLION / 10, 8); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 8"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 30, 10 * MILLION, 0, MILLION / 10, 16); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 16"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 20, 10 * MILLION, 0, MILLION / 10, 24); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 24"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 24"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sknuth_MaxOft (gen, res, 20, 10 * MILLION, 0, MILLION / 10, 32); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft, t = 32"); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MaxOft AD, t = 32"); + } + sknuth_DeleteRes1 (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleProd (gen, res, 40, 10 * MILLION, 0, 8); + bbattery_pVal[++j] = res->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleProd, t = 8"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleProd (gen, res, 20, 10*MILLION, 0, 16); + bbattery_pVal[++j] = res->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleProd, t = 16"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleProd (gen, res, 20, 10*MILLION, 0, 24); + bbattery_pVal[++j] = res->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleProd, t = 24"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleMean (gen, res, 20*MILLION, 30, 0); + bbattery_pVal[++j] = res->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleMean, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleMean (gen, res, 20*MILLION, 30, 10); + bbattery_pVal[++j] = res->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleMean, r = 10"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleCorr (gen, res, 1, 2*BILLION, 0, 1); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleCorr, k = 1"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SampleCorr (gen, res, 1, 2*BILLION, 0, 2); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SampleCorr, k = 2"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_AppearanceSpacings (gen, res, 1, 10 * MILLION, BILLION, + r, 3, 15); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AppearanceSpacings, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_AppearanceSpacings (gen, res, 1, 10 * MILLION, BILLION, + 27, 3, 15); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AppearanceSpacings, r = 27"); + } + sres_DeleteBasic (res); + } + { + smarsa_Res2 *res2; + sres_Chi2 *res; + res = sres_CreateChi2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 20 * MILLION, 0, 256, 0.0, 0.25); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 20 * MILLION, 20, 256, 0.0, 0.25); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 20"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 20 * MILLION, 28, 256, 0.0, 0.25); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 28"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 20 * MILLION, 0, 256, 0.0, 0.0625); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 20 * MILLION, 10, 256, 0.0, 0.0625); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 10"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_WeightDistrib (gen, res, 1, 20 * MILLION, 26, 256, 0.0, 0.0625); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "WeightDistrib, r = 26"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + svaria_SumCollector (gen, res, 1, 500 * MILLION, 0, 10.0); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "SumCollector"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 10, MILLION, r, 5, 30, 30); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, L=30, r=0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 10, MILLION, 25, 5, 30, 30); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, L=30, r=26"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 5 * THOUSAND, r, 4, 1000, 1000); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, L=1000, r=0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 5 * THOUSAND, 26, 4, 1000, 1000); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, L=1000, r=26"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 80, 15, 15, 5000, 5000); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, L=5000"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_MatrixRank (gen, res, 1, 80, 0, 30, 5000, 5000); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, L=5000"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_Savir2 (gen, res, 10, 10 * MILLION, 10, 1024*1024, 30); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Savir2"); + } + sres_DeleteChi2 (res); + + res2 = smarsa_CreateRes2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smarsa_GCD (gen, res2, 10, 50 * MILLION, 0, 30); + bbattery_pVal[++j] = res2->GCD->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "GCD"); + } + smarsa_DeleteRes2 (res2); + } + { + swalk_Res *res; + res = swalk_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 100 * MILLION, r, 5, 50, 50); + GetPVal_Walk (1, res, &j, " (L=50, r=0)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 100 * MILLION, 25, 5, 50, 50); + GetPVal_Walk (1, res, &j, " (L=50, r=25)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 10 * MILLION, r, 10, 1000, 1000); + GetPVal_Walk (1, res, &j, " (L=1000, r=0)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 10 * MILLION, 20, 10, 1000, 1000); + GetPVal_Walk (1, res, &j, " (L=1000, r=20)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 1 * MILLION, r, 15, 10000, 10000); + GetPVal_Walk (1, res, &j, " (L=10000, r=0)", j2); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, 1, 1 * MILLION, 15, 15, 10000, 10000); + GetPVal_Walk (1, res, &j, " (L=10000, r=15)", j2); + } + swalk_DeleteRes (res); + } + { + scomp_Res *res; + res = scomp_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LinearComp (gen, res, 1, 400 * THOUSAND + 20, r, 1); + bbattery_pVal[++j] = res->JumpNum->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 0"); + bbattery_pVal[++j] = res->JumpSize->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LinearComp (gen, res, 1, 400 * THOUSAND + 20, 29, 1); + bbattery_pVal[++j] = res->JumpNum->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 29"); + bbattery_pVal[++j] = res->JumpSize->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp, r = 0"); + } + scomp_DeleteRes (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LempelZiv (gen, res, 10, 27, r, s); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LempelZiv, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LempelZiv (gen, res, 10, 27, 15, 15); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LempelZiv, r = 15"); + } + sres_DeleteBasic (res); + } + { + sspectral_Res *res; + res = sspectral_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sspectral_Fourier3 (gen, res, 100 * THOUSAND, 14, r, 3); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Fourier3, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sspectral_Fourier3 (gen, res, 100 * THOUSAND, 14, 27, 3); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Fourier3, r = 27"); + } + sspectral_DeleteRes (res); + } + { + sstring_Res2 *res; + res = sstring_CreateRes2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_LongestHeadRun (gen, res, 1, 1000, r, 3, 20 + 10 * MILLION); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 0"); + bbattery_pVal[++j] = res->Disc->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_LongestHeadRun (gen, res, 1, 1000, 27, 3, 20 + 10 * MILLION); + bbattery_pVal[++j] = res->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 27"); + bbattery_pVal[++j] = res->Disc->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun, r = 27"); + } + sstring_DeleteRes2 (res); + } + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_PeriodsInStrings (gen, res, 10, BILLION/2, r, 10); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "PeriodsInStrings, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_PeriodsInStrings (gen, res, 10, BILLION/2, 20, 10); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "PeriodsInStrings, r = 20"); + } + sres_DeleteChi2 (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingWeight2 (gen, res, 10, BILLION, r, 3, MILLION); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingWeight2, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingWeight2 (gen, res, 10, BILLION, 27, 3, MILLION); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingWeight2, r = 27"); + } + sres_DeleteBasic (res); + } + { + sstring_Res *res; + res = sstring_CreateRes (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, 1, BILLION, 10, 10, s); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 30"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, 1, 100 * MILLION, 10, 10, 10 * s); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 300"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, 1, 100 * MILLION, 10, 10, 40 * s); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 1200"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 10, 30 * MILLION, r, 3, s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L=30, r=0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 10, 30 * MILLION, 27, 3, s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L=30, r=27"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 30 * MILLION, r, 4, 10 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L=300, r=0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 30 * MILLION, 26, 4, 10 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L=300, r=26"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 10 * MILLION, r, 5, 40 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L=1200, r=0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, 1, 10 * MILLION, 25, 5, 40 * s, 0); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L=1200, r=25"); + } + sstring_DeleteRes (res); + } + { + sstring_Res3 *res; + res = sstring_CreateRes3 (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_Run (gen, res, 1, 2*BILLION, r, 3); + bbattery_pVal[++j] = res->NRuns->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 0"); + bbattery_pVal[++j] = res->NBits->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_Run (gen, res, 1, 2*BILLION, 27, 3); + bbattery_pVal[++j] = res->NRuns->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 27"); + bbattery_pVal[++j] = res->NBits->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits, r = 27"); + } + sstring_DeleteRes3 (res); + } + { + sres_Basic *res; + res = sres_CreateBasic (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 10, 30 + BILLION, r, 3, 1); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d=1, r=0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 10, 30 + BILLION, r, 3, 3); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d=3, r=0"); + } + + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 10, 30 + BILLION, 27, 3, 1); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d=1, r=27"); + } + + ++j2; + util_Assert (j2 <= BIGCRUSH_NUM, "BigCrush: j2 > BIGCRUSH_NUM"); + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, 10, 30 + BILLION, 27, 3, 3); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor, d=3, r=27"); + } + sres_DeleteBasic (res); + } + + bbattery_NTests = ++j; + GetName (gen, genName); + WriteReport (genName, "BigCrush", bbattery_NTests, bbattery_pVal, + Timer, FALSE, TRUE, 0.0); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void bbattery_BigCrush (unif01_Gen * gen) +{ + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= BIGCRUSH_NUM; ++i) + Rep[i] = 1; + BigCrush (gen, Rep); +} + + +/*=========================================================================*/ + +void bbattery_RepeatBigCrush (unif01_Gen * gen, int Rep[]) +{ + BigCrush (gen, Rep); +} + + +/*=========================================================================*/ +#if 0 +static void WriteTime (time_t t0, time_t t1) +{ + int y1; + double y = 0; + + y = difftime (t1, t0); + /* printf (" Total time: %.2f sec\n\n", y); */ + printf (" Total time: "); + y1 = y / 3600; + printf ("%02d:", y1); + y -= y1 * 3600.0; + y1 = y / 60; + printf ("%02d:", y1); + y -= y1 * 60.0; + printf ("%.2f\n\n", y); +} +#endif + +/*-------------------------------------------------------------------------*/ + +static void Alphabit (unif01_Gen * gen, char *fname, double nb, int r, int s, + lebool blocFlag, int w, int Rep[]) +{ + chrono_Chrono *Timer; + /* time_t t0, t1; */ + int NbDelta = 1; + double ValDelta[] = { 1 }; + long N = 1; + long n, L; + int j = 0; + int j2 = 0; + int i; + lebool fileFlag; + long bufsiz; + char genName[LEN + 1] = ""; + double z; + unif01_Gen *gen0; + + Timer = chrono_Create (); + /* t0 = time (NULL); */ + InitBat (); + if (swrite_Basic) { + printf ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " Starting Alphabit: nb = %.0f\n" + " Version: %s\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n", + nb, PACKAGE_STRING); + } + util_Assert (nb > 0, "Alphabit: nb <= 0"); + /* Bits will be read as 32-bit unsigned integers */ + nb -= fmod (nb, 32.0); + bufsiz = nb / 32.0; + + if (blocFlag) { + gen0 = ufile_CreateReadBin (fname, bufsiz); + gen = unif01_CreateBitBlockGen (gen0, r, s, w); + nb -= fmod (nb, 1024.0 / w); + fileFlag = TRUE; + } else if (NULL == gen) { + gen = ufile_CreateReadBin (fname, bufsiz); + fileFlag = TRUE; + } else { + fileFlag = FALSE; + } + + { + smultin_Param *par = NULL; + smultin_Res *res; + par = smultin_CreateParam (NbDelta, ValDelta, smultin_GenerCellSerial, + 3); + res = smultin_CreateRes (par); + if (fileFlag) + ufile_InitReadBin (); + + if (nb > BILLION) + N = 1 + nb / BILLION; + else + N = 1; + n = nb / N; + /* Set n as a multiple of s = 32 */ + n -= n % 32; + j = -1; + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smultin_MultinomialBitsOver (gen, par, res, N, n, r, s, 2, FALSE); + strcpy (bbattery_TestNames[++j], "MultinomialBitsOver, L = 2"); + if (N == 1) + bbattery_pVal[j] = res->pVal2[0][gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[0][gofw_AD]; + TestNumber[j] = j2; + } + + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + smultin_MultinomialBitsOver (gen, par, res, N, n, r, s, 4, FALSE); + strcpy (bbattery_TestNames[++j], "MultinomialBitsOver, L = 4"); + if (N == 1) + bbattery_pVal[j] = res->pVal2[0][gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[0][gofw_AD]; + TestNumber[j] = j2; + } + + ++j2; + if (n > 250) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + smultin_MultinomialBitsOver (gen, par, res, N, n, r, s, 8, FALSE); + strcpy (bbattery_TestNames[++j], "MultinomialBitsOver, L = 8"); + if (N == 1) + bbattery_pVal[j] = res->pVal2[0][gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[0][gofw_AD]; + TestNumber[j] = j2; + } + } + + ++j2; + if (n > 65000) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + smultin_MultinomialBitsOver (gen, par, res, N, n, r, s, 16, FALSE); + strcpy (bbattery_TestNames[++j], "MultinomialBitsOver, L = 16"); + if (N == 1) + bbattery_pVal[j] = res->pVal2[0][gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[0][gofw_AD]; + TestNumber[j] = j2; + } + } + + smultin_DeleteRes (res); + smultin_DeleteParam (par); + } + + { + sstring_Res *res; + res = sstring_CreateRes (); + + if (fileFlag) + ufile_InitReadBin (); + z = nb / s; + N = 1 + z / BILLION; + n = z / N; + ++j2; + if (n >= 20) { + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, N, n, r, s, 16, 0); + j++; + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 16"); + TestNumber[j] = j2; + } + } + + if (fileFlag) + ufile_InitReadBin (); + n /= 2; + ++j2; + if (n >= 20) { + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingIndep (gen, res, N, n, r, s, 32, 0); + j++; + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 32"); + TestNumber[j] = j2; + } + } + + if (fileFlag) + ufile_InitReadBin (); + n *= 2; + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, N, n, r, s, 32); + j++; + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 32"); + } + } + + { + swalk_Res *res; + res = swalk_CreateRes (); + + if (fileFlag) + ufile_InitReadBin (); + L = 64; + z = nb / L; + N = 1 + z / BILLION; + n = z / N; + j2++; + if (n >= 30) { + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, N, n, r, s, L, L); + GetPVal_Walk (N, res, &j, " (L = 64)", j2); + } + } + + if (fileFlag) + ufile_InitReadBin (); + L = 320; + z = nb / L; + N = 1 + z / BILLION; + n = z / N; + j2++; + util_Assert (j2 <= ALPHABIT_NUM, "Alphabit: j2 > ALPHABIT_NUM"); + if (n >= 30) { + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, N, n, r, s, L, L); + GetPVal_Walk (N, res, &j, " (L = 320)", j2); + } + } + swalk_DeleteRes (res); + } + + bbattery_NTests = ++j; + if (blocFlag) { + unif01_DeleteBitBlockGen (gen); + gen = gen0; + } + if (fileFlag) { + WriteReport (fname, "Alphabit", bbattery_NTests, + bbattery_pVal, Timer, TRUE, TRUE, nb); + ufile_DeleteReadBin (gen); + } else { + GetName (gen, genName); + WriteReport (genName, "Alphabit", bbattery_NTests, bbattery_pVal, + Timer, FALSE, TRUE, nb); + } + + chrono_Delete (Timer); + /* t1 = time (NULL); + WriteTime (t0, t1); */ +} + + +/*=========================================================================*/ + +void bbattery_Alphabit (unif01_Gen * gen, double nb, int r, int s) +{ + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= ALPHABIT_NUM; ++i) + Rep[i] = 1; + Alphabit (gen, NULL, nb, r, s, FALSE, 0, Rep); +} + + +/*=========================================================================*/ + +void bbattery_AlphabitFile (char *filename, double nb) +{ + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= ALPHABIT_NUM; ++i) + Rep[i] = 1; + Alphabit (NULL, filename, nb, 0, 32, FALSE, 0, Rep); +} + + +/*=========================================================================*/ + +void bbattery_RepeatAlphabit (unif01_Gen * gen, double nb, int r, int s, + int Rep[]) +{ + Alphabit (gen, NULL, nb, r, s, FALSE, 0, Rep); +} + + +/*=========================================================================*/ + +void bbattery_BlockAlphabit (unif01_Gen * gen, double n, int r, int s) +{ + unif01_Gen *gen2; + int L = 1; + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= ALPHABIT_NUM; ++i) + Rep[i] = 1; + while ((L <= 32) && (L <= s)) { + gen2 = unif01_CreateBitBlockGen (gen, r, s, L); + Alphabit (gen2, NULL, n, r, s, FALSE, 0, Rep); + unif01_DeleteBitBlockGen (gen2); + L *= 2; + } +} + + +/*=========================================================================*/ + +void bbattery_RepeatBlockAlphabit (unif01_Gen * gen, double nb, int r, int s, + int Rep[], int L) +{ + if ((L <= 32) && (L <= s)) { + unif01_Gen *gen2; + gen2 = unif01_CreateBitBlockGen (gen, r, s, L); + Alphabit (gen2, NULL, nb, r, s, FALSE, 0, Rep); + unif01_DeleteBitBlockGen (gen2); + } +} + + +/*=========================================================================*/ + +void bbattery_BlockAlphabitFile (char *filename, double nb) +{ + int w = 1; + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= ALPHABIT_NUM; ++i) + Rep[i] = 1; + while (w <= 32) { + Alphabit (NULL, filename, nb, 0, 32, TRUE, w, Rep); + w *= 2; + } +} + + +/*=========================================================================*/ + +static void DoMultinom (lebool fileFlag, /* */ + unif01_Gen * gen, /* */ + double nb, /* Number of bits */ + int *pj, /* j */ + int j2, /* Test number in the battery */ + int Rep[] /* Number of replications */ + ) +/* + * Do the smultin_MultinomialBits in Rabbit + */ +{ + const long NLIM = 10000000; + long n, N; + int L, t; + double x; + int i; + int j = *pj; + smultin_Res *res; + smultin_Param *par = NULL; + double ValDelta[] = { -1 }; + + util_Assert (nb > 0.0, "MultinomialBits: nb <= 0"); + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, -3); + res = smultin_CreateRes (par); + if (fileFlag) + ufile_InitReadBin (); + +#ifdef USE_LONGLONG + /* Limit sample size n to NLIM because of memory limitations. */ + /* Determine number of replications N from this. */ + N = 1 + nb / NLIM; + n = nb / N; + /* Time limit on test: N = 30 */ + N = util_Min (30, N); + /* Set n as a multiple of s = 32 */ + n -= n % 32; + L = num_Log2 (n / 200.0 * n); + L = util_Max (4, L); + for (i = 0; i < Rep[j2]; ++i) { + smultin_MultinomialBitsOver (gen, par, res, N, n, 0, 32, L, TRUE); + strcpy (bbattery_TestNames[++j], "MultinomialBitsOver"); + bbattery_pVal[j] = res->pColl; + TestNumber[j] = j2; + } + +#else + x = nb / 32.0; + N = 1 + x / NLIM; + n = x / N; + N = util_Min (30, N); + L = 16; + t = 32 / L; + /* We want a number of collisions >= 2 */ + while ((L > 1) && (n / num_TwoExp[L] * n * t * t < 2.0)) { + L /= 2; + t = 32 / L; + } + n = n * (32 / L); + /* We want a density n / k < 2 to use case Sparse = TRUE */ + if (n > 2 * num_TwoExp[L]) { + N = n / num_TwoExp[L] * N; + n /= N; + while ((double) N * n * L > nb) + n--; + } + while (n * L % 32 > 0) + n--; + if (n > 3) { + for (i = 0; i < Rep[j2]; ++i) { + smultin_MultinomialBits (gen, par, res, N, n, 0, 32, L, TRUE); + strcpy (bbattery_TestNames[++j], "MultinomialBits"); + bbattery_pVal[j] = res->pColl; + TestNumber[j] = j2; + } + } +#endif + *pj = j; + smultin_DeleteRes (res); + smultin_DeleteParam (par); +} + + +/*-------------------------------------------------------------------------*/ + +static void DoAppear (lebool fileFlag, /* */ + unif01_Gen * gen, double nb, /* Number of bits to test */ + int *pj, /* j */ + int j2, /* Test number in the battery */ + int Rep[] + ) +/* + * Do the svaria_AppearanceSpacings test in Rabbit + */ +{ + sres_Basic *res; + const long NLIM = 2000000000; + int L; + long N, Q; + int i; + int j = *pj; + double temp = nb * (30.0 / 32.0) / 20.0; + + res = sres_CreateBasic (); + if (num_TwoExp[30] < temp / 30.0) + L = 30; + else if (num_TwoExp[15] < temp / 15.0) + L = 15; + else if (num_TwoExp[10] < temp / 10.0) + L = 10; + else if (num_TwoExp[6] < temp / 6.0) + L = 6; + else if (num_TwoExp[5] < temp / 5.0) + L = 5; + else if (num_TwoExp[3] < temp / 3.0) + L = 3; + else + L = 2; + temp = nb / 2; + temp *= 30.0 / 32.0; + temp /= L; + N = 1 + temp / NLIM; + Q = temp / N; + N = 1; + + if (Q < 50) + return; + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + svaria_AppearanceSpacings (gen, res, N, Q, Q, 0, 30, L); + j++; + if (N == 1) + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AppearanceSpacings"); + } + sres_DeleteBasic (res); + *pj = j; +} + + +/*-------------------------------------------------------------------------*/ + +static void DoWalk (lebool fileFlag, /* */ + unif01_Gen * gen, /* */ + double nb, /* Number of bits to test */ + int *pj, /* j */ + int j2, /* Test number in the battery */ + int Rep[] + ) +/* + * Do 3 swalk_RandomWalk1 tests in Rabbit + */ +{ + swalk_Res *res; + long n, N, L; + double z; + int i; + + L = 128; + z = nb / L; + N = 1 + z / BILLION; + n = z / N; + N = 1; + while (n < 100) { + L /= 2; + n *= 2; + } + if (L < 4) + return; + n = nb / (L * N); + n = util_Min (n, 500 * MILLION); + if (L < 32) { + while (32 * n > nb) + n--; + } + if (n < 30) + return; + + res = swalk_CreateRes (); + ++j2; + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, N, n, 0, 32, L, L); + GetPVal_Walk (N, res, pj, "", j2); + } + if (L < 96) + return; + + L = 1024; + z = nb / L; + N = 1 + z / BILLION; + n = z / N; + n = util_Min (n, 50 * MILLION); + N = 1; + while ((double) n * L > nb) + n--; + if (n < 30) + return; + + ++j2; + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, N, n, 0, 32, L, L); + GetPVal_Walk (N, res, pj, " (L = 1024)", j2); + } + + L = 10016; + z = nb / L; + N = 1 + z / BILLION; + n = z / N; + n = util_Min (n, 5 * MILLION); + N = 1; + while ((double) n * L > nb) + n--; + if (n < 30) + return; + ++j2; + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + swalk_RandomWalk1 (gen, res, N, n, 0, 32, L, L); + GetPVal_Walk (N, res, pj, " (L = 10016)", j2); + } + + swalk_DeleteRes (res); +} + + +/*-------------------------------------------------------------------------*/ + +static void Rabbit (unif01_Gen * gen, char *fname, double nb, int Rep[]) +/* + * A battery of statistical tests for a file of n random bits. + */ +{ + const int s = 32; + int k, j = 0, j2 = 0; + int i; + long n, N, L; + double nw, x; + chrono_Chrono *Timer; + long bufsiz; + lebool fileFlag; + char genName[LEN + 1] = ""; + + Timer = chrono_Create (); + InitBat (); + if (swrite_Basic) { + printf ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " Starting Rabbit: nb = %.0f\n" + " Version: %s\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n", + nb, PACKAGE_STRING); + } + util_Assert (nb >= 500.0, "bbattery_Rabbit: nb < 500"); + + /* Bits will be read as 32-bit unsigned integers */ + nb -= fmod (nb, 32.0); + nw = nb / 32.0; + bufsiz = nw; + + if (NULL == gen) { + gen = ufile_CreateReadBin (fname, bufsiz); + fileFlag = TRUE; + } else + fileFlag = FALSE; + + j = -1; + ++j2; + DoMultinom (fileFlag, gen, nb, &j, j2, Rep); + + { + const long NLIM = 4000000; + snpair_Res *res; + res = snpair_CreateRes (); + N = 1 + nw / NLIM; + n = nw / N; + N = util_Min (N, 25); + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairsBitMatch (gen, res, N, n / 2, 0, 2); + bbattery_pVal[++j] = res->pVal[snpair_BM]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "ClosePairsBitMatch, t = 2"); + } + + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + snpair_ClosePairsBitMatch (gen, res, N, n / 4, 0, 4); + bbattery_pVal[++j] = res->pVal[snpair_BM]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "ClosePairsBitMatch, t = 4"); + } + snpair_DeleteRes (res); + } + + ++j2; + DoAppear (fileFlag, gen, nb, &j, j2, Rep); + + { + const long NLIM1 = 300000; + const long NLIM2 = 10000; + scomp_Res *res; + res = scomp_CreateRes (); + n = NLIM2 + 2.0 * sqrt (nb); + n = util_Min (n, nb); + n = util_Min (n, NLIM1); + N = 1; + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LinearComp (gen, res, N, n, 0, s); + j++; + if (N == 1) + bbattery_pVal[j] = res->JumpSize->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->JumpSize->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp"); + j++; + if (N == 1) + bbattery_pVal[j] = res->JumpNum->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->JumpNum->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LinearComp"); + } + scomp_DeleteRes (res); + } + + k = num_Log2 (nb + 0.5); + if (k > 28) + k = 28; + N = 1; + { + sres_Basic *res; + res = sres_CreateBasic (); + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + scomp_LempelZiv (gen, res, N, k, 0, s); + j++; + if (N == 1) + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LempelZiv"); + } + sres_DeleteBasic (res); + } + { + sspectral_Res *res; + k = num_Log2 (nb + 0.5); + k = util_Min (20, k); + res = sspectral_CreateRes (); + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sspectral_Fourier1 (gen, res, 1, k, 0, s); + j++; + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Fourier1"); + } + + x = sqrt (2.0 * nb); + N = x / 2.0; + if (N < 32) { + k = 5; + N = nb / 32.0; + } else if (N >= 16384) { + k = 14; + N = nb / 16384.0; + } else { + k = num_Log2 (x / 2.0 + 0.5); + N = nb / (num_TwoExp[k]); + } + N = util_Min (N, 300000); + while ((num_TwoExp[k] + 32) * N > nb) + N--; + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sspectral_Fourier3 (gen, res, N, k, 0, s); + j++; + bbattery_pVal[j] = res->Bas->pVal2[gofw_AD]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Fourier3"); + } + sspectral_DeleteRes (res); + } + { + sstring_Res2 *res; + res = sstring_CreateRes2 (); + x = util_Min (BILLION * 100.0, nb); + n = 600; + L = x / n; + if (L <= 100000) { + n /= 10; + L *= 10; + } + if (L <= 10000) { + n /= 2; + L *= 2; + } + ++j2; + if ((L >= 1032) && (n >= 30)) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + sstring_LongestHeadRun (gen, res, 1, n, 0, s, L); + j++; + bbattery_pVal[j] = res->Chi->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "LongestHeadRun"); + } + } + sstring_DeleteRes2 (res); + } + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + nw = nb / 32.0; + nw = util_Min (nw, 4.0 * BILLION); + N = 1 + nw / BILLION; + n = nw / N; + ++j2; + if (n >= 30) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + sstring_PeriodsInStrings (gen, res, N, n, 0, 31); + ++j; + if (N == 1) + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "PeriodsInStrings"); + } + } + + nw = nb / s; + N = 1 + nw / BILLION; + n = nw / N; + N = util_Min (10, N); + ++j2; + if (n > 29) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingWeight (gen, res, N, n, 0, s, s); + ++j; + if (N == 1) + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingWeight"); + } + } + sres_DeleteChi2 (res); + } + { + sstring_Res *res; + res = sstring_CreateRes (); + nw = nb / s; + N = 1 + nw / BILLION; + n = nw / N; + N = util_Min (10, N); + ++j2; + if (n > 2) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + sstring_HammingCorr (gen, res, N, n, 0, s, 32); + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 32"); + } + } + + nw = nb / 64; + N = 1 + nw / BILLION; + n = nw / N; + N = 1; + ++j2; + if (n > 2) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + sstring_HammingCorr (gen, res, N, n, 0, s, 2 * s); + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 64"); + } + } + + nw = nb / (4 * s); + N = 1 + nw / BILLION * 4; + n = nw / N; + N = 1; + ++j2; + if (n > 2) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + sstring_HammingCorr (gen, res, N, n, 0, s, 4 * s); + j++; + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingCorr, L = 128"); + } + } + + nw = nb / s; + N = 1 + nw / BILLION; + n = nw / N; + N = util_Min (5, N); + ++j2; + if (n > 29) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + sstring_HammingIndep (gen, res, N, n, 0, s, 16, 0); + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 16"); + } + } + + nw = nb / (2 * s); + N = 1 + nw / BILLION * 2; + n = nw / N; + N = 1; + ++j2; + if (n > 29) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + sstring_HammingIndep (gen, res, N, n, 0, s, s, 0); + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 32"); + } + } + + nw = nb / (4 * s); + N = 1 + nw / BILLION * 10; + n = nw / N; + N = 1; + ++j2; + if (n > 29) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + sstring_HammingIndep (gen, res, N, n, 0, s, 2 * s, 0); + if (N == 1) + bbattery_pVal[j] = res->Bas->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->Bas->pVal2[gofw_Sum]; + strcpy (bbattery_TestNames[j], "HammingIndep, L = 64"); + TestNumber[j] = j2; + } + } + sstring_DeleteRes (res); + } + { + sres_Basic *res; + int d; + res = sres_CreateBasic (); + + d = 1; + N = 1 + nb / BILLION; + n = nb / N - d; + n -= n % 32; + N = util_Min (100, N); + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, N, n, 0, s, d); + j++; + if (N == 1) + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor"); + } + + d = 2; + N = 1 + nb / BILLION; + n = nb / N - d; + n -= n % 32; + N = util_Min (100, N); + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_AutoCor (gen, res, N, n, 0, s, d); + j++; + if (N == 1) + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "AutoCor"); + } + + sres_DeleteBasic (res); + } + { + sstring_Res3 *res; + res = sstring_CreateRes3 (); + nw = nb / 5; + N = 1 + nw / BILLION; + n = nw / N; + N = util_Min (20, N); + if (fileFlag) + ufile_InitReadBin (); + ++j2; + for (i = 0; i < Rep[j2]; ++i) { + sstring_Run (gen, res, N, n, 0, s); + j++; + if (N == 1) + bbattery_pVal[j] = res->NRuns->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->NRuns->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits"); + j++; + if (N == 1) + bbattery_pVal[j] = res->NBits->pVal2[gofw_Mean]; + else + bbattery_pVal[j] = res->NBits->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of bits"); + } + sstring_DeleteRes3 (res); + } + + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + n = nb / (s * s); + n = util_Min (n, 50 * MILLION); + ++j2; + if (n >= 50) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + smarsa_MatrixRank (gen, res, 1, n, 0, s, s, s); + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 32 x 32"); + } + } + + n = nb / (100.0 * s * s); + n = util_Min (n, 300000); + ++j2; + if (n >= 50) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + smarsa_MatrixRank (gen, res, 1, n, 0, s, 10 * s, 10 * s); + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 320 x 320"); + } + } + + n = nb / (1024.0 * s * s); + n = util_Min (n, 20000); + ++j2; + if (n >= 50) { + if (fileFlag) + ufile_InitReadBin (); + for (i = 0; i < Rep[j2]; ++i) { + j++; + smarsa_MatrixRank (gen, res, 1, n, 0, s, 32 * s, 32 * s); + bbattery_pVal[j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank, 1024 x 1024"); + } + } + sres_DeleteChi2 (res); + } + + DoWalk (fileFlag, gen, nb, &j, j2, Rep); + util_Assert (j2 <= RABBIT_NUM, "Rabbit: j2 > RABBIT_NUM"); + + bbattery_NTests = ++j; + if (fileFlag) { + WriteReport (fname, "Rabbit", bbattery_NTests, + bbattery_pVal, Timer, TRUE, TRUE, nb); + ufile_DeleteReadBin (gen); + } else { + GetName (gen, genName); + WriteReport (genName, "Rabbit", bbattery_NTests, bbattery_pVal, + Timer, FALSE, TRUE, nb); + } + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void bbattery_Rabbit (unif01_Gen * gen, double nb) +{ + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= RABBIT_NUM; ++i) + Rep[i] = 1; + Rabbit (gen, NULL, nb, Rep); +} + + +/*=========================================================================*/ + +void bbattery_RabbitFile (char *filename, double nb) +{ + int i; + int Rep[NDIM + 1] = {0}; + for (i = 1; i <= RABBIT_NUM; ++i) + Rep[i] = 1; + Rabbit (NULL, filename, nb, Rep); +} + + +/*=========================================================================*/ + +void bbattery_RepeatRabbit (unif01_Gen * gen, double nb, int Rep[]) +{ + Rabbit (gen, NULL, nb, Rep); +} + + +/*=========================================================================*/ + +void bbattery_pseudoDIEHARD (unif01_Gen * gen) +/* + * As close as possible to the DIEHARD test suite. + */ +{ + chrono_Chrono *Timer; + smultin_Param *par = NULL; + double ValDelta[] = { 1 }; + char genName[LEN + 1] = ""; + int k, i, j = -1; + int j2 = 0; + double x; + long Count[7]; + double NumExp[7] = { + 67.668, 135.335, 135.335, 90.224, 45.112, 18.045, 8.282 + }; + + Timer = chrono_Create (); + InitBat (); + if (swrite_Basic) { + printf ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " Starting pseudoDIEHARD\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n"); + } + { + sres_Poisson *res; + sres_Chi2 *Chi; + Chi = sres_CreateChi2 (); + sres_InitChi2 (Chi, 1, 6, ""); + res = sres_CreatePoisson (); + printf ("smarsa_BirthdaySpacings test with r = 0, 1, 2, 3, 4, 5," + " 6, 7, 8,\n .....\n\n"); + swrite_Basic = FALSE; + ++j2; + for (i = 0; i <= 8; i++) { + printf (" r = %d\n", i); + for (k = 0; k <= 6; k++) + Count[k] = 0; + for (k = 0; k < 500; k++) { + smarsa_BirthdaySpacings (gen, res, 1, 512, i, 16777216, 1, 1); + if (res->sVal2 >= 6) + ++Count[6]; + else + ++Count[(int) res->sVal2]; + } + x = gofs_Chi2 (NumExp, Count, 0, 6); + printf ("ChiSquare statistic :"); + bbattery_pVal[++j] = fbar_ChiSquare2 (6, 12, x); + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "BirthdaySpacings"); + gofw_Writep2 (x, bbattery_pVal[j]); + } + printf ("\n\n\n\n"); + sres_DeletePoisson (res); + sres_DeleteChi2 (Chi); + swrite_Basic = TRUE; + } + ++j2; + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + smarsa_MatrixRank (gen, res, 1, 40000, 0, 31, 31, 31); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = ++j2; + strcpy (bbattery_TestNames[j], "MatrixRank"); + + smarsa_MatrixRank (gen, res, 1, 40000, 0, 32, 32, 32); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank"); + + for (i = 0; i <= 24; i++) { + smarsa_MatrixRank (gen, res, 1, 100000, i, 8, 6, 8); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "MatrixRank"); + } + sres_DeleteChi2 (res); + } + { + smultin_Res *res; + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, 0); + res = smultin_CreateRes (par); + smultin_MultinomialBitsOver (gen, par, res, 20, 2097152, 0, 32, 20, + TRUE); + bbattery_pVal[++j] = res->pVal2[0][gofw_AD]; + TestNumber[j] = ++j2; + strcpy (bbattery_TestNames[j], "MultinomialBitsOver"); + smultin_DeleteRes (res); + smultin_DeleteParam (par); + } + { + smarsa_Res *res; + res = smarsa_CreateRes (); + ++j2; + for (i = 22; i >= 0; i--) { + smarsa_Opso (gen, res, 1, i, 1); + bbattery_pVal[++j] = res->Pois->pVal2; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "OPSO"); + } + ValDelta[0] = -1.0; + ++j2; + for (i = 27; i >= 0; i--) { + if (swrite_Basic) + printf ("***********************************************************\n" + "Test OQSO calling smarsa_CollisionOver\n\n"); + smarsa_CollisionOver (gen, res, 1, 2097152, i, 32, 4); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "OQSO"); + } + ++j2; + for (i = 30; i >= 0; i--) { + if (swrite_Basic) + printf ("***********************************************************\n" + "Test DNA calling smarsa_CollisionOver\n\n"); + smarsa_CollisionOver (gen, res, 1, 2097152, i, 4, 10); + bbattery_pVal[++j] = res->Bas->pVal2[gofw_Mean]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "DNA"); + } + smarsa_DeleteRes (res); + } + j2 += 2; + { + snpair_Res *res; + res = snpair_CreateRes (); + snpair_ClosePairs (gen, res, 100, 8000, 0, 2, 2, 1); + bbattery_pVal[++j] = res->pVal[snpair_NP]; + TestNumber[j] = ++j2; + strcpy (bbattery_TestNames[j], "ClosePairs"); + + snpair_ClosePairs (gen, res, 20, 4000, 0, 3, 2, 1); + bbattery_pVal[++j] = res->pVal[snpair_NP]; + TestNumber[j] = ++j2; + strcpy (bbattery_TestNames[j], "ClosePairs"); + snpair_DeleteRes (res); + } + { + sres_Chi2 *res; + res = sres_CreateChi2 (); + smarsa_Savir2 (gen, res, 1, 100000, 0, 90000, 18); + bbattery_pVal[++j] = res->pVal2[gofw_Mean]; + TestNumber[j] = ++j2; + strcpy (bbattery_TestNames[j], "Savir2"); + + ++j2; + sknuth_Run (gen, res, 10, 10000, 0, TRUE); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = ++j2; + strcpy (bbattery_TestNames[j], "Run of U01"); + + sknuth_Run (gen, res, 10, 10000, 0, FALSE); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of U01"); + + sknuth_Run (gen, res, 10, 10000, 0, TRUE); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + TestNumber[j] = j2; + strcpy (bbattery_TestNames[j], "Run of U01"); + + sknuth_Run (gen, res, 10, 10000, 0, FALSE); + bbattery_pVal[++j] = res->pVal2[gofw_Sum]; + strcpy (bbattery_TestNames[j], "Run of U01"); + TestNumber[j] = j2; + sres_DeleteChi2 (res); + } + + bbattery_NTests = ++j; + GetName (gen, genName); + WriteReport (genName, "pseudoDIEHARD", bbattery_NTests, bbattery_pVal, + Timer, FALSE, FALSE, 0.0); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static double ProbabiliteLHR (long j, double Lnl) +/* + * Returns the probability that the longest series of successive 1 has + * length = j. + */ +{ + double x, temp; + temp = (j + 1) * num_Ln2 - Lnl; + x = exp (-exp (-temp)); + temp += num_Ln2; + x = exp (-exp (-temp)) - x; + return x; +} + +/*-------------------------------------------------------------------------*/ + +static double GetPLongest (int longest) +/* + * Get the probabilities for the longest run of 1 or 0 over 20000 bits. + */ +{ + double pLeft, pRight; + double LnLen; + int j; + + LnLen = log (20000.0); + pLeft = 0.0; + for (j = 0; j < longest; j++) + pLeft += ProbabiliteLHR (j, LnLen); + pRight = 1.0 - pLeft; + pLeft += ProbabiliteLHR (longest, LnLen); + return gofw_pDisc (pLeft, pRight); +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteReportFIPS_140_2 ( + char *genName, /* Generator or file name */ + lebool Flag, /* = TRUE for a file, FALSE for a gen */ + int nbit, /* Number of bits */ + int longest0, /* Longest string of 0 */ + int longest1, /* Longest string of 1 */ + int nrun0[], /* Number of 0 runs */ + int nrun1[], /* Number of 1 runs */ + int ncount[] /* Number of 4 bits values */ + ) +{ + int i, j; + double X; + fmass_INFO Q; + double p, pLeft, pRight; + lebool failFlag = FALSE; + + printf + ("\n============== Summary results of FIPS-140-2 ==============\n\n"); + if (Flag) { + printf (" File: "); + } else { + printf (" Generator: "); + } + printf ("%s", genName); + printf ("\n Number of bits: 20000\n"); + + printf ("\n Test s-value p-value FIPS Decision\n"); + printf (" --------------------------------------------------------\n"); + + /* Monobit results */ + j = 0; + printf (" %-20s", bbattery_TestNames[j]); + printf (" %5d ", nbit); + Q = fmass_CreateBinomial (20000, 0.5, 0.5); + pLeft = fdist_Binomial2 (Q, nbit); + pRight = fbar_Binomial2 (Q, nbit); + fmass_DeleteBinomial (Q); + p = gofw_pDisc (pLeft, pRight); + gofw_Writep0 (p); + if ((nbit <= 9725) || nbit >= 10275) { + printf (" %10s", "Fail"); + failFlag = TRUE; + } else + printf (" %10s", "Pass"); + + printf ("\n"); + + /* Poker results */ + X = 0; + for (i = 0; i < 16; i++) + X += (double) ncount[i] * ncount[i]; + X = 16 * X / 5000 - 5000; + j = 1; + printf (" %-16s", bbattery_TestNames[j]); + printf ("%10.2f ", X); + p = fbar_ChiSquare2 (15, 12, X); + gofw_Writep0 (p); + if ((X <= 2.16) || X >= 46.17) { + printf (" %10s", "Fail"); + failFlag = TRUE; + } else + printf (" %10s", "Pass"); + printf ("\n\n"); + + /* Run results */ + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun0[1]); + if ((nrun0[1] <= 2315) || nrun0[1] >= 2685) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun0[2]); + if ((nrun0[2] <= 1114) || nrun0[2] >= 1386) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun0[3]); + if ((nrun0[3] <= 527) || nrun0[3] >= 723) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun0[4]); + if ((nrun0[4] <= 240) || nrun0[4] >= 384) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun0[5]); + if ((nrun0[5] <= 103) || nrun0[5] >= 209) { + failFlag = TRUE; + printf (" %25s", "Fail"); + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun0[6]); + if ((nrun0[6] <= 103) || nrun0[6] >= 209) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun1[1]); + if ((nrun1[1] <= 2315) || nrun1[1] >= 2685) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun1[2]); + if ((nrun1[2] <= 1114) || nrun1[2] >= 1386) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun1[3]); + if ((nrun1[3] <= 527) || nrun1[3] >= 723) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun1[4]); + if ((nrun1[4] <= 240) || nrun1[4] >= 384) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun1[5]); + if ((nrun1[5] <= 103) || nrun1[5] >= 209) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d", nrun1[6]); + if ((nrun1[6] <= 103) || nrun1[6] >= 209) { + printf (" %25s", "Fail"); + failFlag = TRUE; + } else + printf (" %25s", "Pass"); + printf ("\n\n"); + + /* Longest run results */ + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d ", longest0); + p = GetPLongest (longest0); + gofw_Writep0 (p); + if (longest0 >= 26) { + printf (" %10s", "Fail"); + failFlag = TRUE; + } else + printf (" %10s", "Pass"); + printf ("\n"); + + printf (" %-20s", bbattery_TestNames[++j]); + printf (" %5d ", longest1); + p = GetPLongest (longest1); + gofw_Writep0 (p); + if (longest1 >= 26) { + printf (" %10s", "Fail"); + failFlag = TRUE; + } else + printf (" %10s", "Pass"); + printf ("\n"); + + if (!failFlag) { + printf (" ----------------------------------------------------------\n"); + printf (" All values are within the required intervals of FIPS-140-2\n"); + } + printf ("\n\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +#define SAMPLE 625 /* 625 * 32 = 20000 */ +#define MASK4 15 /* Mask of 4 bits */ + +static void FIPS_140_2 (unif01_Gen * gen, char *filename) +{ + int i, j; + int nbit = 0; /* Number of bits */ + int longest0 = 0; /* Longest string of 0 */ + int longest1 = 0; /* Longest string of 1 */ + int nrun0[7] = { 0 }; /* Number of 0 runs */ + int nrun1[7] = { 0 }; /* Number of 1 runs */ + int ncount[16] = { 0 }; /* Number of 4 bits values */ + int prevBit; /* Previous bit */ + int len = 0; /* Length of run */ + unsigned long jBit; /* Current bit */ + unsigned long Z; /* Block of 32 bits */ + unsigned long Bits[SAMPLE + 1]; + lebool fileFlag = FALSE; + char genName[LEN + 1] = ""; + + InitBat (); + if (swrite_Basic) { + printf ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " Starting FIPS_140_2\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n"); + } + util_Assert (NULL == gen || NULL == filename, + "bbattery_FIPS_140_2: one of gen or filename must be NULL"); + util_Assert (!(NULL == gen && NULL == filename), + "bbattery_FIPS_140_2: no generator and no file"); + util_Assert (!(NULL == gen && !(strcmp (filename, ""))), + "bbattery_FIPS_140_2: no generator and no file"); + + if ((NULL == gen) && filename && strcmp (filename, "")) { + gen = ufile_CreateReadBin (filename, SAMPLE); + fileFlag = TRUE; + } + + for (j = 0; j < SAMPLE; j++) + Bits[j] = unif01_StripB (gen, 0, 32); + + if (fileFlag) { + ufile_DeleteReadBin (gen); + strncpy (genName, filename, (size_t) LEN); + } else { + GetName (gen, genName); + } + + /* Make sure to count the first run; set prevBit != {0, 1} */ + prevBit = 2; + + for (j = 0; j < SAMPLE; j++) { + /* Count the number of 1 */ + Z = Bits[j]; + while (Z > 0) { + Z &= Z - 1; /* Clear lowest 1 bit */ + ++nbit; + } + + /* Count the number of 4 bits values */ + Z = Bits[j]; + for (i = 0; i < 8; i++) { + (ncount[Z & MASK4])++; + Z >>= 4; + } + + /* Count the number of runs and get the longest runs */ + Z = Bits[j]; + jBit = bitset_maskUL[31]; + + while (jBit > 0) { + if (Z & jBit) { /* bit 1 */ + if (prevBit != 1) { + if (len < 6) + (nrun0[len])++; + else + (nrun0[6])++; + if (len > longest0) + longest0 = len; + len = 1; + } else { + len++; + } + prevBit = 1; + + } else { /* bit 0 */ + if (prevBit != 0) { + if (len < 6) + (nrun1[len])++; + else + (nrun1[6])++; + if (len > longest1) + longest1 = len; + len = 1; + } else { + len++; + } + prevBit = 0; + } + jBit >>= 1; + } + } + + strcpy (bbattery_TestNames[0], "Monobit"); + strcpy (bbattery_TestNames[1], "Poker"); + j = 1; + strcpy (bbattery_TestNames[++j], "0 Runs, length 1: "); + strcpy (bbattery_TestNames[++j], "0 Runs, length 2: "); + strcpy (bbattery_TestNames[++j], "0 Runs, length 3: "); + strcpy (bbattery_TestNames[++j], "0 Runs, length 4: "); + strcpy (bbattery_TestNames[++j], "0 Runs, length 5: "); + strcpy (bbattery_TestNames[++j], "0 Runs, length 6+: "); + strcpy (bbattery_TestNames[++j], "1 Runs, length 1: "); + strcpy (bbattery_TestNames[++j], "1 Runs, length 2: "); + strcpy (bbattery_TestNames[++j], "1 Runs, length 3: "); + strcpy (bbattery_TestNames[++j], "1 Runs, length 4: "); + strcpy (bbattery_TestNames[++j], "1 Runs, length 5: "); + strcpy (bbattery_TestNames[++j], "1 Runs, length 6+: "); + + strcpy (bbattery_TestNames[++j], "Longest run of 0: "); + strcpy (bbattery_TestNames[++j], "Longest run of 1: "); + + WriteReportFIPS_140_2 (genName, fileFlag, nbit, longest0, longest1, + nrun0, nrun1, ncount); +} + + +/*-------------------------------------------------------------------------*/ + +void bbattery_FIPS_140_2 (unif01_Gen * gen) +{ + FIPS_140_2 (gen, NULL); +} + + +/*-------------------------------------------------------------------------*/ + +void bbattery_FIPS_140_2File (char *filename) +{ + FIPS_140_2 (NULL, filename); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/bbattery.tex b/TESTU01/TestU01-1.2.3/testu01/bbattery.tex new file mode 100644 index 0000000..82a7aad --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/bbattery.tex @@ -0,0 +1,1127 @@ +\defmodule {bbattery} + +This module contains predefined batteries of statistical tests for +sources of random bits or sequences of uniform random numbers in +the interval $[0, 1)$. +\hpierre{The choice of tests and parameters in these batteries is + subject to change in the near future, + following further experimentations.} +To test a RNG for general use, one could first apply the +small and fast battery {\tt SmallCrush}. +If it passes, one could then apply the more stringent battery +{\tt Crush}, and finally the yet more time-consuming +battery {\tt BigCrush}. +The batteries {\tt Alphabit} and {\tt Rabbit} can be applied on a binary +file considered as a source of random bits. They can also be applied +on a programmed generator. {\tt Alphabit} has been defined primarily to test +{\it hardware} random bits generators. +The battery {PseudoDIEHARD} applies most of the tests in +the well-known {\it DIEHARD\/} suite of Marsaglia \cite{rMAR96b}. +The battery {\tt FIPS\_140\_2} implements the small suite of tests +of the {\it FIPS-140-2} standard from NIST. + +The batteries described in this module will write the results of each test +(on standard output) with a standard level of details (assuming that the + boolean switches of module {\tt swrite} have their default values), +followed by a summary report of the suspect $p$-values obtained from the + specific tests included in the batteries. +It is also possible to get only the summary report in the output, +with no detailed output from the tests, +by setting the boolean switch {\tt swrite\_Basic} to {\tt FALSE}. + +Some of the tests compute more than one statistic using the same stream of +random numbers and these statistics are thus not independent. +\emph{That is why the number of statistics in the summary reports is larger than +the number of tests in the description of the batteries.} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* bbattery.h for ANSI C */ +#ifndef BBATTERY_H +#define BBATTERY_H +\endhide +#include "unif01.h" + + +extern int bbattery_NTests; +\endcode + \tab The maximum number of $p$-values in the array {\tt bbattery\_pVal}. + For small sample size, some of the tests in the battery may not be done. + Furthermore, some of the tests computes more than one statistic and + its $p$-value, so {\tt bbattery\_NTests} will usually be larger than + the number of tests in the battery. + \endtab +\code + + +extern double bbattery_pVal[]; +\endcode + \tab This array keeps the $p$-values resulting from the battery of tests + that is currently applied (or the last one that has been called). It is + used by any battery in this module. The $p$-value of the $j$-th test in + the battery is kept in {\tt bbattery\_pVal[$j-1$]}, for $1\le j\le $ + {\tt bbattery\_NTests}. +%% When a particular test in the battery +%% is not done (because the sample size is too small), then the +%% corresponding $p$-value is set to $-1$. + \endtab +\code + + +extern char *bbattery_TestNames[]; +\endcode + \tab This array keeps the names of each test from the + battery that is currently applied (or the last one that has + been called). It is used by any battery in this module. + The name of the $j$-th test in the battery is + kept in {\tt bbattery\_TestNames[$j-1$]}, + for $1\le j\le $ {\tt bbattery\_NTests}. + \endtab + + +\guisec{The batteries of tests} + +\code + +void bbattery_SmallCrush (unif01_Gen *gen); + +void bbattery_SmallCrushFile (char *filename); +\endcode + \tab Both functions applies {\tt SmallCrush}, a small and fast battery + of tests, to a RNG. The function {\tt bbattery\_Small\-CrushFile} applies + {\tt SmallCrush} to a RNG given as a text file of floating-point numbers in + $[0, 1)$; the file requires slightly less than 51320000 random numbers. + \label{bat:SmallCrush} + The file will be rewound to the beginning before each test. + \index{SmallCrush}\index{battery of tests!SmallCrush}% + Thus {\tt bbattery\_SmallCrush} applies the tests on one unbroken + stream of successive numbers, while {\tt bbattery\_Small\-CrushFile} + applies each test on the same sequence of numbers. + Some of these tests assume that {\tt gen} returns at least 30 bits of + resolution; if this is not the case, then the generator is most likely to + fail these particular tests. + + The following tests are applied: + \endtab + \begin{enumerate} + \item {\tt smarsa\_BirthdaySpacings} with $N=1$, $n=5*10^6$, $r=0$, + $d = 2^{30}$, $t=2$, $p=1$. + + \item {\tt sknuth\_Collision} with $N=1$, $n=5*10^6$, $r=0$, + $d = 2^{16}$, $t=2$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=2*10^5$, $r=22$, {\tt Alpha} $=0$, + {\tt Beta} $=1/256$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=4*10^5$, $r=24$, + $d = 64$, $k=64$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=5*10^5$, $r=26$, + $d=16$. + + \item {\tt sknuth\_MaxOft} with $N=1$, $n=2*10^6$, $r=0$, + $d = 10^5$, $t=6$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^5$, $r=27$, + $k=256$, {\tt Alpha} $=0$, {\tt Beta} $=1/8$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=20000$, $r=20$, $s=10$, + $L = k=60$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=5*10^5$, $r=20$, $s=10$, + $L = 300$, $d = 0$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^6$, $r=0$, $s=30$, + $L_0 = 150$, $L_1=150$. + + \end{enumerate} + +\code + + +void bbattery_RepeatSmallCrush (unif01_Gen *gen, int rep[]); +\endcode + \tab This function applies specific tests of {\tt SmallCrush} on + generator {\tt gen}. Test numbered $i$ in the enumeration above will + be applied {\tt rep[$i$]} times successively on {\tt gen}. Those tests with + {\tt rep[$i$]} = 0 will not be applied. This is useful when a test in + {\tt SmallCrush} had a suspect $p$-value, and one wants to reapply the + test a few more times to find out whether the generator failed + the test or whether the suspect $p$-value was a statistical fluke. + Restriction: Array {\tt rep} must have one more element than the + number of tests in {\tt SmallCrush}. + \endtab +\bigskip + +\hrule +\code + + +void bbattery_Crush (unif01_Gen *gen); +\endcode + \tab + Applies the battery {\tt Crush}, a suite of stringent statistical + tests, to the generator {\tt gen}. + \index{Crush}\index{battery of tests!Crush}% + The battery includes the classical tests described in Knuth \cite{rKNU98a} + as well as many other tests. Some of these tests assume that + {\tt gen} returns at least 30 bits of resolution; if that + is not the case, then the generator will certainly + fail these particular tests. One test requires 31 bits of resolution: + the {\tt BirthdaySpacings} test with $t=2$. + On a PC with an AMD Athlon 64 Processor 4000+ + of clock speed 2400 MHz running with Red Hat Linux, Crush + will require around 1 hour of CPU time. {\tt Crush} uses approximately + $2^{35}$ random numbers. +%% Some of the tests will require as much as 350 Megs of RAM memory. + The following tests are applied: \label{bat:Crush} + \endtab + + \begin{enumerate} + \item {\tt smarsa\_SerialOver} with $N=1$, $n=5*10^8$, $r=0$, + $d = 2^{12}$, $t=2$. + + \item {\tt smarsa\_SerialOver} with $N=1$, $n=3*10^8$, $r=0$, + $d = 2^6$, $t=4$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=0$, + $d = 2^{20}$, $t=2$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=10$, + $d = 2^{20}$, $t=2$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=0$, + $d = 2^{10}$, $t=4$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=20$, + $d = 2^{10}$, $t=4$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=0$, + $d = 32$, $t=8$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=25$, + $d = 32$, $t=8$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=0$, + $d = 4$, $t=20$. + + \item {\tt smarsa\_CollisionOver} with $N=10$, $n=10^7$, $r=28$, + $d = 4$, $t=20$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=5$, $n=2*10^7$, $r=0$, + $d = 2^{31}$, $t=2$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=5$, $n=2*10^7$, $r=0$, + $d = 2^{21}$, $t=3$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=5$, $n=2*10^7$, $r=0$, + $d = 2^{16}$, $t=4$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=3$, $n=2*10^7$, $r=0$, + $d = 2^{9}$, $t=7$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=3$, $n=2*10^7$, $r=7$, + $d = 2^{9}$, $t=7$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=3$, $n=2*10^7$, $r=14$, + $d = 2^{8}$, $t=8$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=3$, $n=2*10^7$, $r=22$, + $d = 2^{8}$, $t=8$, $p=1$. + + \item {\tt snpair\_ClosePairs} with $N=10$, $n=2*10^6$, $r=0$, $t=2$, + $p=0$, $m=30$. + + \item {\tt snpair\_ClosePairs} with $N=10$, $n=2*10^6$, $r=0$, $t=3$, + $p=0$, $m=30$. + + \item {\tt snpair\_ClosePairs} with $N=5$, $n=2*10^6$, $r=0$, $t=7$, + $p=0$, $m=30$. + + \item {\tt snpair\_ClosePairsBitMatch} with $N=4$, $n=4*10^6$, + $r=0$, $t=2$. + + \item {\tt snpair\_ClosePairsBitMatch} with $N=2$, $n=4*10^6$, + $r=0$, $t=4$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=4*10^7$, $r=0$, $d=16$, $k=16$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=4*10^7$, $r=26$, $d=16$, $k=16$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=10^7$, $r=0$, $d=64$, $k=64$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=10^7$, $r=24$, $d=64$, $k=64$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=4*10^7$, $r=0$, $d=4$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=4*10^7$, $r=28$, $d=4$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=10^7$, $r=0$, $d=16$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=10^7$, $r=26$, $d=16$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=10^8$, $r=0$, {\tt Alpha} $=0$, + {\tt Beta} $=1/8$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=10^8$, $r=27$, {\tt Alpha} $=0$, + {\tt Beta} $=1/8$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=5*10^6$, $r=0$, {\tt Alpha} $=0$, + {\tt Beta} $=1/256$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=5*10^6$, $r=22$, {\tt Alpha} $=0$, + {\tt Beta} $=1/256$. + + \item {\tt sknuth\_Run} with $N=1$, $n=5*10^8$, $r=0$, {\tt Up = TRUE}. + + \item {\tt sknuth\_Run} with $N=1$, $n=5*10^8$, $r=15$, {\tt Up = FALSE}. + + \item {\tt sknuth\_Permutation} with $N=1$, $n=5*10^7$, $r=0$, $t=10$. + + \item {\tt sknuth\_Permutation} with $N=1$, $n=5*10^7$, $r=15$, $t=10$. + + \item {\tt sknuth\_CollisionPermut} with $N=5$, $n=10^7$, $r=0$, $t=13$. + + \item {\tt sknuth\_CollisionPermut} with $N=5$, $n=10^7$, $r=15$, $t=13$. + + \item {\tt sknuth\_MaxOft} with $N=10$, $n=10^7$, $r=0$, $d=10^5$, $t=5$. + + \item {\tt sknuth\_MaxOft} with $N=5$, $n=10^7$, $r=0$, $d=10^5$, $t=10$. + + \item {\tt sknuth\_MaxOft} with $N=1$, $n=10^7$, $r=0$, $d=10^5$, $t=20$. + + \item {\tt sknuth\_MaxOft} with $N=1$, $n=10^7$, $r=0$, $d=10^5$, $t=30$. + + \item {\tt svaria\_SampleProd} with $N=1$, $n=10^7$, $r=0$, $t=10$. + + \item {\tt svaria\_SampleProd} with $N=1$, $n=10^7$, $r=0$, $t=30$. + + \item {\tt svaria\_SampleMean} with $N=10^7$, $n=20$, $r=0$. + + \item {\tt svaria\_SampleCorr} with $N=1$, $n=5*10^8$, $r=0$, $k=1$. + + \item {\tt svaria\_AppearanceSpacings} with $N=1$, $Q=10^7$, $K=4*10^8$, + $r=0$, $s=30$, $L=15$. + + \item {\tt svaria\_AppearanceSpacings} with $N=1$, $Q=10^7$, $K=10^8$, + $r=20$, $s=10$, $L=15$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^6$, $r=0$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/8$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^6$, $r=8$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/8$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^6$, $r=16$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/8$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^6$, $r=24$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/8$. + + \item {\tt svaria\_SumCollector} with $N=1$, $n=2*10^7$, $r=0$, $g=10$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=10^6$, $r=0$, + $s=30$, $L=k=60$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=10^6$, $r=20$, + $s=10$, $L=k=60$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=50000$, $r=0$, + $s=30$, $L=k=300$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=50000$, $r=20$, + $s=10$, $L=k=300$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=2000$, $r=0$, + $s=30$, $L=k=1200$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=2000$, $r=20$, + $s=10$, $L=k=1200$. + + \item {\tt smarsa\_Savir2} with $N=1$, $n=2*10^7$, $r=0$, $m=2^{20}$, $t=30$. + + \item {\tt smarsa\_GCD} with $N=1$, $n=10^8$, $r=0$, $s=30$. + + \item {\tt smarsa\_GCD} with $N=1$, $n=4*10^7$, $r=10$, $s=20$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=5*10^7$, $r=0$, + $s=30$, $L_0=L_1=90$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^7$, $r=20$, + $s=10$, $L_0=L_1=90$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=5*10^6$, $r=0$, + $s=30$, $L_0=L_1=1000$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^6$, $r=20$, + $s=10$, $L_0=L_1=1000$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=5*10^5$, $r=0$, + $s=30$, $L_0=L_1=10000$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^5$, $r=20$, + $s=10$, $L_0=L_1=10000$. + + \item {\tt scomp\_LinearComp} with $N=1$, $n=120000$, $r=0$, $s=1$. + + \item {\tt scomp\_LinearComp} with $N=1$, $n=120000$, $r=29$, $s=1$. + + \item {\tt scomp\_LempelZiv} with $N=10$, $k=25$, $r=0$, $s=30$. + + \item {\tt sspectral\_Fourier3} with $N=50000$, $k=14$, $r=0$, $s=30$. + + \item {\tt sspectral\_Fourier3} with $N=50000$, $k=14$, $r=20$, $s=10$. + + \item {\tt sstring\_LongestHeadRun} with $N=1$, $n=1000$, $r=0$, + $s=30$, $L=10^7$. + + \item {\tt sstring\_LongestHeadRun} with $N=1$, $n=300$, $r=20$, + $s=10$, $L=10^7$. + + \item {\tt sstring\_PeriodsInStrings} with $N=1$, $n=3*10^8$, $r=0$, + $s=30$. + + \item {\tt sstring\_PeriodsInStrings} with $N=1$, $n=3*10^8$, $r=15$, + $s=15$. + + \item {\tt sstring\_HammingWeight2} with $N=100$, $n=10^8$, $r=0$, + $s=30$, $L=10^6$. + + \item {\tt sstring\_HammingWeight2} with $N=30$, $n=10^8$, $r=20$, + $s=10$, $L=10^6$. + + \item {\tt sstring\_HammingCorr} with $N=1$, $n=5*10^8$, $r=0$, + $s=30$, $L=30$. + + \item {\tt sstring\_HammingCorr} with $N=1$, $n=5*10^7$, $r=0$, + $s=30$, $L=300$. + + \item {\tt sstring\_HammingCorr} with $N=1$, $n=10^7$, $r=0$, + $s=30$, $L=1200$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=3*10^8$, $r=0$, + $s=30$, $L=30$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=10^8$, $r=20$, + $s=10$, $L=30$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=3*10^7$, $r=0$, + $s=30$, $L=300$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=10^7$, $r=20$, + $s=10$, $L=300$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=10^7$, $r=0$, + $s=30$, $L=1200$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=10^6$, $r=20$, + $s=10$, $L=1200$, $d=0$. + + \item {\tt sstring\_Run} with $N=1$, $n=10^9$, $r=0$, $s=30$. + + \item {\tt sstring\_Run} with $N=1$, $n=10^9$, $r=20$, $s=10$. + + \item {\tt sstring\_AutoCor} with $N=10$, $n=10^9$, $r=0$, $s=30$, + $d=1$. + + \item {\tt sstring\_AutoCor} with $N=5$, $n=10^9$, $r=20$, $s=10$, + $d=1$. + + \item {\tt sstring\_AutoCor} with $N=10$, $n=10^9$, $r=0$, $s=30$, + $d=30$. + + \item {\tt sstring\_AutoCor} with $N=5$, $n=10^9$, $r=20$, $s=10$, + $d=10$. + +\end{enumerate} + +\code + + +void bbattery_RepeatCrush (unif01_Gen *gen, int rep[]); +\endcode + \tab Similar to {\tt bbattery\_RepeatSmallCrush} above but applied on + {\tt Crush}. + \endtab +\bigskip + +\hrule +\code + + +void bbattery_BigCrush (unif01_Gen *gen); +\endcode + \tab + Applies the battery {\tt BigCrush}, a suite of very stringent statistical + tests, to the generator {\tt gen}. + \index{BigCrush}\index{battery of tests!BigCrush}% + Some of these tests assume that {\tt gen} returns at least 30 bits of + resolution; if that is not the case, then the generator will certainly + fail these particular tests. One test requires 31 bits of resolution: + the {\tt BirthdaySpacings} test with $t=2$. + On a PC with an AMD Athlon 64 Processor 4000+ + of clock speed 2400 MHz running with Linux, BigCrush + will take around 8 hours of CPU time. {\tt BigCrush} uses close to + $2^{38}$ random numbers. + The following tests are applied:\label{bat:BigCrush} + \endtab + + \begin{enumerate} + \item {\tt smarsa\_SerialOver} with $N=1$, $n=10^9$, $r=0$, + $d = 2^{8}$, $t=3$. + + \item {\tt smarsa\_SerialOver} with $N=1$, $n=10^9$, $r=22$, + $d = 2^{8}$, $t=3$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=0$, + $d = 2^{21}$, $t=2$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=9$, + $d = 2^{21}$, $t=2$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=0$, + $d = 2^{14}$, $t=3$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=16$, + $d = 2^{14}$, $t=3$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=0$, + $d = 64$, $t=7$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=24$, + $d = 64$, $t=7$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=0$, + $d = 8$, $t=14$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=27$, + $d = 8$, $t=14$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=0$, + $d =4$, $t=21$. + + \item {\tt smarsa\_CollisionOver} with $N=30$, $n=2*10^7$, $r=28$, + $d =4$, $t=21$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=100$, $n=10^7$, $r=0$, + $d = 2^{31}$, $t=2$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=2*10^7$, $r=0$, + $d = 2^{21}$, $t=3$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=3*10^7$, $r=14$, + $d = 2^{16}$, $t=4$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=2*10^7$, $r=0$, + $d = 2^{9}$, $t=7$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=2*10^7$, $r=7$, + $d = 2^{9}$, $t=7$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=3*10^7$, $r=14$, + $d = 2^{8}$, $t=8$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=3*10^7$, $r=22$, + $d = 2^{8}$, $t=8$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=3*10^7$, $r=0$, + $d = 2^{4}$, $t=16$, $p=1$. + + \item {\tt smarsa\_BirthdaySpacings} with $N=20$, $n=3*10^7$, $r=26$, + $d = 2^{4}$, $t=16$, $p=1$. + + \item {\tt snpair\_ClosePairs} with $N=30$, $n=6*10^6$, $r=0$, $t=3$, + $p=0$, $m=30$. + + \item {\tt snpair\_ClosePairs} with $N=20$, $n=4*10^6$, $r=0$, $t=5$, + $p=0$, $m=30$. + + \item {\tt snpair\_ClosePairs} with $N=10$, $n=3*10^6$, $r=0$, $t=9$, + $p=0$, $m=30$. + + \item {\tt snpair\_ClosePairs} with $N=5$, $n=2*10^6$, $r=0$, $t=16$, + $p=0$, $m=30$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=4*10^8$, $r=0$, $d=8$, $k=8$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=4*10^8$, $r=27$, $d=8$, $k=8$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=10^8$, $r=0$, $d=32$, $k=32$. + + \item {\tt sknuth\_SimpPoker} with $N=1$, $n=10^8$, $r=25$, $d=32$, $k=32$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=2*10^8$, $r=0$, $d=8$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=2*10^8$, $r=10$, $d=8$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=2*10^8$, $r=20$, $d=8$. + + \item {\tt sknuth\_CouponCollector} with $N=1$, $n=2*10^8$, $r=27$, $d=8$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=5*10^8$, $r=0$, {\tt Alpha} $=0$, + {\tt Beta} $=1/16$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=3*10^8$, $r=25$, {\tt Alpha} $=0$, + {\tt Beta} $=1/32$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=10^8$, $r=0$, {\tt Alpha} $=0$, + {\tt Beta} $=1/128$. + + \item {\tt sknuth\_Gap} with $N=1$, $n=10^7$, $r=20$, {\tt Alpha} $=0$, + {\tt Beta} $=1/1024$. + + \item {\tt sknuth\_Run} with $N=5$, $n=10^9$, $r=0$, {\tt Up = FALSE}. + + \item {\tt sknuth\_Run} with $N=5$, $n=10^9$, $r=15$, {\tt Up = TRUE}. + + \item {\tt sknuth\_Permutation} with $N=1$, $n=10^9$, $r=0$, $t=3$. + + \item {\tt sknuth\_Permutation} with $N=1$, $n=10^9$, $r=0$, $t=5$. + + \item {\tt sknuth\_Permutation} with $N=1$, $n=5*10^8$, $r=0$, $t=7$. + + \item {\tt sknuth\_Permutation} with $N=1$, $n=5*10^8$, $r=10$, $t=10$. + + \item {\tt sknuth\_CollisionPermut} with $N=20$, $n=2*10^7$, $r=0$, $t=14$. + + \item {\tt sknuth\_CollisionPermut} with $N=20$, $n=2*10^7$, $r=10$, $t=14$. + + \item {\tt sknuth\_MaxOft} with $N=40$, $n=10^7$, $r=0$, $d=10^5$, $t=8$. + + \item {\tt sknuth\_MaxOft} with $N=30$, $n=10^7$, $r=0$, $d=10^5$, $t=16$. + + \item {\tt sknuth\_MaxOft} with $N=20$, $n=10^7$, $r=0$, $d=10^5$, $t=24$. + + \item {\tt sknuth\_MaxOft} with $N=20$, $n=10^7$, $r=0$, $d=10^5$, $t=32$. + + \item {\tt svaria\_SampleProd} with $N=40$, $n=10^7$, $r=0$, $t=8$. + + \item {\tt svaria\_SampleProd} with $N=20$, $n=10^7$, $r=0$, $t=16$. + + \item {\tt svaria\_SampleProd} with $N=20$, $n=10^7$, $r=0$, $t=24$. + + \item {\tt svaria\_SampleMean} with $N=2*10^7$, $n=30$, $r=0$. + + \item {\tt svaria\_SampleMean} with $N=2*10^7$, $n=30$, $r=10$. + + \item {\tt svaria\_SampleCorr} with $N=1$, $n=2*10^9$, $r=0$, $k=1$. + + \item {\tt svaria\_SampleCorr} with $N=1$, $n=2*10^9$, $r=0$, $k=2$. + + \item {\tt svaria\_AppearanceSpacings} with $N=1$, $Q=10^7$, $K=10^9$, + $r=0$, $s=3$, $L=15$. + + \item {\tt svaria\_AppearanceSpacings} with $N=1$, $Q=10^7$, $K=10^9$, + $r=27$, $s=3$, $L=15$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^7$, $r=0$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/4$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^7$, $r=20$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/4$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^7$, $r=28$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/4$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^7$, $r=0$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/16$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^7$, $r=10$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/16$. + + \item {\tt svaria\_WeightDistrib} with $N=1$, $n=2*10^7$, $r=26$, $k=256$, + {\tt Alpha} $=0$, {\tt Beta} $=1/16$. + + \item {\tt svaria\_SumCollector} with $N=1$, $n=5*10^8$, $r=0$, $g=10$. + + \item {\tt smarsa\_MatrixRank} with $N=10$, $n=10^6$, $r=0$, + $s=5$, $L=k=30$. + + \item {\tt smarsa\_MatrixRank} with $N=10$, $n=10^6$, $r=25$, + $s=5$, $L=k=30$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=5000$, $r=0$, + $s=4$, $L=k=1000$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=5000$, $r=26$, + $s=4$, $L=k=1000$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=80$, $r=15$, + $s=15$, $L=k=5000$. + + \item {\tt smarsa\_MatrixRank} with $N=1$, $n=80$, $r=0$, + $s=30$, $L=k=5000$. + + \item {\tt smarsa\_Savir2} with $N=10$, $n=10^7$, $r=10$, $m=2^{20}$, $t=30$. + + \item {\tt smarsa\_GCD} with $N=10$, $n=5*10^7$, $r=0$, $s=30$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^8$, $r=0$, + $s=5$, $L_0=L_1=50$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^8$, $r=25$, + $s=5$, $L_0=L_1=50$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^7$, $r=0$, + $s=10$, $L_0=L_1=1000$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^7$, $r=20$, + $s=10$, $L_0=L_1=1000$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^6$, $r=0$, + $s=15$, $L_0=L_1=10000$. + + \item {\tt swalk\_RandomWalk1} with $N=1$, $n=10^6$, $r=15$, + $s=15$, $L_0=L_1=10000$. + + \item {\tt scomp\_LinearComp} with $N=1$, $n=400000$, $r=0$, $s=1$. + + \item {\tt scomp\_LinearComp} with $N=1$, $n=400000$, $r=29$, $s=1$. + + \item {\tt scomp\_LempelZiv} with $N=10$, $k=27$, $r=0$, $s=30$. + + \item {\tt scomp\_LempelZiv} with $N=10$, $k=27$, $r=15$, $s=15$. + + \item {\tt sspectral\_Fourier3} with $N=100000$, $r=0$, $s=3$, $k=14$. + + \item {\tt sspectral\_Fourier3} with $N=100000$, $r=27$, $s=3$, $k=14$. + + \item {\tt sstring\_LongestHeadRun} with $N=1$, $n=1000$, $r=0$, + $s=3$, $L=10^7$. + + \item {\tt sstring\_LongestHeadRun} with $N=1$, $n=1000$, $r=27$, + $s=3$, $L=10^7$. + + \item {\tt sstring\_PeriodsInStrings} with $N=10$, $n=5*10^8$, $r=0$, + $s=10$. + + \item {\tt sstring\_PeriodsInStrings} with $N=10$, $n=5*10^8$, $r=20$, + $s=10$. + + \item {\tt sstring\_HammingWeight2} with $N=10$, $n=10^9$, $r=0$, + $s=3$, $L=10^6$. + + \item {\tt sstring\_HammingWeight2} with $N=10$, $n=10^9$, $r=27$, + $s=3$, $L=10^6$. + + \item {\tt sstring\_HammingCorr} with $N=1$, $n=10^9$, $r=10$, + $s=10$, $L=30$. + + \item {\tt sstring\_HammingCorr} with $N=1$, $n=10^8$, $r=10$, + $s=10$, $L=300$. + + \item {\tt sstring\_HammingCorr} with $N=1$, $n=10^8$, $r=10$, + $s=10$, $L=1200$. + + \item {\tt sstring\_HammingIndep} with $N=10$, $n=3*10^7$, $r=0$, + $s=3$, $L=30$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=10$, $n=3*10^7$, $r=27$, + $s=3$, $L=30$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=3*10^7$, $r=0$, + $s=4$, $L=300$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=3*10^7$, $r=26$, + $s=4$, $L=300$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=10^7$, $r=0$, + $s=5$, $L=1200$, $d=0$. + + \item {\tt sstring\_HammingIndep} with $N=1$, $n=10^7$, $r=25$, + $s=5$, $L=1200$, $d=0$. + + \item {\tt sstring\_Run} with $N=1$, $n=2*10^9$, $r=0$, $s=3$. + + \item {\tt sstring\_Run} with $N=1$, $n=2*10^9$, $r=27$, $s=3$. + + \item {\tt sstring\_AutoCor} with $N=10$, $n=10^9$, $r=0$, $s=3$, + $d=1$. + + \item {\tt sstring\_AutoCor} with $N=10$, $n=10^9$, $r=0$, $s=3$, + $d=3$. + + \item {\tt sstring\_AutoCor} with $N=10$, $n=10^9$, $r=27$, $s=3$, + $d=1$. + + \item {\tt sstring\_AutoCor} with $N=10$, $n=10^9$, $r=27$, $s=3$, + $d=3$. + +\end{enumerate} + +\code + + +void bbattery_RepeatBigCrush (unif01_Gen *gen, int rep[]); +\endcode + \tab Similar to {\tt bbattery\_RepeatSmallCrush} above but applied on + {\tt BigCrush}. + \endtab +\bigskip + + +\bigskip +\hrule +\code + + +void bbattery_Rabbit (unif01_Gen *gen, double nb); +\endcode + \tab Applies the {\tt Rabbit} battery of tests to the generator {\tt gen} + using at most {\tt nb} bits for each test. See the description of the + tests in {\tt bbattery\_RabbitFile}. + \endtab +\code + +void bbattery_RabbitFile (char *filename, double nb); +\endcode + \tab Applies the {\tt Rabbit} battery of tests to the first {\tt nb} + bits (or less, if {\tt nb} is too large) of the binary file + {\tt filename}. + \index{Rabbit}\index{battery of tests!Rabbit}% +% All the following tests are applied on the same sequence of +% bits of the file. + For each test, the file is reset and the test is applied to the bit + stream starting at the beginning of the file. The bits themselves are + processed in nearly all the tests as blocks of 32 bits (unsigned + integers); the two exceptions are {\tt svaria\_AppearanceSpacings}, + which uses blocks of 30 bits (and discards the last 2 bits out of + each block of 32), + and {\tt sstring\_PeriodsInStrings} which uses blocks of 31 bits (and + discards 1 bit out of 32). + The parameters of each test are chosen automatically as a function of + {\tt nb}, in order to make the test reasonably sensitive. +% Constraints are also set on the parameter $n$, because of memory limitations, +% in such a way that no test should normally require more than 420 Megs of memory. +% Thus when {\tt nb} is not too large, the number of replications $N$ is +% chosen equal to 1, and the sample size $n$ is determined as a function of +% {\tt nb}. + On a PC with an Athlon processor of clock speed + 1733 MHz running under Linux, {\tt Rabbit} will take about 5 seconds to + test a stream of $2^{20}$ bits, 90 seconds to test a stream of + $2^{25}$ bits, and 28 minutes to test a stream of + $2^{30}$ bits. + Restriction: {\tt nb} $\ge 500$. + \endtab + +\begin{enumerate} + \item {\tt smultin\_MultinomialBitsOver} + \item {\tt snpair\_ClosePairsBitMatch} in $t=2$ dimensions. + \item {\tt snpair\_ClosePairsBitMatch} in $t=4$ dimensions. + \item {\tt svaria\_AppearanceSpacings} + \item {\tt scomp\_LinearComp} + \item {\tt scomp\_LempelZiv} + \item {\tt sspectral\_Fourier1} + \item {\tt sspectral\_Fourier3} + \item {\tt sstring\_LongestHeadRun} + \item {\tt sstring\_PeriodsInStrings} + \item {\tt sstring\_HammingWeight} with blocks of $L = 32$ bits. + \item {\tt sstring\_HammingCorr} with blocks of $L = 32$ bits. + \item {\tt sstring\_HammingCorr} with blocks of $L = 64$ bits. + \item {\tt sstring\_HammingCorr} with blocks of $L = 128$ bits. + \item {\tt sstring\_HammingIndep} with blocks of $L = 16$ bits. + \item {\tt sstring\_HammingIndep} with blocks of $L = 32$ bits. + \item {\tt sstring\_HammingIndep} with blocks of $L = 64$ bits. + \item {\tt sstring\_AutoCor} with a lag $d = 1$. + \item {\tt sstring\_AutoCor} with a lag $d = 2$. + \item {\tt sstring\_Run} + \item {\tt smarsa\_MatrixRank} with $32 \times 32$ matrices. + \item {\tt smarsa\_MatrixRank} with $320 \times 320$ matrices. + \item {\tt smarsa\_MatrixRank} with $1024 \times 1024$ matrices. + \item {\tt swalk\_RandomWalk1} with walks of length $L = 128$. + \item {\tt swalk\_RandomWalk1} with walks of length $L = 1024$. + \item {\tt swalk\_RandomWalk1} with walks of length $L = 10016$. +\end{enumerate} + +\code + +void bbattery_RepeatRabbit (unif01_Gen *gen, double nb, int rep[]); +\endcode + \tab Similar to {\tt bbattery\_RepeatSmallCrush} above but applied on + {\tt Rabbit}. + \endtab + +\bigskip +\hrule +\code + + +void bbattery_Alphabit (unif01_Gen *gen, double nb, int r, int s); +\endcode + \tab Applies the {\tt Alphabit} battery of tests to the generator {\tt gen} + using at most {\tt nb} bits for each test. The bits themselves are + processed as blocks of 32 bits (unsigned integers). For each block of + 32 bits, the $r$ most significant bits are dropped, and the test is + applied on the $s$ following bits. If one wants to test all bits of + the stream, one should set $r=0$ and $s=32$. If one wants to test only + 1 bit out of 32, one should set $s=1$. + See the description of the tests in {\tt bbattery\_AlphabitFile}. + \endtab +\code + + +void bbattery_AlphabitFile (char *filename, double nb); +\endcode + \tab Applies the {\tt Alphabit} battery of tests to the first {\tt nb} + bits (or less, if {\tt nb} is too large) of the binary file + {\tt filename}. Unlike the {\tt bbattery\_Alphabit} function above, + \index{Alphabit}\index{battery of tests!Alphabit}% +%% all the following tests are applied on the same sequence of +%% bits of the file, as the binary file is rewound + for each test, the file is rewound and the test is applied to the bit + stream starting at the beginning of the file. + On a PC with an Athlon processor of clock speed 1733 MHz running under + Linux, {\tt Alphabit} takes about 4.2 seconds to test a file of + $2^{25}$ bits, and 2.3 minutes to test a file of $2^{30}$ bits. + + {\tt Alphabit} and {\tt AlphabitFile} have been designed primarily to test + {\it hardware} random bits generators. The four {\tt MultinomialBitsOver} + tests should detect correlations between successive bits by + applying a {\tt SerialOver} test to overlapping blocks of $2$, $4$, + $8$ and $16$ bits. The {\tt Hamming} tests should detect correlations + between the successive bits of overlapping blocks of $16$ and $32$ bits, + and the {\tt RandomWalk} tests consider blocks of 64 and 320 bits. + +% Restriction: {\tt nb} $\ge 500$. + \endtab + +\begin{enumerate} + \item {\tt smultin\_MultinomialBitsOver} with $L=2$. + \item {\tt smultin\_MultinomialBitsOver} with $L=4$. + \item {\tt smultin\_MultinomialBitsOver} with $L=8$. + \item {\tt smultin\_MultinomialBitsOver} with $L=16$. + \item {\tt sstring\_HammingIndep} with blocks of $L = 16$ bits. + \item {\tt sstring\_HammingIndep} with blocks of $L = 32$ bits. + \item {\tt sstring\_HammingCorr} with blocks of $L = 32$ bits. + \item {\tt swalk\_RandomWalk1} with walks of length $L = 64$. + \item {\tt swalk\_RandomWalk1} with walks of length $L = 320$. +\end{enumerate} + +\code + +void bbattery_RepeatAlphabit (unif01_Gen *gen, double nb, int r, int s, + int rep[]); +\endcode + \tab Similar to {\tt bbattery\_RepeatSmallCrush} above but applied on + {\tt Alphabit}. + \endtab +\code + + +void bbattery_BlockAlphabit (unif01_Gen *gen, double nb, int r, int s); +void bbattery_BlockAlphabitFile (char *filename, double nb); +\endcode + \tab Apply the {\tt Alphabit} battery of tests repeatedly to the generator + {\tt gen} or to the binary file {\tt filename} after reordering the bits + as described in the filter {\tt unif01\_CreateBitBlockGen}. + {\tt Alphabit} will be applied for the different values of + $w \in \{1, 2, 4, 8, 16, 32\}$. If $s <32$, only values of $w \le s$ will + be used. Each test uses at most {\tt nb} bits. + See the description of the tests in {\tt bbattery\_AlphabitFile}. + \endtab +\code + + +void bbattery_RepeatBlockAlphabit (unif01_Gen *gen, double nb, int r, int s, + int rep[], int w); +\endcode + \tab Similar to {\tt bbattery\_RepeatSmallCrush} above but applied on + {\tt BlockAlphabit}. The parameter $w$ is the one described in + {\tt bbattery\_BlockAlphabit}. Restrictions: + $w \in \{1, 2, 4, 8, 16, 32\}$ and $w \le s$. + \endtab + + + + +\guisec {Other Tests Suites} +\code + + +void bbattery_pseudoDIEHARD (unif01_Gen *gen); +\endcode + \tab + \index{DIEHARD}\index{battery of tests!PseudoDIEHARD}% + \index{battery of tests!DIEHARD}% + Applies the battery PseudoDIEHARD, which implements most of + the tests in the popular battery DIEHARD \cite{rMAR96b} + or, in some cases, close approximations to them. \textbf{We do not recommend + this battery as it is not very stringent} (we do not know of any generator + that passes the batteries \textsc{Crush} and \textsc{BigCrush}, and + fails PseudoDIEHARD, while we have seen the converse for several defective + generators). It is included here only for convenience to the user. +% Some of the tests in DIEHARD however are not implemented in TestU01. + The DIEHARD tests and the corresponding tests in PseudoDIEHARD are: + \endtab + +\begin{enumerate} + +\item The {\bf Birthday Spacings} test. This corresponds + to {\tt smarsa\_BirthdaySpacings} with $n=512$, $d=2^{24}$, $t=1$ and + $r=0, 1, 2, 3, 4, 5, 6, 7, 8, 9$ successively. The test with each + value of $r$ is repeated 500 times and a chi-square test is then applied. + +\item The {\bf Overlapping 5-Permutation} test. This test is not +implemented in TestU01. + +\item The {\bf Binary Rank Tests for Matrices}. This corresponds + to {\tt smarsa\_MatrixRank}. + +\item The {\bf Bitstream} test. Closely related to + {\tt smultin\_MultinomialBitsOver} with {\tt Delta} $= -1$, + $n=2^{21}$, $L=20$. + +\item The {\bf OPSO} test. This corresponds to {\tt smarsa\_CollisionOver} + with $n=2^{21}$, $d=1024$, $t=2$ and all values of $r$ from 0 to 22. + +\item The {\bf OQSO} test. This corresponds to {\tt smarsa\_CollisionOver} + with $n=2^{21}$, $d=32$, $t=4$ and all values of $r$ from 0 to 27. + +\item The {\bf DNA} test. This corresponds to {\tt smarsa\_CollisionOver} + with $n=2^{21}$, $d=4$, $t=10$ and all values of $r$ from 0 to 30. + +\item The {\bf Count-the-1's} test is not implemented in TestU01. It is +a 5-dimensional overlapping version of {\tt sstring\_HammingIndep}. + +\item The {\bf Parking Lot} test is not implemented in TestU01. + +\item The {\bf Minimum Distance} test. Closely related + to {\tt snpair\_ClosePairs} with + $N=100$, $n=8000$, $t=2$, $p=2$, $m=1$. + +\item The {\bf 3-D Spheres} test. Closely related + to {\tt snpair\_ClosePairs} with + $N=20$, $n=4000$, $t=3$, $p=2$, $m=1$. + +\item The {\bf Squeeze} test. Closely related + to {\tt smarsa\_Savir2}. + +\item The {\bf Overlapping Sums} test is not implemented in TestU01. + +\item The {\bf Runs} test. This corresponds to {\tt sknuth\_Run}. + +\item The {\bf Craps} test is not implemented in TestU01. + +\end{enumerate} + + +\bigskip +\hrule + +\paragraph{The NIST test suite} + +The NIST (National Institute of Standards and Technology) of the U.S. +federal government has proposed a statistical test suite \cite{rRUK01a} +for use in the evaluation of the randomness of bitstreams +produced by cryptographic random number generators. +\index{NIST tests suite}\index{battery of tests!NIST}% +%% A close equivalent to the NIST test suite is the battery +%% {\tt sbattery\_myNIST}. It will apply on a generator the tests in the +%% NIST test suite that are available in TestU01. +The test parameters are not predetermined. +The NIST tests and the equivalent tests in TestU01 are: + +\begin{enumerate} +\item The {\bf Monobit} test. This corresponds to + {\tt sstring\_HammingWeight2} with $L = n$. +% NIST uses a half normal distribution of the random walk W where bit 0 is +% replaced by -1 and bit 1 by +1. W = s1 + s2 + ...sn. +% TestU01 uses a chi-square distribution with one degree of freedom +% for the number of 1 bits. + +\item The {\bf Frequency test within a Block}. Corresponds to + {\tt sstring\_HammingWeight2}. + +\item The {\bf Runs} test. Is implemented as {\tt sstring\_Run}. + +\item The test for the {\bf Longest Run of Ones in a Block}. + Is implemented as the test + {\tt sstring\_LongestHeadRun}. + +\item The {\bf Binary Matrix rank} test. Is implemented as + {\tt smarsa\_MatrixRank}. + +\item The {\bf Discrete Fourier Transform} test. Is implemented as + {\tt sspectral\_Fourier1}. + +\item The {\bf Non-overlapping Template Matching} test. Is implemented + as the test {\tt smarsa\_CATBits}. + +\item The {\bf Overlapping Template Matching} test. This test does not +exist as such in TestU01, but a similar and more powerful test is +{\tt smultin\_MultinomialBitsOver}. + +\item {\bf Maurer's Universal Statistical} test. This test is implemented as + {\tt svaria\_Appear\-anceSpacings}. + +\item The {\bf Lempel-Ziv Compression} test. Is implemented as + {\tt scomp\_LempelZiv}. + +\item The {\bf Linear Complexity} test. Is implemented as part of + {\tt scomp\_LinearComp}. + +\item The {\bf Serial} test. Corresponds to + {\tt smultin\_MultinomialBitsOver} with {\tt Delta} = 1. + +\item The {\bf Approximate Entropy} test. Corresponds to + {\tt smultin\_MultinomialBitsOver} with {\tt Delta} = 0, and to + {\tt sentrop\_EntropyDiscOver} or {\tt sentrop\_EntropyDiscOver2}. + +\item The {\bf Cumulative Sums} test. This test is closely related to the $M$ + statistic in {\tt swalk\_RandomWalk1}. + +\item The {\bf Random Excursions} test. This test does not +exist in TestU01, but closely related tests are in + {\tt swalk\_RandomWalk1}. + +\item The {\bf Random Excursions Variant} test. This test does not +exist in TestU01, but a closely related test is based on the $R$ statistic in + {\tt swalk\_RandomWalk1}. + +\end{enumerate} + + +\bigskip +\hrule +\code + + +void bbattery_FIPS_140_2 (unif01_Gen *gen); +void bbattery_FIPS_140_2File (char *filename); +\endcode +\tab +\index{FIPS-140-2}\index{battery of tests!FIPS-140-2}% + These functions apply the four tests described in the NIST document + {\sl FIPS PUB 140-2, Security Requirements for Cryptographic Modules}, + page 35, with exactly the same parameters (see the WEB page at + \url{http://csrc.nist.gov/rng/rng6_3.html}). They report the values + of the test statistics and their $p$-values (except for the runs test) + and indicate which values fall outside the intervals specified by + FIPS-140-2. The first function applies the tests on a generator {\tt gen}, + and the second applies them on the file of bits {\tt filename}. First, + 20000 bits are generated and put in an array, then the tests are applied + upon these. The tests applied are: +\endtab + +\begin{enumerate} +\item The {\bf Monobit} test. This corresponds to +% {\tt sstring\_HammingWeight2} with $L = n$. + {\tt smultin\_MultinomialBits} with $s=32$, $L=1$, $n=20000$. + +\item The ``{\bf poker}'' test, which is in fact equivalent to + {\tt smultin\_MultinomialBits} with $s=32$, $L=4$, $n=5000$. + +\item The {\bf Runs} test, which is related to {\tt sstring\_Run}. + +\item The test for the {\bf Longest Run of Ones in a Block}, + which is implemented as {\tt sstring\_LongestHeadRun}. +\end{enumerate} + + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/bintro.tex b/TESTU01/TestU01-1.2.3/testu01/bintro.tex new file mode 100644 index 0000000..22700ad --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/bintro.tex @@ -0,0 +1,97 @@ +\chapter{BATTERIES OF TESTS} + +This chapter describes predefined batteries of tests available +in TestU01. +% Some batteries are more suitable for generators returning uniform +% floating-point numbers in the interval $[0, 1)$, +% while others are more oriented towards random bit generators. +Some batteries are fast and small, and may be used as a first step in +detecting gross defects in generators or errors in their implementation. +Other batteries are more stringent and take longer to run. +% They can often detect flaws in low or medium quality RNGs. +Special batteries are also available to test a stream of random bits +taken from a file. +% One has been designed specially for hardware random bit generators. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{An example: The battery SmallCrush applied to a generator.} \ + +Figure~\ref{fig:bat1.c} shows how to apply a battery of tests to a +generator. The function call to {\tt ulcg\_CreateLCG} creates and initializes the +generator {\tt gen} to the linear congruential generator (LCG) with +modulus $m$ = 2147483647, multiplier $a$ = 16807, additive constant $c=0$, +and initial state $x_0 = 12345$. +% This LCG is still widely used in commercial software. +Then the small battery {\tt SmallCrush}, defined in module +{\tt bbattery}, is applied on this generator. +Figure~\ref{fig:bat1.res} shows a summary report of the results +(assuming that 64-bits integers are available; otherwise, the results could +be slightly different). +Out of the 15 tests applied, the generator failed three with a $p$-value +practically equal to 0, so it is clear that it failed this battery. +It took 20.3 seconds to run this battery on a machine with a +2400 MHz Athlon processor running under Linux. + + +\setbox0=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/bat1.c} +} + +\begin{figure}[hbt] \centering \myboxit{\box0} +\caption{Applying the battery SmallCrush on a LCG generator.} + \label{fig:bat1.c} +\end{figure} + + +\setbox1=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/bat1.res} +} + +\begin{figure}[ht] \centering \myboxit{\box1} +\caption{Results of applying SmallCrush.} \label{fig:bat1.res} +\end{figure} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{Another example: The battery Rabbit applied to a binary file.} \ + + +Figure~\ref{fig:bat2.c} shows how to apply the battery +{\tt Rabbit} to a binary file (presumably, a file of random bits). +The tests will use at most 1048576 ($=2^{20}$) bits from the +binary file named {\tt vax.bin}. +(Incidentally, these bits were obtained by taking the 32 most significant +bits from each uniform number generated by +the well-known LCG with parameters $m = 2^{32}$, $a = 69069$ and $c=1$. + This was the random number generator used under VAX/VMS.) +Since the variable {\tt swrite\_Basic} is set to {\tt FALSE}, +no detailed output is written, only the summary report shown in +Figure~\ref{fig:bat2.res} is printed after running the tests. +Seven tests were failed with a $p$-value practically equal to 0 or 1. +It is clear that the null hypothesis $\cH_0$ must be rejected for + this bit stream. +It took 1.9 seconds to run the entire battery on a machine with a +2400 MHz Athlon processor running under Linux. + +\setbox0=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/bat2.c} +} + +\begin{figure} \centering \myboxit{\box0} +\caption{Applying the battery Rabbit on a file of random bits.} + \label{fig:bat2.c} +\end{figure} + + +\setbox1=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/bat2.res} +} + +\begin{figure} \centering \myboxit{\box1} +\caption{Results of applying Rabbit.} \label{fig:bat2.res} +\end{figure} diff --git a/TESTU01/TestU01-1.2.3/testu01/copyright.tex b/TESTU01/TestU01-1.2.3/testu01/copyright.tex new file mode 100644 index 0000000..4b22902 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/copyright.tex @@ -0,0 +1,26 @@ +\section*{Copyright} + +%\begin{verbatim} + Copyright \copyright {} 2002 by Pierre L'Ecuyer, + Universit\'e de Montr\'eal.\\ + Web address: \url{http://www.iro.umontreal.ca/~lecuyer/} \\ + All rights reserved. + +\noindent Redistribution and use in source and binary forms, with or without + modification, are permitted without a fee for private, research, + academic, or other non-commercial purposes. + Any use of this software in a commercial environment requires a + written licence from the copyright owner. + +\noindent Any changes made to this package must be clearly identified as such. + +\noindent In scientific publications which used this software, a reference to it + would be appreciated. + +\noindent Redistributions of source code must retain this copyright notice + and the following disclaimer: + +\noindent THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +%\end{verbatim} diff --git a/TESTU01/TestU01-1.2.3/testu01/fcho.c b/TESTU01/TestU01-1.2.3/testu01/fcho.c new file mode 100644 index 0000000..734c034 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fcho.c @@ -0,0 +1,262 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fcho.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "fcho.h" +#include "ftab.h" +#include "swrite.h" + +#include +#include +#include + + + +#define EPS2 1.0E-10 +#define LEN 7 + + + + +typedef struct { + double a; + double b; + double c; + fcho_FuncType F; + char *name; +} Sample_Param; + + + +int fcho_Resolution = 30; + + +/*-------------------------------- Functions ------------------------------*/ + + + +double fcho_Linear (double x) +{ + return x; +} + + +/*=========================================================================*/ + +double fcho_LinearInv (double x) +{ + return 1.0/x; +} + + +/*=========================================================================*/ + +double fcho_2Pow (double x) +{ + return pow (2.0, x); +} + + +/*=========================================================================*/ + +static void WriteSample (void *vpar, long junk, long j) +{ + Sample_Param *param = vpar; + const double a = param->a; + const double b = param->b; + const double c = param->c; + + printf ("Choose "); + if (ftab_Style == ftab_Latex) + printf ("$"); + if (param->name) + printf ("%s", param->name); + + if (param->F == fcho_2Pow) + printf (" = 2^{ "); + else if (param->F == fcho_Linear) + printf (" = "); + else + printf (" = F("); + + if (a > EPS2) + printf ("%4.2f*i ", a); + + if (fabs (b*j) > EPS2) { + if (b*j > EPS2) + printf ("+ "); + else + printf ("- "); + if (fabs (b - 1.0) > EPS2) + printf ("%4.2f*%1ld ", fabs (b), labs (j)); + else + printf ("%1ld ", labs (j)); + } + + if (c > EPS2) + printf ("+ %4.2f", fabs (c)); + else if (c < -EPS2) + printf ("- %4.2f", fabs (c)); + + if (param->F == fcho_2Pow) + printf ("}"); + else if (param->F == fcho_Linear) + ; + else + printf (")"); + + if (ftab_Style == ftab_Latex) + printf ("$"); + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static double ChooseSample (void *vpar, long i, long j) +{ + Sample_Param *param = vpar; + double x, y; + + if (swrite_Basic) + WriteSample (vpar, 0, j); + x = i * param->a + j * param->b + param->c; + y = param->F(x); + return y; +} + + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fcho_CreateSampleSize (double a, double b, double c, + fcho_FuncType F, char *name) +{ + fcho_Cho *cho; + Sample_Param *param; + size_t len; + char *name0 = "n"; + + cho = util_Malloc (sizeof (fcho_Cho)); + param = util_Malloc (sizeof (Sample_Param)); + param->a = a; + param->b = b; + param->c = c; + if (NULL == F) + param->F = fcho_2Pow; + else + param->F = F; + + if (NULL == name) + name = name0; + len = strlen (name); + cho->name = util_Calloc (len + 1, sizeof (char)); + strncpy (cho->name, name, (size_t) len); + cho->param = param; + cho->Write = WriteSample; + cho->Choose = ChooseSample; + param->name = cho->name; + return cho; +} + + +/*-------------------------------------------------------------------------*/ + +void fcho_DeleteSampleSize (fcho_Cho *cho) +{ + if (NULL == cho) + return; + cho->name = util_Free (cho->name); + cho->param = util_Free (cho->param); + util_Free (cho); +} + + +/*=========================================================================*/ + +long fcho_ChooseParamL (fcho_Cho *cho, long min, long max, long i, long j) +{ + double n; + + util_Assert (cho, "fcho_ChooseParamL: cho is NULL"); + n = cho->Choose (cho->param, i, j); + + if (n < min) { + if (cho->name) + printf ("%s < %ld\n\n", cho->name, min); + return -1; + } + if (n > max) { + if (cho->name) + printf ("%s > %ld\n\n", cho->name, max); + return -1; + } + return (long) n; +} + + +/*=========================================================================*/ + +int fcho_Chooses (int r, int s, int prec) +{ + int s1; + + if (r + s <= prec) + return s; + + s1 = prec - r; + if (s1 <= 0) + printf ("r >= Resolution of generator\n\n"); + + return s1; +} + + +/*=========================================================================*/ + +fcho_Cho2 * fcho_CreateCho2 (fcho_Cho *Chon, fcho_Cho *Chop2) +{ + fcho_Cho2 *cho; + cho = util_Malloc (sizeof (fcho_Cho2)); + memset (cho, 0, sizeof (fcho_Cho2)); + cho->Chon = Chon; + cho->Chop2 = Chop2; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +void fcho_DeleteCho2 (fcho_Cho2 *cho) +{ + if (NULL == cho) + return; + util_Free (cho); +} + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fcho.tex b/TESTU01/TestU01-1.2.3/testu01/fcho.tex new file mode 100644 index 0000000..89b4f2e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fcho.tex @@ -0,0 +1,186 @@ +\defmodule {fcho} + +This module provides tools to choose the value of some parameters of a +test as a function of the generator's {\it lsize} and other parameters, +when a sequence of tests is applied to a family of generators. +The sample size $n$, for example, is normally chosen by the functions +in this module. + +\bigskip +\hrule +\code\hide +/* fcho.h for ANSI C */ +#ifndef FCHO_H +#define FCHO_H +\endhide +\endcode + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Choosing one parameter} + +\code + +typedef struct { + void *param; + double (*Choose) (void *param, long, long); + void (*Write) (void *param, long, long); + char *name; +} fcho_Cho; +\endcode + \tab This structure is used to choose and keep some of the parameters of a + test (e.g. the sample size) as a function of the {\it lsize} of the + generator and some other parameters. The function {\tt Choose} computes + a parameter which appear as + argument in a test function from a {\tt s} module which is applied + on a family of generators. The parameters of {\tt Choose} itself are kept + in {\tt param}. The function {\tt Write} writes some information about + the parameters and the {\tt Choose} function. The string {\tt name} + is the name of the parameter that is computed by {\tt Choose}. +\endtab +\code + + +long fcho_ChooseParamL (fcho_Cho *cho, long min, long max, long i, long j); +\endcode +\tab This function chooses a parameter (most often the sample +size) by calling {\tt cho->Choose (cho->param, i, j)}. If the chosen +parameter is smaller than {\tt min} or larger than {\tt max}, the function +returns $-1$, otherwise it returns the chosen parameter. +\endtab + + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Choosing two parameters} +\code + +typedef struct { + fcho_Cho *Chon; + fcho_Cho *Chop2; +} fcho_Cho2; +\endcode + \tab + \endtab +\code + + +fcho_Cho2 * fcho_CreateCho2 (fcho_Cho *Chon, fcho_Cho *Chop2); +\endcode + \tab + This function creates and returns a structure to hold the two + sub-structures {\tt Chon} and {\tt Chop2}. It will not create the memory + for {\tt Chon} or {\tt Chop2} themselves, which must have been created + before. These two are used when choosing the sample size $n$ and another + parameter $p2$ in the same test. For some tests, both $n$ and the other + parameter can be varied as the sample size; in this case, one of these + two arguments may be a NULL pointer. For some other tests, both + parameters must be chosen. + \endtab +\code + + +void fcho_DeleteCho2 (fcho_Cho2 *cho); +\endcode + \tab + Frees the memory allocated by {\tt fcho\_CreateCho2}, but not the memory + reserved for the two fields {\tt Chon} and {\tt Chop2}. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Choosing the sample size} +\code + +typedef double (*fcho_FuncType) (double); +\endcode +\tab + This kind of function is used to compute a parameter for a test depending + on the {\it lsize} of the generator and the other parameters of the test. +\endtab +\code + + +double fcho_Linear (double x); +\endcode +\tab + Returns $x$. +\endtab +\code + + +double fcho_LinearInv (double x); +\endcode +\tab + Returns $1/x$. +\endtab +\code + + +double fcho_2Pow (double x); +\endcode +\tab + Returns $2^x$. +\endtab +\code + + +fcho_Cho * fcho_CreateSampleSize (double a, double b, double c, + fcho_FuncType F, char *name); +\endcode +\tab Creates and returns a structure {\tt fcho\_Cho} which is used normally + to compute the sample size of a test. Given the two arguments $i$ and $j$ + of the {\tt Choose} function in {\tt fcho\_Cho}, the function will return + the value of $F(a*i + b*j + c)$. The string {\tt name} is the name of the + variable that is being computed by {\tt Choose}. One can choose both + {\tt F} and {\tt name} as the {\tt NULL} pointers, in which case these + two will be set to + default variables {\tt fcho\_2Pow} and ``$n$''. Then the sample size of the + test will be chosen as $n = 2^{a*i + b*j + c}$, where $i$ is the {\it lsize} + of the generator being tested. +\endtab +\code + + +void fcho_DeleteSampleSize (fcho_Cho *cho); +\endcode +\tab Frees the memory allocated by {\tt fcho\_CreateSampleSize}. +\endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Choosing the number of bits} + +Each generator returns a given number of bits of resolution in its output +values. The resolution usually increases with the {\it lsize} of the generator. +It would be meaningless to apply a test that requires +more bits of resolution than the generator can deliver, since the extra +bits will be akin to noise. + + Many of the tests depend on the two arguments $r$ and $s$. The argument + $r$ is the number of (most significant) bits dropped from each +random number outputted by the generator, while $s$ is the number of bits +from each random number that are kept and used in the test. + +\code + + +int fcho_Chooses (int r, int s, int resol); +\endcode +\tab This function returns the number of bits $s_1$ that are effectively used +in a test when the test function depends on $s$. {\tt resol} is the +resolution of the generator being tested. If $r+s \le {}$ {\tt resol}, then +the function returns $s$ unchanged. Otherwise, the function returns +$s_1 = {}${\tt resol} ${} -r$. When $s_1 \le 0$, then obviously the test +should not be done. +\endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fcong.c b/TESTU01/TestU01-1.2.3/testu01/fcong.c new file mode 100644 index 0000000..544b872 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fcong.c @@ -0,0 +1,824 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fcong.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "num.h" + +#include "fcong.h" +#include "ffam.h" +#include "unif01.h" +#include "ulcg.h" +#include "uinv.h" +#include "ucubic.h" +#include "umrg.h" + +#include + + +#define MAXCAR 256 /* Max length of a line */ +#define SEED 123 /* Default seed for generators */ +#define BIGSEED "12345" /* Default seed for big generators */ +#define BIGCAR "1024" /* Max number of decimals in a big integer */ + + +/* The kinds of predefined families */ +typedef enum { + LCG_a, + LCGPow2_a, + MRG2_a, + MRG3_a, + CombL2_a, + CombWH2_a, + InvImpl_a, + InvImpl2a_a, + InvImpl2b_a, + InvExpl_a, + InvExpl2a_a, + InvExpl2b_a, + InvMRG2_a, + Cubic1_a, + CombCubic2_a, + CombCubLCG_a, + GenN_a +} +GenType; + + + +/*=========================================================================*/ + +static int ReadOneLCG (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m, a; + + /* Pass over LSize; it has been read already */ + if (fam->LSize[i] <= 31) { + status = sscanf (Line, "%*d %ld %ld", &m, &a); + util_Assert (status == 2, + "ReadOneLCG: Error in reading LCG parameter file"); + /* We use the float version since the a satisfy a*m < 2^{53} */ + fam->Gen[i] = ulcg_CreateLCGFloat (m, a, 0, SEED % m); + + } else { +#ifndef USE_GMP + return -1; +#else + char bigm[MAXCAR + 1]; + char biga[MAXCAR + 1]; + char format[20]; + + /* Build reading format for big integers read as a string */ + strncpy (format, "%*d %", (size_t) 6); + strncat (format, BIGCAR, (size_t) 10); + strncat (format, "s %", (size_t) 5); + strncat (format, BIGCAR, (size_t) 10); + strncat (format, "s", (size_t) 2); + status = sscanf (Line, format, bigm, biga); + util_Assert (status == 2, + "ReadOneLCG: Error in reading LCG (Big) parameter file"); + fam->Gen[i] = ulcg_CreateBigLCG (bigm, biga, "0", BIGSEED); +#endif + } + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneLCGPow2 (char *Line, ffam_Fam * fam, int i) +{ + int status; + long a; + long mask = num_TwoExp[fam->LSize[i]] - 1.0; + + /* Pass over LSize; it has been read already */ + if (fam->LSize[i] <= 31) { + status = sscanf (Line, "%*d %ld", &a); + util_Assert (status == 1, + "ReadOneLCG: Error in reading LCGPow2 parameter file"); + fam->Gen[i] = ulcg_CreatePow2LCG (fam->LSize[i], a, 1, SEED & mask); + + } else { +#ifndef USE_GMP + return -1; +#else + char biga[MAXCAR + 1]; + char format[20]; + + /* Build reading format for big integers read as a string */ + strncpy (format, "%*d %", (size_t) 6); + strncat (format, BIGCAR, (size_t) 10); + strncat (format, "s", (size_t) 2); + status = sscanf (Line, format, biga); + util_Assert (status == 1, + "ReadOneLCG: Error in reading LCGPow2 (Big) parameter file"); + fam->Gen[i] = + ulcg_CreateBigPow2LCG (fam->LSize[i], biga, "1", BIGSEED); +#endif + } + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneMRG2 (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m, A[2], S[2] = { SEED, SEED }; + + /* Pass over LSize; it has been read already */ + status = sscanf (Line, "%*d %ld %ld %ld", &m, &A[0], &A[1]); + util_Assert (status == 3, + "ReadOneMRG2: Error in reading MRG2 parameter file"); + S[0] %= m; + S[1] %= m; + fam->Gen[i] = umrg_CreateMRGFloat (m, 2, A, S); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneInvMRG2 (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m, A[2], S[2] = { SEED, SEED }; + + /* Pass over LSize; it has been read already */ + status = sscanf (Line, "%*d %ld %ld %ld", &m, &A[0], &A[1]); + util_Assert (status == 3, + "ReadOneInvMRG2: Error in reading MRG2 parameter file"); + S[0] %= m; + S[1] %= m; + fam->Gen[i] = uinv_CreateInvMRGFloat (m, 2, A, S); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneMRG3 (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m, A[3], S[3] = { SEED, SEED, SEED }; + + /* Pass over LSize; it has been read already */ + status = sscanf (Line, "%*d %ld %ld %ld %ld", &m, &A[0], &A[1], &A[2]); + util_Assert (status == 4, + "ReadOneMRG3: Error in reading MRG3 parameter file"); + S[0] %= m; + S[1] %= m; + S[2] %= m; + fam->Gen[i] = umrg_CreateMRGFloat (m, 3, A, S); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneCombL2 (char *Line, ffam_Fam * fam, int i) +{ + int status, LSize; + long m1, m2, a1, a2; + + status = sscanf (Line, "%d %ld %ld %ld %ld", &LSize, &m1, &m2, &a1, &a2); + util_Assert (status == 5, + "ReadOneCombL2: Error in reading CombL2 parameter file"); + if (LSize < 54) + fam->Gen[i] = ulcg_CreateCombLEC2Float (m1, m2, a1, a2, 0, 0, + SEED % m2, SEED % m2); + else + fam->Gen[i] = ulcg_CreateCombLEC2 (m1, m2, a1, a2, 0, 0, + SEED % m2, SEED % m2); + + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneCombWH2 (char *Line, ffam_Fam * fam, int i) +{ + int status, LSize; + long m1, m2, a1, a2; + + status = sscanf (Line, "%d %ld %ld %ld %ld", &LSize, &m1, &m2, &a1, &a2); + util_Assert (status == 5, + "ReadOneCombWH2: Error in reading CombWH2 parameter file"); + if (LSize < 54) + fam->Gen[i] = ulcg_CreateCombWH2Float (m1, m2, a1, a2, 0, 0, + SEED % m2, SEED % m2); + else + fam->Gen[i] = ulcg_CreateCombWH2 (m1, m2, a1, a2, 0, 0, + SEED % m2, SEED % m2); + + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneInvImpl (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m, a1, a2; + + /* Pass over LSize; it has been read already */ + status = sscanf (Line, "%*d %ld %ld %ld", &m, &a1, &a2); + util_Assert (status == 3, + "ReadOneInvImpl: Error in reading InvImpl parameter file"); + fam->Gen[i] = uinv_CreateInvImpl (m, a1, a2, SEED % m); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneInvExpl (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m; + + /* Pass over LSize; it has been read already */ + status = sscanf (Line, "%*d %ld", &m); + util_Assert (status == 1, + "ReadOneInvExpl: Error in reading InvExpl parameter file"); + fam->Gen[i] = uinv_CreateInvExpl (m, SEED % m, 0); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneCubic1 (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m, a; + + status = sscanf (Line, "%*d %ld %ld", &m, &a); + util_Assert (status == 2, + "ReadOneCubic1: Error in reading Cubic1 parameter file"); + fam->Gen[i] = ucubic_CreateCubic1Float (m, a, SEED % m); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneCombCubic2 (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m1, m2, a1, a2; + + status = sscanf (Line, "%*d %ld %ld %ld %ld", &m1, &m2, &a1, &a2); + util_Assert (status == 4, + "ReadOneCombCubic2: Error in reading CombCubic2 parameter file"); + fam->Gen[i] = ucubic_CreateCombCubic2 (m1, m2, a1, a2, + SEED % m2, SEED % m2); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneCombCubLCG (char *Line, ffam_Fam * fam, int i) +{ + int status; + long m1, m2, a1, a2; + unif01_Gen *gen1, *gen2; + + status = sscanf (Line, "%*d %ld %ld %ld %ld", &m1, &a1, &m2, &a2); + util_Assert (status == 4, + "ReadOneCombCubLCG: Error in reading CombCubLCG parameter file"); + gen1 = ulcg_CreateLCGFloat (m1, a1, 0, SEED % m1); + gen2 = ucubic_CreateCubic1Float (m2, a2, SEED % m2); + fam->Gen[i] = unif01_CreateCombAdd2 (gen1, gen2, "CombCubLCG"); + return 0; +} + + + +/*=========================================================================*/ + +static ffam_Fam *ReadAllGen (char *filename, char *deffile, GenType g, + int i1, int i2, int istep) +/* + * Read parameter file. If filename exists, it will be read; otherwise, the + * default file deffile will be read. + * Keeps only generators whose LSize are in [i1, i2], and keep only generators + * spaced istep apart. If i1 < the smallest LSize in the file, it will be + * reset to the first LSize in the file; similarly if i2 > the largest LSize + * in the file, it will be reset to the last LSize in the file. + */ +{ + FILE *f; + char Line[MAXCAR + 1]; + ffam_Fam *fam; + int i, j; + int status, LSize; + + f = ffam_OpenFile (filename, deffile); + + /* Read the family name */ + util_GetLine (f, Line, '#'); + fam = ffam_CreateFam ((i2 - i1 + istep) / istep, Line); + + /* Read the parameters */ + i = j = LSize = 0; + while (LSize <= i2) { + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + break; + + status = sscanf (Line, "%d", &LSize); + util_Assert (status == 1, "Error in reading LSize of generator"); + + /* Consider only generators with (LSize >= i1) and (LSize <= i2) */ + if (LSize < i1) + continue; + if (LSize > i2) + break; + if (j++ % istep) + continue; + if (i >= fam->Ng) + ffam_ReallocFam (fam, 2 * i); + fam->LSize[i] = LSize; + + switch (g) { + case LCG_a: + fam->Resol[i] = LSize; + status = ReadOneLCG (Line, fam, i); + break; + case LCGPow2_a: + fam->Resol[i] = LSize; + status = ReadOneLCGPow2 (Line, fam, i); + break; + case MRG2_a: + fam->Resol[i] = LSize / 2; + status = ReadOneMRG2 (Line, fam, i); + break; + case MRG3_a: + fam->Resol[i] = LSize / 3; + status = ReadOneMRG3 (Line, fam, i); + break; + case CombL2_a: + fam->Resol[i] = LSize / 2; + status = ReadOneCombL2 (Line, fam, i); + break; + case CombWH2_a: + fam->Resol[i] = util_Min (LSize, 53); + status = ReadOneCombWH2 (Line, fam, i); + break; + case InvImpl_a: + fam->Resol[i] = LSize; + status = ReadOneInvImpl (Line, fam, i); + break; + case InvExpl_a: + fam->Resol[i] = LSize; + status = ReadOneInvExpl (Line, fam, i); + break; + case InvMRG2_a: + fam->Resol[i] = LSize / 2; + status = ReadOneInvMRG2 (Line, fam, i); + break; + case Cubic1_a: + fam->Resol[i] = LSize; + status = ReadOneCubic1 (Line, fam, i); + break; + case CombCubic2_a: + fam->Resol[i] = LSize; + status = ReadOneCombCubic2 (Line, fam, i); + break; + case CombCubLCG_a: + fam->Resol[i] = LSize; + status = ReadOneCombCubLCG (Line, fam, i); + break; + default: + util_Error ("fcong_Create...: impossible case"); + } + + if (status) /* EOF? */ + break; + i++; + } + util_Assert (i > 0, "fcong_Create...: no generator"); + ffam_ReallocFam (fam, i); + return fam; +} + + +/*=========================================================================*/ + +static ffam_Fam *ReadInvGen (char *filename, char *deffile, GenType g, + int i1, int i2, int istep) +/* + * Read parameter file for the inversive generators. If filename exists, + * it will be read; otherwise, the default file deffile will be read. + */ +{ + FILE *f; + char Line[MAXCAR + 1]; + ffam_Fam *fam; + int i, j; + int status; + unsigned long a1, a2; + + f = ffam_OpenFile (filename, deffile); + + /* Read the family name */ + util_GetLine (f, Line, '#'); + fam = ffam_CreateFam ((i2 - i1 + istep) / istep, Line); + + /* Read the parameters */ + status = util_GetLine (f, Line, '#'); + util_Assert (status == 0, "ReadInvGen: EOF or error"); + + j = 0; + switch (g) { + case InvImpl2a_a: + status = sscanf (Line, "%lu %lu ", &a1, &a2); + util_Assert (status == 2, "ReadInvGen: Error in reading."); + i1 = util_Max (i1, 7); + i2 = util_Min (i2, 31); + for (i = i1; i <= i2; i += istep) { + fam->LSize[j] = i; + fam->Resol[j] = i + 1; + fam->Gen[j] = uinv_CreateInvImpl2a (i + 1, a1, a2, 1); + j++; + } + util_Assert (j > 0, "fcong_CreateInvImpl2a: no generator!!"); + break; + + case InvImpl2b_a: + status = sscanf (Line, "%lu %lu ", &a1, &a2); + util_Assert (status == 2, "ReadInvGen: Error in reading."); + i1 = util_Max (i1, 7); + i2 = util_Min (i2, 32); + for (i = i1; i <= i2; i += istep) { + fam->LSize[j] = i; + fam->Resol[j] = i; + fam->Gen[j] = uinv_CreateInvImpl2b (i, a1, a2, 1); + j++; + } + util_Assert (j > 0, "fcong_CreateInvImpl2b: no generator!!"); + break; + + case InvExpl2a_a: + status = sscanf (Line, "%lu", &a1); + util_Assert (status == 1, "ReadInvGen: Error in reading."); + i1 = util_Max (i1, 7); + i2 = util_Min (i2, 32); + for (i = i1; i <= i2; i += istep) { + fam->LSize[j] = i; + fam->Resol[j] = i; + fam->Gen[j] = uinv_CreateInvExpl2a (i, (long) a1, 1); + j++; + } + util_Assert (j > 0, "fcong_CreateInvExpl2a: no generator!!"); + break; + + case InvExpl2b_a: + status = sscanf (Line, "%lu", &a1); + util_Assert (status == 1, "ReadInvGen: Error in reading."); + i1 = util_Max (i1, 7); + i2 = util_Min (i2, 32); + for (i = i1; i <= i2; i += istep) { + fam->LSize[j] = i; + fam->Resol[j] = i; + fam->Gen[j] = uinv_CreateInvExpl2b (i, (long) a1, 1); + j++; + } + util_Assert (j > 0, "fcong_CreateInvExpl2b: no generator!!"); + break; + + default: + util_Error ("ReadInvGen: impossible case"); + } + + ffam_ReallocFam (fam, j); + return fam; +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateLCG (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "LCGGood.par", LCG_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteLCG (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) { + if (fam->LSize[i] <= 31) + ulcg_DeleteGen (fam->Gen[i]); +#ifdef USE_GMP + else + ulcg_DeleteBigLCG (fam->Gen[i]); +#endif + } + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateLCGPow2 (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "LCGPow2.par", LCGPow2_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteLCGPow2 (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) { + if (fam->LSize[i] <= 31) + ulcg_DeleteGen (fam->Gen[i]); +#ifdef USE_GMP + else + ulcg_DeleteBigPow2LCG (fam->Gen[i]); +#endif + } + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateMRG2 (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "MRG2.par", MRG2_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteMRG2 (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) + umrg_DeleteMRGFloat (fam->Gen[i]); + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateMRG3 (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "MRG3.par", MRG3_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteMRG3 (ffam_Fam * fam) +{ + fcong_DeleteMRG2 (fam); +} + + +/*=========================================================================*/ + + +ffam_Fam *fcong_CreateCombL2 (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "CombL2.par", CombL2_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteCombL2 (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) + ulcg_DeleteGen (fam->Gen[i]); + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateCombWH2 (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "CombWH2.par", CombWH2_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteCombWH2 (ffam_Fam * fam) +{ + fcong_DeleteCombL2 (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateInvImpl (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "InvImpl.par", InvImpl_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteInvImpl (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) + uinv_DeleteGen (fam->Gen[i]); + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateInvImpl2a (char *filename, int i1, int i2, int istep) +{ + return ReadInvGen (filename, "InvImpl2a.par", InvImpl2a_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteInvImpl2a (ffam_Fam * fam) +{ + fcong_DeleteInvImpl (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateInvImpl2b (char *filename, int i1, int i2, int istep) +{ + return ReadInvGen (filename, "InvImpl2b.par", InvImpl2b_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteInvImpl2b (ffam_Fam * fam) +{ + fcong_DeleteInvImpl (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateInvExpl (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "InvExpl.par", InvExpl_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteInvExpl (ffam_Fam * fam) +{ + fcong_DeleteInvImpl (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateInvExpl2a (char *filename, int i1, int i2, int istep) +{ + return ReadInvGen (filename, "InvExpl2a.par", InvExpl2a_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteInvExpl2a (ffam_Fam * fam) +{ + fcong_DeleteInvImpl (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateInvExpl2b (char *filename, int i1, int i2, int istep) +{ + return ReadInvGen (filename, "InvExpl2b.par", InvExpl2b_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteInvExpl2b (ffam_Fam * fam) +{ + fcong_DeleteInvImpl (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateInvMRG2 (char *filename, int i1, int i2, int istep) +{ + ffam_Fam *fam; + size_t len; + fam = ReadAllGen (filename, "MRG2.par", InvMRG2_a, i1, i2, istep); + len = strlen ("InvMRG2"); + fam->name = util_Realloc (fam->name, (1 + len) * sizeof (char)); + strncpy (fam->name, "InvMRG2", (size_t) len); + return fam; +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteInvMRG2 (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) + uinv_DeleteInvMRGFloat (fam->Gen[i]); + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateCubic1 (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "Cubic1.par", Cubic1_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteCubic1 (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) + ucubic_DeleteGen (fam->Gen[i]); + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateCombCubic2 (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "CombCubic2.par", CombCubic2_a, i1, i2, + istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteCombCubic2 (ffam_Fam * fam) +{ + fcong_DeleteCubic1 (fam); +} + + +/*=========================================================================*/ + +ffam_Fam *fcong_CreateCombCubLCG (char *filename, int i1, int i2, int istep) +{ + return ReadAllGen (filename, "CombCubLCG.par", CombCubLCG_a, i1, i2, + istep); +} + +/*-------------------------------------------------------------------------*/ + +void fcong_DeleteCombCubLCG (ffam_Fam * fam) +{ + unif01_Comb2_Param *param; + int i; + + for (i = 0; i < fam->Ng; i++) { + param = fam->Gen[i]->param; + ulcg_DeleteGen (param->gen1); + ucubic_DeleteGen (param->gen2); + unif01_DeleteCombGen (fam->Gen[i]); + } + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fcong.tex b/TESTU01/TestU01-1.2.3/testu01/fcong.tex new file mode 100644 index 0000000..6347563 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fcong.tex @@ -0,0 +1,307 @@ +\defmodule {fcong} + +The functions in this module creates whole families of generators of the same +kind (such as LCGs, MRGs, inversive, cubic, \ldots), based on recurrences +modulo some integer $m$, of different period lengths (the number of states) +near powers of 2. +Each {\tt Create} function will return a family of generators whose +{\it lsize\/} varies from {\tt i1} to {\tt i2} by step of {\tt +istep}, and whose parameters are taken from a file. +The {\it lsize\/} of a generator is defined as the (rounded) base-2 +logarithm of its period length. + + There are predefined families of each +kind whose parameters are given in files with extension {\tt .par} in +directory {\tt param} of TestU01. + If the file name in the {\tt Create} functions +below is set to {\tt NULL}, a default predefined family +will be used. Otherwise, the given file will be used to set the parameters +of the generators of a family. +The members of a predefined family usually have a {\it lsize\/} equal +to successive integers in [{\tt i1, i2}]. +\index{family of generators!congruential}% + +The user may want to define his own family of generators. If it is closely +related to one of the predefined family, he may use one of the {\tt Create} +function in this module to create his family. In that case, his +parameter file must contain the family parameters in the same order as the +predefined family of the same kind +(see the different cases of {\tt fcong\_CreateLCG} below for an example). + +More information about each specific kind of generator considered can +be found by looking at the corresponding function in modules {\tt u\ldots} +For example, {\tt fcong\_CreateInvImpl2b} implements the same generators +as in function {\tt uinv\_CreateInvImpl2b}. + + +\bigskip +\hrule +\code\hide +/* fcong.h for ANSI C */ +#ifndef FCONG_H +#define FCONG_H +\endhide +#include "ffam.h" +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The families of generators} + +\code + +ffam_Fam * fcong_CreateLCG (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of LCG generators whose parameters + are defined in file named {\tt fname}, beginning with the first + generator whose {\it lsize\/} is {\tt i1}, up to the last generator whose + {\it lsize\/} is {\tt i2}, taking every {\tt istep} generator. + The predefined LCG files are: + +\begin{itemize} +\item {\bf LCGGood.par}: the generators have a good lattice structure up to + dimension 8 (at least), with a prime modulus $m$ just below $2^i$ and + period $m-1$, for $10 \le i \le 60$. For each $i$, the LCG provided + is the one with the best value of $M_8$ in \cite{rLEC99c}. + Restrictions: $10 \le i1 \le i2 \le 60$. + + +\item {\bf LCGBad2.par}: Similar to the LCGGood family, but with a lattice + structure that is bad in dimension 2. The figure of merit + $S_2$ in dimension 2 is approximately 0.05. + Restrictions: $10 \le i1 \le i2 \le 40$. + +\item {\bf LCGWu2.par}: the generators have a good lattice structure as the + LCGGood family, but with the restriction that the multiplier is a sum + or a difference of two powers of 2, as suggested by P. C. Wu + \cite{rWU97a}. Restrictions: $ 10 \le i1 \le i2 \le 40$. + +\item {\bf LCGGranger.par}: the generators have a good lattice structure up + to dimension 8 (at least), with a prime modulus $m$ just below $2^i$, + for $10 \le i \le 31$. They were chosen so as to give a + maximal period for the combined generators in modules {\tt ugranger} + and {\tt tgranger}. +\end{itemize} +\endtab +\code + + +ffam_Fam * fcong_CreateLCGPow2 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of LCG generators whose parameters are defined in file + named {\tt fname}. By default, uses a predefined family of generators + with a good lattice structure as the LCGGood family, but with the modulus + equal to $2^i$ and period + length also equal to $2^i$. (The recurrence has a nonzero constant term.) + Restrictions: $10 \le i1 \le i2 \le 40$. +\endtab +\code + + +ffam_Fam * fcong_CreateMRG2 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of MRG (multiple-recursive generators) of order 2 whose + parameters are defined in file named {\tt fname}. By default, uses + a predefined family of generators with + a good lattice structure up to dimension 8 (at least), with a prime + modulus $m$ just below $2^{i/2}$ and period length $m^2-1$. + The implementation is similar to that of the LCGs. + Restrictions: $ 20 \le i1 \le i2 \le 60$. +\endtab +\code + + +ffam_Fam * fcong_CreateMRG3 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of MRG of order 3 whose parameters are defined in + file named {\tt fname}. + By default, uses a predefined family of generators with + a good lattice structure up to dimension 8 (at least), with a prime + modulus $m$ just below $2^{i/3}$ and period length $m^3-1$. + Restrictions: $ 30 \le i1 \le i2 \le 90$. +\endtab +\code + + +ffam_Fam * fcong_CreateCombL2 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of combined LCG with two components, whose + parameters are defined in {\tt fname}. + The combination uses the method of L'Ecuyer \cite{rLEC88a}. + By default, uses a predefined family of generators + with a good lattice structure up to dimension 8 (at least). + The components have distinct prime moduli $m_1$ and $m_2$ + just below $2^{i/2}$ and the period length is $(m_1-1)(m_2-1)/2$. + The parameters are chosen to get an excellent value of $M_8$ + where $M_8$ is defined as in \cite{rLEC99c}. + Restrictions: $20 \le i1 \le i2 \le 60$. +\endtab +\code + + +ffam_Fam * fcong_CreateCombWH2 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Same as {\tt fcong\_CreateCombL2}, except that the combination is of the + Wichmann and Hill type (see \cite{rLEC91b}). + Restrictions: $20 \le i1 \le i2 \le 60$. +\endtab +\code + + +ffam_Fam * fcong_CreateInvImpl (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of implicit inversive generators whose + parameters are defined in {\tt fname}. By default, uses a + predefined family of generators with prime modulus $m$ + slightly below $2^i$ and period length $m$. + Restrictions: $10 \le i1 \le i2 \le 30$. +\endtab +\code + + +ffam_Fam * fcong_CreateInvImpl2a (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a predefined family of implicit inversive generators whose + parameters are fixed, with prime modulus $m$ + slightly below $2^{i+1}$ and period length $m/2$. + Restrictions: $7 \le i1 \le i2 \le 31$. +\endtab +\code + + +ffam_Fam * fcong_CreateInvImpl2b (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a predefined family of implicit inversive generators whose + parameters are fixed, with prime modulus $m$ + slightly below $2^i$ and period length $m$. + Restrictions: $7 \le i1 \le i2 \le 32$. +\endtab +\code + + +ffam_Fam * fcong_CreateInvExpl (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of explicit inversive generators whose + parameters are defined in {\tt fname}. By default, uses a + predefined family of generators with prime modulus $m$ + slightly below $2^i$ and period length $m$. + Restrictions: $10 \le i1 \le i2 \le 31$. +\endtab +\code + + +ffam_Fam * fcong_CreateInvExpl2a (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a predefined family of explicit inversive generators whose + parameters are fixed, with prime modulus $m$ + slightly below $2^i$ and period length $m$. + Restrictions: $7 \le i1 \le i2 \le 32$. +\endtab +\code + + +ffam_Fam * fcong_CreateInvExpl2b (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a predefined family of explicit inversive generators whose + parameters are fixed, with prime modulus $m$ + slightly below $2^i$ and period length $m$. + Restrictions: $7 \le i1 \le i2 \le 32$. +\endtab +\code + + +ffam_Fam * fcong_CreateInvMRG2 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of inversive MRG of order 2 whose + parameters are defined in file {\tt fname}. By default, uses + a predefined family of generators with a prime modulus $m$ + just below $2^{i/2}$ and period length $\approx m^2$. + Restrictions: $ 20 \le i1 \le i2 \le 60$. +\endtab +\code + + +ffam_Fam * fcong_CreateCubic1 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of cubic congruential generator whose + parameters are defined in file {\tt fname}. By default, uses + a predefined family of generators with modulus $m$ + slightly below $2^i$ and period length $m$. + Restrictions: $6 \le i1 \le i2 \le 18$. +\endtab +\code + + +ffam_Fam * fcong_CreateCombCubic2 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of combined cubic congruential generators with 2 + components whose parameters are defined in file {\tt fname}. By default, + uses a predefined family of generators with moduli $m_1$ and $m_2$ + slightly below $2^{e_1}$ and $2^{e_2}$, where $e_1 + e_2 = i$ and + $e_2 = \lfloor i/2\rfloor$. The period length should be near $2^i$. + Restrictions: $12 \le i1 \le i2 \le 36$. +\endtab +\code + + +ffam_Fam * fcong_CreateCombCubLCG (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates the family of combined generators with one component a cubic + congruential and the other component an LCG whose parameters are defined + in file {\tt fname}. By default, uses a predefined family of generators + with respective moduli of the components $m_1$ and $m_2$ slightly below + $2^{e_1}$ and $2^{e_2}$, where $e_1 + e_2 = i$ and $e_2 = \lfloor i/2\rfloor$. + Restrictions: $19 \le i1 \le i2 \le 36$. +\endtab + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Clean-up functions} +\code + +void fcong_DeleteLCG (ffam_Fam *fam); +void fcong_DeleteLCGPow2 (ffam_Fam *fam); +void fcong_DeleteMRG2 (ffam_Fam *fam); +void fcong_DeleteMRG3 (ffam_Fam *fam); +void fcong_DeleteCombL2 (ffam_Fam *fam); +void fcong_DeleteCombWH2 (ffam_Fam *fam); +void fcong_DeleteInvImpl (ffam_Fam *fam); +void fcong_DeleteInvImpl2a (ffam_Fam *fam); +void fcong_DeleteInvImpl2b (ffam_Fam *fam); +void fcong_DeleteInvExpl (ffam_Fam *fam); +void fcong_DeleteInvExpl2a (ffam_Fam *fam); +void fcong_DeleteInvExpl2b (ffam_Fam *fam); +void fcong_DeleteInvMRG2 (ffam_Fam *fam); +void fcong_DeleteCubic1 (ffam_Fam *fam); +void fcong_DeleteCombCubic2 (ffam_Fam *fam); +void fcong_DeleteCombCubLCG (ffam_Fam *fam); +\endcode +\tab + Frees the dynamic memory allocated to {\tt fam} by the corresponding + {\tt Create} function. +\endtab + +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ffam.c b/TESTU01/TestU01-1.2.3/testu01/ffam.c new file mode 100644 index 0000000..53c7b0e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ffam.c @@ -0,0 +1,172 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ffam.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "gdef.h" +#include "util.h" +#include "ffam.h" +#include "unif01.h" + +#include + +#define MAXCAR 256 /* Max length of a line */ + + + + +/*=========================================================================*/ + +ffam_Fam * ffam_CreateFam (int Ng, char *name) +{ + ffam_Fam *fam; + size_t len; + + fam = util_Malloc (sizeof (ffam_Fam)); + fam->Resol = util_Calloc ((size_t) Ng, sizeof (int)); + fam->LSize = util_Calloc ((size_t) Ng, sizeof (int)); + fam->Gen = util_Calloc ((size_t) Ng, sizeof (unif01_Gen *)); + fam->Ng = Ng; + len = strlen (name); + fam->name = util_Calloc (1 + len, sizeof (char)); + strncpy (fam->name, name, (size_t) len); + return fam; +} + + +/*-------------------------------------------------------------------------*/ + +void ffam_DeleteFam (ffam_Fam *fam) +{ + if (fam == NULL) + return; + util_Free (fam->Resol); + util_Free (fam->Gen); + util_Free (fam->LSize); + util_Free (fam->name); + util_Free (fam); +} + + +/*-------------------------------------------------------------------------*/ + +void ffam_PrintFam (ffam_Fam *fam) +{ + int i; + if (fam == NULL) { + util_Warning (TRUE, "ffam_PrintFam: fam is NULL"); + return; + } + printf ("-------------------------------------------------\n"); + printf ("Family: %s\nNumber of generators: %d\n\n", + fam->name, fam->Ng); + printf ("LSize Resol Generator\n"); + printf ("-------------------------------------------------\n"); + for (i = 0; i < fam->Ng; i++) { + printf ("%3d %3d %s\n", fam->LSize[i], fam->Resol[i], + fam->Gen[i]->name); + } + printf ("\n\n"); +} + + +/*=========================================================================*/ + +void ffam_ReallocFam (ffam_Fam * fam, int Ng) +{ + fam->Resol = util_Realloc (fam->Resol, (size_t) Ng * sizeof (int)); + fam->LSize = util_Realloc (fam->LSize, (size_t) Ng * sizeof (int)); + fam->Gen = util_Realloc (fam->Gen, (size_t) Ng * sizeof (unif01_Gen *)); + fam->Ng = Ng; +} + + +/*=========================================================================*/ + +FILE *ffam_OpenFile (char *filename, char *deffile) +/* + * Open the file filename if it exists; otherwise if filename == NULL, open + * deffile in the param directory; otherwise open filename in the param + * directory. + */ +{ + FILE *f; + char path[MAXCAR + 1]; /* Directory of parameter files */ + + /* Is the parameter filename in the current directory? */ + if (filename) { + f = fopen (filename, "r"); + if (f) + return f; + else + printf ("Cannot open file %s in current directory." + " Searching directory param ...\n", filename); + } + + /* Build directory: "../param/" on Linux, "..\\param\\" on Windows */ + strncpy (path, "..", (size_t) 3); + strncat (path, DIR_SEPARATOR, (size_t) 3); + strncat (path, "param", (size_t) 6); + strncat (path, DIR_SEPARATOR, (size_t) 3); + + /* Is filename NULL? open default file */ + if (filename == NULL) + strncat (path, deffile, (size_t) MAXCAR - 20); + else + strncat (path, filename, (size_t) MAXCAR - 20); + + f = util_Fopen (path, "r"); + return f; +} + + +/*=========================================================================*/ + +ffam_Fam * ffam_CreateSingle (unif01_Gen *gen, int prec, int i1, int i2) +{ + int i; + ffam_Fam *fam; + + fam = ffam_CreateFam (i2 - i1 + 1, gen->name); + for (i = 0; i < fam->Ng; i++) { + fam->Gen[i] = gen; + fam->LSize[i] = i + i1; + fam->Resol[i] = prec; + } + return fam; +} + + +void ffam_DeleteSingle (ffam_Fam *fam) +{ + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/ffam.tex b/TESTU01/TestU01-1.2.3/testu01/ffam.tex new file mode 100644 index 0000000..1f8bea4 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ffam.tex @@ -0,0 +1,148 @@ +\defmodule {ffam} + +This module provides generic tools used in testing whole families of +generators. There are many predefined families of generators of the same +kind (see modules {\tt fcong} and {\tt ffsr} for some examples); + their defining parameters are in files kept in directory {\tt param} +of TestU01. For each generator in a given family, we define a +size (the period length) and a resolution. We shall define +the {\it lsize} of a generator as the (rounded) base-2 logarithm of the +period length. \emph{Resolution} is a somewhat fuzzy notion. +If we have a LCG with modulus $m = 2^b$, say, then each output number +is a multiple of $2^{-b}$ and we say we have $b$ bits of resolution +in the output. +More generally, if the number of \emph{different} output values +that can be produced +by the generator is $n$ (not necessarily a power of 2), we say that +the ``resolution'' is (approximately) $\lfloor\log_2 n\rfloor$. + \index{family of generators} + + +For the predefined families, each generator of the family has been chosen +in such a way that its period length (the number of possible states of the +generator) is very close to a power of 2. Thus, a given test may be applied +with a variable sample size on generators of the same kind whose size +varies as successive powers of 2. One may then observe some interactions +between a test and the structure of the generators of a given kind, and this +will appear as regularities in the results. +The user may also define his own family of generators. + +\bigskip +\hrule +\code\hide +/* ffam.h for ANSI C */ +#ifndef FFAM_H +#define FFAM_H +\endhide +#include "unif01.h" +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Families of generators} + +The following structure is used in the {\tt f} modules +to keep a family of generators upon which tests with variable sample +sizes are applied. Such a structure must always be created, directly or +indirectly, before calling a testing function. Usually, this structure will +be created indirectly by one of the {\tt Create} function in modules +{\tt fcong} and {\tt ffsr}. + +\code + + +typedef struct { + unif01_Gen **Gen; + int *LSize; + int *Resol; + int Ng; + char *name; +} ffam_Fam; +\endcode +\tab Array element {\tt Gen[i]} is a generator of + the family, array element {\tt Resol[i]} gives the (approximate) number + of bits of resolution in the output values of generator {\tt Gen[i]}. + Array element {\tt LSize[i]} gives the base-2 logarithm of the approximate + period length of {\tt Gen[i]}, i.e. if {\tt LSize[i]} $= h$, then + {\tt Gen[i]} has a period that is very close to $2^h$. There are {\tt Ng} + members in the family (and the size of the above arrays is + {\tt Ng}), so their elements are numbered from $0 \le i \le$ {\tt Ng-1}. + The string {\tt name} gives the name of the family. +\endtab +\code + + +ffam_Fam * ffam_CreateFam (int Ng, char *name); +\endcode + \tab + Creates and returns a structure to hold a family named + {\tt name} that can contains up to {\tt Ng} generators. + \endtab +\code + + +void ffam_DeleteFam (ffam_Fam *fam); +\endcode + \tab + Frees the memory allocated to {\tt fam} by {\tt ffam\_CreateFam}. + \endtab +\code + + +void ffam_PrintFam (ffam_Fam *fam); +\endcode + \tab + Prints all the fields of the family {\tt fam}. + \endtab +\code + + +void ffam_ReallocFam (ffam_Fam *fam, int Ng); +\endcode + \tab + Reallocs memory to the three arrays of {\tt fam} so that they can contain + up to {\tt Ng} elements. + \endtab +\code + + +ffam_Fam * ffam_CreateSingle (unif01_Gen *gen, int resol, int i1, int i2); +\endcode + \tab + Creates and returns a structure to hold a family that can contains up + to {\tt i2}${} - {}${\tt i1} ${} + {}$ 1 generators. All members of + the family will be the same generator {\tt gen} of resolution {\tt resol}. + The generator will imitate a family of generators of lsize in + {\tt i1} $ \le $ lsize $\le$ {\tt i2}. + This is useful, amongst other things, to explore the domain of + the approximation error in the distribution function of a test with the + help of a high quality generator, or to find out the behaviour of a + given generator with respect to a given test as the + sample size increases. + \endtab +\code + + +void ffam_DeleteSingle (ffam_Fam *fam); +\endcode + \tab + Frees the memory allocated to {\tt fam} by {\tt ffam\_CreateSingle}. + \endtab +\code +\hide +#include + +FILE * ffam_OpenFile (char *filename, char *defaultfile); +\endcode + \tab + Opens a file of parameters describing a family of generators in reading + mode. Opens the file {\tt filename} if it exists; otherwise if + {\tt filename == NULL}, opens {\tt defaultfile} in the {\tt param} + directory. Otherwise opens {\tt filename} in the {\tt param} + directory. + \endtab +\code + +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ffsr.c b/TESTU01/TestU01-1.2.3/testu01/ffsr.c new file mode 100644 index 0000000..3080fce --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ffsr.c @@ -0,0 +1,321 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ffsr.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "num.h" +#include "util.h" + +#include "ffsr.h" +#include "ffam.h" +#include "utaus.h" +#include "ulec.h" + +#include + +#define MAXCAR 256 /* Max length of a line */ +#define SEED 123 /* Default seed for generators */ + + + + +/* The kinds of predefined families */ +typedef enum { + LFSR1_a, + LFSR2_a, + LFSR3_a, + TausLCG2_a, + GenN_a +} +GenType; + + + +/*=========================================================================*/ + +static int ReadOneLFSR1 (char *Line, ffam_Fam * fam, int i) +{ + int status; + unsigned int k, q, s; + + status = sscanf (Line, "%u %u %u", &k, &q, &s); + util_Assert (status == 3, + "ReadOneLFSR1: Error in reading LFSR1 parameter file"); + if (k <= 32) + fam->Gen[i] = utaus_CreateTaus (k, q, s, + SEED & (unsigned long) (num_TwoExp[k] - 1.0)); +#ifdef USE_LONGLONG + else + fam->Gen[i] = utaus_CreateLongTaus (k, q, s, (ulonglong) SEED); +#endif + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneLFSR2 (FILE *f, char *Line, ffam_Fam * fam, int i) +{ + int status; + unsigned int k1, q1, s1; + unsigned int k2, q2, s2; + + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + return -1; + status = sscanf (Line, "%u %u %u", &k1, &q1, &s1); + util_Assert (status == 3, + "ReadOneLFSR2: Error in reading LFSR2 parameter file"); + + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + return -1; + status = sscanf (Line, "%u %u %u", &k2, &q2, &s2); + util_Assert (status == 3, + "ReadOneLFSR2: Error in reading LFSR2 parameter file"); + + + fam->Gen[i] = utaus_CreateCombTaus2 (k1, k2, q1, q2, s1, s2, + SEED & (unsigned long) (num_TwoExp[k1] - 1.0), + SEED & (unsigned long) (num_TwoExp[k2] - 1.0)); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneLFSR3 (FILE *f, char *Line, ffam_Fam * fam, int i) +{ + int status; + unsigned int k1, q1, s1; + unsigned int k2, q2, s2; + unsigned int k3, q3, s3; + + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + return -1; + status = sscanf (Line, "%u %u %u", &k1, &q1, &s1); + util_Assert (status == 3, + "ReadOneLFSR3: Error in reading LFSR3 parameter file"); + + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + return -1; + status = sscanf (Line, "%u %u %u", &k2, &q2, &s2); + util_Assert (status == 3, + "ReadOneLFSR3: Error in reading LFSR3 parameter file"); + + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + return -1; + status = sscanf (Line, "%u %u %u", &k3, &q3, &s3); + util_Assert (status == 3, + "ReadOneLFSR3: Error in reading LFSR3 parameter file"); + + fam->Gen[i] = utaus_CreateCombTaus3 (k1, k2, k3, q1, q2, q3, s1, s2, s3, + SEED & (unsigned long) (num_TwoExp[k1] - 1.0), + SEED & (unsigned long) (num_TwoExp[k2] - 1.0), + SEED & (unsigned long) (num_TwoExp[k3] - 1.0)); + return 0; +} + + +/*=========================================================================*/ + +static int ReadOneTausLCG2 (FILE *f, char *Line, ffam_Fam * fam, int i) +{ + int status; + unsigned int k1, q1, s1; + unsigned int k2, q2, s2; + long m, a; + + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + return -1; + status = sscanf (Line, "%u %u %u %u %u %u", &k1, &q1, &s1, &k2, &q2, &s2); + util_Assert (status == 6, + "ReadOneTausLCG2: Error in reading TausLCG2 parameter file"); + + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + return -1; + status = sscanf (Line, "%ld %ld", &m, &a); + util_Assert (status == 2, + "ReadOneTausLCG2: Error in reading TausLCG2 parameter file"); + + fam->Gen[i] = ulec_CreateCombTausLCG21 ( + k1, q1, s1, SEED & (unsigned long) (num_TwoExp[k1] - 1.0), + k2, q2, s2, SEED & (unsigned long) (num_TwoExp[k2] - 1.0), + m, a, 0, SEED % m); + return 0; +} + + +/*=========================================================================*/ + +static ffam_Fam *ReadAllGen (char *filename, char *deffile, GenType g, + int i1, int i2, int istep) +/* + * Read parameter file. If filename exists, it will be read; otherwise, the + * default file deffile will be read. + * Keeps only generators whose LSize are in [i1, i2], and keep only generators + * spaced istep apart. If i1 < the smallest LSize in the file, it will be + * reset to the first LSize in the file; similarly if i2 > the largest LSize + * in the file, it will be reset to the last LSize in the file. + */ +{ + FILE *f; + char Line[MAXCAR + 1]; + ffam_Fam *fam; + int i, j; + int status, LSize; + + f = ffam_OpenFile (filename, deffile); + + /* Read the family name */ + util_GetLine (f, Line, '#'); + fam = ffam_CreateFam ((i2 - i1 + istep) / istep, Line); + + /* Read the parameters */ + i = j = LSize = 0; + while (LSize <= i2) { + status = util_GetLine (f, Line, '#'); + if (status) /* if EOF or error */ + break; + + status = sscanf (Line, "%d", &LSize); + util_Assert (status == 1, "Error in reading LSize of generator"); + + /* Consider only generators with (LSize >= i1) and (LSize <= i2) */ + if (LSize < i1) + continue; + if (LSize > i2) + break; + if (j++ % istep) + continue; + if (i >= fam->Ng) + ffam_ReallocFam (fam, 2 * i); + fam->LSize[i] = LSize; + + switch (g) { + case LFSR1_a: + fam->Resol[i] = util_Min (32, LSize); + status = ReadOneLFSR1 (Line, fam, i); + break; + case LFSR2_a: + fam->Resol[i] = util_Min (32, LSize); + status = ReadOneLFSR2 (f, Line, fam, i); + break; + case LFSR3_a: + fam->Resol[i] = util_Min (32, LSize); + status = ReadOneLFSR3 (f, Line, fam, i); + break; + case TausLCG2_a: + fam->Resol[i] = util_Min (32, LSize); + status = ReadOneTausLCG2 (f, Line, fam, i); + break; + + default: + util_Error ("ReadAllGen: impossible case"); + } + + if (status) /* EOF? */ + break; + i++; + } + util_Assert (i > 0, "ffsr: no generator"); + ffam_ReallocFam (fam, i); + return fam; +} + + +/*=========================================================================*/ + +ffam_Fam * ffsr_CreateLFSR1 (char *fname, int i1, int i2, int istep) +{ + return ReadAllGen (fname, "LFSR1.par", LFSR1_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void ffsr_DeleteLFSR1 (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) + utaus_DeleteGen (fam->Gen[i]); + ffam_DeleteFam (fam); +} + + +/*=========================================================================*/ + +ffam_Fam * ffsr_CreateLFSR2 (char *fname, int i1, int i2, int istep) +{ + return ReadAllGen (fname, "LFSR2.par", LFSR2_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void ffsr_DeleteLFSR2 (ffam_Fam * fam) +{ + ffsr_DeleteLFSR1 (fam); +} + + +/*=========================================================================*/ + +ffam_Fam * ffsr_CreateLFSR3 (char *fname, int i1, int i2, int istep) +{ + return ReadAllGen (fname, "LFSR3.par", LFSR3_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void ffsr_DeleteLFSR3 (ffam_Fam * fam) +{ + ffsr_DeleteLFSR1 (fam); +} + + +/*=========================================================================*/ + +ffam_Fam * ffsr_CreateTausLCG2 (char *fname, int i1, int i2, int istep) +{ + return ReadAllGen (fname, "TausLCG2.par", TausLCG2_a, i1, i2, istep); +} + +/*-------------------------------------------------------------------------*/ + +void ffsr_DeleteTausLCG2 (ffam_Fam * fam) +{ + int i; + for (i = 0; i < fam->Ng; i++) + ulec_DeleteCombTausLCG21 (fam->Gen[i]); + ffam_DeleteFam (fam); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ffsr.tex b/TESTU01/TestU01-1.2.3/testu01/ffsr.tex new file mode 100644 index 0000000..702f9d2 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ffsr.tex @@ -0,0 +1,134 @@ +\defmodule {ffsr} + +This module operates in the same way as {\tt fcong} +(see the introduction in module {\tt fcong}). +It defines {\em linear feedback shift register\/} (LFSR) generators +of different period lengths (or number of states) near powers of 2, +and different kinds such as Tausworthe, GFSR, twisted GFSR (TGFSR), +and their combinations. +All these generators are based on linear recurrences modulo 2. +\index{family of generators!shift-register}% + + +\bigskip +\hrule +\code\hide +/* ffsr.h for ANSI C */ +#ifndef FFSR_H +#define FFSR_H +\endhide +#include "ffam.h" +\endcode + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The families of generators} +\code + +ffam_Fam * ffsr_CreateLFSR1 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of simple LFSR (or Tausworthe) generators whose + parameters are defined in file named {\tt fname}. By default, uses a + predefined family of generators with primitive characteristic trinomial of + degree $i$ (with period length $2^i-1$) and the best equidistribution + properties within its class. + Restrictions: $10 \le i1 \le i2 \le 60$. +\endtab +\code + + +ffam_Fam * ffsr_CreateLFSR2 (char *fname, int i1, int i2, int istep); +\endcode +\tab Creates a family of combined LFSR generators with two components, whose + parameters are defined in file named {\tt fname}. By default, uses a + predefined family with each component + based on a primitive characteristic trinomial. + The combination generator has period length near $2^i-1$ and the best + possible equidistribution within its class. + Restrictions: $10 \le i1 \le i2 \le 36$. +\endtab +\code + + +ffam_Fam * ffsr_CreateLFSR3 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of combined LFSR generators with three components, whose + parameters are defined in file named {\tt fname}. By default, uses a + predefined family with each component + based on a primitive characteristic trinomial. + The combination generator has period length near $2^i-1$ and the best + possible equidistribution within its class. + Restrictions: $14 \le i1 \le i2 \le 36$. +\endtab +\code + + +ffam_Fam * ffsr_CreateGFSR3 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of generalized feedback shift register (GFSR) generators + with primitive characteristic trinomial of degree $i$ + (period length $2^i-1$) and good equidistribution. + ***** NOT YET IMPLEMENTED. +\endtab +\code + + +ffam_Fam * ffsr_CreateGFSR5 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of generalized feedback shift register (GFSR) generators + with primitive characteristic pentanomial of degree $i$ + (period length $2^i-1$) and good equidistribution. + ***** NOT YET IMPLEMENTED. +\endtab +\code + + +ffam_Fam * ffsr_CreateTGFSR1 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of twisted GFSR generators with primitive characteristic + trinomial of degree $i$ + (period length $2^i-1$) and good equidistribution. + ***** NOT YET IMPLEMENTED. +\endtab +\code + + +ffam_Fam * ffsr_CreateTausLCG2 (char *fname, int i1, int i2, int istep); +\endcode +\tab + Creates a family of combined generators that adds the outputs of an LCG + and an LFSR2, modulo 1, whose parameters are defined in file named + {\tt fname}. Each generator is created by calling the function + {\tt ulec\_CreateCombTausLCG21}. By default, uses a + predefined family with generators having a period near $2^i$. + Restrictions: $20 \le i1 \le i2 \le 62$. +\endtab + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Clean-up functions} +\code + +void ffsr_DeleteLFSR1 (ffam_Fam *fam); +void ffsr_DeleteLFSR2 (ffam_Fam *fam); +void ffsr_DeleteLFSR3 (ffam_Fam *fam); +void ffsr_DeleteTausLCG2 (ffam_Fam *fam); +\endcode +\tab + Frees the dynamic memory allocated to {\tt fam} by the corresponding + {\tt Create} function. +\endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fftc.c b/TESTU01/TestU01-1.2.3/testu01/fftc.c new file mode 100644 index 0000000..f1fe37f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fftc.c @@ -0,0 +1,230 @@ +/* +CC=================================================================CC +CC CC +CC Subroutine RSRFFT(X,M): CC +CC A real-valued, in-place, split-radix FFT program CC +CC Decimation-in-time, cos/sin in second loop CC +CC and computed recursively CC +CC Output in order: CC +CC [ Re(0),Re(1),....,Re(N/2),Im(N/2-1),...Im(1)] CC +CC CC +CC Input/output CC +CC X Array of input/output (length >= N) CC +CC M Transform length is N=2**M CC +CC CC +CC Calls: CC +CC RSTAGE,RBITREV CC +CC CC +CC Author: CC +CC H.V. Sorensen, University of Pennsylvania, Oct. 1985 CC +CC Arpa address: hvs@ee.upenn.edu CC +CC Modified: CC +CC F. Bonzanigo, ETH-Zurich, Sep. 1986 CC +CC H.V. Sorensen, University of Pennsylvania, Mar. 1987 CC +CC H.V. Sorensen, University of Pennsylvania, Oct. 1987 CC +CC R. Simard, Université de Montréal, Mar. 2014 CC +CC CC +CC Reference: CC +CC Sorensen, Jones, Heideman, Burrus :"Real-valued fast CC +CC Fourier transform algorithms", IEEE Tran. ASSP, CC +CC Vol. ASSP-35, No. 6, pp. 849-864, June 1987 CC +CC CC +CC This program may be used and distributed freely as CC +CC as long as this header is included CC +CC CC +CC=================================================================CC +*/ +#include + +//-------------------Functions Prototypes---------------------------- +void rsrfft (double *x, int m); +void rstage (int n, int n2, int n4, double *x1, double *x2, double *x3, double *x4); +void rbitrev (double *x, int m); +//------------------------------------------------------------------- + + +void rsrfft (double *x, int m) +{ + int n, is, id, i0, n2, n4, k; + double t1; + x--; + n = 1 << m; + /*C-------Digit reverse counter---------------------------------------C*/ + rbitrev (x, m); + /*C-----Length two butterflies----------------------------------------C*/ + is = 1; + id = 4; + do { + for (i0 = is; i0 <= n; i0 += id) { + t1 = x[i0]; + x[i0] = t1 + x[i0 + 1]; + x[i0 + 1] = t1 - x[i0 + 1]; + } + is = 2 * id - 1; + id = 4 * id; + } while (is < n); + /*C-------L shaped butterflies----------------------------------------C*/ + n2 = 2; + for (k = 2; k <= m; k++) { + n2 = n2 * 2; + n4 = n2 / 4; + rstage (n, n2, n4, &x[0], &x[n4], &x[2 * n4], &x[3 * n4]); + } + return ; +} + +/* +C===================================================================C +C Subroutine RSTAGE - the work-horse of the RFFT C +C Computes a stage of a real-valued split-radix length N C +C transform. C +C Author C +C H.V. Sorensen, University of Pennsylvania, Mar. 1987 C +C===================================================================C +*/ +void rstage (int n, int n2, int n4, double *x1, double *x2, double *x3, double *x4) +{ + int n8, is, id, i1, i2, j, jn; + double t1, t2, e, t3, t4, t5; + double ss1, sd1, ss3, sd3; + double cc1, cd1, cc3, cd3; + n8 = n2 / 8; + is = 0; + id = n2 * 2; + + do { + for (i1 = is + 1; i1 <= n; i1 += id) { + t1 = x4[i1] + x3[i1]; + x4[i1] = x4[i1] - x3[i1]; + x3[i1] = x1[i1] - t1; + x1[i1] = x1[i1] + t1; + } + is = 2 * id - n2; + id = 4 * id; + } while (is < n); + /*C*/ + if (n4 - 1 <= 0) + return ; + + is = 0; + id = n2 * 2; + do { + for (i2 = is + 1 + n8; i2 <= n; i2 += id) { + t1 = (x3[i2] + x4[i2]) * .7071067811865475; + t2 = (x3[i2] - x4[i2]) * .7071067811865475; + x4[i2] = x2[i2] - t1; + x3[i2] = -x2[i2] - t1; + x2[i2] = x1[i2] - t2; + x1[i2] = x1[i2] + t2; + } + is = 2 * id - n2; + id = 4 * id; + } while (is < n); + /*C*/ + if (n8 - 1 <= 0) + return ; + + e = 2 * 3.14159265358979323 / n2; + ss1 = sin (e); + sd1 = ss1; + sd3 = 3 * sd1 - 4 * (sd1 * sd1 * sd1); + ss3 = sd3; + cc1 = cos (e); + cd1 = cc1; + cd3 = 4 * (cd1 * cd1 * cd1) - 3. * cd1; + cc3 = cd3; + + for (j = 2; j <= n8; j++) { + is = 0; + id = 2 * n2; + jn = n4 - 2 * j + 2; + do { + for (i1 = is + j; i1 <= n; i1 += id) { + i2 = i1 + jn; + t1 = x3[i1] * cc1 + x3[i2] * ss1; + t2 = x3[i2] * cc1 - x3[i1] * ss1; + t3 = x4[i1] * cc3 + x4[i2] * ss3; + t4 = x4[i2] * cc3 - x4[i1] * ss3; + t5 = t1 + t3; + t3 = t1 - t3; + t1 = t2 + t4; + t4 = t2 - t4; + x3[i1] = t1 - x2[i2]; + x4[i2] = t1 + x2[i2]; + x3[i2] = -x2[i1] - t3; + x4[i1] = x2[i1] - t3; + x2[i2] = x1[i1] - t5; + x1[i1] = x1[i1] + t5; + x2[i1] = x1[i2] + t4; + x1[i2] = x1[i2] - t4; + } + is = 2 * id - n2; + id = 4 * id; + } while (is < n); + /*C*/ + t1 = cc1 * cd1 - ss1 * sd1; + ss1 = cc1 * sd1 + ss1 * cd1; + cc1 = t1; + t3 = cc3 * cd3 - ss3 * sd3; + ss3 = cc3 * sd3 + ss3 * cd3; + cc3 = t3; + } + /*C*/ return ; +} + + +/* +CC=================================================================CC +CC CC +CC Subroutine RBITREV(X,M): CC +CC Bitreverses the array X of length 2**M. It generates a CC +CC table ITAB (minimum length is SQRT(2**M) if M is even CC +CC or SQRT(2*2**M) if M is odd). ITAB need only be generated CC +CC once for a given transform length. CC +CC CC +CC Author: CC +CC H.V. Sorensen, University of Pennsylvania, Aug. 1987 CC +CC Arpa address: hvs@ee.upenn.edu CC +CC CC +CC This program may be used and distributed freely as long CC +CC as this header is included. CC +CC CC +CC=================================================================CC +*/ +void rbitrev (double *x, int m) +{ + int itab[66000]; + int m2, nbit, imax, lbss, i, j, k, l, j0; + double t1; + /*C-------Initialization of ITAB array--------------------------------C*/ + m2 = m / 2; + nbit = 1 << m2; + if (2 * m2 != m) + m2 = m2 + 1; + itab[1] = 0; + itab[2] = 1; + imax = 1; + + for (lbss = 2; lbss <= m2; lbss++) { + imax = 2 * imax; + for (i = 1; i <= imax; i++) { + itab[i] = 2 * itab[i]; + itab[i + imax] = 1 + itab[i]; + } + } + + /*C-------The actual bitreversal--------------------------------------C*/ + for (k = 2; k <= nbit; k++) { + j0 = nbit * itab[k] + 1; + i = k; + j = j0; + for (l = 2; l <= itab[k] + 1; l++) { + t1 = x[i]; + x[i] = x[j]; + x[j] = t1; + i = i + nbit; + j = j0 + itab[l]; + } + } + return ; +} diff --git a/TESTU01/TestU01-1.2.3/testu01/fintro.tex b/TESTU01/TestU01-1.2.3/testu01/fintro.tex new file mode 100644 index 0000000..1fa63e2 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fintro.tex @@ -0,0 +1,390 @@ +\chapter {FAMILIES OF GENERATORS} + +\def\eps {$\epsilon\quad$} +\def\epsm {--$\epsilon_1\quad$} + +The tools described in this chapter are convenient for examining +systematically the interaction between specific tests +and certain families of RNGs. +The framework is as follows. +For each family, an RNG of period length near $2^i$ has been selected, +on the basis on some theoretical criteria +that depend on the family, for all integers $i$ in some interval +(from 10 to 40, for example). +% Here, for several families of RNGs, +The parameters of the pre-selected instances are stored in text files +in directory {\tt param}. + +Typically, for a given RNG that fails a test, when the +sample size of the test is increased, the $p$-value would remain +``reasonable'' for a while, say for $n$ up to some +threshold $n_0$ (roughly), and will then converges to 0 or 1 exponentially +fast as a function of $n$. +It is interesting to examine the relationship between $n_0$ and $i$. +The idea is to fit a crude regression model of $n_0$ as a function +of $i$. For example, one may consider a model of the form +\eq + \log_2 n_0 = \gamma i + \nu + \delta, +\endeq +where $\gamma$ and $\nu$ are constants and $\delta$ represents +the noise. The result may give an idea of what period length $\rho$ +of the RNG is required, within a given family, to be safe with respect +to the test that is considered, for a given computer budget. + +This methodology has been applied in +\cite{rGRA01a,rLEC98h,rLEC00c,rLEC01a,rLEC02c,rLEC03c}, +using an earlier version of the present library, +and gave surprisingly good results in many cases. +For full-period LCGs with good spectral test behavior, for example, +the relationships $n_0 \approx 16\,\rho^{1/2}$ +for the collision test and $n_0 \approx 16\,\rho^{1/3}$ +for the birthday spacings test have been obtained. +This means that no LCG is safe with respect to these particular tests +unless its period length $\rho$ is so large that generating +$\rho^{1/3}$ numbers is practically unfeasible. +A period length of $2^{48}$ or less, for example, does not satisfy +this requirement. + + +%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{Common parameters.} \ + + +The first argument of each testing function in the {\tt f} modules +is the family {\tt fam} of random number generators to be tested +(see module {\tt ffam} for details). +That family must be created by calling the appropriate function in +the module {\tt fcong} or {\tt ffsr}, and deleted when no longer needed. + +The second argument (the third one in the {\tt fmultin} module) +of each testing function is a structure {\tt res} that can keep the tables + of $p$-values and other results (see module {\tt fres} for details). +This is useful if one wishes to do something else with the tables of +results after all tests are ended. If one does not +want to post-process or use the tables of results after a {\tt f} test, +it suffices to set the {\tt res} argument to the {\tt NULL} pointer. +Then, the structure is created and deleted automatically inside the +testing function. In any case, the tables of results will be printed +automatically on standard output. + +The third argument (the fourth one in the {\tt fmultin} module) +of each testing function is a structure +{\tt cho} that allows the user to choose varying sample sizes and +other parameters of the tests as a function of the generators {\it lsize} +and the fixed parameters (see module {\tt fcho} for details). + +For each of these three arguments (except possibly for {\tt res} as +explained above), one must call the appropriate {\tt Create} function +before using them, and call the corresponding {\tt Delete} function +when they are no longer needed. + +The last four arguments of each testing function are the integers +{\tt Nr, j1, j2} and {\tt jstep}. The test functions will be applied on +the first {\tt Nr} generators of the family {\tt fam}. +If there are less than {\tt Nr} generators in the family, then {\tt Nr} + will be reset to the number of generators in the tested family. + For each of the generator, tests will be +applied with varying sample sizes determined by the parameter $j$ for +$j$ varying from {\tt j1} to {\tt j2} by step of {\tt jstep}. + + + +\begin {table} +\begin {center} +\caption {Some good LCGs according to the spectral test in up to + dimension 8.} +\label {tab:lcg1} +\smallskip +\begin {tabular}{|@{\quad}l@{\quad}|@{\quad}r@{\quad}|} +\hline +\qquad $m$ & $a$ \\ +\hline +$2^{10}-3\phantom{0} = 1021$ & \rule{0pt}{14pt} 65 \\ +$2^{11}-9\phantom{0} = 2039$ & 995 \\ + $2^{12}-3\phantom{0} = 4093$ & 209 \\ + $2^{13}-1\phantom{0} = 8191$ & 884 \\ + $2^{14}-3\phantom{0} = 16381$ & 572 \\ + $2^{15}-19 = 32749$ & 219 \\ + $2^{16}-15 = 65521$ & 17364 \\ + $2^{17}-1\phantom{0} = 131071$ & 43165 \\ + $2^{18}-5\phantom{0} = 262139$ & 92717 \\ + $2^{19}-1\phantom{0} = 524287$ & 283741 \\ + $2^{20}-3\phantom{0} = 1048573$ & 380985 \\ + $2^{21}-9\phantom{0} = 2097143$ & 360889 \\ + $2^{22}-3\phantom{0} = 4194301$ & 914334 \\ + $2^{23}-15 = 8388593$ & 653276 \\ + $2^{24}-3\phantom{0} = 16777213$ & 6423135 \\ + $2^{25}-39 = 33554393$ & 25907312 \\ + $2^{26}-5\phantom{0} = 67108859$ & 26590841 \\ + $2^{27}-39 = 134217689$ & 45576512 \\ + $2^{28}-57 = 268435399$ & 31792125 \\ + $2^{29}-3\phantom{0} = 536870909$ & 16538103 \\ + $2^{30}-35 = 1073741789$ & 5122456 \\ +\hline +\end {tabular} +\end {center} +\end {table} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\setbox0=\vbox {\hsize = 6.1in +\smallc +\verbatiminput{../examples/fcoll.c} +} + +\begin{figure} +\centering +\myboxit{\box0} +\caption {Applying the collision test to a family of LCGs.} +\label{fig:tmultin} +\end{figure} + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{An example: The collision test applied to a family of LCG's.} \ + + + +For a concrete illustration, Figure~\ref{fig:tmultin} shows +a program applying the collision test (see tests {\tt sknuth\_Collision} +and {\tt smultin\_Multinomial}) +systematically to a family of LCGs. First, the call to + {\tt fcong\_CreateLCG} creates the family of generators to which +the tests are applied; i.e., each generator +instance has its parameters predefined in the file {\tt LCGGood.par}. +These ``good LCGs'' have prime modulus $m$ (the largest prime less + than $2^i$), full period length $m-1$, +and perform well in the spectral test for up to dimension 8. +They are taken from \cite{rLEC99c} and are listed in +Table~\ref{tab:lcg1} for $10\le i\le 30$. + + +The following instruction in the program, {\tt smultin\_CreateParam} with + {\tt NbDelta = 1} and {\tt ValDelta[0] = -1}, specifies that only +the collision test will be applied. The {\tt par} parameter in the test + could be replaced by the {\tt NULL} pointer, +in which case default values would be used and it would not be necessary to + create a {\tt par} structure. The next instruction {\tt fmultin\_CreateRes} + creates a structure to hold the results of the test. If one does not want + to postprocess the results after all the tests are ended, one +may also pass a {\tt NULL} pointer as argument {\tt res} to the test, in +which case it would not be necessary to create a {\tt res} structure +either. The instruction {\tt fcho\_CreateSampleSize} +specifies that the sample size $n$ (the number of points) +will be chosen as $n = 2^{i/2 + j}$. +The next instruction {\tt fmultin\_CreatePer\_DT} says that +the number of cells $k$ will be equal to the period length of the +generator tested, and that the relation between $k$, the one-dimensional +interval $d$, and the dimension $t$ (here 2) is given by $k=d^t$. +Then these two ``choose'' functions are set in the structure {\tt cho} +that will be passed as argument to the test. +The call {\tt fmultin\_Serial1} launches the series of collision +tests, with the parameters $N=1$, $r=0$, $t=2$, +{\tt Sparse = TRUE}. LCGs with period lengths near $2^i$ will +be tested for $i=10,11,\dots,30$, each with sample size $n = 2^{i/2 + j}$ +for $j=1,2,3,4,5$. Finally, all the created structures are deleted to +free the memory used by each of them. + +\input{../examples/fcoll.res1.tex} + +Tables~\ref{tab:coll1} and \ref{tab:coll11} give the results +of this program. +In Table~\ref{tab:coll1}, for each value of $i$ and $j$, the expected +number of collisions is given on the left, and the observed number of +collisions on the right. +We see that for $j\ge 3$, the observed number of collisions is generally +much too small (there are exceptions at $j=5$ and $i =$ 10 and 11). +The $p$-values written in Table~\ref{tab:coll11} are those which fall +outside the interval $[0.01, 0.99]$, which may be called suspect $p$-values. +A $p$-value smaller than $10^{-300}$ is noted by $\epsilon$. +A $p$-value larger than $1 - 10^{-15}$ is noted by $-\epsilon_1$ +($p$-values close to 1 are written as $-p$ instead of $1-p$). +We see that for $j\ge 3$, the $p$-values in Table~\ref{tab:coll11} +are very close to 1. +This means that the two-dimensional points produced by these generators +are too evenly distributed and the test starts detecting this when the +sample size reaches $n_0 \approx 2^{i/2 + 3} \approx 8 \sqrt{\rho}$. +Very clear rejection occurs in all cases for $j=4$, i.e., at sample size +$n \approx 16 \sqrt{\rho}$. + + +\input{../examples/fcoll.res2.tex} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\paragraph*{Another example: The {birthday spacings} test applied + to a family of LCG's.} \ + +The next example in Figure \ref{tab:fbirth} gives a program applying the +{birthday spacings} test (see {\tt smarsa\_BirthdaySpacings}) to a +family of generators. +First the family {\tt LCGPow2} is created by calling +function {\tt fcong\_CreateLCGPow2}. Each generator of the family +has its parameters predefined in file {\tt LCGPow2.par}. These generators +have been chosen such that their modulus $m$ is exactly equal to a power of 2, +i.e. $m = 2^i$ for $10 \le i \le 30$, and their multiplier +gives them a good structure according to the spectral test. +The sample size of the test (the number of points $n$) is then chosen +(by calling {\tt fcho\_CreateSampleSize}) to follow the law $n = 2^{i/3 + j}$, +for generator of modulus $m=2^i$. +The next instruction {\tt fmarsa\_CreateBirthEC} indicates that, given +$N=1$ replication of the test and dimension $t=2$, the number of segments $d$ +on the interval $[0, 1)$ will be chosen so that the expected +number of collisions is (approximately) equal to 1. +These two ``choose'' functions are set in the structure {\tt cho} by the call +{\tt fcho\_CreateCho2} and will thus be + passed as arguments to the tests. +Then function {\tt fmarsa\_BirthdayS1} applies the birthday spacings test +on the 21 selected generators of the family, for $1 \le j \le 5$ and with the +other parameters determined by the above functions. After all the tests are +completed, the following {\tt Delete} functions free the resources used +by the program. + + +\setbox0=\vbox {\hsize = 6.1in +\smallc +\verbatiminput{../examples/fbirth.c} +} + +\begin{figure} +\centering +\myboxit{\box0} +\caption {Applying the birthday spacings test to a family of LCGs.} +\label{tab:fbirth} +\end{figure} + + + +Tables~\ref{tab:birth.res1} and \ref{tab:birth.res2} +give the results of this program. +In Table~\ref{tab:birth.res1}, for each value of $i$ and $j$, the expected +number of collisions is given on the left and the observed number of +collisions on the right. +We see that for $j\ge 2$, the observed number of collisions is +much too large and the more so as $j$ increases. +The right $p$-values written in Table~\ref{tab:birth.res2} are those which fall +outside the interval $[0.01, 0.99]$. A $p$-value smaller than $10^{-300}$ +is noted by $\epsilon$. For $j = 1$, the number of collisions is close +to the expected value and the corresponding $p$-values are in the interval +$[0.01, 0.99]$. The generators pass the test also for $j \le 1$. +But for $j\ge 2$, the $p$-values in Table~\ref{tab:birth.res2} +becomes smaller as $j$ increases. +The tests signals catastrophic failures of the generators already for $j\ge3$. +This is because the two-dimensional points produced by these generators +are too evenly distributed and the test starts detecting this when the +sample size reaches $n \approx 2^{i/3 + 2}$. % \approx 16 \sqrt{\rho}$. +These are quite small sample sizes; for example, for the generator +with $m= 2^{30}$, the tests start to fail for $n$ as small as 4096. + + +\input{../examples/fbirth.res1.tex} +\input{../examples/fbirth.res2.tex} + + + +\iffalse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin {table} +\begin {center} +\caption {Some good and bad (baby) LCGs} +\label {tab:lcg1t} +\smallskip +\begin {tabular}{|lrr|} +\hline +\qquad $m$ & $a$ (good LCG) & $a$ (bad LCG) \\ +\hline + $2^{10}-3 = 1021$ & 65 & 127 \\ + $2^{11}-9 = 2039$ & 995 & 1359 \\ + $2^{12}-3 = 4093$ & 209 & 5 \\ + $2^{13}-1 = 8191$ & 884 & 2341 \\ + $2^{14}-3 = 16381$ & 572 & 2731 \\ + $2^{15}-19 = 32749$ & 219 & 10 \\ + $2^{16}-15 = 65521$ & 17364 & 17 \\ + $2^{17}-1 = 131071$ & 43165 & 68985 \\ + $2^{18}-5 = 262139$ & 92717 & 203883 \\ + $2^{19}-1 = 524287$ & 283741 & 458756 \\ + $2^{20}-3 = 1048573$ & 380985 & 213598 \\ + $2^{21}-9 = 2097143$ & 360889 & 202947 \\ + $2^{22}-3 = 4194301$ & 914334 & 4079911 \\ + $2^{23}-15 = 8388593$ & 653276 & 2696339 \\ + $2^{24}-3 = 16777213$ & 6423135 & 486293 \\ + $2^{25}-39 = 33554393$ & 25907312 & 5431467 \\ + $2^{26}-5 = 67108859$ & 26590841 & 42038579 \\ + $2^{27}-39 = 134217689$ & 45576512 & 24990322 \\ + $2^{28}-57 = 268435399$ & 31792125 & 31842465 \\ + $2^{29}-3 = 536870909$ & 16538103 & 8903330 \\ + $2^{30}-35 = 1073741789$ & 5122456 & 3930720 \\ + $2^{31}-1 = 2147483647$ & 1389796 & 868723 \\ + $2^{32} -5 = 4294967291$ & 1588635695 & 1123161 \\ + $2^{33}-9 = 8589934583 $ & 7425194315 & 1026767 \\ + $2^{34}-41 = 17179869143$ & 5295517759 & 10045 \\ + $2^{35}-31 = 34359738337$ & 3124199165 & 10052 \\ + $2^{36}-5 = 68719476731$ & 49865143810 & 102254510 \\ +% $2^{37}-25 = 137438953447$ & 76886758244 & 87666368 \\ +% $2^{38}-45 $ & 17838542566 & 1045020214 \\ +% $2^{39}-7 $ & 61992693052 & 809807353 \\ +% $2^{40}-87 $ & 1038914804222 & 87666376 \\ +\hline +\end {tabular} +\end {center} +\end {table} + + +We apply a test to a whole family while varying the sample size $n$ +following a law of the form $n=2^{\alpha\, e + \beta}$. If we happen to +select suitable $\alpha$ and $\beta$, we may be able to discover a + regularity between the sample size and the size (modulus) of the +generator. + + +Par exemple, la table \ref{tab:coll} montre les $p$-values du test +de Collisions pour les +{\tt BadLCG2} en fonction de $n$, pour un nombre de cases $k\approx 2^e$ +en 2 dimensions, et o\`u $\epsilon$ denote une value $< 10^{-15}$. + Les values de $n$ sont donnees par +$$ +n = 2^{\frac e 2 + \nu}. +$$ + + +\begin {table} +\centering +\caption {The $p$-values of $C$ for the bad LCGs, for $t=2$ +and $k\approx 2^e$.} +\label {tab:coll} +\smallskip +\begin {tabular}{|r|@{\extracolsep{16pt}}lllll|} +\hline + $i$& $\nu=-3$ & $\nu=-2$ & $\nu=-1$ & $\nu=0$ & $\nu=1$ \\ +\hline + 14 & & 4.5E-4 & 7.0E-3 & 3.1E-9 & \eps \\ + 15 & & & 9.2E-6 & 1.6E-10 & \eps \\ + 16 & & 4.6E-4 & 7.1E-3 & 6.0E-8 & \eps \\ + 17 & & 4.8E-4 & & 6.0E-8 & \eps \\ + 18 & & & 7.1E-3 & 3.4E-9 & \eps \\ + 19 & & 4.7E-4 & & 3.4E-9 & \eps \\ + 20 & & & & 1.7E-4 & \eps \\ + 21 & & & & 3.4E-9 & \eps \\ + 22 & & 4.8E-4 & 7.2E-3 & 3.2E-13 & \eps \\ + 23 & & 4.8E-4 & & 1.7E-4 & \eps \\ + 24 & & & 7.2E-3 & 1.7E-4 & \eps \\ + 25 & & & 3.0E-4 & 1.0E-6 & \eps \\ + 26 & & & & 1.0E-6 & \eps \\ + 27 & & & 7.2E-3 & 1.4E-5 & \eps \\ + 28 & & & 7.2E-3 & 6.2E-8 & \eps \\ + 29 & & 4.8E-4 & 7.2E-3 & 1.0E-6 & \eps \\ + 30 & & & 3.0E-4 & \eps & \eps \\ + 31 & & 4.8E-4 & 7.2E-3 & 1.8E-3 & \eps \\ + 32 & & & 9.2E-6 & 6.2E-8 & \eps \\ + 33 & & 4.8E-4 & 7.2E-3 & 1.8E-3 & 2.4E-4 \\ + 34 & & 4.8E-4 & 9.2E-6 & & \eps \\ +\hline +\end {tabular} +\end {table} + + +\fi %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/TESTU01/TestU01-1.2.3/testu01/fknuth.c b/TESTU01/TestU01-1.2.3/testu01/fknuth.c new file mode 100644 index 0000000..9fd5ca0 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fknuth.c @@ -0,0 +1,486 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fknuth.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "gofs.h" +#include "gofw.h" + +#include "fknuth.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" +#include "ftab.h" +#include "sknuth.h" + +#include +#include + + +long fknuth_Maxn = 4194304; + +enum { + A_GAP, + A_SIMPPOKER, + A_COUPONCOLLECTOR, + A_RUN, + A_MAXOFT, + A_N +}; + + +/*------------------------------- Functions ------------------------------*/ + +static void InitRes1 ( + ffam_Fam *fam, + fknuth_Res1 *res, /* Results holder */ + int N, /* Number of replications */ + int Nr, + int j1, int j2, int jstep, + char *name1, + char *name2 +) +/* + * Initializes the fknuth_Res1 structure + */ +{ + fres_InitCont (fam, res->AD, N, Nr, j1, j2, jstep, name2); + fres_InitCont (fam, res->Chi, N, Nr, j1, j2, jstep, name1); +} + + +/*-------------------------------------------------------------------------*/ + +fknuth_Res1 * fknuth_CreateRes1 (void) +{ + fknuth_Res1 *res; + res = util_Malloc (sizeof (fknuth_Res1)); + res->Chi = fres_CreateCont (); + res->AD = fres_CreateCont (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fknuth_DeleteRes1 (fknuth_Res1 *res) +{ + if (res == NULL) + return; + fres_DeleteCont (res->AD); + fres_DeleteCont (res->Chi); + util_Free (res); +} + + +/*=========================================================================*/ + +static void PrintHead (char *name, ffam_Fam *fam, int test, void *par1, + int Nr, int j1, int j2, int jstep) +{ + long *Par = par1; + double *ParD = par1; + + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", name); + if (test == A_GAP) + printf (" N = %ld, r = %d", (long) ParD[0], (int) ParD[1]); + else + printf (" N = %ld, r = %d", Par[0], (int) Par[1]); + + switch (test) { + case A_GAP: + printf (", Alpha = %f, Beta = %f", ParD[2], ParD[3]); + break; + case A_SIMPPOKER: + printf (", d = %d, k = %d", (int) Par[2], (int) Par[3]); + break; + case A_COUPONCOLLECTOR: + printf (", d = %d", (int) Par[2]); + break; + case A_RUN: + printf (", Up = "); util_WriteBool (Par[2], 5); + printf (", Indep = "); util_WriteBool (Par[3], 5); + break; + case A_MAXOFT: + printf (", d = %d, t = %d", (int) Par[2], (int) Par[3]); + break; + default: + util_Error ("in fknuth, PrintHead: no such case"); + } + + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); +} + + +/*=========================================================================*/ + +static void TabGap (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r; + long N, n; + double Alpha, Beta; + double *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + r = Par[1]; + Alpha = Par[2]; + Beta = Par[3]; + + n = fcho_ChooseParamL (cho, (long) (gofs_MinExpected /(Beta - Alpha)), + fknuth_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateChi2 (); + sknuth_Gap (fam->Gen[irow], sres, N, n, r, Alpha, Beta); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*========================================================================*/ + +void fknuth_Gap1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, double Alpha, double Beta, + int Nr, int j1, int j2, int jstep) +{ + double Par[4]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = Alpha; + Par[3] = Beta; + + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fknuth_Gap1", fam, A_GAP, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fknuth_Gap1"); + ftab_MakeTables (fam, res, cho, Par, TabGap, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabSimpPoker (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, d, k; + long N, n; + long *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + r = Par[1]; + d = Par[2]; + k = Par[3]; + + n = fcho_ChooseParamL (cho, (long) (3.0 * gofs_MinExpected), + fknuth_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateChi2 (); + sknuth_SimpPoker (fam->Gen[irow], sres, N, n, r, d, k); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*========================================================================*/ + +void fknuth_SimpPoker1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int d, int k, + int Nr, int j1, int j2, int jstep) +{ + long Par[4]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = d; + Par[3] = k; + + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fknuth_SimpPoker1", fam, A_SIMPPOKER, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fknuth_SimpPoker1"); + ftab_MakeTables (fam, res, cho, Par, TabSimpPoker, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabCouponCollector (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, d; + long N, n; + long *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + r = Par[1]; + d = Par[2]; + + n = fcho_ChooseParamL (cho, (long) (3.0 * gofs_MinExpected), + fknuth_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateChi2 (); + sknuth_CouponCollector (fam->Gen[irow], sres, N, n, r, d); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*========================================================================*/ + +void fknuth_CouponCollector1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int d, + int Nr, int j1, int j2, int jstep) +{ + long Par[3]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = d; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fknuth_CouponCollector1", + fam, A_COUPONCOLLECTOR, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fknuth_CouponCollector1"); + ftab_MakeTables (fam, res, cho, Par, TabCouponCollector, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabRun (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r; + lebool Up, Indep; + long N, n; + long *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + long nmin; + + N = Par[0]; + r = Par[1]; + Up = Par[2]; + Indep = Par[3]; + if (!Indep) + nmin = 600; + else + nmin = 3.0 * gofs_MinExpected; + + n = fcho_ChooseParamL (cho, nmin, fknuth_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateChi2 (); + if (Indep) + sknuth_RunIndep (fam->Gen[irow], sres, N, n, r, Up); + else + sknuth_Run (fam->Gen[irow], sres, N, n, r, Up); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*========================================================================*/ + +void fknuth_Run1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, lebool Up, lebool Indep, + int Nr, int j1, int j2, int jstep) +{ + long Par[4]; + lebool localRes; + char Name[30]; + + Par[0] = N; + Par[1] = r; + Par[2] = Up; + Par[3] = Indep; + + if (Indep) + strcpy (Name, "fknuth_RunIndep1"); + else + strcpy (Name, "fknuth_Run1"); + + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead (Name, fam, A_RUN, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, Name); + ftab_MakeTables (fam, res, cho, Par, TabRun, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabMaxOft (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, d, t; + long N, n; + long *Par = par1; + fknuth_Res1 *fres = res1; + sknuth_Res1 *sres; + + N = Par[0]; + r = Par[1]; + d = Par[2]; + t = Par[3]; + + n = fcho_ChooseParamL (cho, (long) (d * gofs_MinExpected), fknuth_Maxn, + i, j); + if (n <= 0) + return; + + sres = sknuth_CreateRes1 (); + sknuth_MaxOft (fam->Gen[irow], sres, N, n, r, d, t); + fres_FillTableEntryC (fres->Chi, sres->Chi->pVal2, N, irow, icol); + fres_FillTableEntryC (fres->AD, sres->Bas->pVal2, N, irow, icol); + sknuth_DeleteRes1 (sres); +} + + +/*========================================================================*/ + +void fknuth_MaxOft1 (ffam_Fam *fam, fknuth_Res1 *res, fcho_Cho *cho, + long N, int r, int d, int t, + int Nr, int j1, int j2, int jstep) +{ + long Par[4]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = d; + Par[3] = t; + if (res == NULL) { + localRes = TRUE; + res = fknuth_CreateRes1 (); + } else + localRes = FALSE; + + PrintHead ("fknuth_MaxOft1", fam, A_MAXOFT, Par, Nr, j1, j2, jstep); + InitRes1 (fam, res, N, Nr, j1, j2, jstep, "fknuth_MaxOft1, Chi", + "fknuth_MaxOft1, AD"); + ftab_MakeTables (fam, res, cho, Par, TabMaxOft, Nr, j1, j2, jstep); + fres_PrintCont (res->Chi); + fres_PrintCont (res->AD); + if (localRes) + fknuth_DeleteRes1 (res); +} + + +/*========================================================================*/ + +void fknuth_Serial1 (void) +{ + util_Error ("fknuth_Serial1: use fmultin_Serial1 instead"); +} + + +/*========================================================================*/ + +void fknuth_SerialSparse1 (void) +{ + util_Error ("fknuth_SerialSparse1: use fmultin_Serial1 instead"); +} + + +/*========================================================================*/ + +void fknuth_Collision1 (void) +{ + util_Error ("fknuth_Collision1: use fmultin_Serial1 instead"); +} + + +/*========================================================================*/ + +void fknuth_Permutation1 (void) +{ + util_Error ("fknuth_Permutation1: use fmultin_Permut1 instead"); +} + + +/*========================================================================*/ + +void fknuth_CollisionPermut1 (void) +{ + util_Error ("fknuth_CollisionPermut1: use fmultin_Permut1 instead"); +} + + +/*========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fknuth.tex b/TESTU01/TestU01-1.2.3/testu01/fknuth.tex new file mode 100644 index 0000000..0daf57c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fknuth.tex @@ -0,0 +1,176 @@ +\defmodule {fknuth} + +This module applies tests from the module {\tt sknuth} +to families of generators of different sizes, +and prints tables of the corresponding $p$-values. +% The results are placed in tables of $p$-values. + + +\bigskip +\hrule +\code\hide +/* fknuth.h for ANSI C */ +#ifndef FKNUTH_H +#define FKNUTH_H +\endhide +#include "gdef.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" + + +extern long fknuth_Maxn; +\endcode +\tab + Upper bound on $n$. + A test is called only when $n$ does not exceed this value. + Default value: $2^{22}$. + \hpierre {Pourquoi $2^{22}$ ici et $2^{20}$ ailleurs? } + \hrichard {Il n'y a pas de raison sp\'eciale. Je ne sais pas quelle valeur + mettre par d\'efaut.} + \hpierre {Alors il me semble qu'il faut mettre la m\^eme valeur partout. + Peut-\^etre $2^{22}$, ou plus. } +\endtab +\ifdetailed %%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} + +The test results for the {\tt fknuth\_MaxOft} test can be recovered +in the following structure. + +\code + +typedef struct { + fres_Cont *Chi; + fres_Cont *AD; +} fknuth_Res1; +\endcode + \tab + Structure for keeping the tables of results of the tests in + {\tt fknuth\_MaxOft}. The results for the chi-square test are kept in + {\tt Chi}, and for the Anderson-Darling test in {\tt AD}. + \endtab +\code + + +fknuth_Res1 * fknuth_CreateRes1 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt fknuth\_MaxOft} test. + \endtab +\code + + +void fknuth_DeleteRes1 (fknuth_Res1 *res); +\endcode + \tab + Frees the memory allocated by {\tt fknuth\_CreateRes1}. + \endtab + +\fi %%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Applying the tests} + +\code + +void fknuth_Serial1 (void); +\endcode +\tab This is equivalent to calling + {\tt fmultin\_Serial1} with {\tt Sparse = FALSE}, + {\tt NbDelta = 1}, and {\tt Val\-Delta[0] = 1}. + \endtab +\code + + +void fknuth_SerialSparse1 (void); +\endcode +\tab This is equivalent to calling {\tt fmultin\_Serial1} with + {\tt Sparse = TRUE}, {\tt NbDelta = 1}, and {\tt Val\-Delta[0] = 1}. + \endtab +\code + + +void fknuth_Collision1 (void); +\endcode +\tab This is equivalent to calling {\tt fmultin\_Serial1} with + {\tt Sparse = TRUE, NbDelta = 1}, and {\tt Val\-Delta[0] = -1}. + \endtab +\code + + +void fknuth_Permutation1 (void); +\endcode +\tab This is equivalent to calling {\tt fmultin\_Permut1} with + {\tt Sparse = FALSE, NbDelta = 1}, and + {\tt Val\-Delta[0] = 1}. + \endtab +\code + + +void fknuth_CollisionPermut1 (void); +\endcode +\tab This is equivalent to calling {\tt fmultin\_Permut1} with + {\tt Sparse = TRUE}, {\tt NbDelta = 1}, and {\tt Val\-Delta[0] = -1}. + \endtab +\code + + +void fknuth_Gap1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, double Alpha, double Beta, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + This function calls the test {\tt sknuth\_Gap} with parameters + {\tt N, $n$, r, Alpha, Beta}, for sample size $n$ chosen by the function + {\tt cho->Choose(param, i, j)}, + for the first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. The parameters in {\tt param} + were set at the creation of {\tt cho} and $i$ is the lsize of the + generator being tested. + When $n$ exceeds {\tt fknuth\_Maxn}, the test is not run. +\endtab +\code + + +void fknuth_SimpPoker1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int d, int k, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fknuth\_Gap} but with {\tt sknuth\_SimpPoker}. + \endtab +\code + + +void fknuth_CouponCollector1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int d, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fknuth\_Gap} but with {\tt sknuth\_CouponCollector}. + \endtab +\code + + +void fknuth_Run1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, lebool Up, lebool Indep, + int Nr, int j1, int j2, int jstep); + +\endcode + \tab Similar to {\tt fknuth\_Gap} but with {\tt sknuth\_RunIndep} + if {\tt Indep = TRUE}, and {\tt sknuth\_Run} otherwise. + \endtab +\code + + +void fknuth_MaxOft1 (ffam_Fam *fam, fknuth_Res1 *res, fcho_Cho *cho, + long N, int r, int d, int t, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fknuth\_Gap} but with {\tt sknuth\_MaxOft}. + \endtab +\code\hide +#endif +\endhide\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fmarsa.c b/TESTU01/TestU01-1.2.3/testu01/fmarsa.c new file mode 100644 index 0000000..0c7e8d1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fmarsa.c @@ -0,0 +1,483 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fmarsa.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "util.h" +#include "gofs.h" +#include "num.h" + +#include "fmarsa.h" +#include "fcho.h" +#include "ffam.h" +#include "fres.h" +#include "ftab.h" +#include "smarsa.h" +#include "unif01.h" + +#include +#include +#include + +long fmarsa_Maxn = 1024 * 1024 * 32; +long fmarsa_MaxL = 1024 * 4; + + + + +/*------------------------------ Functions --------------------------------*/ + + +static void InitRes2 ( + ffam_Fam *fam, + fmarsa_Res2 *res, /* Results holder */ + int N, /* Number of replications */ + int Nr, + int j1, int j2, int jstep, + char *name1, + char *name2 +) +/* + * Initializes the fmarsa_Res2 structure + */ +{ + fres_InitCont (fam, res->GCD, N, Nr, j1, j2, jstep, name1); + fres_InitCont (fam, res->NumIter, N, Nr, j1, j2, jstep, name2); +} + + +/*-------------------------------------------------------------------------*/ + +fmarsa_Res2 * fmarsa_CreateRes2 (void) +{ + fmarsa_Res2 *res; + res = util_Malloc (sizeof (fmarsa_Res2)); + res->NumIter = fres_CreateCont (); + res->GCD = fres_CreateCont (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fmarsa_DeleteRes2 (fmarsa_Res2 *res) +{ + if (res == NULL) + return; + fres_DeleteCont (res->GCD); + fres_DeleteCont (res->NumIter); + util_Free (res); +} + + +/*=========================================================================*/ + +static void PrintHead (char *test, ffam_Fam * fam, + long N, long n, int r, int s, int L, int t, int p, + int Nr, int j1, int j2, int jstep) +{ + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", test); + printf (" N = %ld,", N); + if (n) + printf (" n = %ld,", n); + printf (" r = %d,", r); + if (s) + printf (" s = %d,", s); + if (L) + printf (" L = %d", L); + if (t) + printf (" t = %d,", t); + if (p) + printf (" p = %d", p); + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); +} + + +/*=========================================================================*/ + +static int CheckParamMat (int prec, void *cho, + long *pn, int *pr, int *ps, long *pL, long LMin, int i, int j) +/* + * Set the values of the parameters for the test. If a parameter is < 0, + * will call a choose function to set it. Otherwise, will accept it as is. + * Returns 0 if parameters are ok for the test, returns -1 if the test + * should not be done for these parameters. + */ +{ + fcho_Cho2 *cho2 = cho; + fcho_Cho *chon; + fcho_Cho *choL; + + util_Assert (cho, "fmarsa: cho is NULL"); + chon = cho2->Chon; + choL = cho2->Chop2; + if (*pn < 0) { + util_Assert (chon, "fmarsa: n < 0 and chon is NULL"); + *pn = chon->Choose (chon->param, i, j); + + if (*pn <= 3.0 * gofs_MinExpected) { + printf ("n is too small\n\n"); + return -1; + } + if (*pn > fmarsa_Maxn) { + printf ("n > %2ld\n\n", fmarsa_Maxn); + return -1; + } + } + + *ps = fcho_Chooses (*pr, *ps, prec); + if (*ps <= 0) + return -1; + + if (*pL < 0) { + util_Assert (choL, "fmarsa: L < 0 and chop2 is NULL"); + *pL = choL->Choose (choL->param, i, j); + + if (*pL <= LMin) { + printf ("L is too small\n\n"); + return -1; + } + if (*pL > fmarsa_MaxL) { + printf ("L > %2ld\n\n", fmarsa_MaxL); + return -1; + } + } + return 0; +} + + +/*=========================================================================*/ + + +static void TabMatrixR (ffam_Fam * fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n, L; + const long *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + L = Par[4]; + + if (CheckParamMat (fam->Resol[irow], cho, &n, &r, &s, &L, 1, i, j)) + return; + + sres = sres_CreateChi2 (); + smarsa_MatrixRank (fam->Gen[irow], sres, N, n, r, s, L, L); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fmarsa_MatrixR1 (ffam_Fam * fam, fres_Cont * res, fcho_Cho2 * cho, + long N, long n, int r, int s, int L, int Nr, int j1, int j2, int jstep) +{ + long Par[5] = { 0 }; + lebool localRes; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = s; + Par[4] = L; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + util_Assert (n < 0 || L < 0, + "fmarsa_MatrixR1: Either n or L must be < 0" ); + PrintHead ("fmarsa_MatrixR1", fam, N, n, r, s, L, 0, 0, Nr, j1, j2, + jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fmarsa_MatrixR1"); + ftab_MakeTables (fam, res, cho, Par, TabMatrixR, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*=========================================================================*/ + +static void WriteBirthEC (void *vpar, long junk1, long junk2) +{ + double *Par = vpar; + double EC = Par[2]; + printf ("Choose d such that EC = %f\n\n", EC); +} + +/*-------------------------------------------------------------------------*/ + +static double ChooseBirthEC (void *vpar, long n, long junk) +{ + double *Par = vpar; + long N = Par[0]; + int t = Par[1]; + double EC = Par[2]; + long d; + double k, dr; + double Mu; + + WriteBirthEC (vpar, 0, 0); + k = (N * (double) n * n * n) / (4.0 * EC); + if (k >= smarsa_Maxk) { + printf ("k >= %2.0f\n\n", smarsa_Maxk); + return -1.0; + } + d = dr = pow (k, 1.0 / t); + if (dr > LONG_MAX) { + printf ("d > LONG_MAX\n\n"); + return -1.0; + } + + k = pow ((double) d, (double) t); + Mu = N * (double) n * n * n / (4.0 * k); + if (8.0 * Mu > sqrt (sqrt (k))) { + printf ("8 EC > k^(1/4)\n\n"); + return -1.0; + } + return (double) d; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho *fmarsa_CreateBirthEC (long N, int t, double EC) +{ + fcho_Cho *cho; + double *Par; + + cho = util_Malloc (sizeof (fcho_Cho)); + Par = util_Calloc (3, sizeof (double)); + Par[0] = N; + Par[1] = t; + Par[2] = EC; + cho->param = Par; + cho->Write = WriteBirthEC; + cho->Choose = ChooseBirthEC; + cho->name = util_Calloc (2, sizeof (char)); + strcpy (cho->name, "d"); + return cho; +} + +/*-------------------------------------------------------------------------*/ + +void fmarsa_DeleteBirthEC (fcho_Cho * cho) +{ + if (NULL == cho) + return; + cho->name = util_Free (cho->name); + cho->param = util_Free (cho->param); + util_Free (cho); +} + + +/*=========================================================================*/ + +static int CheckParamBirth (int prec, void *cho, + long *pn, int *pr, long *pd, int i, int j) +/* + * Set the values of the parameters for the test. + * Returns 0 if parameters are ok for the test, returns -1 if the test + * should not be done for these parameters. + */ +{ + fcho_Cho2 *cho2 = cho; + fcho_Cho *chon; + fcho_Cho *chod; + int s; + + util_Assert (cho, "fmarsa: cho is NULL"); + chon = cho2->Chon; + chod = cho2->Chop2; + util_Assert (chon, "fmarsa: chon is NULL"); + *pn = chon->Choose (chon->param, i, j); + if (*pn > fmarsa_Maxn) { + printf ("n > %2ld\n\n", fmarsa_Maxn); + return -1; + } + + util_Assert (chod, "fmarsa: chop2 is NULL"); + *pd = chod->Choose (chod->param, *pn, 0); + if (*pd <= 1.0) + return -1; + + s = num_Log2 ((double) *pd); + if (*pr + s > prec) { + printf ("r + Lg(d) > Resolution of generator\n\n"); + return -1; + } + + return 0; +} + + +/*=========================================================================*/ + +static void TabBirthdayS (ffam_Fam * fam, void *vres, void *cho, + void *vpar, int i, int j, int irow, int icol) +{ + int r, t, p; + long N, n, d; + const long *Par = vpar; + fres_Poisson *fres = vres; + sres_Poisson *sres; + + N = Par[0]; + r = Par[1]; + t = Par[2]; + p = Par[3]; + + if (CheckParamBirth (fam->Resol[irow], cho, &n, &r, &d, i, j)) + return; + + sres = sres_CreatePoisson (); + smarsa_BirthdaySpacings (fam->Gen[irow], sres, N, n, r, d, t, p); + fres_FillTableEntryPoisson (fres, sres->Mu, sres->sVal2, sres->pLeft, + sres->pRight, sres->pVal2, irow, icol); + sres_DeletePoisson (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fmarsa_BirthdayS1 (ffam_Fam * fam, fres_Poisson * res, fcho_Cho2 * cho, + long N, int r, int t, int p, int Nr, int j1, int j2, int jstep) +{ + long Par[4] = { 0 }; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = t; + Par[3] = p; + + if (res == NULL) { + localRes = TRUE; + res = fres_CreatePoisson (); + } else + localRes = FALSE; + + PrintHead ("fmarsa_BirthdayS1", + fam, N, 0, r, 0, 0, t, p, Nr, j1, j2, jstep); + fres_InitPoisson (fam, res, Nr, j1, j2, jstep, "fmarsa_BirthdayS1"); + ftab_MakeTables (fam, res, cho, Par, TabBirthdayS, Nr, j1, j2, jstep); + ftab_PrintTable2 (res->Exp, res->Obs, FALSE); + ftab_PrintTable (res->PVal2); + if (localRes) + fres_DeletePoisson (res); +} + + +/*========================================================================*/ + +void fmarsa_SerialOver1 (void) +{ + util_Error ("fmarsa_SerialOver1: use fmultin_SerialOver1 instead"); +} + +/*========================================================================*/ + +void fmarsa_CollisionOver1 (void) +{ + util_Error ("fmarsa_CollisionOver1: use fmultin_SerialOver1 instead"); +} + + +/*=========================================================================*/ + +static void TabGCD (ffam_Fam * fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n; + const long *Par = par1; + fmarsa_Res2 *fres = res1; + smarsa_Res2 *sres; + + N = Par[0]; + r = Par[1]; + s = Par[2]; + + n = fcho_ChooseParamL (cho, (long) (3.0 * gofs_MinExpected), + fmarsa_Maxn, i, j); + if (n <= 0) + return; + s = fcho_Chooses (r, s, fam->Resol[irow]); + if (s <= 0) + return; + + sres = smarsa_CreateRes2 (); + smarsa_GCD (fam->Gen[irow], sres, N, n, r, s); + fres_FillTableEntryC (fres->GCD, sres->GCD->pVal2, N, irow, icol); + fres_FillTableEntryC (fres->NumIter, sres->NumIter->pVal2, N, irow, icol); + smarsa_DeleteRes2 (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fmarsa_GCD1 (ffam_Fam *fam, fmarsa_Res2 *res, fcho_Cho *cho, + long N, int r, int s, int Nr, int j1, int j2, int jstep) +{ + long Par[3] = { 0 }; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = s; + if (res == NULL) { + localRes = TRUE; + res = fmarsa_CreateRes2 (); + } else + localRes = FALSE; + + PrintHead ("fmarsa_GCD1", fam, N, 0, r, s, 0, 0, 0, Nr, j1, j2, jstep); + InitRes2 (fam, res, N, Nr, j1, j2, jstep, + "fmarsa_GCD1, GCD", "fmarsa_GCD1, NumIter"); + ftab_MakeTables (fam, res, cho, Par, TabGCD, Nr, j1, j2, jstep); + fres_PrintCont (res->GCD); + /* fres_PrintCont (res->NumIter); */ + if (localRes) + fmarsa_DeleteRes2 (res); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fmarsa.tex b/TESTU01/TestU01-1.2.3/testu01/fmarsa.tex new file mode 100644 index 0000000..9b54a58 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fmarsa.tex @@ -0,0 +1,175 @@ +\defmodule {fmarsa} + +This module applies tests from the module {\tt smarsa} +to a family of generators of different sizes. + + +\bigskip\hrule +\code\hide +/* fmarsa.h for ANSI C */ +#ifndef FMARSA_H +#define FMARSA_H +\endhide +#include "ffam.h" +#include "fres.h" +#include "fcho.h" + + +extern long fmarsa_Maxn, fmarsa_MaxL; +\endcode +\tab + Upper bound on the sample size $n$ in {\tt fmarsa\_BirthdayS1} and on + the dimension $L \times L$ of the matrices in {\tt fmarsa\_MatrixR1}. + A test is called only when $n$ and $L$ do not exceed their limit value. + Default values: $n = 2^{24}$ and $L = 2^{12}$. +\endtab + +\ifdetailed %%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} + +The test results for the {\tt fmarsa\_GCD1} test can be recovered +in the following structure. + +\code + +typedef struct { + fres_Cont *GCD; + fres_Cont *NumIter; +} fmarsa_Res2; +\endcode + \tab + Structure for keeping the tables of results of the tests in + {\tt fmarsa\_GCD1}. The field {\tt GCD} holds the results for the + greatest common divisor and {\tt NumIter} holds the results for the + number of iterations used to find the GCD. + This last field is unused for now. + \endtab +\code + + +fmarsa_Res2 * fmarsa_CreateRes2 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt fmarsa\_GCD1} test. + \endtab +\code + + +void fmarsa_DeleteRes2 (fmarsa_Res2 *res); +\endcode + \tab + Frees the memory allocated by {\tt fmarsa\_CreateRes2}. + \endtab + +\fi %%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Choosing the parameters} + +\code + +fcho_Cho * fmarsa_CreateBirthEC (long N, int t, double EC); +\endcode + \tab + Given the number of replications $N$, the dimension $t$ and the sample + size $n$, the parameter $d$ in {\tt smarsa\_BirthdaySpacings} will be chosen + so that the expected number of collisions is approximately $EC$, + i.e. $EC = Nn^3/4d^t$. + The returned structure must be passed as the second pointer in the + argument {\tt cho} of the test. + % Recommendation: $EC = 16$ and $t = 2$. + \endtab +\code + + +void fmarsa_DeleteBirthEC (fcho_Cho *cho); +\endcode + \tab + Frees the memory allocated by {\tt fmarsa\_CreateBirthEC}. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code + +void fmarsa_SerialOver1 (void); +\endcode +\tab This is equivalent to calling {\tt fmultin\_SerialOver1} with + {\tt Sparse = FALSE}, {\tt NbDelta = 1}, and {\tt Val\-Delta[0] = 1}. +\endtab +\code + + +void fmarsa_CollisionOver1 (void); +\endcode + +\tab This is equivalent to calling {\tt fmultin\_SerialOver1} with + {\tt Sparse = TRUE}, {\tt NbDelta = 1}, and {\tt Val\-Delta[0] = -1}. +\endtab +\code + + +void fmarsa_BirthdayS1 (ffam_Fam *fam, fres_Poisson *res, fcho_Cho2 *cho, + long N, int r, int t, int p, + int Nr, int j1, int j2, int jstep); +\endcode +\tab This function calls the test {\tt smarsa\_BirthdaySpacings} with + parameters {\tt N}, $n$, {\tt r}, $d$, {\tt t} and {\tt p} for the + first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. The sample size $n$ and + the one-dimensional interval $d$ are chosen from + $n = {}$ {\tt cho->Chon->Choose(param, i, j)} and + $d = {}$ {\tt cho->Chop2->Choose(param, n, 0)}. {\tt Chon} and + {\tt Chop2} must have been created before. When $n$ exceeds + {\tt fmarsa\_Maxn} or $k = d^t$ exceeds {\tt fmarsa\_Maxk}, + the test is not run. +\endtab +\code + + +void fmarsa_MatrixR1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, int L, + int Nr, int j1, int j2, int jstep); +\endcode + \tab This function calls the test {\tt smarsa\_MatrixRank} with + parameters {\tt N}, $n$, {\tt r}, {\tt s}, $L$ for the first {\tt Nr} + generators of family {\tt fam}, for $j$ going from {\tt j1} to {\tt j2} + by steps of {\tt jstep}. Either or both of $n$ and $L$ can be varied as + the sample size, by passing a negative value as an argument of the + function. One must then create the corresponding function + {\tt cho->Chon} or {\tt cho->Chop2} before calling the test. + One will have either $n = {}$ {\tt cho->Chon->Choose(param, i, j)}, + or $L = {}$ {\tt cho->Chop2->Choose(param, i, j)}. A positive value for + $n$ or $L$ will be used as is by the test. When $n$ exceeds + {\tt fmarsa\_Maxn} or $L$ exceeds {\tt fmarsa\_MaxL}, the test is not + run. Only square matrices of order $L\times L$ are considered. + \endtab +\code + + +void fmarsa_GCD1 (ffam_Fam *fam, fmarsa_Res2 *res, fcho_Cho *cho, + long N, int r, int s, + int Nr, int j1, int j2, int jstep); +\endcode + \tab This function calls the test {\tt smarsa\_GCD} with + parameters {\tt N}, $n$, {\tt r}, {\tt s} for sample size $n$ chosen + by $n={}$ {\tt cho->Choose(param, i, j)}, for the first {\tt Nr} + generators of family {\tt fam}, for $j$ going from {\tt j1} to {\tt j2} + by steps of {\tt jstep}. When $n$ exceeds + {\tt fmarsa\_Maxn}, the test is not run. + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fmultin.c b/TESTU01/TestU01-1.2.3/testu01/fmultin.c new file mode 100644 index 0000000..854eb56 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fmultin.c @@ -0,0 +1,1054 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fmultin.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "num.h" +#include "util.h" + +#include "fmultin.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" +#include "ftab.h" +#include "smultin.h" + +#include +#include +#include +#include + + +long fmultin_Maxn = 16777216; + +#define LEN 127 +#define LEN2 50 +#define LEN3 10 + +typedef enum { + A_MULT, + A_BITS, + A_PERM +} TestType; + +typedef enum { + B_DT, + B_2HT, + B_2L, + B_T +} KType; + +typedef struct { + long N; /* Number of replications */ + int t; /* Dimension */ + double R; + char *name; + KType kcho; +} Multin_Param; + +static const double EPSILON = 1.0E-14; + +/* The stable parameters values used by default */ +static smultin_Param ParamDefault = { + 2, /* NbDelta */ + {-1, 1}, /* ValDelta */ + smultin_GenerCellSerial, /* GenerCell */ + -1 /* bmax */ +}; + + +/* The approximation used in the distribution of the CollisionOver test */ +#define NMESS 5 +static char COAMessages[NMESS][LEN3 + 1]; + + + + +/*------------------------------- Functions ------------------------------*/ + + +static void InitCOAStrings (void) +/* + * Type of approximation used in CollisionOver test. + */ +{ + strncpy (COAMessages[smultin_CollNormal], " N ", (size_t) LEN3); + strncpy (COAMessages[smultin_CollPoissonSparse], " C ", (size_t) LEN3); + strncpy (COAMessages[smultin_CollPoissonDense], " V ", (size_t) LEN3); + strncpy (COAMessages[smultin_CollNotInit], " --- ", (size_t) LEN3); +} + + +/*========================================================================*/ + + +static void InitRes ( + ffam_Fam *fam, + fmultin_Res *res, + smultin_Param *par, + int N, + int Nr, + int j1, int j2, int jstep, + char *name, + lebool Over +) +/* + * Initializes the fmultin_Res structure + */ +{ + int s, i; + char str[LEN + 1] = { 0 }; + char str2[LEN2 + 1] = { 0 }; + smultin_Param *parold = res->Par; + Nr = util_Min (Nr, fam->Ng); + + for (s = par->NbDelta; s < parold->NbDelta; s++) + fres_DeleteCont (res->PowDiv[s]); + for (s = parold->NbDelta; s < par->NbDelta; s++) + res->PowDiv[s] = fres_CreateCont (); + + for (s = 0; s < par->NbDelta; s++) { + if (fabs (par->ValDelta[s] + 1.0) < EPSILON) { + strncpy (str, name, (size_t) LEN); + if (Over) { + strncat (str, ": CollisionOver test", (size_t) LEN2); + ftab_DeleteTable (res->COApprox); + res->COApprox = ftab_CreateTable (Nr, j1, j2, jstep, + "Approximation used for distribution of CollisionOver", + ftab_String, NMESS); + for (i = 0; i < Nr; i++) + res->COApprox->LSize[i] = fam->LSize[i]; + InitCOAStrings (); + for (i = 0; i < NMESS; i++) { + res->COApprox->Strings[i] = COAMessages[i]; + } + } else { + strncat (str, ": Collision test", (size_t) LEN2); + } + fres_InitPoisson (fam, res->Coll, Nr, j1, j2, jstep, str); + strncpy (str, name, (size_t) LEN); + strncat (str, ": empty cells", (size_t) LEN2); + fres_InitPoisson (fam, res->Empty, Nr, j1, j2, jstep, str); + for (i = 1; i <= par->bmax; i++) { + strncpy (str, name, (size_t) LEN); + strncat (str, ": cells with at least ", (size_t) LEN2); + sprintf (str2, "%1d", i); + strncat (str, str2, (size_t) 3); + strncat (str, " balls", (size_t) LEN2); + fres_InitPoisson (fam, res->Balls[i], Nr, j1, j2, jstep, str); + } + } + + strncpy (str, name, (size_t) LEN); + strncat (str, ": ValDelta = ", (size_t) LEN2); + sprintf (str2, "%6.3f,", par->ValDelta[s]); + strncat (str, str2, (size_t) LEN2); + strncat (str, " test", (size_t) LEN2); + fres_InitCont (fam, res->PowDiv[s], N, Nr, j1, j2, jstep, str); + } + /* + ftab_DeleteTable (res->CellRatio); + res->CellRatio = ftab_CreateTable (Nr, j1, j2, jstep, + "Actual number of cells / Chosen number of cells", ftab_Real, 0); + */ +} + + +/*-------------------------------------------------------------------------*/ + +fmultin_Res *fmultin_CreateRes (smultin_Param * par) +{ + fmultin_Res *res; + int s, j; + + res = util_Malloc (sizeof (fmultin_Res)); + if (par == NULL) + par = &ParamDefault; + res->Par = par; + + for (s = 0; s < par->NbDelta; s++) + res->PowDiv[s] = fres_CreateCont (); + + /* For the collision test */ + res->Coll = fres_CreatePoisson (); + res->Empty = fres_CreatePoisson (); + for (j = 1; j <= par->bmax; j++) + res->Balls[j] = fres_CreatePoisson (); + res->COApprox = ftab_CreateTable (1, 1, 1, 1, + "Approximation used for distribution of CollisionOver", ftab_String, 4); + /* + res->CellRatio = ftab_CreateTable (1, 1, 1, 1, + "Actual number of cells / Chosen number of cells", ftab_Real, 0); + */ + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fmultin_DeleteRes (fmultin_Res * res) +{ + int s, j; + if (res == NULL) + return; + for (s = 0; s < res->Par->NbDelta; s++) + fres_DeleteCont (res->PowDiv[s]); + fres_DeletePoisson (res->Coll); + fres_DeletePoisson (res->Empty); + for (j = 1; j <= res->Par->bmax; j++) + fres_DeletePoisson (res->Balls[j]); + ftab_DeleteTable (res->COApprox); + /* ftab_DeleteTable (res->CellRatio); */ + util_Free (res); +} + + +/*========================================================================*/ + +static void PrintHead (char *name, TestType test, ffam_Fam * fam, + smultin_Param * spar, long *Par, int Nr, int j1, int j2, int jstep) +{ + int j; + + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", name); + printf (" N = %ld, r = %ld", Par[0], Par[1]); + + switch (test) { + case A_BITS: + printf (", s = %ld, Sparse = ", Par[2]); + break; + case A_MULT: + printf (", t = %ld, Sparse = ", Par[3]); + break; + case A_PERM: + printf (", Sparse = "); + break; + default: + util_Error ("in fmultin, PrintHead: no such case"); + } + util_WriteBool (Par[4], -5); + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); + + if (spar) { + printf (" NbDelta = %d, ValDelta = { ", spar->NbDelta); + for (j = 0; j < spar->NbDelta; j++) { + printf ("%5.3g", spar->ValDelta[j]); + if (j < spar->NbDelta - 1) + printf (", "); + else + printf (" }\n\n "); + } + } +} + + +/*=========================================================================*/ + +static void PrintRes (fmultin_Res * res, lebool Over) +{ + int s, j; + if (res == NULL) + return; + for (s = 0; s < res->Par->NbDelta; s++) { + if (fabs (res->Par->ValDelta[s] + 1.0) > EPSILON) + fres_PrintCont (res->PowDiv[s]); + if (fabs (res->Par->ValDelta[s] + 1.0) < EPSILON) { + fres_PrintPoisson (res->Coll, FALSE, FALSE); + if (res->Par->bmax >= 0) + fres_PrintPoisson (res->Empty, FALSE, TRUE); + for (j = 2; j <= res->Par->bmax; j++) + fres_PrintPoisson (res->Balls[j], FALSE, FALSE); + /* ftab_PrintTable (res->CellRatio); */ + if (Over) + ftab_PrintTable (res->COApprox); + } + } +} + + +/*=========================================================================*/ + +static fcho_Cho *CreateKcho (long N, int t, double R, KType kcho) +{ + fcho_Cho *cho; + Multin_Param *Par; + + cho = util_Malloc (sizeof (fcho_Cho)); + Par = util_Malloc (sizeof (Multin_Param)); + Par->N = N; + Par->t = t; + Par->R = R; + Par->kcho = kcho; + cho->param = Par; + cho->name = util_Calloc (2, sizeof (char)); + Par->name = cho->name; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +static double CheckK1 (void *vpar, double K, long n) +{ + Multin_Param *Par = vpar; + KType kcho = Par->kcho; + double d, x; + int h, L, t; + + if (n / K < 1.0 / num_TwoExp[30]) + return -1.0; + if (K > smultin_env.Maxk) { + printf ("K > smultin_env->Maxk\n\n"); + return -1.0; + } + switch (kcho) { + case B_DT: + d = pow (K, 1.0 / Par->t); + strcpy (Par->name, "d"); + if (d > LONG_MAX) + return -1.0; + else + return d; + break; + + case B_2HT: + h = 0.5 + num_Log2(K) / Par->t; + d = num_TwoExp[h]; + strcpy (Par->name, "d"); + if (d > LONG_MAX) + return -1.0; + else + return d; + break; + + case B_2L: + L = 0.5 + num_Log2(K); + strcpy (Par->name, "L"); + return L; + break; + + case B_T: + strcpy (Par->name, "t"); + /* Find smallest t such that t! > k */ + x = 2.0; + t = 2; + while (x < K) { + t++; + x *= t; + } + /* Choose t or (t-1) that gives t! closest to K */ + if ((x - K)/K > (K - x/t)/K) + t--; + return t; + break; + + default: + util_Error ("in fmultin, CheckK1: no such case"); + } + return -1.0; +} + + +/*=========================================================================*/ + +static void WriteEC (void *vpar, long junk1, long junk2) +{ + Multin_Param *Par = vpar; + switch (Par->kcho) { + case B_DT: + printf ("Choose EC_DT with EC = "); + break; + case B_2HT: + printf ("Choose EC_2HT with EC = "); + break; + case B_2L: + printf ("Choose EC_2L with EC = "); + break; + case B_T: + printf ("Choose EC_T with EC = "); + break; + default: + util_Error ("in fmultin, WriteEC: no such case"); + } + num_WriteD (Par->R, 8, 2, 2); + printf ("\n\n"); +} + +/*-------------------------------------------------------------------------*/ + +static double ChooseEC (void *vpar, long junk, long n) +{ + Multin_Param *Par = vpar; + double K; + WriteEC (vpar, 0, 0); + K = ((double) n * n * Par->N) / (2.0 * Par->R); + return CheckK1 (vpar, K, n); +} + + +/*=========================================================================*/ + +void fmultin_DeleteEC (fcho_Cho * cho) +{ + if (NULL == cho) + return; + cho->name = util_Free (cho->name); + cho->param = util_Free (cho->param); + util_Free (cho); +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho *fmultin_CreateEC_DT (long N, int t, double EC) +{ + fcho_Cho *cho; + cho = CreateKcho (N, t, EC, B_DT); + cho->Write = WriteEC; + cho->Choose = ChooseEC; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreateEC_2HT (long N, int t, double EC) +{ + fcho_Cho *cho; + cho = CreateKcho (N, t, EC, B_2HT); + cho->Write = WriteEC; + cho->Choose = ChooseEC; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreateEC_2L (long N, double EC) +{ + fcho_Cho *cho; + cho = CreateKcho (N, -1, EC, B_2L); + cho->Write = WriteEC; + cho->Choose = ChooseEC; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreateEC_T (long N, double EC) +{ + fcho_Cho *cho; + cho = CreateKcho (N, -1, EC, B_T); + cho->Write = WriteEC; + cho->Choose = ChooseEC; + return cho; +} + + +/*=========================================================================*/ + +static void WriteDens (void *vpar, long junk1, long junk2) +{ + Multin_Param *Par = vpar; + switch (Par->kcho) { + case B_DT: + printf ("Choose Dens_DT with density = "); + break; + case B_2HT: + printf ("Choose Dens_2HT with density = "); + break; + case B_2L: + printf ("Choose Dens_2L with density = "); + break; + case B_T: + printf ("Choose Dens_T with density = "); + break; + default: + util_Error ("in fmultin, WriteDens: no such case"); + } + if (Par->R > 0.999999) + num_WriteD (Par->R, 8, 2, 2); + else { + printf (" 1 /"); + num_WriteD (1.0 / Par->R, 8, 2, 2); + } + printf ("\n\n"); +} + +/*-------------------------------------------------------------------------*/ + +static double ChooseDens (void *vpar, long junk, long n) +{ + Multin_Param *Par = vpar; + double K; + WriteDens (vpar, 0, 0); + K = n / Par->R; + return CheckK1 (vpar, K, n); +} + + +/*=========================================================================*/ + +void fmultin_DeleteDens (fcho_Cho * cho) +{ + if (NULL == cho) + return; + cho->name = util_Free (cho->name); + cho->param = util_Free (cho->param); + util_Free (cho); +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho *fmultin_CreateDens_DT (int t, double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, t, R, B_DT); + cho->Write = WriteDens; + cho->Choose = ChooseDens; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreateDens_2HT (int t, double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, t, R, B_2HT); + cho->Write = WriteDens; + cho->Choose = ChooseDens; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreateDens_2L (double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, -1, R, B_2L); + cho->Write = WriteDens; + cho->Choose = ChooseDens; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreateDens_T (double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, -1, R, B_T); + cho->Write = WriteDens; + cho->Choose = ChooseDens; + return cho; +} + + +/*=========================================================================*/ + +static void WritePer (void *vpar, long junk1, long junk2) +{ + Multin_Param *Par = vpar; + switch (Par->kcho) { + case B_DT: + printf ("Choose Per_DT with R = "); + break; + case B_2HT: + printf ("Choose Per_2HT with R = "); + break; + case B_2L: + printf ("Choose Per_2L with R = "); + break; + case B_T: + printf ("Choose Per_T with R = "); + break; + default: + util_Error ("in fmultin, WritePer: no such case"); + } + if (Par->R > 0.999999) + num_WriteD (Par->R, 8, 2, 2); + else { + printf (" 1 /"); + num_WriteD (1.0 / Par->R, 8, 2, 2); + } + printf ("\n\n"); +} + +/*-------------------------------------------------------------------------*/ + +static double ChoosePer (void *vpar, long lsize, long n) +{ + Multin_Param *Par = vpar; + double K; + WritePer (vpar, 0, 0); + K = Par->R * pow (2.0, (double) lsize); + return CheckK1 (vpar, K, n); +} + + +/*=========================================================================*/ + +void fmultin_DeletePer (fcho_Cho * cho) +{ + if (NULL == cho) + return; + cho->name = util_Free (cho->name); + cho->param = util_Free (cho->param); + util_Free (cho); +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho *fmultin_CreatePer_DT (int t, double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, t, R, B_DT); + cho->Write = WritePer; + cho->Choose = ChoosePer; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreatePer_2HT (int t, double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, t, R, B_2HT); + cho->Write = WritePer; + cho->Choose = ChoosePer; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreatePer_2L (double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, -1, R, B_2L); + cho->Write = WritePer; + cho->Choose = ChoosePer; + return cho; +} + +/*-------------------------------------------------------------------------*/ + +fcho_Cho * fmultin_CreatePer_T (double R) +{ + fcho_Cho *cho; + cho = CreateKcho (0, -1, R, B_T); + cho->Write = WritePer; + cho->Choose = ChoosePer; + return cho; +} + + +/*=========================================================================*/ + +static void FillTables (fmultin_Res *fres, smultin_Res *sres, long N, + int irow, int icol, lebool Over) +{ + int i, j; + for (i = 0; i < fres->Par->NbDelta; i++) { + fres_FillTableEntryC (fres->PowDiv[i], sres->pVal2[i], N, irow, icol); + if (fabs (fres->Par->ValDelta[i] + 1.0) < EPSILON) { + fres_FillTableEntryPoisson (fres->Coll, sres->Mu[i], + sres->NbCollisions, -1.0, -1.0, sres->pColl, irow, icol); + fres_FillTableEntryPoisson (fres->Empty, sres->EsEmpty, + (double) sres->NbCells[0], -1.0, -1.0, sres->pEmpty, irow, icol); + for (j = 1; j <= fres->Par->bmax; j++) + fres_FillTableEntryPoisson (fres->Balls[j], sres->EsCells[j], + (double) sres->WbCells[j], -1.0, -1.0, sres->pWb[j], irow, icol); + if (Over) + fres->COApprox->Mat[irow][icol] = sres->CollApprox; + } + } +} + + +/*=========================================================================*/ + +static void TabMultin (ffam_Fam *fam, void *vres, void *vcho, + void *vpar, int i, int j, int irow, int icol) +{ + int r, t; + long N, n, d; + lebool Sparse, Over; + smultin_Res *sres; + fmultin_Res *fres = vres; + fcho_Cho2 *cho = vcho; + fcho_Cho *chon; + fcho_Cho *chop2; + long *Par = vpar; + Multin_Param *kpar; + TestType Test; + + N = Par[0]; + r = Par[1]; + d = Par[2]; + t = Par[3]; + Sparse = Par[4]; + Over = Par[5]; + Test = Par[6]; + + util_Assert (cho, "fmultin: cho is NULL"); + chon = cho->Chon; + chop2 = cho->Chop2; + util_Assert (chon, "fmultin: cho->Chon is NULL"); + util_Assert (chop2, "fmultin: cho->Chop2 is NULL"); + kpar = chop2->param; + if (Test == A_PERM) { + util_Assert (kpar->kcho == B_T, + "cho->Chop2: wrong function for choosing number of cells"); + } else if (Test == A_MULT) { + util_Assert ((kpar->kcho == B_DT) || (kpar->kcho == B_2HT), + "cho->Chop2: wrong function for choosing number of cells"); + } + + n = fcho_ChooseParamL (chon, 5, fmultin_Maxn, i, j); + if (n < 0) + return; + if (d < 0) { + strncpy (chop2->name, "d", 1); + d = fcho_ChooseParamL (chop2, 2, LONG_MAX, i, n); + if (d < 0) + return; + /* The number of bits used must be <= resolution of generator */ + if (r + num_Log2 ((double) d) + 0.5 > fam->Resol[irow]) { + printf ("Resolution of generator too small\n\n"); + return; + } + } else { + strncpy (chop2->name, "t", 1); + t = fcho_ChooseParamL (chop2, 2, 18, i, n); + if (t < 0) + return; + } + if (Over && t < 2) { + printf ("t < 2\n\n"); + return; + } + + sres = smultin_CreateRes (fres->Par); + if (Over) + smultin_MultinomialOver (fam->Gen[irow], fres->Par, sres, + N, n, r, d, t, Sparse); + else + smultin_Multinomial (fam->Gen[irow], fres->Par, sres, + N, n, r, d, t, Sparse); + + FillTables (fres, sres, N, irow, icol, Over); + smultin_DeleteRes (sres); +} + + +/*========================================================================*/ + +static int Chooses (int r, int s, int prec, int L) +{ + if (r + s > prec) + s = prec - r; + if (s <= 0) { + printf ("r >= Resolution of generator\n\n"); + return -1; + } + if (L >= s) { + while (L % s) + s--; + } else { + while (s % L) + s--; + } + return s; +} + + +/*-------------------------------------------------------------------------*/ + +static void TabSerialBits (ffam_Fam * fam, void *vres, void *vcho, + void *vpar, int i, int j, int irow, int icol) +{ + int r, s, s1, L; + long N, n; + lebool Sparse, Over; + smultin_Res *sres; + fmultin_Res *fres = vres; + fcho_Cho2 *cho = vcho; + fcho_Cho *chon; + fcho_Cho *chop2; + long *Par = vpar; + Multin_Param *kpar; + + N = Par[0]; + r = Par[1]; + s = Par[2]; + L = Par[3]; + Sparse = Par[4]; + Over = Par[5]; + + util_Assert (cho, "fmultin: cho is NULL"); + chon = cho->Chon; + chop2 = cho->Chop2; + util_Assert (chon, "fmultin: cho->Chon is NULL"); + util_Assert (chop2, "fmultin: cho->Chop2 is NULL"); + kpar = chop2->param; + util_Assert (kpar->kcho == B_2L, + "cho->Chop2: wrong function for choosing number of cells"); + + n = fcho_ChooseParamL (chon, 5, fmultin_Maxn, i, j); + if (n < 0) + return; + + strncpy (chop2->name, "L", 1); + L = fcho_ChooseParamL (chop2, 1, 53, i, n); + if (L < 0) + return; + + if (Over) + s1 = fcho_Chooses (r, s, fam->Resol[irow]); + else + s1 = Chooses (r, s, fam->Resol[irow], L); + if (s1 <= 0) + return; + + sres = smultin_CreateRes (fres->Par); + if (Over) + smultin_MultinomialBitsOver (fam->Gen[irow], fres->Par, sres, + N, n, r, s1, L, Sparse); + else + smultin_MultinomialBits (fam->Gen[irow], fres->Par, sres, + N, n, r, s1, L, Sparse); + + FillTables (fres, sres, N, irow, icol, Over); + smultin_DeleteRes (sres); +} + + +/*========================================================================*/ + +void fmultin_Serial1 (ffam_Fam *fam, smultin_Param *spar, + fmultin_Res *res, fcho_Cho2 *cho, long N, int r, int t, + lebool Sparse, int Nr, int j1, int j2, int jstep) +{ + long Par[7]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = -1; + Par[3] = t; + Par[4] = Sparse; + Par[5] = FALSE; + Par[6] = A_MULT; + + if (spar == NULL) + spar = &smultin_ParamDefault; + if ((spar->GenerCell != smultin_GenerCellSerial) + && (spar->GenerCell != smultin_GenerCellSerial2)) { + spar->GenerCell = smultin_GenerCellSerial; + util_Warning (TRUE, + "fmultin_Serial1: changing spar->GenerCell to smultin_GenerCellSerial"); + } + if (res == NULL) { + localRes = TRUE; + res = fmultin_CreateRes (spar); + } else + localRes = FALSE; + + PrintHead ("fmultin_Serial1", A_MULT, fam, spar, Par, Nr, j1, j2, jstep); + InitRes (fam, res, spar, N, Nr, j1, j2, jstep, "fmultin_Serial1", FALSE); + ftab_MakeTables (fam, res, cho, Par, TabMultin, Nr, j1, j2, jstep); + PrintRes (res, FALSE); + if (localRes) + fmultin_DeleteRes (res); +} + + +/*========================================================================*/ + +void fmultin_SerialOver1 (ffam_Fam *fam, smultin_Param *spar, + fmultin_Res *res, fcho_Cho2 *cho, long N, int r, int t, + lebool Sparse, int Nr, int j1, int j2, int jstep) +{ + long Par[7]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = -1; + Par[3] = t; + Par[4] = Sparse; + Par[5] = TRUE; + Par[6] = A_MULT; + + if (spar == NULL) + spar = &smultin_ParamDefault; + if ((spar->GenerCell != smultin_GenerCellSerial) + && (spar->GenerCell != smultin_GenerCellSerial2)) { + spar->GenerCell = smultin_GenerCellSerial; + util_Warning (TRUE, + "fmultin_SerialOver1: changing spar->GenerCell to smultin_GenerCellSerial"); + } + if (res == NULL) { + localRes = TRUE; + res = fmultin_CreateRes (spar); + } else + localRes = FALSE; + + PrintHead ("fmultin_SerialOver1", A_MULT, fam, spar, Par, Nr, + j1, j2, jstep); + InitRes (fam, res, spar, N, Nr, j1, j2, jstep, "fmultin_SerialOver1", + TRUE); + ftab_MakeTables (fam, res, cho, Par, TabMultin, Nr, j1, j2, jstep); + PrintRes (res, TRUE); + if (localRes) + fmultin_DeleteRes (res); +} + + +/*========================================================================*/ + +void fmultin_SerialBits1 (ffam_Fam *fam, smultin_Param *spar, + fmultin_Res *res, fcho_Cho2 *cho, long N, int r, int s, lebool Sparse, + int Nr, int j1, int j2, int jstep) +{ + long Par[6]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = s; + Par[3] = 0; + Par[4] = Sparse; + Par[5] = FALSE; + + if (spar == NULL) + spar = &smultin_ParamDefault; + if ((spar->GenerCell != smultin_GenerCellSerial) + && (spar->GenerCell != smultin_GenerCellSerial2)) { + spar->GenerCell = smultin_GenerCellSerial; + util_Warning (TRUE, + "fmultin_SerialBits1: changing spar->GenerCell to smultin_GenerCellSerial"); + } + if (res == NULL) { + localRes = TRUE; + res = fmultin_CreateRes (spar); + } else + localRes = FALSE; + + PrintHead ("fmultin_SerialBits1", A_BITS, fam, spar, Par, Nr, + j1, j2, jstep); + InitRes (fam, res, spar, N, Nr, j1, j2, jstep, "fmultin_SerialBits1", + FALSE); + ftab_MakeTables (fam, res, cho, Par, TabSerialBits, Nr, j1, j2, jstep); + PrintRes (res, FALSE); + if (localRes) + fmultin_DeleteRes (res); +} + + +/*========================================================================*/ + +void fmultin_SerialBitsOver1 (ffam_Fam *fam, smultin_Param *spar, + fmultin_Res *res, fcho_Cho2 *cho, long N, int r, int s, lebool Sparse, + int Nr, int j1, int j2, int jstep) +{ + long Par[6]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = s; + Par[3] = 0; + Par[4] = Sparse; + Par[5] = TRUE; + + if (spar == NULL) + spar = &smultin_ParamDefault; + if ((spar->GenerCell != smultin_GenerCellSerial) + && (spar->GenerCell != smultin_GenerCellSerial2)) { + spar->GenerCell = smultin_GenerCellSerial; + util_Warning (TRUE, + "fmultin_SerialBitsOver1: changing spar->GenerCell to smultin_GenerCellSerial"); + } + if (res == NULL) { + localRes = TRUE; + res = fmultin_CreateRes (spar); + } else + localRes = FALSE; + + PrintHead ("fmultin_SerialBitsOver1", A_BITS, fam, spar, Par, Nr, + j1, j2, jstep); + InitRes (fam, res, spar, N, Nr, j1, j2, jstep, "fmultin_SerialBitsOver1", + TRUE); + ftab_MakeTables (fam, res, cho, Par, TabSerialBits, Nr, j1, j2, jstep); + PrintRes (res, TRUE); + if (localRes) + fmultin_DeleteRes (res); +} + + +/*========================================================================*/ + +void fmultin_Permut1 (ffam_Fam *fam, smultin_Param *spar, + fmultin_Res *res, fcho_Cho2 *cho, long N, int r, + lebool Sparse, int Nr, int j1, int j2, int jstep) +{ + long Par[7]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = 1; + Par[3] = -1; + Par[4] = Sparse; + Par[5] = FALSE; + Par[6] = A_PERM; + + if (spar == NULL) + spar = &smultin_ParamDefault; + if ((spar->GenerCell != smultin_GenerCellPermut)) { + spar->GenerCell = smultin_GenerCellPermut; + util_Warning (TRUE, + "fmultin_Permut1: changing GenerCell to smultin_GenerCellPermut"); + } + if (res == NULL) { + localRes = TRUE; + res = fmultin_CreateRes (spar); + } else + localRes = FALSE; + + PrintHead ("fmultin_Permut1", A_PERM, fam, spar, Par, Nr, j1, j2, jstep); + InitRes (fam, res, spar, N, Nr, j1, j2, jstep, "fmultin_Permut1", FALSE); + ftab_MakeTables (fam, res, cho, Par, TabMultin, Nr, j1, j2, jstep); + PrintRes (res, FALSE); + if (localRes) + fmultin_DeleteRes (res); +} + + +/*========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fmultin.tex b/TESTU01/TestU01-1.2.3/testu01/fmultin.tex new file mode 100644 index 0000000..d7609a6 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fmultin.tex @@ -0,0 +1,265 @@ +\defmodule {fmultin} + +This module applies multinomial tests, from the module {\tt smultin}, +% (the collisions and permutation tests are described in {\tt sknuth}) +to a family of generators of different sizes. + +\iffalse %%%%%%% +There are different functions to choose the different parameters for the + tests. The dimension $t$ and the interval length $d$ are mutually exclusive: + we fix one of them and the other will be chosen by the program. + Usually, we fix the dimension $t$, +and the interval $d$ will be chosen by one of the function {\tt Choose\_d}. +We may also fix the interval $d$, and then one of the function + {\tt Choose\_t} will select a value of $t$. +\fi %%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* fmultin.h for ANSI C */ +#ifndef FMULTIN_H +#define FMULTIN_H +\endhide +#include "gdef.h" +#include "ftab.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" +#include "smultin.h" + + +extern long fmultin_Maxn; +\endcode +\tab + Upper bound on $n$. + A test is called only when $n$ does not exceed this value. + Default value: $2^{24}$. +\endtab + +\ifdetailed %%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} + +The results of the tests in this module can be recovered +in the following structure. + +\code + +typedef struct { + smultin_Param *Par; + fres_Cont *PowDiv[smultin_MAX_DELTA]; + fres_Poisson *Coll; + fres_Poisson *Empty; + fres_Poisson *Balls[1 + smultin_MAXB]; + ftab_Table *COApprox; +} fmultin_Res; +\endcode +\tab + {\tt PowDiv} keeps the results of the Power Divergence tests for each + value of $\delta$. The results for the numbers of collisions are kept in + {\tt Coll}, for the number of empty cells in {\tt Empty} for the number of + cells containing at least $j$ balls in {\tt Balls[j]}. +% {\tt CellRatio} contains the ratio of the actual number of cells +% over the desired number of cells (in high dimensions, because of the +% discrete nature of the 1-dimensional interval, it is not always +% possible to obtain exactly a given number of cells). + {\tt COApprox} keeps tag on which approximation is used for the + distribution function of the {\tt CollisionOver} test: + $N$ is for the normal approximation for the number of collisions, + $C$ is for the Poisson approximation for the number of collisions, + $V$ is for the Poisson approximation for the number of empty cells, and + --- is for the case where it is not known how to compute the distribution. +\endtab +\code + + +fmultin_Res * fmultin_CreateRes (smultin_Param *par); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt fmultin} test. + \endtab +\code + + +void fmultin_DeleteRes (fmultin_Res *res); +\endcode + \tab + Frees the memory allocated by {\tt fmultin\_CreateRes}. + \endtab + +\fi %%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Choosing the parameters} + + Given the sample size $n$, the following functions determines + how the number of cells $k$ is chosen according to different criteria. + This will determine the other varying parameter of the tests besides $n$. + The returned structure must be passed as the second member in the + argument {\tt cho} of the test, the first member of {\tt cho} being always + the function that chooses the sample size $n$. +\code + + +fcho_Cho * fmultin_CreateEC_DT (long N, int t, double EC); +fcho_Cho * fmultin_CreateEC_2HT (long N, int t, double EC); +fcho_Cho * fmultin_CreateEC_2L (long N, double EC); +fcho_Cho * fmultin_CreateEC_T (long N, double EC); +\endcode + \tab + Given the number of replications $N$, the sample size $n$, these + functions choose the number of cells $k$ so that the expected + number of collisions is approximately $EC$, i.e. $EC \approx Nn^2/2k$. + Given the dimension $t$, the function {\tt fmultin\_CreateEC\_DT} + chooses the one-dimensional interval $d$ so that $k= d^t$, and + {\tt fmultin\_CreateEC\_2HT} chooses $d=2^h$ + so that $k= 2^{ht}$ ($d$ is a power of 2 with $h$ integer). + These two cases apply to the tests {\tt fmultin\_Serial1} and + {\tt fmultin\_SerialOver1}. + The function {\tt fmultin\_CreateEC\_2L} chooses $L$ so that $k= 2^L$. + This case applies to the tests {\tt fmultin\_SerialBits1} and + {\tt fmultin\_SerialBitsOver1}. + The function {\tt fmultin\_CreateEC\_T} chooses $t$ so that $k= t!$. + This case applies to the test {\tt fmultin\_Permut1}. + % Recommendation: $EC \ge 100$ and $t = 2$. + \endtab +\code + + +void fmultin_DeleteEC (fcho_Cho *cho); +\endcode + \tab + Frees the memory allocated by the create functions + {\tt fmultin\_CreateEC...} + \endtab +\code + + +fcho_Cho * fmultin_CreateDens_DT (int t, double R); +fcho_Cho * fmultin_CreateDens_2HT (int t, double R); +fcho_Cho * fmultin_CreateDens_2L (double R); +fcho_Cho * fmultin_CreateDens_T (double R); +\endcode +\tab Similar to {\tt fmultin\_CreateEC...}, but the parameters are chosen + so that the density (the number of points per cell) is approximately + $R \approx n/k $. +\endtab +\code + + +void fmultin_DeleteDens (fcho_Cho *cho); +\endcode + \tab + Frees the memory allocated by {\tt fmultin\_CreateDens...} + \endtab +\code + + +fcho_Cho * fmultin_CreatePer_DT (int t, double R); +fcho_Cho * fmultin_CreatePer_2HT (int t, double R); +fcho_Cho * fmultin_CreatePer_2L (double R); +fcho_Cho * fmultin_CreatePer_T (double R); +\endcode +\tab Similar to {\tt fmultin\_CreateEC...}, but the parameters are chosen + so that the number of cells $k$ is approximately $R$ times the + period length of the generator, i.e., $k \approx R\, 2^{\it lsize}$. +\endtab +\code + + +void fmultin_DeletePer (fcho_Cho *cho); +\endcode + \tab + Frees the memory allocated by {\tt fmultin\_CreatePer...} + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code + +void fmultin_Serial1 (ffam_Fam *fam, smultin_Param *par, + fmultin_Res *res, fcho_Cho2 *cho, + long N, int r, int t, lebool Sparse, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + Applies the same tests as in {\tt smultin\_Multinomial} + with {\tt smultin\_GenerCellSerial}, + with parameters $N$ and $r$, in + dimension $t$ and with the same parameter {\tt Sparse}, for the + first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. + The sample size $n$ is chosen by the function + {\tt cho->Chon} while the number of cells $k$ is chosen by {\tt cho->Chop2}. + This last must have been initialized by one of + the method for choosing cells described above. + Whenever $n$ exceeds {\tt fmultin\_Maxn} or $k$ exceeds + {\tt smultin\_Maxk}, the test is not run. +%% \ifdetailed %%% +%% The results are put in {\tt res->Coll}, +%% {\tt res->Empty}, {\tt res->Balls}, {\tt res->PowDiv}. +%% \fi %%% +\endtab +\code + + +void fmultin_SerialOver1 (ffam_Fam *fam, smultin_Param *par, + fmultin_Res *res, fcho_Cho2 *cho, + long N, int r, int t, lebool Sparse, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + Similar to {\tt fmultin\_Serial1}, except that it applies the + tests in the function {\tt smultin\_Multi\-no\-mialOver}. +\endtab +\code + + +void fmultin_SerialBits1 (ffam_Fam *fam, smultin_Param *par, + fmultin_Res *res, fcho_Cho2 *cho, + long N, int r, int s, lebool Sparse, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + Similar to {\tt fmultin\_Serial1}, except that it applies the + tests in the function {\tt smultin\_Multi\-no\-mialBits}. +\endtab +\code + + +void fmultin_SerialBitsOver1 (ffam_Fam *fam, smultin_Param *par, + fmultin_Res *res, fcho_Cho2 *cho, + long N, int r, int s, lebool Sparse, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + Similar to {\tt fmultin\_SerialBits1}, except that it applies the + tests in the function {\tt smultin\_Mul\-ti\-no\-mialBitsOver}. +\endtab +\code + + +void fmultin_Permut1 (ffam_Fam *fam, smultin_Param *par, + fmultin_Res *res, fcho_Cho2 *cho, + long N, int r, lebool Sparse, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + Similar to {\tt fmultin\_Serial1} except that it uses + {\tt smultin\_GenerCellPermut} to generate the cell numbers. + Here, $d$ is unused and $t$ is chosen as a function of $k$ by $k=t!$. +\endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fnpair.c b/TESTU01/TestU01-1.2.3/testu01/fnpair.c new file mode 100644 index 0000000..a237a4d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fnpair.c @@ -0,0 +1,461 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fnpair.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "util.h" +#include "fnpair.h" +#include +#include + +long fnpair_Maxn = 4194304; + + +typedef enum { + A_CLOSEPAIRS, + A_BICKEL, + A_BITMATCH, + A_N +} TestType; + + +/*------------------------------- Functions ------------------------------*/ + + +static void PrintRes1 (fnpair_Res1 * res, TestType test, long N, int m) +{ + switch (test) { + case A_BITMATCH: + ftab_PrintTable (res->PVal[snpair_BM]); + break; + case A_BICKEL: + ftab_PrintTable (res->PVal[snpair_BB]); + break; + default: + ftab_PrintTable (res->PVal[snpair_NP]); + if (m > 1) { + ftab_PrintTable (res->PVal[snpair_mNP]); + if (N > 1) { + ftab_PrintTable (res->PVal[snpair_mNP1]); + ftab_PrintTable (res->PVal[snpair_mNP2]); + } + } + } +} + + +/*-------------------------------------------------------------------------*/ + +static ftab_Table *InitTable (ffam_Fam * fam, + char *name, int Nr, int j1, int j2, int jstep) +{ + int j; + ftab_Table *T; + + Nr = util_Min (Nr, fam->Ng); + T = ftab_CreateTable (Nr, j1, j2, jstep, name, ftab_pVal2, 0); + ftab_InitMatrix (T, -1.0); + for (j = 0; j < Nr; j++) + T->LSize[j] = fam->LSize[j]; + return T; +} + + +/*-------------------------------------------------------------------------*/ + +static void InitRes1 ( + ffam_Fam *fam, + TestType test, + fnpair_Res1 *res, + int N, /* Number of replications */ + int Nr, + int j1, int j2, int jstep +) +/* + * Initializes the fnpair_Res1 structure + */ +{ + int j; + Nr = util_Min (Nr, fam->Ng); + + for (j = 0; j < snpair_StatType_N; j++) + ftab_DeleteTable (res->PVal[j]); + memset (res, 0, sizeof (fnpair_Res1)); + + if (test == A_BITMATCH) { + res->PVal[snpair_BM] = InitTable (fam, "ClosePairsBitMatch", + Nr, j1, j2, jstep); + return; + } + if (test == A_BICKEL) { + res->PVal[snpair_BB] = InitTable (fam, + "The pVal of AD for BickelBreiman", Nr, j1, j2, jstep); + return; + } + + res->PVal[snpair_NP] = InitTable (fam, "", Nr, j1, j2, jstep); + if (N == 1) + ftab_SetDesc (res->PVal[snpair_NP], + "ClosePairs: The closest distance"); + else + ftab_SetDesc (res->PVal[snpair_NP], + "ClosePairs: Stat. AD on the N values (NP)"); + + res->PVal[snpair_mNP] = InitTable (fam, + "ClosePairs: A2 test on the values of A2 (m-NP)", Nr, j1, j2, jstep); + + res->PVal[snpair_mNP1] = InitTable (fam, + "ClosePairs: Test on the Nm values of W_{n,i}(mNP1)", + Nr, j1, j2, jstep); + res->PVal[snpair_mNP2] = InitTable (fam, + "ClosePairs: Stat. AD (mNP2)", Nr, j1, j2, jstep); +} + + +/*-------------------------------------------------------------------------*/ + +fnpair_Res1 *fnpair_CreateRes1 (void) +{ + fnpair_Res1 *res; + + res = util_Malloc (sizeof (fnpair_Res1)); + memset (res, 0, sizeof (fnpair_Res1)); + /* for (j = 0; j < snpair_StatType_N; j++) + res->PVal[j] = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal2, 0);*/ + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fnpair_DeleteRes1 (fnpair_Res1 * res) +{ + int j; + if (res == NULL) + return; + for (j = 0; j < snpair_StatType_N; j++) + ftab_DeleteTable (res->PVal[j]); + util_Free (res); +} + + +/*=========================================================================*/ + +static void PrintHead (char *name, ffam_Fam * fam, TestType test, void *par1, + int Nr, int j1, int j2, int jstep) +{ + long *Par = par1; + + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", name); + printf (" N = %ld, r = %d, t = %d", Par[0], (int) Par[1], + (int) Par[2]); + + switch (test) { + case A_BITMATCH: + break; + + case A_CLOSEPAIRS: + printf (", p = %d, m = %d", (int) Par[3], (int) Par[4]); + break; + + case A_BICKEL: + printf (", p = %d, Torus = ", (int) Par[3]); + util_WriteBool (Par[4], -5); + break; + + default: + util_Error ("in fnpair, PrintHead: no such case"); + } + + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); +} + + +/*=========================================================================*/ + +static void WriteM1 (void *vpar, long junk1, long junk2) +{ + int *Par = vpar; + int maxm; + maxm = Par[0]; + + if (ftab_Style == ftab_Plain) + printf ("Choose m = Min{%d, sqrt(n/sqrt(N)) / 2}\n\n", maxm); + else + printf + ("Choose $m = \\min\\left\\{%d, \\sqrt{\\frac {n}{4\\sqrt{N}}}\\right\\}$\n\n", + maxm); +} + +/*-------------------------------------------------------------------------*/ + +static double ChooseM1 (void *vpar, long N, long n) +{ + int m; + int *Par = vpar; + int maxm; + maxm = Par[0]; + + WriteM1 (vpar, 0, 0); + m = sqrt (n / sqrt ((double) N)) / 2.0; + m = util_Min (m, maxm); + if (m < 1.0) + return -1.0; + else + return m; +} + + +/*-------------------------------------------------------------------------*/ + +fcho_Cho *fnpair_CreateM1 (int maxm) +{ + fcho_Cho *cho; + int *Par; + + util_Assert (maxm <= snpair_MAXM, + "fnpair_CreateM1: maxm > snpair_MAXM"); + cho = util_Malloc (sizeof (fcho_Cho)); + Par = util_Calloc (1, sizeof (int)); + Par[0] = maxm; + cho->param = Par; + cho->Write = WriteM1; + cho->Choose = ChooseM1; + cho->name = util_Calloc (2, sizeof (char)); + strncpy (cho->name, "m", 1); + return cho; +} + +/*-------------------------------------------------------------------------*/ + +void fnpair_DeleteM1 (fcho_Cho * cho) +{ + if (NULL == cho) + return; + cho->name = util_Free (cho->name); + cho->param = util_Free (cho->param); + util_Free (cho); +} + + +/*=========================================================================*/ + +static void TabClosePairs (ffam_Fam * fam, void *vres, void *vcho, + void *par1, int i, int j, int irow, int icol) +{ + int r, t, p, m; + long N, n; + long *Par = par1; + fnpair_Res1 *fres = vres; + snpair_Res *sres; + fcho_Cho2 *cho = vcho; + fcho_Cho *chon; + fcho_Cho *chom; + + N = Par[0]; + r = Par[1]; + t = Par[2]; + p = Par[3]; + m = Par[4]; + + util_Assert (cho, "fnpair: cho is NULL"); + chon = cho->Chon; + chom = cho->Chop2; + n = fcho_ChooseParamL (chon, 2, fnpair_Maxn, i, j); + if (n <= 0) + return; + if (m < 0) { + util_Assert (chom, "fnpair: chom is NULL"); + m = chom->Choose (chom->param, N, n); + if (m < 1) + return; + } + if (n < sqrt ((double) N) * 4 * m * m) + return; + + sres = snpair_CreateRes (); + snpair_ClosePairs (fam->Gen[irow], sres, N, n, r, t, p, m); + fres->PVal[snpair_NP]->Mat[irow][icol] = sres->pVal[snpair_NP]; + if (m > 1) + fres->PVal[snpair_mNP]->Mat[irow][icol] = sres->pVal[snpair_mNP]; + if ((m > 1) && (N > 1)) { + fres->PVal[snpair_mNP1]->Mat[irow][icol] = sres->pVal[snpair_mNP1]; + fres->PVal[snpair_mNP2]->Mat[irow][icol] = sres->pVal[snpair_mNP2]; + } + snpair_DeleteRes (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fnpair_ClosePairs1 (ffam_Fam * fam, fnpair_Res1 * res, fcho_Cho2 * cho, + long N, int r, int t, int p, int m, int Nr, int j1, int j2, int jstep) +{ + long Par[5]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = t; + Par[3] = p; + Par[4] = m; + if (res == NULL) { + localRes = TRUE; + res = fnpair_CreateRes1 (); + } else + localRes = FALSE; + + PrintHead ("fnpair_ClosePairs1", + fam, A_CLOSEPAIRS, Par, Nr, j1, j2, jstep); + InitRes1 (fam, A_CLOSEPAIRS, res, N, Nr, j1, j2, jstep); + ftab_MakeTables (fam, res, cho, Par, TabClosePairs, Nr, j1, j2, jstep); + if (m < 0) + PrintRes1 (res, A_CLOSEPAIRS, N, 2); + else + PrintRes1 (res, A_CLOSEPAIRS, N, m); + if (localRes) + fnpair_DeleteRes1 (res); +} + + +/*=========================================================================*/ + +static void TabBickel (ffam_Fam * fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, t, p; + lebool Torus; + long N, n; + long *Par = par1; + fnpair_Res1 *fres = res1; + snpair_Res *sres; + + N = Par[0]; + r = Par[1]; + t = Par[2]; + p = Par[3]; + Torus = Par[4]; + + n = fcho_ChooseParamL (cho, 2, fnpair_Maxn, i, j); + if (n <= 0) + return; + + sres = snpair_CreateRes (); + snpair_BickelBreiman (fam->Gen[irow], sres, N, n, r, t, p, Torus); + fres->PVal[snpair_BB]->Mat[irow][icol] = sres->pVal[snpair_BB]; + snpair_DeleteRes (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fnpair_Bickel1 (ffam_Fam * fam, fnpair_Res1 * res, fcho_Cho * cho, + long N, int r, int t, int p, lebool Torus, + int Nr, int j1, int j2, int jstep) +{ + long Par[5]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = t; + Par[3] = p; + Par[4] = Torus; + if (res == NULL) { + localRes = TRUE; + res = fnpair_CreateRes1 (); + } else + localRes = FALSE; + + PrintHead ("fnpair_Bickel1", fam, A_BICKEL, Par, Nr, j1, j2, jstep); + InitRes1 (fam, A_BICKEL, res, N, Nr, j1, j2, jstep); + ftab_MakeTables (fam, res, cho, Par, TabBickel, Nr, j1, j2, jstep); + PrintRes1 (res, A_BICKEL, N, 0); + if (localRes) + fnpair_DeleteRes1 (res); +} + + +/*=========================================================================*/ + +static void TabBitMatch (ffam_Fam * fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, t; + long N, n; + long *Par = par1; + fnpair_Res1 *fres = res1; + snpair_Res *sres; + + N = Par[0]; + r = Par[1]; + t = Par[2]; + + n = fcho_ChooseParamL (cho, 2, fnpair_Maxn, i, j); + if (n <= 0) + return; + + sres = snpair_CreateRes (); + snpair_ClosePairsBitMatch (fam->Gen[irow], sres, N, n, r, t); + fres->PVal[snpair_BM]->Mat[irow][icol] = sres->pVal[snpair_BM]; + snpair_DeleteRes (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fnpair_BitMatch1 (ffam_Fam * fam, fnpair_Res1 * res, fcho_Cho * cho, + long N, int r, int t, int Nr, int j1, int j2, int jstep) +{ + long Par[3]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = t; + if (res == NULL) { + localRes = TRUE; + res = fnpair_CreateRes1 (); + } else + localRes = FALSE; + + PrintHead ("fnpair_BitMatch1", fam, A_BITMATCH, Par, Nr, j1, j2, jstep); + InitRes1 (fam, A_BITMATCH, res, N, Nr, j1, j2, jstep); + ftab_MakeTables (fam, res, cho, Par, TabBitMatch, Nr, j1, j2, jstep); + PrintRes1 (res, A_BITMATCH, N, 0); + if (localRes) + fnpair_DeleteRes1 (res); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fnpair.tex b/TESTU01/TestU01-1.2.3/testu01/fnpair.tex new file mode 100644 index 0000000..e191468 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fnpair.tex @@ -0,0 +1,156 @@ +\defmodule {fnpair} + +This module applies close-pairs tests from the module {\tt snpair} +to a family of generators of different sizes. + +\bigskip +\hrule +\code\hide +/* fnpair.h for ANSI C */ +#ifndef FNPAIR_H +#define FNPAIR_H +\endhide +#include "gdef.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" +#include "snpair.h" + + +extern long fnpair_Maxn; +\endcode +\tab + Upper bound on $n$. + When $n$ exceeds its limit value, the test is not done. + Default value: $n = 2^{22}$. +\endtab +\ifdetailed %%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} + +The test results for the tests in this module can be recovered +in the following structure. + +\code + +typedef struct { + ftab_Table *PVal[snpair_StatType_N]; +} fnpair_Res1; +\endcode + \tab + Structure for keeping the tables of results of the tests in + this module. Depending on the test, not all elements of the array + will be meaningful; those elements that are not will be set to + the NULL pointer. + \endtab +\code + + +fnpair_Res1 * fnpair_CreateRes1 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of the tests in this module. + \endtab +\code + + +void fnpair_DeleteRes1 (fnpair_Res1 *res); +\endcode + \tab + Frees the memory allocated by {\tt fnpair\_CreateRes1}. + \endtab + +\fi %%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Choosing the parameter $\mathbf{m}$} + + One may choose to vary the parameter $m$ as a function of the sample size +in the test {\tt fnpair\_ClosePairs1}. In that case, one must create + an appropriate Choose function, pass it as a member of the argument {\tt +cho} to the test, and call the test with a negative $m$ to signal that +this is the case. If one wants to + do the test with a fixed $m$, one has but to give the given $m> 0$ as a +parameter to the test. + +\code + + +fcho_Cho *fnpair_CreateM1 (int maxm); +\endcode + \tab + Given the number of replications $N$ and the sample + size $n$, the parameter $m$ in {\tt snpair\_Close\-Pairs} will be chosen + by the relation + $m = \min\left\{{\tt maxm},\sqrt{{n}/\left(4\sqrt{N}\right)}\right\}$. + If this method + of choosing $m$ is used, then the returned structure must be passed as + the second pointer in the argument {\tt cho} of the test and the + argument $m$ of the test {\tt fnpair\_ClosePairs1} must be negative. + \endtab +\code + + +void fnpair_DeleteM1 (fcho_Cho * cho); +\endcode + \tab + Frees the memory allocated by {\tt fnpair\_CreateM1}. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Applying the tests} + +\code + + +void fnpair_ClosePairs1 (ffam_Fam *fam, fnpair_Res1 *res, fcho_Cho2 *cho, + long N, int r, int t, int p, int m, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + This function calls the test {\tt snpair\_ClosePairs} + with parameters $N$ and $r$, in dimension $t$, with $L_p$ norm, + sample size $n =$ {\tt cho->Chon->Choose(param, $i$, $j$)}, + for the first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. The parameters in {\tt param} + were set at the creation of {\tt cho} and $i$ is the lsize of the + generator being tested. If $m > 0$, it will be used as is in the test. + If $m < 0$, it will be chosen by $m =$ + {\tt cho->Chop2->Choose(param, $N$, $n$)}. + When $n$ exceeds {\tt fnpair\_Maxn} or $n < 4m^2 N^{1/2}$, the test + is not done. +\endtab +\code + + +void fnpair_Bickel1 (ffam_Fam *fam, fnpair_Res1 *res, fcho_Cho *cho, + long N, int r, int t, int p, lebool Torus, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + Similar to {\tt fnpair\_ClosePairs1} but with {\tt snpair\_BickelBreiman}. + There is no parameter $m$ in this test. +\endtab +\code + + +void fnpair_BitMatch1 (ffam_Fam *fam, fnpair_Res1 *res, fcho_Cho *cho, + long N, int r, int t, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + Similar to {\tt fnpair\_Bickel1} but with + {\tt snpair\_ClosePairsBitMatch}. +\endtab +\code +\hide +#endif +\endhide +\endcode + diff --git a/TESTU01/TestU01-1.2.3/testu01/fres.c b/TESTU01/TestU01-1.2.3/testu01/fres.c new file mode 100644 index 0000000..06adfe5 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fres.c @@ -0,0 +1,386 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fres.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "bitset.h" +#include "fres.h" +#include "ftab.h" + +#include + +#define LEN 100 + + + + +/*=========================================================================*/ + +void fres_InitCont (ffam_Fam *fam, fres_Cont *res, int N, + int Nr, int f1, int f2, int fstep, char *nam) +{ + int i, j; + char str[LEN + 1] = {0}; + size_t len1; + char *p; + + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); + Nr = util_Min (Nr, fam->Ng); + res->Active = 0; + + for (j = 0; j < gofw_NTestTypes; j++) { + if ((gofw_Mean == j) || + (N > 1 && (bitset_TestBit (gofw_ActiveTests, j)))) { + strncpy (str, nam, (size_t) LEN); + len1 = strlen (str); + strncat (str, ": ", 3); + p = strstr (res->PVal[j]->Desc, "p-value"); + if (p) + strncat (str, p, (size_t) LEN - len1); + ftab_DeleteTable (res->PVal[j]); + res->PVal[j] = ftab_CreateTable (Nr, f1, f2, fstep, str, + ftab_pVal2, 0); + ftab_InitMatrix (res->PVal[j], -1.0); + bitset_SetBit (res->Active, j); + for (i = 0; i < Nr; i++) + res->PVal[j]->LSize[i] = fam->LSize[i]; + } + } + if (N > 1) + bitset_ClearBit (res->Active, gofw_Mean); +} + + +/*-------------------------------------------------------------------------*/ + +fres_Cont * fres_CreateCont (void) +{ + fres_Cont *res; + char str[LEN + 1]; + gofw_TestType j; + size_t m; + + res = util_Malloc (sizeof (fres_Cont)); + res->name = util_Calloc (1, sizeof (char)); + + m = strlen ("p-value for statistic "); + for (j = 0; j < gofw_NTestTypes; j++) { + if ((gofw_Mean == j) || (bitset_TestBit (gofw_ActiveTests, j))) { + strncpy (str, "p-value for ", (size_t) LEN); + if (gofw_Mean != j) + strncat (str, gofw_TestNames[j], (size_t) LEN - m); + strncat (str, " statistic", (size_t) LEN - m); + res->PVal[j] = ftab_CreateTable (1, 0, 1, 1, str, ftab_pVal2, 0); + } + } + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fres_DeleteCont (fres_Cont *res) +{ + gofw_TestType j; + + if (res == NULL) + return; + res->name = util_Free (res->name); + + for (j = 0; j < gofw_NTestTypes; j++) { + if ((gofw_Mean == j) || (bitset_TestBit (gofw_ActiveTests, j))) { + ftab_DeleteTable (res->PVal[j]); + res->PVal[j] = NULL; + } + } + util_Free (res); +} + + +/*=========================================================================*/ + +void fres_PrintCont (fres_Cont *res) +{ + gofw_TestType j; + + for (j = 0; j <= gofw_Mean; j++) { + if (bitset_TestBit (res->Active, j)) + ftab_PrintTable (res->PVal[j]); + } +} + + +/*=========================================================================*/ + +void fres_FillTableEntryC (fres_Cont *fres, gofw_TestArray pval, + int N, int i, int j) +/* + * Writes the results of one test in the tables. + */ +{ + gofw_TestType k; + + if (N == 1) { + fres->PVal[gofw_Mean]->Mat[i][j] = pval[gofw_Mean]; + + } else { + for (k = 0; k <= gofw_Mean; k++) { + if (bitset_TestBit (gofw_ActiveTests, k)) { + fres->PVal[k]->Mat[i][j] = pval[k]; + } + } + } +} + + +/*=========================================================================*/ + +void fres_InitDisc (ffam_Fam *fam, fres_Disc *res, + int Nr, int f1, int f2, int fstep, char *nam) +{ + char str[LEN + 1] = {0}; + char str2[LEN + 1] = {0}; + size_t len1; + int i; + + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); + strncpy (str, nam, (size_t) LEN); + len1 = strlen (nam); + + Nr = util_Min (Nr, fam->Ng); + + ftab_DeleteTable (res->PVal2); + ftab_DeleteTable (res->PRight); + ftab_DeleteTable (res->PLeft); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", Left p-value", (size_t) LEN - len1); + res->PLeft = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_pVal1, 0); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", Right p-value", (size_t) LEN - len1); + res->PRight = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_pVal1, 0); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", p-value for discrete statistic", (size_t) LEN - len1); + res->PVal2 = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_pVal2, 0); + + ftab_InitMatrix (res->PLeft, -1.0); + ftab_InitMatrix (res->PRight, -1.0); + ftab_InitMatrix (res->PVal2, -1.0); + + for (i = 0; i < Nr; i++) { + res->PLeft->LSize[i] = fam->LSize[i]; + res->PRight->LSize[i] = fam->LSize[i]; + res->PVal2->LSize[i] = fam->LSize[i]; + } +} + + +/*-------------------------------------------------------------------------*/ + +fres_Disc * fres_CreateDisc (void) +{ + fres_Disc *res; + + res = util_Malloc (sizeof (fres_Disc)); + res->name = util_Calloc (1, sizeof (char)); + + res->PLeft = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal1, 0); + res->PRight = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal1, 0); + res->PVal2 = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal2, 0); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fres_DeleteDisc (fres_Disc *res) +{ + if (res == NULL) + return; + res->name = util_Free (res->name); + ftab_DeleteTable (res->PVal2); + ftab_DeleteTable (res->PRight); + ftab_DeleteTable (res->PLeft); + util_Free (res); +} + + +/*=========================================================================*/ + +void fres_PrintDisc (fres_Disc *res, lebool LR) +{ + if (LR) { + ftab_PrintTable (res->PLeft); + ftab_PrintTable (res->PRight); + } + ftab_PrintTable (res->PVal2); +} + + +/*=========================================================================*/ + +void fres_FillTableEntryD (fres_Disc *fres, + double pLeft, double pRight, double pVal2, int i, int j) +/* + * Writes the results of one test in the tables. + */ +{ + fres->PLeft->Mat[i][j] = pLeft; + fres->PRight->Mat[i][j] = pRight; + fres->PVal2->Mat[i][j] = pVal2; +} + + +/*=========================================================================*/ + +void fres_InitPoisson (ffam_Fam *fam, fres_Poisson *res, + int Nr, int f1, int f2, int fstep, char *nam) +{ + char str[LEN + 1] = {0}; + char str2[LEN + 1] = {0}; + size_t len1; + int i; + + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); + strncpy (str, nam, (size_t) LEN); + len1 = strlen (nam); + + Nr = util_Min (Nr, fam->Ng); + + ftab_DeleteTable (res->Obs); + ftab_DeleteTable (res->Exp); + ftab_DeleteTable (res->PVal2); + ftab_DeleteTable (res->PRight); + ftab_DeleteTable (res->PLeft); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", Expected numbers", (size_t) LEN - len1); + res->Exp = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_Real, 0); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", Observed numbers", (size_t) LEN - len1); + res->Obs = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_Integer, 0); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", Left p-value", (size_t) LEN - len1); + res->PLeft = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_pVal1, 0); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", Right p-value", (size_t) LEN - len1); + res->PRight = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_pVal1, 0); + + strncpy (str2, nam, (size_t) LEN); + strncat (str2, ", p-value for discrete statistic", (size_t) LEN - len1); + res->PVal2 = ftab_CreateTable (Nr, f1, f2, fstep, str2, ftab_pVal2, 0); + + ftab_InitMatrix (res->Exp, -1.0); + ftab_InitMatrix (res->Obs, -1.0); + ftab_InitMatrix (res->PLeft, -1.0); + ftab_InitMatrix (res->PRight, -1.0); + ftab_InitMatrix (res->PVal2, -1.0); + + for (i = 0; i < Nr; i++) { + res->PLeft->LSize[i] = fam->LSize[i]; + res->PRight->LSize[i] = fam->LSize[i]; + res->PVal2->LSize[i] = fam->LSize[i]; + res->Exp->LSize[i] = fam->LSize[i]; + res->Obs->LSize[i] = fam->LSize[i]; + } +} + + +/*-------------------------------------------------------------------------*/ + +fres_Poisson * fres_CreatePoisson (void) +{ + fres_Poisson *res; + + res = util_Malloc (sizeof (fres_Poisson)); + res->name = util_Calloc (1, sizeof (char)); + + res->Obs = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal1, 0); + res->Exp = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal1, 0); + res->PLeft = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal1, 0); + res->PRight = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal1, 0); + res->PVal2 = ftab_CreateTable (1, 0, 1, 1, "", ftab_pVal2, 0); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fres_DeletePoisson (fres_Poisson *res) +{ + if (res == NULL) + return; + res->name = util_Free (res->name); + ftab_DeleteTable (res->PVal2); + ftab_DeleteTable (res->PRight); + ftab_DeleteTable (res->PLeft); + ftab_DeleteTable (res->Obs); + ftab_DeleteTable (res->Exp); + util_Free (res); +} + + +/*=========================================================================*/ + +void fres_PrintPoisson (fres_Poisson *res, lebool LR, lebool Ratio) +{ + ftab_PrintTable2 (res->Exp, res->Obs, Ratio); + if (LR) { + ftab_PrintTable (res->PLeft); + ftab_PrintTable (res->PRight); + } + ftab_PrintTable (res->PVal2); +} + + +/*=========================================================================*/ + +void fres_FillTableEntryPoisson (fres_Poisson *fres, double Exp, double Obs, + double pLeft, double pRight, double pVal2, int i, int j) +/* + * Writes the results of one test in the tables. + */ +{ + fres->Obs->Mat[i][j] = Obs; + fres->Exp->Mat[i][j] = Exp; + fres->PLeft->Mat[i][j] = pLeft; + fres->PRight->Mat[i][j] = pRight; + fres->PVal2->Mat[i][j] = pVal2; +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fres.tex b/TESTU01/TestU01-1.2.3/testu01/fres.tex new file mode 100644 index 0000000..bb6c65d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fres.tex @@ -0,0 +1,284 @@ +\defmodule {fres} + +This module defines common structures used to keep the results of tests +in the {\tt f} modules when the statistics of the test obey a +simple distribution. Some tests require more specialized structures for +the results and those are defined in the appropriate {\tt f} modules. + +The argument {\tt res} of each testing function is a structure + that can keep the tables of $p$-values and other results. +This is useful if one wishes to do something else with the tables of +results after the tests are ended. In that case, one +{\it must} call the appropriate {\tt Create} function to create the + {\tt res} structure. Simply declaring a variable {\tt +res} and passing its address as the argument will not work. +That structure must also be deleted when no longer needed. If one does not +want to post-process or use the tables of results after a {\tt f} test, +it suffices to set the {\tt res} argument of the testing function +to the {\tt NULL} pointer. +Then, the structure is created and deleted automatically inside the +testing function. In any case, the tables of results will be printed on +standard output. + +\bigskip +\hrule +\code +\hide +/* fres.h for ANSI C */ +#ifndef FRES_H +#define FRES_H +\endhide +#include "gofw.h" +#include "ftab.h" +#include "ffam.h" +#include "bitset.h" +\endcode + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\guisec{Common structure for test results (continuous distribution)} + +The tables of $p$-values for tests in the {\tt f} modules, based on simple +continuous distributions can be recovered in the structure defined below. +Tests which produces many tables of different results use more complicated +structures and are defined in the appropriate {\tt f} module. + +\code + + +typedef struct { + ftab_Table *PVal [gofw_NTestTypes]; + bitset_BitSet Active; + char *name; +} fres_Cont; +\endcode + \tab + The tables in this structure contain the $p$-values resulting from + the tests applied to a whole family of generators. + When the number of replications $N$ is equal to 1, the $p$-values + are returned in {\tt PVal2[gofw\_Mean]}. When $N > 1$, the relevant + $p$-values are returned in {\tt PVal [$j$]}, where $j$ is a member + of the set {\tt Active}. The active statistics are usually those + in {\tt gofw\_ActiveTests} (see module {\tt gofw} in library + ProbDist). Using the non-active {\tt PVal [$j$]} is illegal and will + give unpredictable results. The variable + {\tt name} gives the name of the test which produced the above results. + \endtab +\code + + +fres_Cont *fres_CreateCont (void); +\endcode + \tab + Creates and returns a structure that will hold the tables of $p$-values + above. + \endtab +\code + + +void fres_DeleteCont (fres_Cont *res); +\endcode + \tab + Frees the memory allocated to {\tt res} by {\tt fres\_CreateCont}. + \endtab +\code +\hide + +void fres_InitCont (ffam_Fam *fam, fres_Cont *res, int N, + int Nr, int j1, int j2, int jstep, char *nam); +\endcode + \tab + Initializes the {\tt res} structure, ensures that it can keep results + for the first {\tt Nr} generators of family {\tt fam}, with sample sizes + varying from {\tt j1} to {\tt j2} by step of {\tt jstep} for a given + generator, and sets its {\tt name} field to {\tt nam}. {\tt N} + is the number of replications of the base test. This function + must not be called directly by the user. It has been made public because + it is called internally by the tests in the {\tt f} modules. + \endtab +\code +\endhide + +void fres_PrintCont (fres_Cont *res); +\endcode + \tab Prints the tables in {\tt res}. + \endtab +\code + + +void fres_FillTableEntryC (fres_Cont *res, gofw_TestArray pval, int N, + int irow, int icol); +\endcode + \tab This function fills the entry in row {\tt irow} and column {\tt icol} + of the active tables in {\tt res} with the values in {\tt pval}. {\tt N} + is the number of replications of the base test. + \endtab + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Common structure for test results (discrete distribution)} + +The tables of $p$-values for tests in the {\tt f} modules, based on simple +discrete distributions can be recovered in the structure defined below. +Tests which produces many tables of different results use more complicated +structures and are defined in the appropriate {\tt f} module. + +\code + +typedef struct { + ftab_Table *PLeft; + ftab_Table *PRight; + ftab_Table *PVal2; + char *name; +} fres_Disc; +\endcode + \tab + The tables in this structure contain the left $p$-values, + the right $p$-values, and the resulting + $p$-values (as computed in function {\tt gofw\_pDisc} of library + ProbDist) for a statistic taking discrete values. The variable + {\tt name} gives the name of the test which produced the above results. + \endtab +\code + + +fres_Disc * fres_CreateDisc (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a simple test based on a discrete distribution. + \endtab +\code + + +void fres_DeleteDisc (fres_Disc *res); +\endcode + \tab + Frees the memory allocated to {\tt res} by {\tt fres\_CreateDisc}. + \endtab +\code +\hide + +void fres_InitDisc (ffam_Fam *fam, fres_Disc *res, + int Nr, int j1, int j2, int jstep, char *nam); +\endcode + \tab + Initializes the {\tt res} structure, ensures that it can keep results + for the first {\tt Nr} generators of family {\tt fam}, with sample sizes + varying from {\tt j1} to {\tt j2} by step of {\tt jstep} for a given + generator, and sets its {\tt name} field to {\tt nam}. This function + must not be called directly by the user. It has been made public because + it is called internally by the tests in the {\tt f} modules. + \endtab +\code +\endhide + +void fres_PrintDisc (fres_Disc *res, lebool LR); +\endcode + \tab Prints the tables in {\tt res}. If {\tt LR} is {\tt TRUE}, prints the + tables {\tt PLeft} and {\tt PRight}; otherwise, + prints only the {\tt PVal2} table. + \endtab +\code + + +void fres_FillTableEntryD (fres_Disc *res, double pLeft, double pRight, + double pVal2, int irow, int icol); +\endcode + \tab This function fills the entry in row {\tt irow} and column {\tt icol} + of the tables in {\tt res} with the values {\tt pLeft}, {\tt pRight} + and {\tt pVal2}. + \endtab + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for Poisson test results} + +The tables of $p$-values for tests in the {\tt f} modules based on a +Poisson distribution can be recovered in the structure defined below. + +\code + +typedef struct { + ftab_Table *Exp; + ftab_Table *Obs; + ftab_Table *PLeft; + ftab_Table *PRight; + ftab_Table *PVal2; + char *name; +} fres_Poisson; +\endcode + \tab + The tables in this structure contain the expected numbers, the observed + numbers, the left $p$-values, the right $p$-values, and the resulting + $p$-values (as computed in function {\tt gofw\_pDisc} of library + ProbDist) for a statistic obeying the Poisson law. The variable + {\tt name} gives the name of the test which produced the above results. + \endtab +\code + + +fres_Poisson * fres_CreatePoisson (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a test based on the Poisson distribution. + \endtab +\code + + +void fres_DeletePoisson (fres_Poisson *res); +\endcode + \tab + Frees the memory allocated to {\tt res} by {\tt fres\_CreatePoisson}. + \endtab +\code +\hide + +void fres_InitPoisson (ffam_Fam *fam, fres_Poisson *res, + int Nr, int j1, int j2, int jstep, char *nam); +\endcode + \tab + Initializes the {\tt res} structure, ensures that it can keep results + for the first {\tt Nr} generators of family {\tt fam}, with sample sizes + varying from {\tt j1} to {\tt j2} by step of {\tt jstep} for a given + generator, and sets its {\tt name} field to {\tt nam}. This function + must not be called directly by the user. It has been made public because + it is called internally by the tests in the {\tt f} modules. + \endtab +\code +\endhide + +void fres_PrintPoisson (fres_Poisson *res, lebool LR, lebool Ratio); +\endcode + \tab Prints the tables in {\tt res}. If {\tt LR} is {\tt TRUE}, prints the + tables {\tt PLeft} and {\tt PRight}; otherwise does not print them. + If {\tt Ratio} is {\tt TRUE}, prints the observed numbers in {\tt Obs} as + a ratio over the corresponding numbers in {\tt Exp}, otherwise prints + them as themselves. + \endtab +\code + + +void fres_FillTableEntryPoisson (fres_Poisson *res, double Exp, double Obs, + double pLeft, double pRight, double pVal2, + int irow, int icol); +\endcode + \tab This function fills the entry in row {\tt irow} and column {\tt icol} + of the tables in {\tt res} with the expected number {\tt Exp}, + the observed number {\tt Obs}, the left $p$-value {\tt pLeft}, + the right $p$-value {\tt pRight}, and the resulting + $p$-value {\tt pVal2}. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fresshort.tex b/TESTU01/TestU01-1.2.3/testu01/fresshort.tex new file mode 100644 index 0000000..b13b5ce --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fresshort.tex @@ -0,0 +1,16 @@ +\defmodule {fres} + +This module defines common structures used to keep the results of tests +in the {\tt f} modules. They are described in the detailed version of +this guide. + + +The argument {\tt res} of each testing function is a structure +that can keep the test results, i.e. tables of $p$-values, \ldots. +This is useful if one wishes to do something else with the +results or the information generated during a test. +If one does not want to post-process or use the results after a test, +it suffices to set the {\tt res} argument to the {\tt NULL} pointer. +Then, the structure is created and deleted automatically inside the +testing function. In any case, the tables of results will be printed +automatically on standard output. diff --git a/TESTU01/TestU01-1.2.3/testu01/fspectral.c b/TESTU01/TestU01-1.2.3/testu01/fspectral.c new file mode 100644 index 0000000..f09eb53 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fspectral.c @@ -0,0 +1,118 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fspectral.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "fspectral.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" +#include "ftab.h" +#include "sspectral.h" + +#include "num.h" + +long fspectral_Maxn = 4194304; + + + + +/*------------------------------- Functions ------------------------------*/ + + +static void PrintHead (char *name, ffam_Fam *fam, void *par1, + int Nr, int j1, int j2, int jstep) +{ + int *Par = par1; + + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", name); + printf (" k = %d, r = %d, s = %d", Par[0], Par[1], Par[2]); + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); +} + + +/*=========================================================================*/ + +static void TabFourier3 (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s, k; + long N; + int *Par = par1; + fres_Cont *fres = res1; + sspectral_Res *sres; + + k = Par[0]; + r = Par[1]; + s = Par[2]; + + N = fcho_ChooseParamL (cho, (long) num_TwoExp[k], fspectral_Maxn, i, j); + if (N < 0) + return; + s = fcho_Chooses (r, s, fam->Resol[irow]); + if (s <= 0) + return; + + + sres = sspectral_CreateRes (); + sspectral_Fourier3 (fam->Gen[irow], sres, N, k, r, s); + fres_FillTableEntryC (fres, sres->Bas->pVal2, N, irow, icol); + sspectral_DeleteRes (sres); +} + + +/*========================================================================*/ + +void fspectral_Fourier3 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + int k, int r, int s, + int Nr, int j1, int j2, int jstep) +{ + int Par[3]; + lebool localRes; + + Par[0] = k; + Par[1] = r; + Par[2] = s; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fspectral_Fourier3", fam, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, 2, Nr, j1, j2, jstep, "fspectral_Fourier3"); + ftab_MakeTables (fam, res, cho, Par, TabFourier3, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/fspectral.tex b/TESTU01/TestU01-1.2.3/testu01/fspectral.tex new file mode 100644 index 0000000..393bc67 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fspectral.tex @@ -0,0 +1,51 @@ +\defmodule {fspectral} + +This module applies spectral tests from the module {\tt sspectral} +to a family of generators of different sizes. + +\bigskip +\hrule +\code\hide +/* fspectral.h for ANSI C */ +#ifndef FSPECTRAL_H +#define FSPECTRAL_H +\endhide +#include "ffam.h" +#include "fres.h" +#include "fcho.h" + + +extern long fspectral_MaxN; +\endcode +\tab + Upper bound on $N$. + When $N$ exceeds its limit value, the tests are not done. + Default value: $N = 2^{22}$. +\endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code +void fspectral_Fourier3 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + int k, int r, int s, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + This function calls the test {\tt sspectral\_Fourier3} with parameters + $N$, {\tt k}, {\tt r}, and {\tt s} for sample size $N$ chosen by + $N = {}$ {\tt cho->Choose(param, i, j)}, + for the first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. The parameters in {\tt param} + were set at the creation of {\tt cho} and $i$ is the lsize of the + generator being tested. + When $N$ exceeds {\tt fspectral\_MaxN}, the test is not done. +\endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fstring.c b/TESTU01/TestU01-1.2.3/testu01/fstring.c new file mode 100644 index 0000000..335b8df --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fstring.c @@ -0,0 +1,675 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fstring.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "gofs.h" + +#include "fstring.h" +#include "fcho.h" +#include "ffam.h" +#include "fres.h" +#include "ftab.h" +#include "sstring.h" +#include "unif01.h" + +#include + + +long fstring_Maxn = 1024*1024*4; +long fstring_MaxL = 1024*1024*1; + + +/* Type of structure to choose the parameter of the sample size */ +typedef enum { + CHO_CHO, + CHO_STRING +} cho_Type; + + + +/*------------------------------ Functions --------------------------------*/ + +static void InitRes1 ( + ffam_Fam *fam, + fstring_Res1 *res, /* Results holder */ + int N, /* Number of replications */ + int Nr, + int j1, int j2, int jstep, + char *name1, + char *name2 +) +/* + * Initializes the fstring_Res1 structure + */ +{ + fres_InitCont (fam, res->BLen, N, Nr, j1, j2, jstep, name1); + fres_InitDisc (fam, res->GLen, Nr, j1, j2, jstep, name2); +} + + +/*-------------------------------------------------------------------------*/ + +fstring_Res1 * fstring_CreateRes1 (void) +{ + fstring_Res1 *res; + res = util_Malloc (sizeof (fstring_Res1)); + res->BLen = fres_CreateCont (); + res->GLen = fres_CreateDisc (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_DeleteRes1 (fstring_Res1 *res) +{ + if (res == NULL) + return; + fres_DeleteCont (res->BLen); + fres_DeleteDisc (res->GLen); + util_Free (res); +} + + +/*=========================================================================*/ + +static void InitRes2 ( + ffam_Fam *fam, + fstring_Res2 *res, /* Results holder */ + int N, /* Number of replications */ + int Nr, + int j1, int j2, int jstep, + char *name1, + char *name2 +) +/* + * Initializes the fstring_Res2 structure + */ +{ + fres_InitCont (fam, res->NBits, N, Nr, j1, j2, jstep, name1); + fres_InitCont (fam, res->NRuns, N, Nr, j1, j2, jstep, name2); +} + + +/*-------------------------------------------------------------------------*/ + +fstring_Res2 * fstring_CreateRes2 (void) +{ + fstring_Res2 *res; + res = util_Malloc (sizeof (fstring_Res2)); + res->NBits = fres_CreateCont (); + res->NRuns = fres_CreateCont (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_DeleteRes2 (fstring_Res2 *res) +{ + if (res == NULL) + return; + fres_DeleteCont (res->NBits); + fres_DeleteCont (res->NRuns); + util_Free (res); +} + + +/*=========================================================================*/ + +static void PrintHead (char *test, ffam_Fam *fam, + long N, long n, int r, int s, long L, int d, + int Nr, int j1, int j2, int jstep) +{ + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", test); + printf (" N = %ld,", N); + if (n) + printf (" n = %ld,", n); + printf (" r = %d, s = %d", r, s); + if (L) + printf (", L = %ld", L); + if (d) + printf (", d = %d", d); + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); +} + + +/*=========================================================================*/ + +static int ChooseParam (int prec, void *cho, cho_Type ver, + long *pn, int *pr, int *ps, long *pL, long LMin, int i, int j) +/* + * Set the values of the parameters for the test. If a parameter is < 0, + * will call a choose function to set it. Otherwise, will accept it as is. + * Returns 0 if parameters are ok for the test, returns -1 if the test + * should not be done for these parameters. + */ +{ + fcho_Cho *cho1 = cho; + fcho_Cho2 *cho2 = cho; + fcho_Cho *chon; + fcho_Cho *choL; + + switch (ver) { + case CHO_STRING: + util_Assert (cho2, "fstring: cho2 is NULL"); + chon = cho2->Chon; + choL = cho2->Chop2; + util_Assert (*pn < 0 || *pL < 0, + "fstring: Either n or L must be < 0" ); + break; + case CHO_CHO: + chon = cho1; + break; + default: + util_Error ("in fstring, ChooseParam: no such case"); + } + + if (*pn < 0) { + util_Assert (chon, "fstring: n < 0 and chon is NULL"); + *pn = chon->Choose (chon->param, i, j); + + if (*pn <= 3.0 * gofs_MinExpected) { + printf ("n is too small\n\n"); + return -1; + } + if (*pn > fstring_Maxn) { + printf ("n > %2ld\n\n", fstring_Maxn); + return -1; + } + } + + *ps = fcho_Chooses (*pr, *ps, prec); + if (*ps <= 0) + return -1; + + if (*pL < 0) { + util_Assert (choL, "fstring: L < 0 and choL is NULL"); + *pL = choL->Choose (choL->param, i, j); + + if (*pL <= LMin) { + printf ("L is too small\n\n"); + return -1; + } + if (*pL > fstring_MaxL) { + printf ("L > %2ld\n\n", fstring_MaxL); + return -1; + } + } + + return 0; +} + + +/*=========================================================================*/ + +static void TabPeriod (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n, junk = 0; + const long *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + + if (ChooseParam (fam->Resol[irow], cho, CHO_CHO, &n, &r, &s, &junk, 0, i, j)) + return; + + sres = sres_CreateChi2 (); + sstring_PeriodsInStrings (fam->Gen[irow], sres, N, n, r, s); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_Period1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int s, + int Nr, int j1, int j2, int jstep) +{ + long Par[5] = { 0 }; + lebool localRes; + + Par[0] = N; + Par[1] = -1; + Par[2] = r; + Par[3] = s; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fstring_Period1", fam, N, 0, r, s, 0, 0, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fstring_Period1"); + ftab_MakeTables (fam, res, cho, Par, TabPeriod, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*=========================================================================*/ + +static void TabRun (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n, junk = 0; + const long *Par = par1; + fstring_Res2 *fres = res1; + sstring_Res3 *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + + if (ChooseParam (fam->Resol[irow], cho, CHO_CHO, &n, &r, &s, &junk, 0, i, j)) + return; + + sres = sstring_CreateRes3 (); + sstring_Run (fam->Gen[irow], sres, N, n, r, s); + fres_FillTableEntryC (fres->NRuns, sres->NRuns->pVal2, N, irow, icol); + fres_FillTableEntryC (fres->NBits, sres->NBits->pVal2, N, irow, icol); + sstring_DeleteRes3 (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_Run1 (ffam_Fam *fam, fstring_Res2 *res, fcho_Cho *cho, + long N, int r, int s, + int Nr, int j1, int j2, int jstep) +{ + long Par[5] = {0}; + lebool localRes; + + Par[0] = N; + Par[1] = -1; + Par[2] = r; + Par[3] = s; + if (res == NULL) { + localRes = TRUE; + res = fstring_CreateRes2 (); + } else + localRes = FALSE; + + PrintHead ("fstring_Run1", fam, N, 0, r, s, 0, 0, Nr, j1, j2, jstep); + InitRes2 (fam, res, N, Nr, j1, j2, jstep, "fstring_Run1, Number of Bits", + "fstring_Run1, Number of Runs"); + ftab_MakeTables (fam, res, cho, Par, TabRun, Nr, j1, j2, jstep); + fres_PrintCont (res->NRuns); + fres_PrintCont (res->NBits); + if (localRes) + fstring_DeleteRes2 (res); +} + + +/*=========================================================================*/ + +static void TabAutoCor (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s, d; + long N, n, junk = 0; + const long *Par = par1; + fres_Cont *fres = res1; + sres_Basic *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + d = Par[5]; + + if (ChooseParam (fam->Resol[irow], cho, CHO_CHO, &n, &r, &s, &junk, 0, i, j)) + return; + + sres = sres_CreateBasic (); + sstring_AutoCor (fam->Gen[irow], sres, N, n, r, s, d); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteBasic (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_AutoCor1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int s, int d, + int Nr, int j1, int j2, int jstep) +{ + long Par[6] = {0}; + lebool localRes; + + Par[0] = N; + Par[1] = -1; + Par[2] = r; + Par[3] = s; + Par[5] = d; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fstring_AutoCor1", fam, N, 0, r, s, 0, d, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fstring_AutoCor1"); + ftab_MakeTables (fam, res, cho, Par, TabAutoCor, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*=========================================================================*/ + +static void TabLongHead (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n, L; + const long *Par = par1; + fstring_Res1 *fres = res1; + sstring_Res2 *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + L = Par[4]; + + if (ChooseParam (fam->Resol[irow], cho, CHO_STRING, + &n, &r, &s, &L, 1050, i, j)) + return; + if (L < 1000 + s) + return; + + sres = sstring_CreateRes2 (); + sstring_LongestHeadRun (fam->Gen[irow], sres, N, n, r, s, L); + fres_FillTableEntryC (fres->BLen, sres->Chi->pVal2, N, irow, icol); + fres_FillTableEntryD (fres->GLen, sres->Disc->pLeft, sres->Disc->pRight, + sres->Disc->pVal2, irow, icol); + sstring_DeleteRes2 (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_LongHead1 (ffam_Fam *fam, fstring_Res1 *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep) +{ + long Par[5] = {0}; + lebool localRes; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = s; + Par[4] = L; + if (res == NULL) { + localRes = TRUE; + res = fstring_CreateRes1 (); + } else + localRes = FALSE; + + PrintHead ("fstring_LongHead1", fam, N, n, r, s, L, 0, Nr, j1, j2, jstep); + InitRes1 (fam, res, N, Nr, j1, j2, jstep, + "fstring_LongHead1, n block lengths", + "fstring_LongHead1, 1 global length"); + ftab_MakeTables (fam, res, cho, Par, TabLongHead, Nr, j1, j2, jstep); + fres_PrintCont (res->BLen); + ftab_PrintTable (res->GLen->PVal2); + if (localRes) + fstring_DeleteRes1 (res); +} + + +/*=========================================================================*/ + +static void TabHamWeight2 (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s, ver; + long N, n, L; + const long *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres1; + sres_Basic *sres2; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + L = Par[4]; + ver = Par[5]; + + if (ChooseParam (fam->Resol[irow], cho, CHO_STRING, &n, &r, &s, &L, 0, i, j)) + return; + if ((ver == 2) && (L > n)) { + printf ("L > n\n\n"); + return; + } + if ((ver == 1) && (n <= 2.0 * gofs_MinExpected)) { + printf ("n <= 2 gofs_MinExpected\n\n"); + return; + } + if (ver == 2) { + sres2 = sres_CreateBasic (); + sstring_HammingWeight2 (fam->Gen[irow], sres2, N, n, r, s, L); + fres_FillTableEntryC (fres, sres2->pVal2, N, irow, icol); + sres_DeleteBasic (sres2); + } else { + sres1 = sres_CreateChi2 (); + sstring_HammingWeight (fam->Gen[irow], sres1, N, n, r, s, L); + fres_FillTableEntryC (fres, sres1->pVal2, N, irow, icol); + sres_DeleteChi2 (sres1); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void Ver_HamWeight (ffam_Fam *fam, fres_Cont *res, + fcho_Cho2 *cho, long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep, int ver) +{ + long Par[6] = {0}; + lebool localRes; + char Name[60]; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = s; + Par[4] = L; + Par[5] = ver; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + if (ver == 2) + strcpy (Name, "fstring_HamWeight2"); + else + strcpy (Name, "fstring_HamWeight1"); + + PrintHead (Name, fam, N, n, r, s, L, 0, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, Name); + ftab_MakeTables (fam, res, cho, Par, TabHamWeight2, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_HamWeight2 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep) +{ + Ver_HamWeight (fam, res, cho, N, n, r, s, L, Nr, j1, j2, jstep, 2); +} + + +void fstring_HamWeight1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep) +{ + Ver_HamWeight (fam, res, cho, N, n, r, s, L, Nr, j1, j2, jstep, 1); +} + + +/*=========================================================================*/ + +static void TabHamCorr (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n, L; + const long *Par = par1; + fres_Cont *fres = res1; + sstring_Res *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + L = Par[4]; + + if (ChooseParam (fam->Resol[irow], cho, CHO_STRING, &n, &r, &s, &L, 0, i, j)) + return; + + sres = sstring_CreateRes (); + sstring_HammingCorr (fam->Gen[irow], sres, N, n, r, s, L); + fres_FillTableEntryC (fres, sres->Bas->pVal2, N, irow, icol); + sstring_DeleteRes (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_HamCorr1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep) +{ + long Par[5]; + lebool localRes; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = s; + Par[4] = L; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fstring_HamCorr1", fam, N, n, r, s, L, 0, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fstring_HamCorr1"); + ftab_MakeTables (fam, res, cho, Par, TabHamCorr, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*=========================================================================*/ + +static void TabHamIndep (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n, L; + const long *Par = par1; + fres_Cont *fres = res1; + sstring_Res *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + L = Par[4]; + + if (ChooseParam (fam->Resol[irow], cho, CHO_STRING, &n, &r, &s, &L, 0, i, j)) + return; + + sres = sstring_CreateRes (); + sstring_HammingIndep (fam->Gen[irow], sres, N, n, r, s, L, -1); + fres_FillTableEntryC (fres, sres->Bas->pVal2, N, irow, icol); + sstring_DeleteRes (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fstring_HamIndep1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep) +{ + long Par[5]; + lebool localRes; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = s; + Par[4] = L; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fstring_HamIndep1", fam, N, n, r, s, L, 0, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fstring_HamIndep1"); + ftab_MakeTables (fam, res, cho, Par, TabHamIndep, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fstring.tex b/TESTU01/TestU01-1.2.3/testu01/fstring.tex new file mode 100644 index 0000000..d0452c3 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fstring.tex @@ -0,0 +1,202 @@ +\defmodule {fstring} + +This module applies tests from the module {\tt sstring} +to a family of generators of different lsizes. +The results are placed in tables of $p$-values. + +\bigskip +\hrule +\code\hide +/* fstring.h for ANSI C */ +#ifndef FSTRING_H +#define FSTRING_H +\endhide +#include "ffam.h" +#include "fres.h" +#include "fcho.h" + + +extern long fstring_Maxn, fstring_MaxL; +\endcode +\tab + Upper bound on $n$ and $L$. + A test is called only when $n$ and $L$ do not exceed their limit value. + Default values: $n = 2^{22}$ and $L = 2^{20}$. +\endtab + + +\ifdetailed %%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structures for test results} + +\code + +typedef struct { + fres_Cont *BLen; + fres_Disc *GLen; +} fstring_Res1; +\endcode + \tab Structure used to keep the results of tests + {\tt fstring\_LongHead1}. {\tt GLen} corresponds to the global length + over all blocks considered as a single sequence. {\tt BLen} corresponds + to one length for each block. + \endtab +\code + + +fstring_Res1 * fstring_CreateRes1 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt fstring\_LongHead1} test. + \endtab +\code + + +void fstring_DeleteRes1 (fstring_Res1 *res); +\endcode + \tab + Frees the memory allocated by {\tt fstring\_CreateRes1}. + \endtab +\bigskip\hrule\bigskip +\code + +typedef struct { + fres_Cont *NBits; + fres_Cont *NRuns; +} fstring_Res2; +\endcode + \tab Structure used to keep the results of tests {\tt fstring\_Run1}. + The member {\tt NBits} keeps the results for the number of + bits, while {\tt NRuns} keeps the results for the number of runs. + \endtab +\code + + +fstring_Res2 * fstring_CreateRes2 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt fstring\_Run1} test. + \endtab +\code + + +void fstring_DeleteRes2 (fstring_Res2 *res); +\endcode + \tab + Frees the memory allocated by {\tt fstring\_CreateRes2}. + \endtab + +\fi %%%%%%%%%%%%%%%%%% + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} +\code + +void fstring_Period1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int s, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + This function calls the test {\tt sstring\_PeriodsInStrings} with + parameters {\tt N}, {\tt r}, {\tt s} and sample size + $n =$ {\tt cho->Choose(param, i, j)}, + for the first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. The parameters in {\tt param} + were set at the creation of {\tt cho} and $i$ is the lsize of the + generator being tested. + When $n$ exceeds {\tt fstring\_Maxn}, the test is not run. +\endtab +\code + + +void fstring_Run1 (ffam_Fam *fam, fstring_Res2 *res, fcho_Cho *cho, + long N, int r, int s, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fstring\_Period1} but with + {\tt sstring\_Run}. + \endtab +\code + + +void fstring_AutoCor1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int s, int d, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fstring\_Period1} but with + {\tt sstring\_AutoCor}. + \endtab +\code + + +void fstring_LongHead1 (ffam_Fam *fam, fstring_Res1 *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep); +\endcode + \tab This function calls the test {\tt sstring\_LongestHeadRun} with + parameters {\tt N}, {\tt r}, {\tt s} for the first {\tt Nr} generators of + family {\tt fam}, for $j$ going from {\tt j1} to {\tt j2} by steps of + {\tt jstep}. If {\tt s} is greater than the resolution of the + generator, it will be reset to the resolution of the + generator. Either or both of $n$ and $L$ can be varied as + the sample size, by passing a negative value as an argument of the + function. One must then create the corresponding function + {\tt cho->Chon} or {\tt cho->Chop2} before calling the test. + One will have either $n = {}$ {\tt cho->Chon->Choose(param, i, j)}, + or $L = {}$ {\tt cho->Chop2->Choose(param, i, j)} (or both). A positive value + for $n$ or $L$ will be used as is by the test. + When $n$ exceeds {\tt fstring\_Maxn} or $L$ exceeds {\tt fstring\_MaxL}, + the test is not run. + \endtab +\code + + +void fstring_HamWeight1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fstring\_LongHead1} but with + {\tt sstring\_HammingWeight}. + \endtab +\code + + +void fstring_HamWeight2 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fstring\_LongHead1} but with + {\tt sstring\_HammingWeight2}. + \endtab +\code + + +void fstring_HamCorr1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fstring\_LongHead1} but with + {\tt sstring\_HammingCorr}. + \endtab +\code + + +void fstring_HamIndep1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep); +\endcode + \tab Similar to {\tt fstring\_LongHead1} but with + {\tt sstring\_HammingIndep}. + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ftab.c b/TESTU01/TestU01-1.2.3/testu01/ftab.c new file mode 100644 index 0000000..4b819db --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ftab.c @@ -0,0 +1,625 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ftab.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "util.h" +#include "chrono.h" +#include "num.h" +#include "tables.h" +#include "gofw.h" + +#include "ftab.h" +#include "ffam.h" +#include "swrite.h" + +#include +#include +#include +#include + + +#define MAXLEN 100 /* Max number of chars in Desc[] */ + + + +/*---------------------------- extern variables ---------------------------*/ + +ftab_StyleType ftab_Style = ftab_Plain; + +double ftab_Suspectp = 0.01; + +int ftab_SuspectLog2p = 6; + + + + +/*---------------------------- module variables ---------------------------*/ + +static double SuspectLog2pval; + + + + + +/*-------------------------------- Functions ------------------------------*/ + + +void ftab_SetDesc (ftab_Table *T, char *Desc) +{ + size_t len; + util_Assert (T != NULL, "ftab_SetDesc: ftab_Table is a NULL pointer"); + len = strlen (Desc); + if (len > MAXLEN) { + len = MAXLEN; + util_Warning (1, "ftab_Table->Desc truncated"); + } + if (T->Desc != NULL) + T->Desc = util_Free (T->Desc); + T->Desc = util_Calloc (len + 1, sizeof (char)); + strncpy (T->Desc, Desc, (size_t) len); + T->Desc[len] = '\0'; +} + + +/*=========================================================================*/ + +ftab_Table *ftab_CreateTable (int Nr, int j1, int j2, int jstep, + char *Desc, ftab_FormType Form, int Ns) +{ + ftab_Table *T; + T = util_Malloc (sizeof (ftab_Table)); + memset (T, 0, sizeof (ftab_Table)); + T->Nr = Nr; + T->j1 = j1; + T->j2 = j2; + T->jstep = jstep; + T->Nc = 1 + (j2 - j1)/jstep; + T->Mat = tables_CreateMatrixD (T->Nr, T->Nc); + T->LSize = util_Calloc ((size_t) T->Nr, sizeof (int)); + T->Desc = NULL; + ftab_SetDesc (T, Desc); + T->Form = Form; + if (Form == ftab_String) { + T->Strings = util_Calloc ((size_t) Ns, sizeof (char *)); + T->Ns = Ns; + } else + T->Strings = NULL; + return T; +} + + +/*=========================================================================*/ + +void ftab_DeleteTable (ftab_Table * T) +{ + if (T == NULL) + return; + tables_DeleteMatrixD (&T->Mat); + T->LSize = util_Free (T->LSize); + T->Desc = util_Free (T->Desc); + if (T->Form == ftab_String) + T->Strings = util_Free (T->Strings); + util_Free (T); +} + + +/*=========================================================================*/ + +void ftab_InitMatrix (ftab_Table * T, double x) +{ + int i, j; + + for (i = 0; i < T->Nr; i++) + for (j = 0; j < T->Nc; j++) + T->Mat[i][j] = x; +} + + +/*=========================================================================*/ + +void ftab_MakeTables (ffam_Fam *fam, void *res, void *cho, void *par, + ftab_CalcType Calc, int Nr, int f1, int f2, int fstep) +{ + int i, j; /* Row and column of matrices for results of one test */ + int f; + chrono_Chrono *Timer; + unif01_Gen *gen; + + SuspectLog2pval = 1.0 / (num_TwoExp[ftab_SuspectLog2p] - 1.0); + + Timer = chrono_Create (); + + Nr = util_Min (Nr, fam->Ng); + for (i = 0; i < Nr; i++) { + if (swrite_Basic) { + printf ("CPU cumulative time: "); + chrono_Write (Timer, chrono_hms); + printf ("\n\n=============================================" + "==============\n\nLSize = i = %2d\n\n", fam->LSize[i]); + } + if ((gen = fam->Gen[i])) { + f = f1; + j = 0; + while (f <= f2) { + Calc (fam, res, cho, par, fam->LSize[i], f, i, j); + f += fstep; + j++; + } + } + } + if (swrite_Basic) { + printf ("Total CPU time: "); + chrono_Write (Timer, chrono_hms); + printf + ("\n\n======================================================\n"); + } + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void PrintTexName (char *nam) +/* + * Make sure that any _ char in Latex format name is printed as \_ + */ +{ + char *p, *name = nam; + size_t len; + + if (NULL == nam) + return; + len = strlen (name) + 1; + name = util_Calloc (len, sizeof (char)); + strncpy (name, nam, (size_t) len); + + while ((p = strchr(name, '_'))) { + *p = '\0'; + printf ("%s", name); + printf ("\\_"); + name = p + 1; + } + printf ("%s", name); +} + + +/*=========================================================================*/ + +static void PrintLog2 (double d) +/* + * Prints the logarithm (rounded) of d in base 2, when d is outside the + * interval [SuspectLog2pval, 1 - SuspectLog2pval]; otherwise prints + * nothing. + */ +{ + int s; + + if (d <= gofw_Epsilonp) { + printf (" inf "); + } else if (d <= SuspectLog2pval) { + s = 0.5 - num_Log2 (d); + printf (" %2d ", s); + } else if (d >= 1.0 - gofw_Epsilonp1) { + printf (" -inf "); + } else if (d >= 1.0 - SuspectLog2pval) { + s = 0.5 - num_Log2 (1.0 - d); + if (s > 9) + printf (" "); + else + printf (" "); + printf ("-%1d ", s); + } else + printf (" "); +} + + +/*-------------------------------------------------------------------------*/ + +static void PrintLog2Tex (double d) +/* + * Similar to PrintLog2, but prints in Latex style. + */ +{ + int s; + if (d <= gofw_Epsilonp) { + printf (" & $\\infty$ "); + } else if (d <= SuspectLog2pval) { + s = 0.5 - num_Log2 (d); + printf (" & %3d ", s); + } else if (d >= 1.0 - gofw_Epsilonp1) { + printf (" & $-\\infty$ "); + } else if (d >= 1.0 - SuspectLog2pval) { + s = 0.5 - num_Log2 (1.0 - d); + if (s > 9) + printf (" & $-"); + else + printf (" & $-"); + printf ("%1d $ ", s); + } else + printf (" & "); +} + + +/*=========================================================================*/ + +static void PrintLog10 (double d) +/* + * Prints the logarithm (rounded) of d in base 10, when d is outside the + * interval [ftab_Suspectp, 1 - ftab_Suspectp]; otherwise prints + * nothing. + */ +{ + int s; + if (d <= gofw_Epsilonp) { + printf (" inf "); + } else if (d <= ftab_Suspectp) { + s = 0.5 - log10 (d); + printf (" %2d ", s); + } else if (d >= 1.0 - gofw_Epsilonp1) { + printf (" -inf "); + } else if (d >= 1.0 - ftab_Suspectp) { + s = 0.5 - log10 (1.0 - d); + if (s > 9) + printf (" "); + else + printf (" "); + printf ("-%1d ", s); + } else { + printf (" "); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void PrintLog10Tex (double d) +/* + * Similar to PrintLog10, but prints in LaTex style. + */ +{ + int s; + if (d <= gofw_Epsilonp) { + printf (" & $\\infty$ "); + } else if (d <= ftab_Suspectp) { + s = 0.5 - log10 (d); + printf (" & %3d ", s); + } else if (d >= 1.0 - gofw_Epsilonp1) { + printf (" & $-\\infty$ "); + } else if (d >= 1.0 - ftab_Suspectp) { + s = 0.5 - log10 (1.0 - d); + if (s > 9) + printf (" & $-"); + else + printf (" & $-"); + printf ("%1d $ ", s); + } else { + printf (" & "); + } +} + + +/*=========================================================================*/ + +static void PrintVal (ftab_Table * T, double d, ftab_FormType Form) +/* + * Prints the value d according to format Form. + */ +{ + int s; + /* All Table tables are initialized to -1; thus the test was not done for + this pair (e, f) if d = -1. */ + if (d < -0.9) { + printf (" --- "); + } else if (Form == ftab_String) { + printf (" "); + s = 0.5 + d; + printf ("%s", T->Strings[s]); + } else if (Form == ftab_Integer) { + printf (" "); + if (d <= LONG_MAX) + printf ("%8ld", (long) d); + else + num_WriteD (d, 8, 0, 0); + } else if (Form == ftab_Real) { + printf (" "); + num_WriteD (d, 8, 2, 2); + } else if (Form == ftab_pLog2) { + PrintLog2 (d); + } else if (Form == ftab_pLog10) { + PrintLog10 (d); + } else if (d < gofw_Epsilonp) { + printf (" eps "); + } else if (d < ftab_Suspectp) { + printf (" "); + num_WriteD (d, 8, 2, 2); + } else if (d > 1.0 - gofw_Epsilonp1 && Form == ftab_pVal2) { + printf (" -eps1 "); + } else if (d > 1.0 - ftab_Suspectp && Form == ftab_pVal2) { + printf (" "); + num_WriteD (d - 1.0, 8, 2, 2); + } else if (Form == ftab_NotInit) { + util_Error ("ftab_PrintTable: Form is not initialized"); + } else { + printf (" "); + } +} + + +/*=========================================================================*/ + +static void PrintValTex (ftab_Table * T, double d, ftab_FormType Form) +/* + * Similar to PrintVal, but prints in LaTex style. + */ +{ + int s; + if (d < -0.9) { + printf (" & --- "); + } else if (Form == ftab_String) { + printf (" & "); + s = d + 0.5; + printf ("%s", T->Strings[s]); + } else if (Form == ftab_Integer) { + printf (" & "); + if (d <= LONG_MAX) + printf ("%8ld", (long) d); + else + num_WriteD (d, 8, 0, 0); + } else if (Form == ftab_Real) { + printf (" & "); + num_WriteD (d, 8, 2, 2); + } else if (Form == ftab_pLog10) { + PrintLog10Tex (d); + } else if (Form == ftab_pLog2) { + PrintLog2Tex (d); + } else if (d < gofw_Epsilonp) { + printf (" & \\eps "); + } else if (d < ftab_Suspectp) { + printf (" & "); + num_WriteD (d, 8, 2, 2); + } else if (d > 1.0 - gofw_Epsilonp1 && Form == ftab_pVal2) { + printf (" & \\epsm "); + } else if (d > 1.0 - ftab_Suspectp && Form == ftab_pVal2) { + printf (" & "); + num_WriteD (d - 1.0, 8, 2, 2); + } else if (Form == ftab_NotInit) { + util_Error ("ftab\\_PrintTable: Form is not initialized"); + } else { + printf (" & "); + } +} + + +/*=========================================================================*/ + +static void PrintTablePlain (ftab_Table * T) +/* + * Prints table T in plain text style, according to format Form. + */ +{ + int i, j; + int j1 = T->j1; + int j2 = T->j2; + int jstep = T->jstep; + double d; + ftab_FormType Form = T->Form; + + printf ("%s", T->Desc); + printf ("\n\nLSize j =%2d", j1); + j = j1 + jstep; + while (j <= j2) { + printf (" j =%2d", j); + j += jstep; + } + printf ("\n------------------------------------------------------\n"); + + for (i = 0; i < T->Nr; i++) { + printf ("%3d", T->LSize[i]); + for (j = 0; j < T->Nc; j++) { + d = T->Mat[i][j]; + PrintVal (T, d, Form); + } + printf ("\n"); + } + printf ("\n=======================================================\n"); +} + + +/*=========================================================================*/ + +static void PrintTableTex (ftab_Table * T) +/* + * Prints table T in Latex style, according to format Form. + */ +{ + int i, j; + int j1 = T->j1; + int j2 = T->j2; + int jstep = T->jstep; + ftab_FormType Form = T->Form; + + printf ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" + "\\begin {tabular}{|c|@{\\extracolsep{10pt}}"); + j = j1; + while (j <= j2) { + printf ("c"); + j += jstep; + } + printf ("|}\n\\multicolumn{%1d", (j2 - j1) / jstep + 2); + printf ("}{l}{\\makebox[0pt][l]{"); + PrintTexName (T->Desc); + printf ("}}\\\\\n\\hline\nLSize & $ j=%2d", j1); + j = j1 + jstep; + while (j <= j2) { + printf (" $ & $ j=%2d", j); + j += jstep; + } + printf ("$ \\\\\n\\hline\n"); + + for (i = 0; i < T->Nr; i++) { + printf ("%3d ", T->LSize[i]); + for (j = 0; j < T->Nc; j++) { + PrintValTex (T, T->Mat[i][j], Form); + } + printf (" \\\\\n"); + } + printf ("\\hline\n\\end {tabular} \\\\\n\\medskip\n\n"); +} + + +/*=========================================================================*/ + +void ftab_PrintTable (ftab_Table * T) +{ + if (NULL == T) + return; + if (ftab_Style == ftab_Plain) + PrintTablePlain (T); + else + PrintTableTex (T); +} + + +/*=========================================================================*/ + +static void PrintTable2Tex (ftab_Table * T1, ftab_Table * T2, lebool Flag) +/* + * Prints tables in Latex style, T1 according to format Form1, + * T2 according to format Form2. + */ +{ + int i, j; + int j1 = T1->j1; + int j2 = T1->j2; + int jstep = T1->jstep; + double x; + ftab_FormType Form1 = T1->Form; + ftab_FormType Form2 = T2->Form; + + printf ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" + "\\begin {tabular}{|c|@{\\extracolsep{10pt}}"); + j = j1; + while (j <= j2) { + printf ("rr|"); + j += jstep; + } + printf ("}\n\\multicolumn{%1d", 2 * ((j2 - j1) / jstep + 1) + 1); + printf ("}{l}{\\makebox[0pt][l]{"); + PrintTexName (T1->Desc); + printf ("---"); + PrintTexName (T2->Desc); + if (Flag) + printf (" (RATIO)"); + printf ("}}\\\\\n\\hline\n" " LSize& \\multicolumn{2}{c|}{$ j=%1d $}", j1); + j = j1 + jstep; + while (j <= j2) { + printf (" & \\multicolumn{2}{c|}{$ j=%1d $}", j); + j += jstep; + } + printf (" \\\\\n\\hline\n"); + + for (i = 0; i < T1->Nr; i++) { + printf ("%3d", T1->LSize[i]); + for (j = 0; j < T1->Nc; j++) { + PrintValTex (T1, T1->Mat[i][j], Form1); + x = T2->Mat[i][j]; + if (!Flag || x < -0.9) + PrintValTex (T2, x, Form2); + else { + x = x / T1->Mat[i][j]; + PrintValTex (T2, x, ftab_Real); + } + } + printf (" \\\\\n"); + } + printf ("\\hline\n\\end {tabular} \\\\\n\\medskip\n\n"); +} + + +/*=========================================================================*/ + +static void PrintTable2Plain (ftab_Table * T1, ftab_Table * T2, lebool Flag) +/* + * Prints tables in plain text style, T1 according to format Form1, + * T2 according to format Form2. + */ +{ + int i, j; + int j1 = T1->j1; + int j2 = T1->j2; + int jstep = T1->jstep; + double x; + ftab_FormType Form1 = T1->Form; + ftab_FormType Form2 = T2->Form; + + printf ("%s", T1->Desc); + printf ("---"); + printf ("%s", T2->Desc); + if (Flag) + printf (" (RATIO)"); + printf ("\n\n LSize j=%1d", j1); + printf (" j=%2d", j1); + j = j1 + jstep; + while (j <= j2) { + printf (" j=%2d", j); + printf (" j=%2d", j); + j += jstep; + } + printf ("\n----------------------------------------------------\n"); + + for (i = 0; i < T1->Nr; i++) { + printf ("%3d", T1->LSize[i]); + for (j = 0; j < T1->Nc; j++) { + PrintVal (T1, T1->Mat[i][j], Form1); + x = T2->Mat[i][j]; + if (!Flag || x < -0.9) + PrintVal (T2, x, Form2); + else { + x = x / T1->Mat[i][j]; + PrintVal (T2, x, ftab_Real); + } + } + printf ("\n"); + } + printf ("\n=======================================================\n"); +} + + +/*=========================================================================*/ + +void ftab_PrintTable2 (ftab_Table * T1, ftab_Table * T2, lebool Flag) +{ + if (NULL == T1 || NULL == T2) + return; + if (ftab_Style == ftab_Plain) + PrintTable2Plain (T1, T2, Flag); + else + PrintTable2Tex (T1, T2, Flag); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ftab.tex b/TESTU01/TestU01-1.2.3/testu01/ftab.tex new file mode 100644 index 0000000..9c25bde --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ftab.tex @@ -0,0 +1,280 @@ +\defmodule {ftab} + +This module provides tools to manipulate and print tables of $p$-values +and other results, when statistical tests with different sample sizes are +applied to a whole family of generators of different sizes or different +resolutions (or precisions). Each table contains a two-dimensional array of +values ({\tt Mat}), indexed by $i$ and $j$. The row $i$ of {\tt Mat} is +associated with a generator of the family that is being tested, while the +column $j$ is associated with the different sample sizes for the test +being applied on the generator. Such a table can be created by +{\tt ftab\_CreateTable}, printed by {\tt ftab\_PrintTable} or +{\tt ftab\_PrintTable2}, and deleted by {\tt ftab\_DeleteTable}. +The function {\tt ftab\_MakeTables} is used to run a series of tests on a +whole family of generators and to fill up the tables of results. + +\bigskip +\hrule +\code\hide +/* ftab.h for ANSI C */ +#ifndef FTAB_H +#define FTAB_H +\endhide +#include "ffam.h" +#include "unif01.h" +\endcode +\code +\hide +typedef enum { + ftab_NotInit, /* Uninitialized */ + ftab_pVal1, /* One-sided p-value */ + ftab_pVal2, /* Two-sided p-value */ + ftab_pLog10, /* Logarithm of p-value in base 10 */ + ftab_pLog2, /* Logarithm of p-value in base 2 */ + ftab_Integer, /* Integer number */ + ftab_Real, /* Real number */ + ftab_String /* String */ +} ftab_FormType; +\endhide + +typedef struct { + double **Mat; + int *LSize; + int Nr, Nc; + int j1, j2, jstep; + ftab_FormType Form; + char *Desc; + char **Strings; + int Ns; +} ftab_Table; +\endcode + \tab + A structure that contains a two-dimensional matrix {\tt Mat} with {\tt Nr} + rows and {\tt Nc} columns, used to store the values of statistics, their + $p$-values, or some other information depending on the format {\tt Form}, + though the numbers are always stored as {\tt double}'s. + The values are stored in matrix element {\tt Mat[$i$][$j$]} for + $0 \le i <$ {\tt Nr} and $0 \le j <$ {\tt Nc}. Row $i$ of {\tt Mat} + is associated with a generator of size {\tt LSize[$i$]}. The index $j$ is + used to select the different sample sizes of a test for a given + generator. The character string {\tt Desc} gives a short description of + the table. + + The array {\tt Strings} points to the {\tt Ns} possible messages that can + be printed for each element {\tt Mat[$i$][$j$]} when {\tt Form} is {\tt + ftab\_String}. In this case, {\tt Mat[$i$][$j$]} is an integer giving the + index $s$ of the message {\tt Strings[$s$]} to be printed. When {\tt Form} + is not {\tt ftab\_String}, {\tt Strings} is set to the {\tt NULL} + pointer. + The function {\tt ftab\_CreateTable} creates such a structure. + \endtab + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Functions to manipulate tables} +\code + +ftab_Table *ftab_CreateTable (int Nr, int j1, int j2, int jstep, + char *Desc, ftab_FormType Form, int Ns); +\endcode +\tab + Creates a structure {\tt ftab\_Table} and its matrix {\tt Mat} so that + it can store test results in format {\tt Form} for a family of {\tt Nr} + generators. Each generator is subjected to tests with different sample sizes + indexed by $j$, with $j$ varying from {\tt j1} to {\tt j2} by step of + {\tt jstep}. The function initializes the description of the table to + {\tt Desc}. If {\tt Form = ftab\_String}, it also allocate an array of + {\tt Ns} pointers of {\tt char} for the field {\tt Strings} of the + structure. +\endtab +\code + + +void ftab_DeleteTable (ftab_Table *T); +\endcode +\tab + Frees all the memory allocated for {\tt T} and deletes {\tt T}. +\endtab +\code + + +void ftab_SetDesc (ftab_Table *T, char *Desc); +\endcode + \tab + Sets the {\tt Desc} field of {\tt T} to {\tt Desc}. +\endtab +\code + + +void ftab_InitMatrix (ftab_Table *T, double x); +\endcode +\tab + Initializes all the values in {\tt T->Mat} to {\tt x}. +\endtab +\code + + +typedef void (*ftab_CalcType) (ffam_Fam *fam, void *res, void *cho, + void *par, int LSize, int j, + int irow, int icol); +\endcode + \tab Type of function called by {\tt ftab\_MakeTables} to fill up + the entry ({\tt irow}, {\tt icol}) in one or more tables of results. + Typically, it computes $p$-values to be put in the appropriate table. + It tests one generator of the family {\tt fam}, using {\tt res} to keep + the tables of results, {\tt cho} is used to choose the values of the + varying parameters of the test as a function of the generator size + {\tt LSize}, of {\tt j} and the other parameters, while {\tt par} holds + the fixed parameters of the test. + This function is used internally by the tests. +\endtab +\code + + +void ftab_MakeTables (ffam_Fam *fam, void *res, void *cho, void *par, + ftab_CalcType Calc, + int Nr, int j1, int j2, int jstep); +\endcode +\tab This function calls {\tt Calc(fam, res, cho, par, LSize, j, irow, icol)} + on each of the first {\tt Nr} generators of family {\tt fam}, for + {\tt j} going from {\tt j1} to {\tt j2} by step of {\tt jstep} (thus varying + the sample size for a given generator). + It uses {\tt res} to keep the tables of results after all the tests have + been done on the family, {\tt cho} is used to choose the values of the + varying parameters of the test as a function of the generator size and + the other parameters, while {\tt par} holds the fixed parameters of the + test. Normally, {\tt Calc} calls a test and places the results + (e.g., $p$-values) in the entries of the appropriate tables. +\endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Printing the tables} +\code + +typedef enum { + ftab_Plain, /* To print tables in plain text */ + ftab_Latex /* To print tables in Latex format */ +} ftab_StyleType; +\endcode + \tab The possible styles in which the tables of this module can be printed. +\endtab +\code + + +extern ftab_StyleType ftab_Style; +\endcode +\tab This environment variable determines the style in which all the tables + of this module will be printed. The default value is {\tt ftab\_Plain}. +\endtab +\mycode + + +typedef enum { + ftab_NotInit, /* Uninitialized */ + ftab_pVal1, /* One-sided p-value */ + ftab_pVal2, /* Two-sided p-value */ + ftab_pLog10, /* Logarithm of p-value in base 10 */ + ftab_pLog2, /* Logarithm of p-value in base 2 */ + ftab_Integer, /* Integer number */ + ftab_Real, /* Real number */ + ftab_String /* String */ +} ftab_FormType; +\myendcode + \tab Possible formats that can be used to print the table entries. + An appropriate format must be chosen before printing. + Here, {\tt ftab\_pVal1} + stands for a one-sided $p$-value (a number in the interval [0, 1]), + printed only when it is near 0; {\tt ftab\_pVal2} stands for a + two-sided $p$-value, printed when it is near 0 or near 1 + ($p$-values near 1 are printed as $-p$ instead of $1 -p$). + The other formats are self-evident. + \endtab +\code + + +extern double ftab_Suspectp; +\endcode + \tab Environment variable + used in {\tt ftab\_PrintTable} and {\tt ftab\_PrintTable2} to determine + which $p$-values should be printed in the table. + When the format {\tt ftab\_pVal2} is used, only the + $p$-values outside the interval [{\tt ftab\_Suspectp}, + $1 - {}${\tt ftab\_Suspectp}] will be considered suspect and printed. + The default value is 0.01. + \endtab +\code + + +extern int ftab_SuspectLog2p; +\endcode + \tab Environment variable used in {\tt ftab\_PrintTable} and + {\tt ftab\_PrintTable2} to determine which $p$-values should be printed + in the table, when using the format {\tt ftab\_pLog2}. + If {\tt ftab\_SuspectLog2p} $= \sigma$, the $p$-values + outside the interval $[1/{2^\sigma},\, 1-1/{2^\sigma}]$ are + considered suspect and are printed. + The default value is 6. + \endtab +\code + + +void ftab_PrintTable (ftab_Table *T); +\endcode + \tab + Prints the values {\tt T->Mat[$i$][$j$]}, one value of $i$ per line, + for $0 \le i < ${ \tt T->Nr} and $0 \le j < ${ \tt T->Nc}. + + If {\tt Form = ftab\_pVal1}, prints the entries as $p$-values for + one-sided tests (prints only the ones close to 0, i.e., less than + {\tt ftab\_Suspectp}). + If {\tt Form = ftab\_pVal2}, prints the entries as $p$-values for + two-sided tests (prints only those close to 0 or 1, i.e., + less than {\tt ftab\_Suspectp} or larger than $1 - {}${\tt ftab\_Suspectp}). + If the $p$-value $p <$ {\tt ftab\_Suspectp}, then print $p$ as is. + unless $p <$ {\tt gofw\_Epsilonp}, in which case {\tt eps} will be printed + ({\tt $\backslash$eps} when {\tt ftab\_Latex} style is chosen). + If $p > 1 - {}${\tt ftab\_Suspectp}, then print $p-1$. + unless $p > 1 - {}$ {\tt gofw\_Epsilonp}, in which case {\tt -eps} will be + printed ({\tt $\backslash$epsm} when {\tt ftab\_Latex} style is chosen). + + In the case where {\tt Form = ftab\_pLog10}, + if $p \le $ {\tt ftab\_Suspectp} it prints Round$(- \log_{10} p)$, + else if $p \ge 1 - $ {\tt ftab\_Suspectp} it prints + $-$Round$(- \log_{10} (1-p))$, otherwise it prints nothing. + In the case where {\tt Form = ftab\_pLog2}, + if $p \le 2^{-\sigma}$, where $\sigma =$ {\tt ftab\_SuspectLog2p}, + it prints {\rm Round$( - \log_2 p)$}, else if $p \ge 1 - 1/2^\sigma$ + it prints $-${\rm Round$(- \log_2 (1-p))$}, and otherwise it prints + nothing. + + If {\tt Form = ftab\_Integer}, it prints them as (rounded) integers. + If {\tt Form = ftab\_Real}, it prints them as {\tt double}'s. + If {\tt Form = ftab\_String}, prints the string + {\tt T->Strings[s]} where {\tt s = {\rm Round}(T->Mat[i][j])}. + + \endtab +\code + + +void ftab_PrintTable2 (ftab_Table *T1, ftab_Table *T2, lebool ratioF); +\endcode + \tab + Similar to {\tt ftab\_PrintTable}, but prints two tables simultaneously, + using two columns for each entry, for purposes of comparison. + If the flag {\tt ratioF} is {\tt TRUE}, it prints the numbers of the + first table in a first column, and the ratio of the numbers from the + second table over the corresponding numbers from the first table in the + second column. This is done for each element of the tables. + If the flag {\tt ratioF} is {\tt FALSE}, the numbers from the second + table will be printed as is. + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fvaria.c b/TESTU01/TestU01-1.2.3/testu01/fvaria.c new file mode 100644 index 0000000..1916a64 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fvaria.c @@ -0,0 +1,536 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fvaria.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "util.h" +#include "gofs.h" +#include "num.h" + +#include "fvaria.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" + +#include "svaria.h" +#include "sres.h" + + + +long fvaria_MaxN = 1048576 * 4; +long fvaria_Maxn = 1048576 * 4; +long fvaria_Maxk = 1048576 * 4; +long fvaria_MaxK = 1048576 * 4; + + +enum { + A_SAMPLEMEAN, + A_SAMPLECORR, + A_SAMPLEPROD, + A_SUMLOGS, + A_SUMCOLLECTOR, + A_APPEARANCE, + A_WEIGHTDISTRIB, + A_N +}; + + + + +/*----------------------------- Functions --------------------------------*/ + + +static void PrintHead (char *name, ffam_Fam *fam, int test, void *par1, + int Nr, int j1, int j2, int jstep) +{ + long *Par = par1; + double *ParD = par1; + + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", name); + + switch (test) { + case A_SAMPLEMEAN: + printf (" n = %ld, r = %d", Par[0], (int) Par[1]); + break; + case A_SAMPLECORR: + printf (" N = %ld, r = %d, k = %d", + Par[0], (int) Par[1], (int) Par[2]); + break; + case A_SAMPLEPROD: + printf (" N = %ld, r = %d, t = %d", + Par[0], (int) Par[1], (int) Par[2]); + break; + case A_SUMLOGS: + printf (" N = %ld, r = %d", Par[0], (int) Par[1]); + break; + case A_SUMCOLLECTOR: + printf (" N = %ld, r = %d, g = %f", (long) ParD[0], (int) ParD[1], + ParD[2]); + break; + case A_APPEARANCE: + printf (" N = %ld, r = %d, s = %d, L = %d", + Par[0], (int) Par[1], (int) Par[2], (int) Par[3]); + break; + case A_WEIGHTDISTRIB: + printf (" N = %ld, n = %ld, r = %d, k = %ld,\n alpha = %6.4g, beta = %6.4g", + (long) ParD[0], (long) ParD[1], (int) ParD[2], (long) ParD[3], + ParD[4], ParD[5]); + break; + default: + util_Error ("in fknuth, PrintHead: no such case"); + } + + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); +} + + +/*=========================================================================*/ + +static void TabSampleMean (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r; + long N, n; + long *Par = par1; + fres_Cont *fres = res1; + sres_Basic *sres; + + n = Par[0]; + r = Par[1]; + + N = fcho_ChooseParamL (cho, 0, fvaria_MaxN, i, j); + if (N <= 0) + return; + + sres = sres_CreateBasic (); + svaria_SampleMean (fam->Gen[irow], sres, N, n, r); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteBasic (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fvaria_SampleMean1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long n, int r, + int Nr, int j1, int j2, int jstep) +{ + long Par[2]; + lebool localRes; + + Par[0] = n; + Par[1] = r; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fvaria_SampleMean1", + fam, A_SAMPLEMEAN, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, 2, Nr, j1, j2, jstep, "fvaria_SampleMean1"); + ftab_MakeTables (fam, res, cho, Par, TabSampleMean, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabSampleCorr (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, k; + long N, n; + long *Par = par1; + fres_Cont *fres = res1; + sres_Basic *sres; + + N = Par[0]; + r = Par[1]; + k = Par[2]; + + n = fcho_ChooseParamL (cho, 2, fvaria_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateBasic (); + svaria_SampleCorr (fam->Gen[irow], sres, N, n, r, k); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteBasic (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fvaria_SampleCorr1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int k, + int Nr, int j1, int j2, int jstep) +{ + long Par[3]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = k; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fvaria_SampleCorr1", + fam, A_SAMPLECORR, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fvaria_SampleCorr1"); + ftab_MakeTables (fam, res, cho, Par, TabSampleCorr, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabSampleProd (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, t; + long N, n; + long *Par = par1; + fres_Cont *fres = res1; + sres_Basic *sres; + + N = Par[0]; + r = Par[1]; + t = Par[2]; + + n = fcho_ChooseParamL (cho, 1, fvaria_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateBasic (); + svaria_SampleProd (fam->Gen[irow], sres, N, n, r, t); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteBasic (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fvaria_SampleProd1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int t, + int Nr, int j1, int j2, int jstep) +{ + long Par[3]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = t; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fvaria_SampleProd1", + fam, A_SAMPLEPROD, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fvaria_SampleProd1"); + ftab_MakeTables (fam, res, cho, Par, TabSampleProd, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabSumLogs (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r; + long N, n; + long *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + r = Par[1]; + + n = fcho_ChooseParamL (cho, 1, fvaria_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateChi2 (); + svaria_SumLogs (fam->Gen[irow], sres, N, n, r); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fvaria_SumLogs1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, + int Nr, int j1, int j2, int jstep) +{ + long Par[2]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fvaria_SumLogs1", + fam, A_SUMLOGS, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fvaria_SumLogs1"); + ftab_MakeTables (fam, res, cho, Par, TabSumLogs, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabSumCollector (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r; + long N, n; + double g; + double *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + r = Par[1]; + g = Par[2]; + + n = fcho_ChooseParamL (cho, (long) (3.0 * gofs_MinExpected), + fvaria_Maxn, i, j); + if (n <= 0) + return; + + sres = sres_CreateChi2 (); + svaria_SumCollector (fam->Gen[irow], sres, N, n, r, g); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fvaria_SumCollector1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, double g, + int Nr, int j1, int j2, int jstep) +{ + double Par[3]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = g; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fvaria_SumCollector1", + fam, A_SUMCOLLECTOR, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fvaria_SumCollector1"); + ftab_MakeTables (fam, res, cho, Par, TabSumCollector, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabAppearance (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s, L; + long N, Q, K; + long *Par = par1; + fres_Cont *fres = res1; + sres_Basic *sres; + + N = Par[0]; + r = Par[1]; + s = Par[2]; + L = Par[3]; + + s = fcho_Chooses (r, s, fam->Resol[irow]); + if (s <= 0) + return ; + if ((s > L) && (s % L)) + return ; + Q = num_TwoExp[L + 4]; + if (Q > fvaria_MaxK) { + printf ("Q > %ld\n\n", fvaria_MaxK); + return; + } + K = fcho_ChooseParamL (cho, 1, fvaria_MaxK, i, j); + if (K <= 0) + return; + + sres = sres_CreateBasic (); + svaria_AppearanceSpacings (fam->Gen[irow], sres, N, Q, K, r, s, L); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteBasic (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fvaria_Appearance1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int s, int L, + int Nr, int j1, int j2, int jstep) +{ + long Par[4]; + lebool localRes; + + Par[0] = N; + Par[1] = r; + Par[2] = s; + Par[3] = L; + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fvaria_Appearance1", + fam, A_APPEARANCE, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fvaria_Appearance1"); + ftab_MakeTables (fam, res, cho, Par, TabAppearance, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + +static void TabWeightDistrib (ffam_Fam *fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r; + long N, n, k; + double alpha, beta; + double *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + fcho_Cho2 *cho2 = cho; + fcho_Cho *chon; + fcho_Cho *chok; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + k = Par[3]; + alpha = Par[4]; + beta = Par[5]; + + util_Assert (cho, "fvaria: cho is NULL"); + chon = cho2->Chon; + chok = cho2->Chop2; + util_Assert (n < 0 || k < 0, + "fvaria_WeightDistrib1: Either n or k must be < 0"); + + if (n < 0) { + util_Assert (chon, "fvaria_WeightDistrib1: n < 0 and chon is NULL"); + n = fcho_ChooseParamL (chon, (long) (3.0 * gofs_MinExpected), + fvaria_Maxn, i, j); + if (n <= 0) + return; + } + + if (k < 0) { + util_Assert (chok, "fvaria_WeightDistrib1: k < 0 and chop2 is NULL"); + k = fcho_ChooseParamL (chok, 1, fvaria_Maxk, i, j); + if (k <= 0) + return; + } + + sres = sres_CreateChi2 (); + svaria_WeightDistrib (fam->Gen[irow], sres, N, n, r, k, alpha, beta); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*------------------------------------------------------------------------*/ + +void fvaria_WeightDistrib1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, long k, + double alpha, double beta, + int Nr, int j1, int j2, int jstep) +{ + double Par[6]; + lebool localRes; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = k; + Par[4] = alpha; + Par[5] = beta; + + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + PrintHead ("fvaria_WeightDistrib1", + fam, A_WEIGHTDISTRIB, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, "fvaria_WeightDistrib1"); + ftab_MakeTables (fam, res, cho, Par, TabWeightDistrib, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*========================================================================*/ + + diff --git a/TESTU01/TestU01-1.2.3/testu01/fvaria.tex b/TESTU01/TestU01-1.2.3/testu01/fvaria.tex new file mode 100644 index 0000000..c6aa0fc --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fvaria.tex @@ -0,0 +1,127 @@ +\defmodule {fvaria} + +This module applies tests from the module {\tt svaria} +to a family of generators of different sizes. + +\bigskip +\hrule +\code\hide +/* fvaria.h for ANSI C */ +#ifndef FVARIA_H +#define FVARIA_H +\endhide +#include "ffam.h" +#include "fres.h" +#include "fcho.h" + + +extern long fvaria_MaxN; +extern long fvaria_Maxn; +extern long fvaria_Maxk; +extern long fvaria_MaxK; +\endcode +\tab + Upper bounds on $N$, $n$, $k$ and $K$. + When $N$, $n$, $k$ or $K$ exceed their limit value, the test is not done. + Default values: $N = 2^{22}$, $n = 2^{22}$, $k = 2^{22}$ and $K = 2^{22}$. +\endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} +\code + +void fvaria_SampleMean1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long n, int r, + int Nr, int j1, int j2, int jstep); +\endcode +\tab This function calls the test {\tt svaria\_SampleMean} with parameters + $N$, {\tt n} and {\tt r} for sample size $N$ chosen by the function + {\tt cho->Choose(param, i, j)}, + for the first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. The parameters in {\tt param} + were set at the creation of {\tt cho} and $i$ is the lsize of the + generator being tested. + When $N$ exceeds {\tt fvaria\_MaxN}, the test is not done. +\endtab +\code + + +void fvaria_SampleCorr1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int k, + int Nr, int j1, int j2, int jstep); +\endcode +\tab This function calls the test {\tt svaria\_SampleCorr} with parameters + {\tt N}, $n$, {\tt r} and {\tt k} for sample size $n$ chosen by the function + {\tt cho->Choose(param, i, j)}, + for the first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. The parameters in {\tt param} + were set at the creation of {\tt cho} and $i$ is the lsize of the + generator being tested. + When $n$ exceeds {\tt fvaria\_Maxn}, the test is not done. +\endtab +\code + + +void fvaria_SampleProd1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int t, + int Nr, int j1, int j2, int jstep); +\endcode +\tab Similar to {\tt fvaria\_SampleCorr1} but with {\tt svaria\_SampleProd}. +\endtab +\code + + +void fvaria_SumLogs1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, + int Nr, int j1, int j2, int jstep); +\endcode +\tab Similar to {\tt fvaria\_SampleCorr1} but with {\tt svaria\_SumLogs}. +\endtab +\code + + +void fvaria_SumCollector1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, double g, + int Nr, int j1, int j2, int jstep); +\endcode +\tab Similar to {\tt fvaria\_SampleCorr1} but with {\tt svaria\_SumCollector}. +\endtab +\code + + +void fvaria_Appearance1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho *cho, + long N, int r, int s, int L, + int Nr, int j1, int j2, int jstep); +\endcode +\tab Similar to {\tt fvaria\_SampleCorr1} but with + {\tt svaria\_AppearanceSpacings} and with $K$ as the varying sample size. +\endtab +\code + + +void fvaria_WeightDistrib1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, long k, + double alpha, double beta, + int Nr, int j1, int j2, int jstep); +\endcode +\tab This function calls the test {\tt svaria\_WeightDistrib} with + parameters {\tt N}, {\tt n}, {\tt r}, {\tt k}, {\tt alpha}, + and {\tt beta} for the + first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. Either or both of {\tt n} + and {\tt k} can be varied as the sample size, by passing a negative value as + argument of the function. One must then create the corresponding function + {\tt cho->Chon} or {\tt cho->Chop2} before calling the test. + One will have either {\tt n} = {\tt cho->Chon->Choose(param, i, j)}, + or {\tt k} = {\tt cho->Chop2->Choose(param, i, j)} or both. A positive + value for {\tt n} or {\tt k} will be used as is by the test. When {\tt n} + exceeds {\tt fvaria\_Maxn} or {\tt k} exceeds {\tt fvaria\_Maxk}, + the test is not done. +\endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/fwalk.c b/TESTU01/TestU01-1.2.3/testu01/fwalk.c new file mode 100644 index 0000000..bf77174 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fwalk.c @@ -0,0 +1,405 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: fwalk.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "gofs.h" + +#include "fwalk.h" +#include "ffam.h" +#include "fres.h" +#include "fcho.h" +#include "ftab.h" +#include "swalk.h" + +#include + +long fwalk_Maxn = 4194304; +long fwalk_MaxL = 4194304; +double fwalk_MinMu = 1.0 / 4194304; + +typedef enum { + A_VARGEO, + A_RANDOMWALK1, + A_RANDOMWALK1A +} TestType; + + +enum { + B_ALGOP, + B_ALGON +}; + +#define LEN 50 + + + +/*------------------------------ Functions --------------------------------*/ + + +static void InitRes1 (ffam_Fam * fam, fwalk_Res1 * res, int N, + int Nr, int j1, int j2, int jstep, char *name) +/* + * Initializes the fwalk_Res1 structure + */ +{ + char str[LEN + 1]; + size_t len; + + strncpy (str, name, (size_t) LEN); + strncat (str, ", Statistic H", (size_t) LEN - 20); + len = strlen (str); + fres_InitCont (fam, res->H, N, Nr, j1, j2, jstep, str); + str[len - 1] = 'M'; + fres_InitCont (fam, res->M, N, Nr, j1, j2, jstep, str); + str[len - 1] = 'J'; + fres_InitCont (fam, res->J, N, Nr, j1, j2, jstep, str); + str[len - 1] = 'R'; + fres_InitCont (fam, res->R, N, Nr, j1, j2, jstep, str); + str[len - 1] = 'C'; + fres_InitCont (fam, res->C, N, Nr, j1, j2, jstep, str); +} + + +/*-------------------------------------------------------------------------*/ + +fwalk_Res1 *fwalk_CreateRes1 (void) +{ + fwalk_Res1 *res; + res = util_Malloc (sizeof (fwalk_Res1)); + res->H = fres_CreateCont (); + res->M = fres_CreateCont (); + res->J = fres_CreateCont (); + res->R = fres_CreateCont (); + res->C = fres_CreateCont (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void fwalk_DeleteRes1 (fwalk_Res1 * res) +{ + if (res == NULL) + return; + fres_DeleteCont (res->H); + fres_DeleteCont (res->M); + fres_DeleteCont (res->J); + fres_DeleteCont (res->R); + fres_DeleteCont (res->C); + util_Free (res); +} + + +/*-------------------------------------------------------------------------*/ + +static void PrintRes1 (fwalk_Res1 * res) +{ + fres_PrintCont (res->H); + fres_PrintCont (res->M); + fres_PrintCont (res->J); + fres_PrintCont (res->R); + fres_PrintCont (res->C); +} + + +/*=========================================================================*/ + +static void PrintHead (char *name, ffam_Fam * fam, TestType test, void *par1, + int Nr, int j1, int j2, int jstep) +{ + long *Par = par1; + double *ParD = par1; + + printf + ("\n\n================================================================\n"); + printf ("Family: %s\n\n", fam->name); + printf ("Test: %s\n", name); + + if (test == A_VARGEO) + printf (" N = %ld, n = %ld, r = %d", + (long) ParD[0], (long) ParD[1], (int) ParD[2]); + else + printf (" N = %ld, n = %ld, r = %d", + Par[0], Par[1], (int) Par[2]); + + switch (test) { + case A_VARGEO: + printf (", Mu = %f", ParD[3]); + break; + case A_RANDOMWALK1: + printf (", s = %d, L = %ld", (int) Par[3], (long) Par[4]); + break; + case A_RANDOMWALK1A: + printf (", s = %d, t = %d, L = %ld, C = %lu", + (int) Par[3], (int) Par[4], (long) Par[5], (bitset_BitSet) Par[6]); + break; + default: + util_Error ("in fwalk, PrintHead: no such case"); + } + + printf ("\n Nr = %d, j1 = %d, j2 = %d, jstep = %d\n\n", + Nr, j1, j2, jstep); +} + + +/*=========================================================================*/ + +static int ChooseParamRW (int prec, void *cho, + long *pn, int *pr, int *ps, long *pL, long LMin, int i, int j) +/* + * Set the values of the parameters for the test. If a parameter is < 0, + * will call a choose function to set it. Otherwise, will accept it as is. + * Returns 0 if parameters are ok for the test, returns -1 if the test + * should not be done for these parameters. + */ +{ + fcho_Cho2 *cho2 = cho; + fcho_Cho *chon; + fcho_Cho *choL; + + util_Assert (cho, "fwalk: cho is NULL"); + chon = cho2->Chon; + choL = cho2->Chop2; + util_Assert (*pn < 0 || *pL < 0, "fwalk: Either n or L must be < 0"); + + if (*pn < 0) { + util_Assert (chon, "fwalk: n < 0 and chon is NULL"); + *pn = fcho_ChooseParamL (chon, (long) (3.0 * gofs_MinExpected), + fwalk_Maxn, i, j); + if (*pn <= 0) + return -1; + } + + *ps = fcho_Chooses (*pr, *ps, prec); + if (*ps <= 0) + return -1; + + if (*pL < 0) { + util_Assert (choL, "fwalk: L < 0 and choL is NULL"); + *pL = fcho_ChooseParamL (choL, LMin, fwalk_MaxL, i, j); + if (*pL < 0) + return -1; + + /* L must be even */ + if (*pL & 1) + ++(*pL); + } + return 0; +} + + +/*=========================================================================*/ + +static void TabRWalk1 (ffam_Fam * fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, s; + long N, n, L; + long *Par = par1; + fwalk_Res1 *fres = res1; + swalk_Res *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + s = Par[3]; + L = Par[4]; + + if (ChooseParamRW (fam->Resol[irow], cho, &n, &r, &s, &L, 8, i, j)) + return; + + sres = swalk_CreateRes (); + swalk_RandomWalk1 (fam->Gen[irow], sres, N, n, r, s, L, L); + fres_FillTableEntryC (fres->H, sres->H[0]->pVal2, N, irow, icol); + fres_FillTableEntryC (fres->M, sres->M[0]->pVal2, N, irow, icol); + fres_FillTableEntryC (fres->J, sres->J[0]->pVal2, N, irow, icol); + fres_FillTableEntryC (fres->R, sres->R[0]->pVal2, N, irow, icol); + fres_FillTableEntryC (fres->C, sres->C[0]->pVal2, N, irow, icol); + swalk_DeleteRes (sres); +} + + +/*-------------------------------------------------------------------------*/ + +void fwalk_RWalk1 (ffam_Fam * fam, fwalk_Res1 * res, fcho_Cho2 * cho, + long N, long n, int r, int s, long L, int Nr, int j1, int j2, int jstep) +{ + long Par[5] = { 0 }; + lebool localRes; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = s; + Par[4] = L; + if (res == NULL) { + localRes = TRUE; + res = fwalk_CreateRes1 (); + } else + localRes = FALSE; + + PrintHead ("fwalk_RWalk1", fam, A_RANDOMWALK1, Par, Nr, j1, j2, jstep); + + InitRes1 (fam, res, N, Nr, j1, j2, jstep, "fwalk_RWalk1"); + ftab_MakeTables (fam, res, cho, Par, TabRWalk1, Nr, j1, j2, jstep); + PrintRes1 (res); + if (localRes) + fwalk_DeleteRes1 (res); +} + + +/*=========================================================================*/ + +static int ChooseParamVarGeo (void *cho, long *pn, double *pMu, int i, int j) +/* + * Set the values of the parameters for the test. If a parameter is < 0, + * will call a choose function to set it. Otherwise, will accept it as is. + * Returns 0 if parameters are ok for the test, returns -1 if the test + * should not be done for these parameters. + */ +{ + fcho_Cho2 *cho2 = cho; + fcho_Cho *chon; + fcho_Cho *choMu; + + util_Assert (cho, "fwalk: cho is NULL"); + chon = cho2->Chon; + choMu = cho2->Chop2; + util_Assert (*pn < 0 || *pMu < 0, "fwalk: Either n or Mu must be < 0"); + + if (*pn < 0) { + util_Assert (chon, "fwalk: n < 0 and chon is NULL"); + *pn = fcho_ChooseParamL (chon, (long) (3.0 * gofs_MinExpected), + fwalk_Maxn, i, j); + if (*pn < 0) + return -1; + } + + if (*pMu < 0) { + util_Assert (choMu, "fwalk: Mu < 0 and choMu is NULL"); + *pMu = choMu->Choose (choMu->param, i, j); + + if (*pMu < fwalk_MinMu) { + printf ("Mu < %.2g\n\n", fwalk_MinMu); + return -1; + } + } + + return 0; +} + + +/*=========================================================================*/ + +static void TabVarGeo (ffam_Fam * fam, void *res1, void *cho, + void *par1, int i, int j, int irow, int icol) +{ + int r, Algo; + long N, n; + double Mu; + double *Par = par1; + fres_Cont *fres = res1; + sres_Chi2 *sres; + + N = Par[0]; + n = Par[1]; + r = Par[2]; + Mu = Par[3]; + Algo = Par[4]; + + if (ChooseParamVarGeo (cho, &n, &Mu, i, j)) + return; + + sres = sres_CreateChi2 (); + if (Algo == B_ALGOP) + swalk_VarGeoP (fam->Gen[irow], sres, N, n, r, Mu); + else + swalk_VarGeoN (fam->Gen[irow], sres, N, n, r, Mu); + fres_FillTableEntryC (fres, sres->pVal2, N, irow, icol); + sres_DeleteChi2 (sres); +} + + +/*------------------------------------------------------------------------*/ + +static void InVarGeo (ffam_Fam * fam, fres_Cont * res, fcho_Cho2 * cho, + long N, long n, int r, double Mu, int Algo, + int Nr, int j1, int j2, int jstep) +{ + double Par[5]; + lebool localRes; + char Name[30]; + + Par[0] = N; + Par[1] = n; + Par[2] = r; + Par[3] = Mu; + Par[4] = Algo; + + if (res == NULL) { + localRes = TRUE; + res = fres_CreateCont (); + } else + localRes = FALSE; + + if (Algo == B_ALGOP) + strcpy (Name, "fwalk_VarGeoP1"); + else + strcpy (Name, "fwalk_VarGeoN1"); + + PrintHead (Name, fam, A_VARGEO, Par, Nr, j1, j2, jstep); + fres_InitCont (fam, res, N, Nr, j1, j2, jstep, Name); + ftab_MakeTables (fam, res, cho, Par, TabVarGeo, Nr, j1, j2, jstep); + fres_PrintCont (res); + if (localRes) + fres_DeleteCont (res); +} + + +/*------------------------------------------------------------------------*/ + +void fwalk_VarGeoP1 (ffam_Fam * fam, fres_Cont * res, fcho_Cho2 * cho, + long N, long n, int r, double Mu, int Nr, int j1, int j2, int jstep) +{ + InVarGeo (fam, res, cho, N, n, r, Mu, B_ALGOP, Nr, j1, j2, jstep); +} + + +/*------------------------------------------------------------------------*/ + +void fwalk_VarGeoN1 (ffam_Fam * fam, fres_Cont * res, fcho_Cho2 * cho, + long N, long n, int r, double Mu, int Nr, int j1, int j2, int jstep) +{ + InVarGeo (fam, res, cho, N, n, r, Mu, B_ALGON, Nr, j1, j2, jstep); +} + + +/*========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/fwalk.tex b/TESTU01/TestU01-1.2.3/testu01/fwalk.tex new file mode 100644 index 0000000..dde1cc3 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/fwalk.tex @@ -0,0 +1,126 @@ +\defmodule {fwalk} + +This module applies random-walk tests from the module {\tt swalk} +to a family of generators of different sizes. + +\bigskip +\hrule +\code\hide +/* fwalk.h for ANSI C */ +#ifndef FWALK_H +#define FWALK_H +\endhide +#include "ffam.h" +#include "fres.h" +#include "fcho.h" + + +extern long fwalk_Maxn; +extern long fwalk_MaxL; +extern double fwalk_MinMu; +\endcode +\tab + Upper bounds on $n$, $L$ and lower bound on Mu. + When $n$, $L$ or Mu exceed their limit value, the tests are not done. + Default values: $n = 2^{22}$, $L = 2^{22}$ and Mu ${} = 2^{-22}$. +\endtab + + +\ifdetailed %%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} + +This structure is used to keep tables of results for the + {\tt fwalk\_RWalk1} test. +\code + +typedef struct { + fres_Cont *H; + fres_Cont *M; + fres_Cont *J; + fres_Cont *R; + fres_Cont *C; +} fwalk_Res1; +\endcode + \tab The five statistics {\tt H}, {\tt M}, {\tt J}, {\tt R}, and {\tt C} + are defined in the documentation of module {\tt swalk}. + \endtab +\code + + +fwalk_Res1 * fwalk_CreateRes1 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt fwalk\_RWalk1} test. + \endtab +\code + + +void fwalk_DeleteRes1 (fwalk_Res1 *res); +\endcode + \tab + Frees the memory allocated by {\tt fwalk\_CreateRes1}. + \endtab + +\fi %%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} +\code + +void fwalk_RWalk1 (ffam_Fam *fam, fwalk_Res1 *res, fcho_Cho2 *cho, + long N, long n, int r, int s, long L, + int Nr, int j1, int j2, int jstep); +\endcode +\tab This function calls the test {\tt swalk\_RandomWalk1} with + parameters {\tt N}, {\tt n}, {\tt r}, {\tt s}, and {\tt L} for the + first {\tt Nr} generators of family {\tt fam}, for $j$ going from + {\tt j1} to {\tt j2} by steps of {\tt jstep}. Either or both of {\tt n} + and {\tt L} can be varied as the sample size, by passing a negative value as + argument of the function. One must then create the corresponding function + {\tt cho->Chon} or {\tt cho->Chop2} before calling the test. + One will have either {\tt n} = {\tt cho->Chon->Choose(param, i, j)}, + or {\tt L} = {\tt cho->Chop2->Choose(param, i, j)} or both. A positive + value for {\tt n} or {\tt L} will be used as is by the test. When {\tt n} + exceeds {\tt fwalk\_Maxn} or {\tt L} exceeds {\tt fwalk\_MaxL}, + the test is not run. +\endtab +\code + + +void fwalk_VarGeoP1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, double Mu, + int Nr, int j1, int j2, int jstep); +\endcode +\tab + This function calls the test {\tt swalk\_VarGeoP} with + parameters {\tt N, n, r, Mu} for the first {\tt Nr} generators of + family {\tt fam}, for $j$ going from {\tt j1} to {\tt j2} by steps of + {\tt jstep}. Either or both of $n$ and {\tt Mu} can be varied as + the sample size, by passing a negative value as argument of the + function. One must then create the corresponding function + {\tt cho->Chon} or {\tt cho->Chop2} before calling the test. + One will have either $n = {}$ {\tt cho->Chon->Choose(param, i, j)}, + or {\tt Mu} = {\tt cho->Chop2->Choose(param, i, j)}. A positive value + for $n$ or {\tt Mu} will be used as is by the test. When $n$ exceeds + {\tt fwalk\_Maxn} or {\tt Mu} is less than {\tt fwalk\_MinMu}, + the test is not done. +\endtab +\code + + +void fwalk_VarGeoN1 (ffam_Fam *fam, fres_Cont *res, fcho_Cho2 *cho, + long N, long n, int r, double Mu, + int Nr, int j1, int j2, int jstep); +\endcode +\tab Similar to {\tt fwalk\_VarGeoP1} but with {\tt swalk\_VarGeoN}. +\endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/guidelongtestu01.pdf b/TESTU01/TestU01-1.2.3/testu01/guidelongtestu01.pdf new file mode 100644 index 0000000..83d88c3 Binary files /dev/null and b/TESTU01/TestU01-1.2.3/testu01/guidelongtestu01.pdf differ diff --git a/TESTU01/TestU01-1.2.3/testu01/guideshorttestu01.pdf b/TESTU01/TestU01-1.2.3/testu01/guideshorttestu01.pdf new file mode 100644 index 0000000..f3e07d3 Binary files /dev/null and b/TESTU01/TestU01-1.2.3/testu01/guideshorttestu01.pdf differ diff --git a/TESTU01/TestU01-1.2.3/testu01/guidetestu01.bbl b/TESTU01/TestU01-1.2.3/testu01/guidetestu01.bbl new file mode 100644 index 0000000..b1854da --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/guidetestu01.bbl @@ -0,0 +1,1062 @@ +\begin{thebibliography}{100} + +\bibitem{rALT88a} +N.~S. Altman. +\newblock Bit-wise behavior of random number generators. +\newblock {\em SIAM Journal on Scientific and Statistical Computing}, + 9(5):941--949, 1988. + +\bibitem{tAND95b} +N.~H. Anderson and D.~M. Titterington. +\newblock A comparison of two statistics for detecting clustering in one + dimension. +\newblock {\em Journal of Statistical Computation and Simulation}, 53:103--125, + 1995. + +\bibitem{rBAR06a} +E.~Barker and J.~Kelsey. +\newblock Recommendation for random number generation using deterministic + random bit generators. +\newblock {SP}-800-90, U.S. DoC/National Institute of Standards and Technology, + 2006. +\newblock See \url{http://csrc.nist.gov/publications/nistpubs/}. + +\bibitem{mBER84a} +E.~R. Berlekamp. +\newblock {\em Algebraic coding theory}. +\newblock Aegean Park Press, Laguna Hills, CA, USA, 1984. + +\bibitem{tBIC83a} +P.~J. Bickel and L.~Breiman. +\newblock Sums of functions of nearest neighbor distances, moment bounds, limit + theorems and a goodness of fit test. +\newblock {\em The Annals of Probability}, 11(1):185--214, 1983. + +\bibitem{sBRA87a} +P.~Bratley, B.~L. Fox, and L.~E. Schrage. +\newblock {\em A Guide to Simulation}. +\newblock Springer-Verlag, New York, second edition, 1987. + +\bibitem{rBRE94a} +R.~P. Brent. +\newblock On the periods of generalized fibonacci recurrences. +\newblock {\em Mathematics of Computation}, 63(207):389--401, 1994. + +\bibitem{rBRE04a} +R.~P. Brent. +\newblock Note on {M}arsaglia's xorshift random number generators. +\newblock {\em Journal of Statistical Software}, 11(5):1--4, 2004. +\newblock See \url{http://www.jstatsoft.org/v11/i05/brent.pdf}. + +\bibitem{rCAR90a} +D.~G. Carta. +\newblock Two fast implementations of the ``minimal standard'' random number + generator. +\newblock {\em Communications of the ACM}, 33(1):87--88, 1990. + +\bibitem{rCAR89a} +G.~D. Carter. +\newblock {\em Aspects of Local Linear Complexity}. +\newblock PhD thesis, University of London, 1989. + +\bibitem{rCOD94a} +P.~D. Coddington. +\newblock Analysis of random number generators using {M}onte {C}arlo + simulation. +\newblock {\em International Journal of Modern Physics}, C 5:547, 1994. + +\bibitem{rCOR99a} +J.~S. Coron and D.~Naccache. +\newblock An accurate evaluation of {M}aurer's universal test. +\newblock In S.~E. Tavares and H.~Meijer, editors, {\em Selected Areas in + Cryptography, Proceedings of the 5th Annual International Workshop, SAC'98}, + volume 1556 of {\em Lecture Notes in Computer Science}, pages 57--71. + Springer-Verlag, 1999. + +\bibitem{rCOU94a} +R.~Couture and P.~L'Ecuyer. +\newblock On the lattice structure of certain linear congruential sequences + related to {AWC/SWB} generators. +\newblock {\em Mathematics of Computation}, 62(206):798--808, 1994. + +\bibitem{rCOU95a} +R.~Couture and P.~L'Ecuyer. +\newblock Linear recurrences with carry as random number generators. +\newblock In {\em Proceedings of the 1995 Winter Simulation Conference}, pages + 263--267, 1995. + +\bibitem{rCOU97a} +R.~Couture and P.~L'Ecuyer. +\newblock Distribution properties of multiply-with-carry random number + generators. +\newblock {\em Mathematics of Computation}, 66(218):591--607, 1997. + +\bibitem{tCRE76a} +N.~Cressie. +\newblock On the logarithms of high-order spacings. +\newblock {\em Biometrika}, 63(2):343--355, 1976. + +\bibitem{tCRE79a} +N.~Cressie. +\newblock An optimal statistic based on higher-order gaps. +\newblock {\em Biometrika}, 66:619--627, 1979. + +\bibitem{tCRE80a} +N.~Cressie. +\newblock Asymptotic distribution of the scan statistic under uniformity. +\newblock {\em Annals of Probability}, 9:828--840, 1980. + +\bibitem{rDAE02a} +J.~Daemen and V.~Rijmen. +\newblock {\em The Design of Rijndael}. +\newblock Springer Verlag, New York, 2002. +\newblock See \url{http://www.esat.kuleuven.ac.be/~rijmen/rijndael/}. + +\bibitem{rDEM90a} +A.~{De Matteis} and S.~Pagnutti. +\newblock A class of parallel random number generators. +\newblock {\em Parallel Computing}, 13:193--198, 1990. + +\bibitem{tDEL79a} +G.~E. del Pino. +\newblock On the asymptotic distribution of {\it k\/}-spacings with + applications to goodness-of-fits tests. +\newblock {\em Annals of Statistics}, 7:1058--1065, 1979. + +\bibitem{rDEN00a} +L.-Y. Deng and D.~K.~J. Lin. +\newblock Random number generation for the new century. +\newblock {\em The American Statistician}, 54(2):145--150, 2000. + +\bibitem{rDEN02a} +L.-Y. Deng and H.~Xu. +\newblock Design, search, and implementation of high-dimensional, efficient, + long-cycle, and portable uniform random variate generator. +\newblock Technical report, Department of Statistics, University of California + at Los Angeles, 2002. +\newblock Preprint {\#}327. + +\bibitem{rDUD81b} +E.~J. Dudewicz and E.~C. van~der Meulen. +\newblock Entropy-based tests of uniformity. +\newblock {\em Journal of the American Statistical Association}, + 76(376):967--974, 1981. + +\bibitem{rDUD95a} +E.~J. Dudewicz, E.~C. van~der Meulen, M.~G. Sri{R}am, and N.~K.~W. Teoh. +\newblock Entropy-based random number evaluation. +\newblock {\em American Journal of Mathematical and Management Sciences}, + 15:115--153, 1995. + +\bibitem{rDWO01a} +M.~Dworkin. +\newblock Recommandations for block cipher modes of operation. +\newblock {SP} 800-38a, U.S. DoC/National Institute of Standards and + Technology, 2001. +\newblock See \url{http://csrc.nist.gov/CryptoToolkit/modes/}. + +\bibitem{rEIC87a} +J.~Eichenauer and J.~Lehn. +\newblock On the structure of quadratic congruential sequences. +\newblock {\em Manuscripta Mathematica}, 58:129--140, 1987. + +\bibitem{rEIC92c} +J.~{Eichenauer-Herrmann}. +\newblock Inversive congruential pseudorandom numbers: A tutorial. +\newblock {\em International Statistical Reviews}, 60:167--176, 1992. + +\bibitem{rEIC93a} +J.~{Eichenauer-Herrmann}. +\newblock Statistical independence of a new class of inversive congruential + pseudorandom numbers. +\newblock {\em Mathematics of Computation}, 60:375--384, 1993. + +\bibitem{rEIC95d} +J.~{Eichenauer-Herrmann}. +\newblock Modified explicit inversive congruential pseudorandom numbers with + power-of-two modulus. +\newblock {\em Statistics and Computing}, 6:31--36, 1996. + +\bibitem{rEIC92d} +J.~{Eichenauer-Herrmann} and H.~Grothe. +\newblock A new inversive congruential pseudorandom number generator with power + of two modulus. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 2(1):1--11, 1992. + +\bibitem{rEIC97a} +J.~{Eichenauer-Herrmann} and E.~Herrmann. +\newblock Compound cubic congruential pseudorandom numbers. +\newblock {\em Computing}, 59:85--90, 1997. + +\bibitem{rEIC97d} +J.~{Eichenauer-Herrmann}, E.~Herrmann, and S.~Wegenkittl. +\newblock A survey of quadratic and inversive congruential pseudorandom + numbers. +\newblock In P.~Hellekalek, G.~Larcher, H.~Niederreiter, and P.~Zinterhof, + editors, {\em {M}onte {C}arlo and Quasi-{M}onte {C}arlo Methods 1996}, volume + 127 of {\em Lecture Notes in Statistics}, pages 66--97, New York, 1998. + Springer. + +\bibitem{rEIC94b} +J.~{Eichenauer-Herrmann} and K.~Ickstadt. +\newblock Explicit inversive congruential pseudorandom numbers with power of + two modulus. +\newblock {\em Mathematics of Computation}, 62(206):787--797, 1994. + +\bibitem{rEMM97a} +F.~Emmerich. +\newblock Equidistribution properties of quadratic congruential pseudorandom + numbers. +\newblock {\em Journal of Computational and Applied Mathematics}, + 79(2):207--214, 1997. + +\bibitem{rERD92a} +E.~D. Erdmann. +\newblock Empirical tests of binary keystreams. +\newblock Master's thesis, Department of Mathematics, Royal Holloway and + Bedford New College, University of London, 1992. + +\bibitem{rFER92a} +A.~M. Ferrenberg, D.~P. Landau, and Y.~J. Wong. +\newblock {M}onte {C}arlo simulations: Hidden errors from ``good'' random + number generators. +\newblock {\em Physical Review Letters}, 69(23):3382--3384, 1992. + +\bibitem{sFIS78a} +G.~S. Fishman. +\newblock {\em Principles of Discrete Event Simulation}. +\newblock Wiley, New York, 1978. + +\bibitem{rFIS90a} +G.~S. Fishman. +\newblock Multiplicative congruential random number generators with modulus + $2^\beta$: An exhaustive analysis for $\beta=32$ and a partial analysis for + $\beta=48$. +\newblock {\em Mathematics of Computation}, 54(189):331--344, Jan 1990. + +\bibitem{sFIS96a} +G.~S. Fishman. +\newblock {\em {M}onte {C}arlo: Concepts, Algorithms, and Applications}. +\newblock Springer Series in Operations Research. Springer-Verlag, New York, + 1996. + +\bibitem{rFIS86a} +G.~S. Fishman and L.~S. {Moore III}. +\newblock An exhaustive analysis of multiplicative congruential random number + generators with modulus $2^{31}-1$. +\newblock {\em SIAM Journal on Scientific and Statistical Computing}, + 7(1):24--45, 1986. + +\bibitem{rFOG01a} +A.~Fog. +\newblock Chaotic random number generators with random cycle lengths. +\newblock available at \url{http://www.agner.org/random/theory/}, 2001. + +\bibitem{tFOL79a} +A.~F{\"o}ldes. +\newblock The limit distribution of the length of the longest head run. +\newblock {\em Period Math. Hung.}, 10(4):301--310, 1979. + +\bibitem{rFUS83a} +M.~Fushimi. +\newblock Increasing the orders of equidistribution of the leading bits of the + {T}ausworthe sequence. +\newblock {\em Information Processing Letters}, 16:189--192, 1983. + +\bibitem{rFUS90a} +M.~Fushimi. +\newblock Random number generation with the recursion $x_t = x_{t-3p}\oplus + x_{t-3q}$. +\newblock {\em Journal of Computational and Applied Mathematics}, 31:105--118, + 1990. + +\bibitem{rGOO53a} +I.~J. Good. +\newblock The serial test for sampling numbers and other tests for randomness. +\newblock {\em Proceedings of the Cambridge Philos. Society}, 49:276--284, + 1953. + +\bibitem{tGOR86a} +L.~Gordon, M.~F. Schilling, and S.~Waterman. +\newblock An extreme value theory for long head runs. +\newblock {\em Probability Theory and Related Fields}, 72:279--287, 1986. + +\bibitem{rGRA01a} +J.~Granger-Pich\'e. +\newblock G\'en\'erateurs pseudo-al\'eatoires combinant des r\'ecurrences + lin\'eaires et non lin\'eaires. +\newblock Master's thesis, D\'epartement d'informatique et de recherche + op\'eration\-nelle, Universit\'e de Montr\'eal, 2001. + +\bibitem{rGRE55a} +R.~E. Greenwood. +\newblock Coupon collector's test for random digits. +\newblock {\em Math. Tables and other Aids to Computation}, 9:1--5, 224, 229, + 1955. + +\bibitem{pGUI81a} +L.~J. Guibas and A.~M. Odlyzko. +\newblock Periods in strings. +\newblock {\em Journal of Combinatorial Theory, Series A}, 30:19--42, 1981. + +\bibitem{tHAL86a} +P.~Hall. +\newblock On powerful distributional tests based on sample spacings. +\newblock {\em Journal of Multivariate Analysis}, 19:201--224, 1986. + +\bibitem{rHEL03a} +P.~Hellekalek and S.~Wegenkittl. +\newblock Empirical evidence concerning {AES}. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 13(4):322--333, 2003. + +\bibitem{rHOL94a} +B.~L. Holian, O.~E. Percus, T.~T. Warnock, and P.~A. Whitlock. +\newblock Pseudorandom number generator for massively parallel + molecular-dynamics simulations. +\newblock {\em Physical Review {E}}, 50(2):1607--1615, 1994. + +\bibitem{rHOR93a} +W.~H{\"o}rmann and G.~Derflinger. +\newblock A portable random number generator well suited for the rejection + method. +\newblock {\em {ACM} Transactions on Mathematical Software}, 19(4):489--495, + 1993. + +\bibitem{rJAM94a} +F.~James. +\newblock {RANLUX}: A {F}ortran implementation of the high-quality pseudorandom + number generator of {L}{\"u}scher. +\newblock {\em Computer Physics Communications}, 79:111--114, 1994. + +\bibitem{tJAM89a} +S.~R. Jammalamadaka, X.~Zhou, and R.~C. Tiwari. +\newblock Asymptotic efficiencies of spacing tests for goodness of fits. +\newblock {\em Metrika}, 36:355--377, 1989. + +\bibitem{rJEN96a} +B.~Jenkins. +\newblock {ISAAC}. +\newblock In Dieter Gollmann, editor, {\em Fast Software Encryption, + Proceedings of the Third International Workshop, Cambridge, UK}, volume 1039 + of {\em Lecture Notes in Computer Science}, pages 41--49. Springer-Verlag, + 1996. +\newblock Available at \url{http://burtleburtle.net/bob/rand/isaacafa.html}. + +\bibitem{sKAR91a} +Z.~A. Karian and E.~J. Dudewicz. +\newblock {\em Modern Statistical Systems and GPSS Simulation}. +\newblock Computer Science Press, W. H. Freeman, New York, 1991. + +\bibitem{rKEN38a} +M.~G. Kendall and B.~Babington-Smith. +\newblock Randomness and other random sampling numbers. +\newblock {\em Journal of the Royal Statistical Society}, 101:147--166, 1938. + +\bibitem{rKEN39a} +M.~G. Kendall and B.~Babington-Smith. +\newblock Second paper on random sampling numbers. +\newblock {\em Journal of the Royal Statistical Society Supplement}, 6:51--61, + 1939. + +\bibitem{rKER37a} +W.~O. Kermack and A.~G. Kendrick. +\newblock Tests for randomness in a series of numerical observations. +\newblock {\em Proc. of the Royal Society of Edinburgh}, 57:228--240, 1937. + +\bibitem{rKIR81a} +S.~Kirkpatrick and E.~Stoll. +\newblock A very fast shift-register sequence random number generator. +\newblock {\em Journal of Computational Physics}, 40:517--526, 1981. + +\bibitem{iKIR94a} +P.~Kirschenhofer, H.~Prodinger, and W.~Szpankowski. +\newblock Digital search trees again revisited: The internal path length + perspective. +\newblock {\em SIAM Journal on Computing}, 23:598--616, 1994. + +\bibitem{rKNU81a} +D.~E. Knuth. +\newblock {\em The Art of Computer Programming, Volume 2: Seminumerical + Algorithms}. +\newblock Addison-Wesley, Reading, Mass., second edition, 1981. + +\bibitem{iKNU97a} +D.~E. Knuth. +\newblock {\em The Art of Computer Programming, Vol. 1}. +\newblock Addison-Wesley, Reading, Mass., third edition, 1997. + +\bibitem{rKNU98a} +D.~E. Knuth. +\newblock {\em The Art of Computer Programming, Volume 2: Seminumerical + Algorithms}. +\newblock Addison-Wesley, Reading, Mass., third edition, 1998. + +\bibitem{rKOC95a} +C.~Ko{\c{c}}. +\newblock Recurring-with-carry sequences. +\newblock {\em Journal of Applied Probability}, 32:966--971, 1995. + +\bibitem{tKUO81a} +M.~Kuo and J.~S. Rao. +\newblock Limit theory and efficiencies for tests based on higher order + spacings. +\newblock In {\em "Proceedings of the Indian Statistical Institute Golden + Jubilee International Conference on Statistics: Applications and New + Directions}, pages 333--352. Statistical Publishing Society, Calcuta, 1981. + +\bibitem{rLAG93a} +J.~C. Lagarias. +\newblock Pseudorandom numbers. +\newblock {\em Statistical Science}, 8(1):31--39, 1993. + +\bibitem{sLAW91a} +A.~M. Law and W.~D. Kelton. +\newblock {\em Simulation Modeling and Analysis}. +\newblock McGraw-Hill, New York, second edition, 1991. + +\bibitem{rLEC86a} +P.~L'Ecuyer. +\newblock Efficient and portable 32-bit random variate generators. +\newblock In {\em Proceedings of the 1986 Winter Simulation Conference}, pages + 275--277, 1986. + +\bibitem{rLEC88a} +P.~L'Ecuyer. +\newblock Efficient and portable combined random number generators. +\newblock {\em Communications of the ACM}, 31(6):742--749 and 774, 1988. +\newblock See also the correspondence in the same journal, 32, 8 (1989) + 1019--1024. + +\bibitem{rLEC90a} +P.~L'Ecuyer. +\newblock Random numbers for simulation. +\newblock {\em Communications of the ACM}, 33(10):85--97, 1990. + +\bibitem{rLEC92a} +P.~L'Ecuyer. +\newblock Testing random number generators. +\newblock In {\em Proceedings of the 1992 Winter Simulation Conference}, pages + 305--313. {IEEE} Press, Dec 1992. + +\bibitem{rLEC94a} +P.~L'Ecuyer. +\newblock Uniform random number generation. +\newblock {\em Annals of Operations Research}, 53:77--120, 1994. + +\bibitem{rLEC96b} +P.~L'Ecuyer. +\newblock Combined multiple recursive random number generators. +\newblock {\em Operations Research}, 44(5):816--822, 1996. + +\bibitem{rLEC96a} +P.~L'Ecuyer. +\newblock Maximally equidistributed combined {T}ausworthe generators. +\newblock {\em Mathematics of Computation}, 65(213):203--213, 1996. + +\bibitem{rLEC97h} +P.~L'Ecuyer. +\newblock Tests based on sum-functions of spacings for uniform random numbers. +\newblock {\em Journal of Statistical Computation and Simulation}, 59:251--269, + 1997. + +\bibitem{rLEC98t} +P.~L'Ecuyer. +\newblock Random number generators and empirical tests. +\newblock In P.~Hellekalek, G.~Larcher, H.~Niederreiter, and P.~Zinterhof, + editors, {\em {M}onte {C}arlo and Quasi-{M}onte {C}arlo Methods 1996}, volume + 127 of {\em Lecture Notes in Statistics}, pages 124--138. Springer-Verlag, + New York, 1998. + +\bibitem{rLEC99b} +P.~L'Ecuyer. +\newblock Good parameters and implementations for combined multiple recursive + random number generators. +\newblock {\em Operations Research}, 47(1):159--164, 1999. + +\bibitem{rLEC99c} +P.~L'Ecuyer. +\newblock Tables of linear congruential generators of different sizes and good + lattice structure. +\newblock {\em Mathematics of Computation}, 68(225):249--260, 1999. + +\bibitem{rLEC99a} +P.~L'Ecuyer. +\newblock Tables of maximally equidistributed combined {LFSR} generators. +\newblock {\em Mathematics of Computation}, 68(225):261--269, 1999. + +\bibitem{rLEC01d} +P.~L'Ecuyer. +\newblock Software for uniform random number generation: Distinguishing the + good and the bad. +\newblock In {\em Proceedings of the 2001 Winter Simulation Conference}, pages + 95--105, Pistacaway, NJ, 2001. {IEEE} Press. + +\bibitem{rLEC97d} +P.~L'Ecuyer and T.~H. Andres. +\newblock A random number generator based on the combination of four {LCG}s. +\newblock {\em Mathematics and Computers in Simulation}, 44:99--107, 1997. + +\bibitem{rLEC93a} +P.~L'Ecuyer, F.~Blouin, and R.~Couture. +\newblock A search for good multiple recursive random number generators. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 3(2):87--98, 1993. + +\bibitem{rLEC96e} +P.~L'Ecuyer, A.~Compagner, and J.-F. Cordeau. +\newblock Entropy tests for random number generators. +\newblock Manuscript, 1996. + +\bibitem{rLEC00c} +P.~L'Ecuyer, J.-F. Cordeau, and R.~Simard. +\newblock Close-point spatial tests and their application to random number + generators. +\newblock {\em Operations Research}, 48(2):308--317, 2000. + +\bibitem{rLEC94e} +P.~L'Ecuyer and R.~Couture. +\newblock An implementation of the lattice and spectral tests for multiple + recursive linear random number generators. +\newblock {\em INFORMS Journal on Computing}, 9(2):206--217, 1997. + +\bibitem{rLEC03c} +P.~L'Ecuyer and J.~Granger-Pich\'e. +\newblock Combined generators with components from different families. +\newblock {\em Mathematics and Computers in Simulation}, 62:395--404, 2003. + +\bibitem{rLEC98h} +P.~L'Ecuyer and P.~Hellekalek. +\newblock Random number generators: Selection criteria and testing. +\newblock In P.~Hellekalek and G.~Larcher, editors, {\em Random and + Quasi-Random Point Sets}, volume 138 of {\em Lecture Notes in Statistics}, + pages 223--265. Springer-Verlag, New York, 1998. + +\bibitem{rLEC99e} +P.~L'Ecuyer and R.~Simard. +\newblock Beware of linear congruential generators with multipliers of the form + $a = \pm 2^q\pm 2^r$. +\newblock {\em {ACM} Transactions on Mathematical Software}, 25(3):367--374, + 1999. + +\bibitem{iLEC01m} +P.~L'Ecuyer and R.~Simard. +\newblock {\em {MyLib}: A Small Library of Basic Utilities in {ANSI C}}, 2001. +\newblock Software {user's} guide. + +\bibitem{rLEC01a} +P.~L'Ecuyer and R.~Simard. +\newblock On the performance of birthday spacings tests for certain families of + random number generators. +\newblock {\em Mathematics and Computers in Simulation}, 55(1--3):131--137, + 2001. + +\bibitem{iLEC01p} +P.~L'Ecuyer and R.~Simard. +\newblock {\em {ProbDist}: A Software Library of Probability Distributions and + Goodness-of-Fit Statistics in {ANSI C}}, 2001. +\newblock Software {user's} guide. + +\bibitem{rLEC01s} +P.~L'Ecuyer, R.~Simard, E.~J. Chen, and W.~D. Kelton. +\newblock An object-oriented random-number package with many long streams and + substreams. +\newblock {\em Operations Research}, 50(6):1073--1075, 2002. + +\bibitem{rLEC02c} +P.~L'Ecuyer, R.~Simard, and S.~Wegenkittl. +\newblock Sparse serial tests of uniformity for random number generators. +\newblock {\em {SIAM} Journal on Scientific Computing}, 24(2):652--668, 2002. + +\bibitem{rLEC91b} +P.~L'Ecuyer and S.~Tezuka. +\newblock Structural properties for two classes of combined random number + generators. +\newblock {\em Mathematics of Computation}, 57(196):735--746, 1991. + +\bibitem{rLEC00b} +P.~L'Ecuyer and R.~Touzin. +\newblock Fast combined multiple recursive generators with multipliers of the + form $a = \pm 2^q \pm 2^r$. +\newblock In J.~A. Joines, R.~R. Barton, K.~Kang, and P.~A. Fishwick, editors, + {\em Proceedings of the 2000 Winter Simulation Conference}, pages 683--689, + Pistacaway, NJ, 2000. {IEEE} Press. + +\bibitem{rLEE97a} +H.~Leeb and S.~Wegenkittl. +\newblock Inversive and linear congruential pseudorandom number generators in + empirical tests. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 7(2):272--286, 1997. + +\bibitem{rLEV44a} +H.~Levene and J.~Wolfowitz. +\newblock The covariance matrix of runs up and down. +\newblock {\em The Annals of mathematical statistics}, 15:58--69, 1944. + +\bibitem{rLEW69a} +P.~A.~W. Lewis, A.~S. Goodman, and J.~M. Miller. +\newblock A pseudo-random number generator for the system/360. +\newblock {\em {IBM} System's Journal}, 8:136--143, 1969. + +\bibitem{rLUS94a} +M.~L{\"u}scher. +\newblock A portable high-quality random number generator for lattice field + theory simulations. +\newblock {\em Computer Physics Communications}, 79:100--110, 1994. + +\bibitem{rMAR85a} +G.~Marsaglia. +\newblock A current view of random number generators. +\newblock In {\em Computer Science and Statistics, Sixteenth Symposium on the + Interface}, pages 3--10, North-Holland, Amsterdam, 1985. Elsevier Science + Publishers. + +\bibitem{rMAR85c} +G.~Marsaglia. +\newblock Note on a proposed test for random number generators. +\newblock {\em {IEEE} Transactions on Computers}, C-34(8):756--758, 1985. + +\bibitem{rMAR93a} +G.~Marsaglia. +\newblock Remarks on choosing and implementing random number generators. +\newblock {\em Communications of the ACM}, 36(7):105--110, 1993. + +\bibitem{rMAR96b} +G.~Marsaglia. +\newblock {DIEHARD:} a battery of tests of randomness. +\newblock See \url{http://stat.fsu.edu/~geo/diehard.html}, 1996. + +\bibitem{rMAR96a} +G.~Marsaglia. +\newblock The {M}arsaglia random number {CDROM} including the {DIEHARD} battery + of tests of randomness. +\newblock See \url{http://stat.fsu.edu/pub/diehard}, 1996. + +\bibitem{rMAR97a} +G.~Marsaglia. +\newblock A random number generator for {C}. +\newblock Posted to the electronic billboard \url{sci.math.num-analysis}, + September 30 1997. + +\bibitem{rMAR99a} +G.~Marsaglia. +\newblock Random numbers for {C}: The {END}? +\newblock Posted to the electronic billboard \url{sci.crypt.random-numbers}, + January 20 1999. + +\bibitem{rMAR02a} +G.~Marsaglia. +\newblock Good 64-bit {RNG}'s. +\newblock Posted to the electronic billboard \url{sci.crypt.random-numbers}, + August 25 2002. + +\bibitem{rMAR03a} +G.~Marsaglia. +\newblock Xorshift {RNG}s. +\newblock {\em Journal of Statistical Software}, 8(14):1--6, 2003. +\newblock See \url{http://www.jstatsoft.org/v08/i14/xorshift.pdf}. + +\bibitem{rMAR73a} +G.~Marsaglia, K.~Ananthanarayanan, and N.~Paul. +\newblock How to use the {M}c{G}ill {R}andom {N}umber {P}ackage + ``{SUPER-DUPER}''. +\newblock Technical report, School of Computer Science, McGill University, + Montreal, Canada, 1973. + +\bibitem{rMAR90a} +G.~Marsaglia, B.~Narasimhan, and A.~Zaman. +\newblock A random number generator for {PC}'s. +\newblock {\em Computer Physics Communications}, 60:345--349, 1990. + +\bibitem{rMAR02b} +G.~Marsaglia and W.~W. Tsang. +\newblock Some difficult-to-pass tests of randomness. +\newblock {\em Journal of Statistical Software}, 7(3):1--9, 2002. +\newblock See \url{http://www.jstatsoft.org/v07/i03/tuftests.pdf}. + +\bibitem{rMAR85b} +G.~Marsaglia and L.-H. Tsay. +\newblock Matrices and the structure of random number sequences. +\newblock {\em Linear Algebra and its Applications}, 67:147--156, 1985. + +\bibitem{rMAR91a} +G.~Marsaglia and A.~Zaman. +\newblock A new class of random number generators. +\newblock {\em The Annals of Applied Probability}, 1:462--480, 1991. + +\bibitem{rMAR93c} +G.~Marsaglia and A.~Zaman. +\newblock The {KISS} generator. +\newblock Technical report, Department of Statistics, University of Florida, + 1993. + +\bibitem{rMAR93b} +G.~Marsaglia and A.~Zaman. +\newblock Monkey tests for random number generators. +\newblock {\em Computers Math. Applic.}, 26(9):1--10, 1993. + +\bibitem{rMAR90b} +G.~Marsaglia, A.~Zaman, and W.~W. Tsang. +\newblock Towards a universal random number generator. +\newblock {\em Statistics and Probability Letters}, 8:35--39, 1990. + +\bibitem{rMAS00a} +M.~Mascagni and A.~Srinivasan. +\newblock Algorithm 806: {SPRNG}: A scalable library for pseudorandom number + generation. +\newblock {\em {ACM} Transactions on Mathematical Software}, 26:436--461, 2000. + +\bibitem{mMAS69a} +J.~L. Massey. +\newblock Shift-register synthesis and {BCH} decoding. +\newblock {\em IEEE Trans. Inf. Theor}, IT-15:122--127, 1969. + +\bibitem{tSPL00a} +{MathSoft Inc.} +\newblock {\em S-PLUS 6.0 Guide to Statistics}, volume~2. +\newblock Data Analysis Division, Seattle, WA, 2000. + +\bibitem{rMAT98b} +M.~Matsumoto. +\newblock Simple cellular automata as pseudo-random $m$-sequence generators for + built-in self test. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 8(1):31--42, 1998. + +\bibitem{rMAT92a} +M.~Matsumoto and Y.~Kurita. +\newblock Twisted {GFSR} generators. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 2(3):179--194, 1992. + +\bibitem{rMAT94a} +M.~Matsumoto and Y.~Kurita. +\newblock Twisted {GFSR} generators {II}. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 4(3):254--266, 1994. + +\bibitem{rMAT98a} +M.~Matsumoto and T.~Nishimura. +\newblock Mersenne twister: A 623-dimensionally equidistributed uniform + pseudo-random number generator. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 8(1):3--30, 1998. + +\bibitem{rMAU92a} +U.~M. Maurer. +\newblock A universal statistical test for random bit generators. +\newblock {\em Journal of Cryptology}, 5(2):89--105, 1992. + +\bibitem{rMOL04a} +C.~Moler. +\newblock {\em Numerical Computing with {MATLAB}}. +\newblock SIAM, Philadelphia, 2004. + +\bibitem{rNIE92b} +H.~Niederreiter. +\newblock {\em Random Number Generation and Quasi-{M}onte {C}arlo Methods}, + volume~63 of {\em SIAM CBMS-NSF Regional Conference Series in Applied + Mathematics}. +\newblock SIAM, Philadelphia, 1992. + +\bibitem{rNIS01a} +NIST. +\newblock Advanced encryption standard ({AES}). +\newblock {FIPS}-197, U.S. DoC/National Institute of Standards and Technology, + 2001. +\newblock See \url{http://csrc.nist.gov/CryptoToolkit/tkencryption.html}. + +\bibitem{rNIS02a} +{NIST}. +\newblock Secure hash standard ({SHS}). +\newblock {FIPS}-186-2, with change notice added in february 2004, U.S. + DoC/National Institute of Standards and Technology, 2002. +\newblock See \url{http://csrc.nist.gov/CryptoToolkit/tkhash.html}. + +\bibitem{rPAN04c} +F.~Panneton and P.~L'Ecuyer. +\newblock On the xorshift random number generators. +\newblock {\em {ACM} Transactions on Modeling and Computer Simulation}, + 15(4):346--361, 2005. + +\bibitem{rPAR88a} +S.~K. Park and K.~W. Miller. +\newblock Random number generators: Good ones are hard to find. +\newblock {\em Communications of the ACM}, 31(10):1192--1201, 1988. + +\bibitem{rPAY69a} +W.~H. Payne, J.~R. Rabung, and T.~P. Bogyo. +\newblock Coding the {L}ehmer pseudo-random number generator. +\newblock {\em Communications of the ACM}, 12:85--86, Feb. 1969. + +\bibitem{rPER89a} +D.~E. Percus and M.~Kalos. +\newblock Random number generators for {MIMD} parallel processors. +\newblock {\em Journal of Parallel and Distributed Computation}, 6:477--497, + 1989. + +\bibitem{rPER95a} +O.~E. Percus and P.~A. Whitlock. +\newblock Theory and application of {M}arsaglia's monkey test for pseudorandom + number generators. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 5(2):87--100, 1995. + +\bibitem{rPRE92b} +W.~H. Press and S.~A. Teukolsky. +\newblock {\em Numerical Recipes in C}. +\newblock Cambridge University Press, Cambridge, 1992. + +\bibitem{rPRE92a} +W.~H. Press and S.~A. Teukolsky. +\newblock Portable random number generators. +\newblock {\em Computers in Physics}, 6(5):522--524, 1992. + +\bibitem{tGNU03a} +The~GNU Project. +\newblock {\em {R}: An Environment for Statistical Computing and Graphics}. +\newblock The Free Software Foundation, 2003. +\newblock {V}ersion 1.6.2. See \url{http://www.gnu.org/directory/GNU/R.html}. + +\bibitem{tPYK65a} +R.~Pyke. +\newblock Spacings. +\newblock {\em Journal of the Royal Statistical Society, Series B}, + 27:395--449, 1965. + +\bibitem{tRAO84a} +J.~S. Rao and M.~Kuo. +\newblock Asymptotic results on the greenwood statistic and some of its + generalizations. +\newblock {\em Journal of the Royal Statistical Society, Series B}, + 46:228--237, 1984. + +\bibitem{tREA88a} +T.~R.~C. Read and N.~A.~C. Cressie. +\newblock {\em Goodness-of-Fit Statistics for Discrete Multivariate Data}. +\newblock Springer Series in Statistics. Springer-Verlag, New York, 1988. + +\bibitem{rREY98a} +W.~J.~J. Rey. +\newblock On generating random numbers, with help of $y = [(a + x) sin (b x)]$ + mod 1. +\newblock presented at the 22nd European Meeting of Statisticians and the 7th + Vilnius Conference on Probability Theory and Mathematical Statistics, August + 1998. + +\bibitem{rRIJ00a} +V.~Rijmen, A.~Bossel{\ae}rs, and P.~Barreto. +\newblock Optimised {ANSI C} code for the {R}ijndael cipher (now {AES}), 2000. +\newblock Public domain software. + +\bibitem{rRIP90a} +B.~D. Ripley. +\newblock Thoughts on pseudorandom number generators. +\newblock {\em Journal of Computational and Applied Mathematics}, 31:153--163, + 1990. + +\bibitem{tRIP94a} +B.~D. Ripley and W.~N. Venables. +\newblock {\em Modern applied statistics with S-Plus}. +\newblock Springer-Verlag, New York, 1994. + +\bibitem{rRUK01a} +A.~Rukhin, J.~Soto, J.~Nechvatal, M.~Smid, E.~Barker, S.~Leigh, M.~Levenson, + M.~Vangel, D.~Banks, A.~Heckert, J.~Dray, and S.~Vo. +\newblock A statistical test suite for random and pseudorandom number + generators for cryptographic applications. +\newblock {NIST} special publication 800-22, National Institute of Standards + and Technology ({NIST}), Gaithersburg, Maryland, USA, 2001. +\newblock See \url{http://csrc.nist.gov/rng/}. + +\bibitem{rRUK02a} +A.~L. Rukhin. +\newblock Distribution of the number of words with a prescribed frequency and + tests of randomness. +\newblock {\em Advances in Applied Probability}, 34(4):775--797, 2002. + +\bibitem{iSAS90a} +SAS. +\newblock {\em SAS Language: Reference, Version 6}. +\newblock Cary, North Carolina, first edition, 1990. + +\bibitem{rSHC97a} +L.~N. Shchur, J.~R. Heringa, and H.~W.~J. Bl{\"o}te. +\newblock Simulation of a directed random-walk model: The effect of + pseudo-random number correlations. +\newblock {\em Physica {A}}, 241:579--592, 1997. + +\bibitem{rSHE90a} +Y.~S. Sherif and R.~G. Dear. +\newblock Development of a new composite pseudo-random number generator. +\newblock {\em Microelectronics and Reliability}, 30:545--553, 1990. + +\bibitem{rSOT99a} +J.~Soto. +\newblock Statistical testing of random number generators. +\newblock Available at \url{http://csrc.nist.gov/rng/}, 1999. + +\bibitem{tSTE66a} +M.~A. Stephens. +\newblock Statistics connected with the uniform distribution: Percentage points + and application to testing for randomness of directions. +\newblock {\em Biometrika}, 53:235--240, 1966. + +\bibitem{tSTE86a} +M.~S. Stephens. +\newblock Tests for the uniform distribution. +\newblock In R.~B. D'Agostino and M.~S. Stephens, editors, {\em Goodness-of-Fit + Techniques}, pages 331--366. Marcel Dekker, New York and Basel, 1986. + +\bibitem{rSUL93a} +S.~J. Sullivan. +\newblock Another test for randomness. +\newblock {\em Communications of the ACM}, 36(7):108, 1993. + +\bibitem{rTAK96a} +K.~Takashima. +\newblock Last visit time tests for pseudorandom numbers. +\newblock {\em J. Japanese Soc. Comp. Satist.}, 9(1):1--14, 1996. + +\bibitem{rTEZ89a} +S.~Tezuka. +\newblock Random number generation based on the polynomial arithmetic modulo + two. +\newblock Technical Report RT-0017, IBM Research, Tokyo Research Laboratory, + Oct. 1989. + +\bibitem{rTEZ95a} +S.~Tezuka. +\newblock {\em Uniform Random Numbers: Theory and Practice}. +\newblock Kluwer Academic Publishers, Norwell, Mass., 1995. + +\bibitem{rTEZ91b} +S.~Tezuka and P.~L'Ecuyer. +\newblock Efficient and portable combined {T}ausworthe random number + generators. +\newblock {\em ACM Transactions on Modeling and Computer Simulation}, + 1(2):99--112, 1991. + +\bibitem{rTEZ93a} +S.~Tezuka, P.~L'Ecuyer, and R.~Couture. +\newblock On the add-with-carry and subtract-with-borrow random number + generators. +\newblock {\em ACM Transactions of Modeling and Computer Simulation}, + 3(4):315--331, 1994. + +\bibitem{rTIN90a} +G.~Tindo. +\newblock {\em Automates Cellulaires; Applications {\`a} la Mod{\'e}lisation de + Certains Syst{\`e}mes Discrets et {\`a} la Conception d'une Architecture + Parall{\`e}le pour la G{\'e}n{\'e}ration de Suites Pseudo-Al{\'e}atoires}. +\newblock Dissertation (thesis), Universit{\'e} de Nantes, France, 1990. + +\bibitem{rTOM99a} +M.~Tomassini, M.~Sipper, M.~Zolla, and M.~Perrenoud. +\newblock Generating high-quality random numbers in parallel by cellular + automata. +\newblock {\em Future Generation of Computer Systems}, 16:291--305, 1999. + +\bibitem{rTOO73a} +J.~P.~R. Tootill, W.~D. Robinson, and D.~J. Eagle. +\newblock An asymptotically random {T}ausworthe sequence. +\newblock {\em Journal of the ACM}, 20:469--481, 1973. + +\bibitem{rTOU01a} +R.~Touzin. +\newblock Des g\'en\'erateurs r\'ecursifs multiples combin\'es rapides avec des + coefficients de la forme $\pm 2^{p_1}\pm 2^{p_2}$. +\newblock Master's thesis, D\'epartement d'informatique et de recherche + op\'erationnelle, Universit\'e de Montr\'eal, 2001. + +\bibitem{rUGR91a} +G.~{Ugrin-Sparac}. +\newblock Stochastic investigations of pseudo-random number generators. +\newblock {\em Computing}, 46:53--65, 1991. + +\bibitem{rVAT94a} +I.~Vattulainen, T.~Ala-Nissila, and K.~Kankaala. +\newblock Physical tests for random numbers in simulations. +\newblock {\em Physical Review Letters}, 73(19):2513--2516, 11 1994. + +\bibitem{rVAT95a} +I.~Vattulainen, T.~Ala-Nissila, and K.~Kankaala. +\newblock Physical models as tests of randomness. +\newblock {\em Physical Review {E}}, 52(3):3205--3213, 1995. + +\bibitem{tWAL74a} +S.~R. Wallenstein and J.~I. Naus. +\newblock Probabilities for the size of largest clusters and smallest + intervals. +\newblock {\em Journal of the American Statistical Society}, 69:690--695, 1974. + +\bibitem{rWAN97a} +M.~Z. Wang. +\newblock Linear complexity profiles and jump complexity. +\newblock {\em Information Processing Letters}, 61:165--168, 1997. + +\bibitem{rWEY16a} +H.~Weyl. +\newblock {\"U}ber die {G}leichverteilung von {Z}ahlen mod. {E}ins. +\newblock {\em Math. Ann.}, 77:313--352, 1916. + +\bibitem{rWIC82a} +B.~A. Wichmann and I.~D. Hill. +\newblock An efficient and portable pseudo-random number generator. +\newblock {\em Applied Statistics}, 31:188--190, 1982. +\newblock See also corrections and remarks in the same journal by Wichmann and + Hill, {\bf 33} (1984) 123; McLeod {\bf 34} (1985) 198--200; Zeisel {\bf 35} + (1986) 89. + +\bibitem{rWIC87a} +B.~A. Wichmann and I.~D. Hill. +\newblock Building a random number generator. +\newblock {\em Byte}, 12(3):127--128, 1987. + +\bibitem{rWIK89a} +R.~S. Wikramaratna. +\newblock {ACORN}---a new method for generating sequences of uniformly + distributed pseudo-random numbers. +\newblock {\em Journal of Computational Physics}, 83:16--31, 1989. + +\bibitem{rWOL83a} +S.~Wolfram. +\newblock Statistical mechanics of cellular automata. +\newblock {\em Rev. Modern Physics}, 55:601--644, 1983. + +\bibitem{rWOL86a} +S.~Wolfram. +\newblock Random sequence generation by cellular automata. +\newblock {\em Advances in Applied Mathematics}, 7:123--169, 1986. + +\bibitem{rWOL86b} +S.~Wolfram. +\newblock {\em Theory and Applications of Cellular Automata}, volume~1 of {\em + Advanced Series on complex systems}. +\newblock World Scientific Publishing Co., Singapore, 1986. + +\bibitem{rWU97a} +P.-C. Wu. +\newblock Multiplicative, congruential random number generators with multiplier + $\pm 2^{k_1} \pm 2^{k_2}$ and modulus $2^p-1$. +\newblock {\em {ACM} Transactions on Mathematical Software}, 23(2):255--265, + 1997. + +\bibitem{rZIF98a} +R.~M. Ziff. +\newblock Four-tap shift-register-sequence random-number generators. +\newblock {\em Computers in Physics}, 12(4):385--392, 1998. + +\bibitem{iZIV77a} +J.~Ziv and A.~Lempel. +\newblock A universal algorithm for sequential data compression. +\newblock {\em IEEE Trans. on Information Theory}, 23(3):337--343, 1977. + +\bibitem{iZIV78a} +J.~Ziv and A.~Lempel. +\newblock Compression of individual sequences via variable-rate coding. +\newblock {\em IEEE Trans. on Information Theory}, 24(5):530--536, 1978. + +\end{thebibliography} diff --git a/TESTU01/TestU01-1.2.3/testu01/guidetestu01.ind b/TESTU01/TestU01-1.2.3/testu01/guidetestu01.ind new file mode 100644 index 0000000..c339d41 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/guidetestu01.ind @@ -0,0 +1,311 @@ +\begin{theindex} + + \item Alphabit, 154 + + \indexspace + + \item battery of tests + \subitem Alphabit, 154 + \subitem BigCrush, 148 + \subitem Crush, 144 + \subitem Crypt-X, 6 + \subitem DIEHARD, 6, 155 + \subitem ENT, 6 + \subitem FIPS-140-2, 157 + \subitem NIST, 6, 156 + \subitem PseudoDIEHARD, 155 + \subitem Rabbit, 152 + \subitem SmallCrush, 143 + \subitem SPRNG, 6 + \item Berlekamp-Massey algorithm, 123 + \item BigCrush, 148 + + \indexspace + + \item cells generation, 97, 102 + \item collisions, 97 + \item combined generators, 13 + \subitem addition, 13 + \subitem exclusive or, 14 + \item complexity + \subitem linear, 123 + \item compression, 123 + \item correlation of bits, 127, 128 + \item Crush, 144 + \item Crypt-X, 6 + + \indexspace + + \item DIEHARD, 6, 155 + \item discrete distribution, 88 + + \indexspace + + \item ENT, 6 + \item entropy, 97, 105, 119 + + \indexspace + + \item family of generators, 167 + \subitem congruential, 169 + \subitem shift-register, 173 + \item filters, 11 + \item FIPS-140-2, 157 + \item Fourier transform, 125 + + \indexspace + + \item Generator + \subitem ACORN, 84 + \subitem add-with-carry, 31 + \subitem AES, 78 + \subitem CA90(m)', 77 + \subitem cellular automata, 76 + \subitem CLCG4, 54 + \subitem combined, 13 + \subitem CombLec88, 54 + \subitem CombMRG96, 54 + \subitem Combo, 60 + \subitem cubic, 46 + \subitem Deng, 73 + \subitem drand48, 25 + \subitem dummy, 11 + \subitem ECG1, 60 + \subitem ECG2, 60 + \subitem ECG3, 60 + \subitem ECG4, 60 + \subitem Excel, 81 + \subitem external, 15 + \subitem filter + \subsubitem biased output, 12 + \subsubitem bit truncated, 12 + \subsubitem blocks of bits, 12 + \subsubitem increased precision, 11 + \subsubitem lacunary indices, 12 + \subsubitem luxury, 12 + \subitem Fushimi, 38 + \subitem Granger-Pich\'e, 69 + \subitem H\"ormann-Derflinger, 25 + \subitem inversive, 42 + \subitem ISAAC, 79 + \subitem Java, 80 + \subitem Kirkpatrick-Stoll, 38 + \subitem KISS, 63 + \subitem Knuth, 65 + \subitem L'Ecuyer, 26, 54 + \subitem L'Ecuyer-Andres, 54 + \subitem L'Ecuyer-Blouin-Couture, 54 + \subitem lag-Fibonacci, 28, 29 + \subitem LFIB4, 64 + \subitem LFSR, 34 + \subitem lfsr113, 56 + \subitem lfsr258, 56 + \subitem lfsr88, 56 + \subitem linear congruential, 23 + \subitem Marsa90a, 59 + \subitem Marsaglia, 59 + \subitem Mathematica-Integer, 82 + \subitem Mathematica-Real, 82 + \subitem MATLAB, 81 + \subitem Matlab-5, 62 + \subitem Mersenne twister, 40 + \subitem MRG31k3p, 57 + \subitem MRG32k3a, 55 + \subitem MRG32k3b, 55 + \subitem MRG32k5a, 55 + \subitem MRG32k5b, 56 + \subitem MRG63k3a, 56 + \subitem MRG93, 54 + \subitem MT19937, 40 + \subitem MultiCarry, 61 + \subitem multiple recursive, 28 + \subitem multiply-with-carry, 32 + \subsubitem combined, 33 + \subitem Numerical Recipes, 75 + \subitem Payne, 25 + \subitem quadratic, 45 + \subitem Ran0, 75 + \subitem Ran1, 75 + \subitem Ran2, 75 + \subitem ran\_array, 65 + \subitem ranf\_array, 65 + \subitem Ranlux, 31 + \subitem RANMAR, 59 + \subitem RANROT, 84 + \subitem read from file, 86 + \subitem Rey, 84 + \subitem Rijndael, 78 + \subitem Ripley, 38 + \subitem S-PLUS, 80 + \subitem SHA1, 79 + \subitem Sherif-Dear, 84 + \subitem shift-register, 37 + \subitem shift-with-carry, 32 + \subitem SHR3, 64 + \subitem speed, 16 + \subitem subtract-with-borrow, 31 + \subitem supdup64, 62 + \subitem SuperDuper, 61 + \subitem SuperDuper96, 61 + \subitem SWB, 64 + \subitem T800, 39 + \subitem Tausworthe, 34 + \subitem Tezuka, 58 + \subitem The Mother of all RNG's, 59 + \subitem timing, 16 + \subitem Tindo, 84 + \subitem Tootill, 37 + \subitem Touzin, 67, 68 + \subitem TT400, 39 + \subitem TT403, 39 + \subitem TT775, 40 + \subitem TT800, 40 + \subitem ULTRA, 61 + \subitem Unix random, 80 + \subitem user defined, 15, 18 + \subitem VisualBasic, 81 + \subitem Weyl, 74 + \subitem Wichmann-Hill, 26, 55, 56, 81 + \subitem Wu, 24, 72 + \subitem xor4096d, 52 + \subitem xor4096i, 52 + \subitem xor4096l, 52 + \subitem xor4096r, 53 + \subitem xor4096s, 51 + \subitem Xorgen32, 51 + \subitem Xorgen64, 52 + \subitem Xorshift, 48, 51 + \subitem Xorshift13, 50 + \subitem Xorshift7, 49 + \subitem Ziff, 38 + \item goodness-of-fit tests, 89 + + \indexspace + + \item Hamming weight, 128 + + \indexspace + + \item Lempel-Ziv compression, 124 + \item loglikelihood, 96 + + \indexspace + + \item Marsaglia, 113 + \item multinomial, 96 + + \indexspace + + \item NIST tests suite, 6, 156 + + \indexspace + + \item overlapping pairs sparse occupancy, 113 + + \indexspace + + \item Pearson, 97 + \item permutations, 97, 112 + \item power divergence, 96 + + \indexspace + + \item Rabbit, 152 + \item random binary matrix, 115 + \item random walk, 120 + + \indexspace + + \item scatter plot, 133 + \item serial, 97 + \item single-level tests, 88 + \item SmallCrush, 143 + \item spacings, 131 + \subitem logarithms, 131 + \subitem squares, 132 + \item spectral, 125 + \item spectrum, 125 + \item SPRNG, 6 + + \indexspace + + \item Test + \subitem AllSpacings, 132 + \subitem AllSpacings2, 132 + \subitem AppearanceSpacings, 119 + \subitem Auto-correlation + \subsubitem bit, 130 + \subsubitem real, 117 + \subitem AutoCor, 130 + \subitem BickelBreiman, 109 + \subitem BirthdaySpacings, 114 + \subitem CAT, 114 + \subitem CATBits, 114 + \subitem ClosePairs, 109 + \subitem ClosePairsBitMatch, 109 + \subitem Collision, 112 + \subitem CollisionArgMax, 118 + \subitem CollisionOver, 113 + \subitem CollisionPermut, 112 + \subitem compression, \see{LempelZiv}{124} + \subitem CouponCollector, 111 + \subitem EntropyDisc, 105 + \subitem EntropyDiscOver, 105 + \subitem EntropyDiscOver2, 106 + \subitem EntropyDM, 106 + \subitem EntropyDMCirc, 106 + \subitem Fourier1, 125 + \subitem Fourier2, 125 + \subitem Fourier3, 125, 126 + \subitem Frequency, \see{HammingWeight}{128} + \subitem Gap, 111 + \subitem GCD, 116 + \subitem HammingCorr, 128 + \subitem HammingIndep, 128 + \subitem HammingWeight, 128 + \subitem HammingWeight2, 128 + \subitem Independence of bits, 128 + \subitem LempelZiv, 124 + \subitem linear complexity, \see{LinearComp}{123} + \subitem LinearComp, 123 + \subitem Longest Run of ones, \see{LongestHeadRun}{127} + \subitem LongestHeadRun, 127 + \subitem MatrixRank, 115 + \subitem Maurer, \see{Appearance\-Spacings}{119} + \subitem Maximum of $t$, 112 + \subitem Monobit, \see{HammingWeight2}{128} + \subitem Multinomial, 103 + \subitem MultinomialBits, 104 + \subitem MultinomialBitsOver, 104 + \subitem MultinomialOver, 104 + \subitem nearest pairs, 107 + \subitem OPSO, 113 + \subitem PeriodsInStrings, 127 + \subitem Permutation, 110 + \subitem Poker, 111 + \subitem RandomWalk1, 120 + \subitem RandomWalk1a, 121 + \subitem Run + \subsubitem bits, 129 + \subsubitem reals, 111 + \subitem RunIndep, 112 + \subitem SampleCorr, 117 + \subitem SampleMean, 117 + \subitem SampleProd, 117 + \subitem Savir2, 115 + \subitem ScanSpacings, 132 + \subitem Serial, 110 + \subitem SerialOver, 113 + \subitem SerialSparse, 110 + \subitem SumCollector, 119 + \subitem SumLogs, 118 + \subitem SumLogsSpacings, 131 + \subitem SumSquaresSpacings, 132 + \subitem Universal, \see{Appearance\-Spacings}{119} + \subitem VarGeoN, 122 + \subitem VarGeoP, 122 + \subitem WeightDistrib, 118 + \item timer, 16 + \item two-levels tests, 89 + +\end{theindex} diff --git a/TESTU01/TestU01-1.2.3/testu01/guidetestu01.tex b/TESTU01/TestU01-1.2.3/testu01/guidetestu01.tex new file mode 100644 index 0000000..b853a1a --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/guidetestu01.tex @@ -0,0 +1,171 @@ +% +% User's guide for the software library TestU01 +% +\documentclass[12pt]{report} +\usepackage{url} +\usepackage{makeidx} +\usepackage{verbatim} +\usepackage{supertabular} + +% The symbols for the complex, the real, the integers, the fields. +\usepackage{amssymb} +%% $\mathbb{C, R, N, Z, F}$ + +\input ../doc/myarticle.sty + +\def\myboxit#1{\vbox{\hrule height1pt + \hbox{\vrule width1pt\kern10pt + \vbox{\kern3pt#1\kern3pt + }\kern10pt\vrule width1pt + }\hrule height1pt }} + +\makeindex + +\def\To {\Rightarrow} +\def\o {{(o)}} +\newcommand\cH{\mathcal{H}} +\def\bv {{\bf v}} +\def\bx {{\bf x}} +\def\bA {{\bf A}} +\def\bI {{\bf I}} +\def\bL {{\bf L}} +\def\bR {{\bf R}} +\def\tpose{^{\sf T}} + +\newcommand\guisec[1]{\vspace{20pt}% +\noindent\hrulefill\hspace{10pt}{\bf #1}\hspace{10pt}\hrulefill% +\nopagebreak\vspace{10pt}} + +\newcommand{\DelGen}{Frees the dynamic memory used by any generator + returned by the {\tt Create} functions of this module. + This function should be called to clean up any generator object of this + module when it is no longer in use.} + +\newcommand{\resdef}{The parameter {\tt res} is usually set to the + {\tt NULL} pointer. +However, if one wants to examine or post-process the results after a +test, then one must explicitly create a {\tt res} structure. +\ifdetailed \else +See the detailed version of this guide for the definition of the +structures and the relevant instructions.\fi\bigskip} + +\newtheorem {theorem}{Theorem} +\newtheorem {proposition}{Proposition} +\newtheorem {lemma}{Lemma} +\newtheorem {corollary}{Corollary} +\newtheorem {assumption}{Assumption} +\newtheorem {example}{Example} + +% \def\pierre#1 {\fbox {\footnote {\ }}\ \footnotetext { From Pierre: #1}} +\def\richard#1 {\fbox {\footnote {\ }}\ \footnotetext { From Richard: #1}} +\def\hpierre#1{} +\def\hrichard#1{} +\def\myurl{\url{http://www.iro.umontreal.ca/~lecuyer}} +\def\mycode{\code} +\def\myendcode{\endcode} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Switch to get a more/less detailed version of the user's guide. + +\newif\ifdetailed\detailedfalse +\newenvironment{detailed}{\protect\ifdetailed }{\protect\fi } +% \detailedtrue % For a more detailed user's guide. + +% \includeonly {bbattery} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin {document} +\include {title} + +\pagenumbering{roman} +\include {copyright} +\addcontentsline{toc}{chapter}{Copyright} +\tableofcontents +\clearpage + +\pagenumbering{arabic} + +\include {intro} +\include {uintro} +\include {unif01} +\include {ulcg} +\include {umrg} +\include {ucarry} +\include {utaus} +\include {ugfsr} +\include {uinv} +\include {uquad} +\include {ucubic} +\include {uxorshift} +\include {ubrent} +\include {ulec} +\include {utezuka} +\include {umarsa} +\include {uknuth} +\include {utouzin} +\include {ugranger} +\include {uwu} +\include {udeng} +\include {uweyl} +\include {unumrec} +\include {uautomata} +% \include {vectorsF2} +\include {ucrypto} +\include {usoft} +\include {uvaria} +\include {ufile} + +\include {sintro} +\include {swrite} +\ifdetailed + \include {sres} +\else + \include {sresshort} +\fi +\include {smultin} +\include {sentrop} +\include {snpair} +\include {sknuth} +\include {smarsa} +\include {svaria} +\include {swalk} +\include {scomp} +\include {sspectral} +\include {sstring} +\include {sspacings} +\include {scatter} + +\include {bintro} +\include {bbattery} + +\include {fintro} +\include {ffam} +\include {fcong} +\include {ffsr} +\include {ftab} +\ifdetailed + \include {fres} +\else + \include {fresshort} +\fi +\include {fcho} + +\include {fmultin} +% \include {fsentrop} +\include {fnpair} +\include {fknuth} +\include {fmarsa} +\include {fvaria} +\include {fwalk} +% \include {fcomp} +\include {fspectral} +\include {fstring} + + +\bibliographystyle {plain} +\addcontentsline{toc}{chapter}{BIBLIOGRAPHY} +\bibliography{random,ift,simul,stat,prob,math} +\clearpage +\addcontentsline{toc}{chapter}{INDEX} +\input{guidetestu01.ind} +\end {document} diff --git a/TESTU01/TestU01-1.2.3/testu01/intro.tex b/TESTU01/TestU01-1.2.3/testu01/intro.tex new file mode 100644 index 0000000..19eca86 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/intro.tex @@ -0,0 +1,723 @@ +\chapter {INTRODUCTION} + +%%%%%%%%%%%%% +\section {Design and testing of random number generators} + +Random numbers generators (RNGs) are small computer programs whose +purpose is to produce sequences of numbers that +{\em seem to behave\/} as if they were generated randomly from +a specified probability distribution. +These numbers are sometimes called {\em pseudorandom numbers}, +to underline the fact that they are not truly random. +Here, we just call them random numbers, with the usual (slight) +abuse of language. +These RNGs are crucial ingredients +for a whole range of computer usages, such as statistical experiments, +simulation of stochastic systems, numerical analysis, +probabilistic algorithms, cryptology, secure communications, +computer games, and gambling machines, to name a few. + +The numbers must be generated quickly and easily by a +computer program that is small, simple, and deterministic, +except for its initial state which can be selected at random. +% This program, together with the probability distribution of +% its initial state, is an RNG. +In some cases, certain parameters of the generator are also selected +at random, and can be viewed as part of the state. +The quality criteria for an RNG may depend on the application. +For simulation, one usually asks for speed, small memory requirement, +and good statistical properties. +For cryptology-related applications and for gambling machines in casinos, +unpredictability is a crucial requirement for which speed can be +sacrificed up to a certain point. + +% Theoretical analysis +RNGs should be designed and selected based on a +solid {\em theoretical\/} analysis of their mathematical structure. +Here, we suppose that the goal is that the successive output +values of the RNG, say $u_0, u_1, u_2, \dots$, +imitate independent random variables from the uniform +distribution over the interval $[0,1]$ (i.i.d.\ $U[0,1]$), +or over the two-element set $\{0,1\}$ (independent random bits). +In both cases (independent uniforms or random bits) we shall denote the +hypothesis of perfect behavior by $\cH_0$. +These two situations are strongly related, because under the i.i.d.\ +$U[0,1]$ hypothesis, any pre-specified sequence of bits (e.g., +the bit sequence formed by taking all successive bits of $u_0$, +or every second bit, or the first five bits of each $u_i$, etc.) +must be a sequence of independent random bits. +So statistical tests for bit sequences can be used as well +(indirectly) for testing the null hypothesis in the first situation. +In the remainder of this document, unless specified otherwise, +$\cH_0$ refers to this first situation. + +In the $U[0,1]$ case, $\cH_0$ is equivalent to saying that for each +integer $t>0$, the vector $(u_{0},\dots,u_{t-1})$ is uniformly +distributed over the $t$-dimensional unit cube $[0,1]^t$. +Clearly, this cannot be formally true, because these vectors always +take their values only from the {\em finite\/} set $\Psi_t$ of all +$t$-dimensional vectors of $t$ successive values that can be produced by +the generator, from all its possible initial states (or seeds). +The cardinality of this set cannot exceed the number of admissible +seeds for the RNG. +% If the seed is chosen at random, +Assuming that the seed is chosen at random, +vectors are actually generated over $\Psi_t$ +to approximate the uniform distribution over $[0,1]^t$. +This suggests that $\Psi_t$ should be very evenly +distributed over the unit cube. +Theoretical figures of merit for measuring this uniformity are discussed, +e.g., in \cite{rLEC98h,rLEC99b,rLEC01a,rNIE92b,rTEZ95a} and the +references given there. + +In the case of a sequence of random bits, the null hypothesis $\cH_0$ +cannot be formally true as soon as the length $t$ of the sequence exceeds +the number $b$ of bits in the generator's state, for the number of +distinct sequences of bits that can be produced cannot exceed $2^b$. +For $b < t$, the fraction of all sequences that can be visited is at most +$2^{b-t}$. The goal, then, is to make sure that those sequences +that can be visited are ``uniformly scattered'' in the set of all $2^t$ +possible sequences, and perhaps hard to distinguish. + +% Crypto. +Cryptologists use different quality criteria for RNGs. +Their main concern is {\em unpredictability\/} of the forthcoming +numbers. Their theoretical analysis of RNGs is usually asymptotic, +in the framework of computational complexity theory \cite{rKNU98a,rLAG93a}. + +% Statistical testing: +Once an RNG has been designed and implemented, +based on some mathematical analysis of its structure, it is usually +submitted to {\em empirical statistical tests\/} that try to detect +statistical deficiencies by looking for empirical evidence against +the hypothesis $\cH_0$ introduced previously. +A test is defined by a test statistic $Y$, which is a function of a +finite number of $u_n$'s +(or a finite number of bits, in the case of bit generators), +whose distribution under $\cH_0$ is known (sometimes approximately). +The number of different tests that can be defined is infinite and +these different tests detect different problems with the RNGs. +There is no universal test or battery of tests that can guarantee, +when passed, that a given generator is fully reliable for all +kinds of simulations. Passing many tests improves one's +confidence in the RNG, although it never {\em proves\/} that +the RNG is foolproof. +In fact, no RNG can pass every conceivable statistical test. +One could say that a {\em bad\/} RNG is one that fails +{\em simple\/} tests, and a {\em good\/} RNG is one that fails +only very complicated tests that are extremely hard to find +or impractical to run. + +Ideally, $Y$ should mimic the random variable of practical interest +in such a way that a bad structural interference between the RNG and the +problem will show up in the test. +But this is rarely practical. +This cannot be done, for example, for testing RNGs +for general-purpose software packages. + +% Specific statistical tests for RNGs are proposed and studied, e.g., in +% \cite{rKNU98a,rHEL98s,rLEC99e,rLEC00c,rLEC01a,rLEC02c,% +% rMAR85a,rMAR96b,rMAS00a,rSOT99a}, +% and other references given there. +Experience with empirical testing tells us that RNGs with very long +periods, good structure of their set $\Psi_t$, and based on recurrences +that are not too simplistic, pass most reasonable tests, +whereas RNGs with short periods or bad structures are usually easy +to crack by standard statistical tests. +The simple structure that makes certain classes of +generators very fast is also +(often) the source of their major statistical deficiencies, +which sometimes lead to totally wrong simulation results +\cite{rCOU94a,rLEC02c,rLEC00c,rLEC01a,rLEC01d,rFER92a,rTEZ93a}. +Practical tools for detecting these deficiencies are needed. +Offering a rich variety of empirical tests for doing that is +the purpose of the {TestU01} library. + +Some authors suggest that statistical tests should be used to identify +and discard what they call {\em bad subsequences\/} from the output +sequence of random number generators. +We do not believe that this is a good idea. +Such surgical procedures that cut out particular subsequences based on +statistical test results would tend to remove some of the natural +variability in the sequence, yielding a sequence that may lack some of +the randomness properties of typical random sequences. +Typically, when a generator fails a test decisively (e.g., with a +significance level or $p$-value less than $10^{-15}$, for example), +it fails in pretty much the same way for all its subsequences +of a given length. +This is because failure typically depends on the structure of the point +set $\Psi_t$. There are exceptions, but they are not frequent. +Moreover, when a generator starts failing a test decisively, the $p$-value +of the test usually converges to 0 or 1 exponentially fast as a function +of the sample size when the sample size is increased further. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section {Organization of the library} + +The software tools of {TestU01} are organized in four classes of modules: +those implementing RNGs, those implementing statistical tests, +those implementing pre-defined batteries of tests, and those +implementing tools for applying tests to entire families of generators. +The names of the modules in those four classes start with the letters +{\tt u}, {\tt s}, {\tt b}, and {\tt f}, respectively, and we shall refer +to them as the {\tt u}, {\tt s}, {\tt b}, and {\tt f} modules. +The name of every public identifier (type, variable, function, \dots) +is prefixed by the name of the module to which it belongs. +Chapters 2 to 5 of this guide describe these four classes of modules +and give some examples. +Some of these modules use definitions and functions from +the ANSI C libraries MyLib and ProbDist \cite{iLEC01m,iLEC01p}, +also developed in our laboratory. +Several platform-dependent switches are collected in module {\tt gdef} +of MyLib. They must be set to appropriate values, compatible with the +environment in which {TestU01} is running +(see the installation notes, in file {\tt README}). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection {The generator implementations} + +The module {\tt unif01} provides the basic tools for defining and +manipulating uniform RNGs. It contains the type +{\tt unif01\_Gen}, which implements the definition of an arbitrary RNG +object. Every RNG intrinsic to this package is of this type. +Functions are also available to write the current state of a generator, +to filter its output in different ways (e.g., combining successive +values in the sequence to produce an output with more bits of precision, +or taking non-successive values, or selecting only specific bits from +the output, etc.), to combine two or more generators and to test the +speed of different generators. + +One can create an arbitrary number of RNGs of a given kind or of +different kinds in the same program, +with the exception of a few specific RNG's that were programmed directly +in C by their authors, and which use global variables. +For the latter, only one copy of a particular generator can be +in use at any given time, and this is indicated in the documentation of +these specific RNG's. For example, one could use 3 LCGs with different +parameters in the same program; each has its own private set of variables +that does not interfere with the state or the parameters of the other two. +Additional kinds of generators can be defined by the user if needed, +by implementing functions that construct objects of type {\tt unif01\_Gen}. +% See the module {\tt unif01} for an example. + +The other {\tt u} modules implement RNGs and offer functions +of the form {\tt u\dots\_Create\dots} that return a generator object +which can be used as a source of random numbers, and + to which tests can be applied. +A dummy generator that just reads numbers from a file, either in text +or in binary format, is also available +in module {\tt ufile}. There are functions in module {\tt unif01} +that makes it very easy for the user to test his own generator or an +external generator that is not pre-programmed in TestU01. +% this is convenient for testing supposedly random bits +% produced by physical devices or stored on a compact disk. + +It is important to underline that most of the RNG implementations given here +are {\em not\/} intended for direct use in simulation or other similar +purposes. Other RNG packages, based on robust generators and with +multiple streams and other convenient facilities, have been designed +for that \cite{rLEC97d,rLEC01s}. +The purpose of the RNG implementations provided here is essentially +for empirical testing and experimentation with variants, combinations, etc. + + +\iffalse %%%%%%% +Standard linear congruential and multiple recursive linear +congruential generators, combined multiple recursive generators, +additive, subtractive and multiplicative lagged-Fibonacci generators, +add-with-carry, subtract-with-borrow, and more general ``multiply-with +carry'' generators, simple Tausworthe generators of +different flavors based on 3-tap, 5-tap, and multiple-tap linear +recurrences modulo 2, generalized feedback shift register (GFSR) +and twisted GFSR generators, including Mersenne twisters, +different families of nonlinear inversive generators (explicit +and implicit), quadratic and cubic congruential generators, +and Weyl and nested Weyl generators. +% and the Blum-Blum-Shub (BBS) generators. +Generators combining two or more of the above, by bitwise exclusive-or +or by addition modulo 1, are also supported. + +Generators used in popular software such as Unix, Excel, +Visual Basic, Java, Mathematica, S-Plus, etc., and specific generators +proposed by different people in the recent years, are available. +The latter include RNGs proposed by Knuth, Marsaglia, Matsumoto, +Kurita, Nishimura, Tezuka, L'Ecuyer, Wu, Couture, and their collaborators. +Generators proposed for security applications, such as +Isaac (\url{http://burtleburtle.net/bob/rand/isaac.html}), +are included as well. +In the near future, we plan to add other generators originating from +the world of cryptology +(see, e.g., the links on the web page {\tt http://csrc.nist.gov/rng/}). +Finally, a dummy generator that just reads numbers from a file will +also be available; this is convenient for testing supposedly random bits +produced by physical devices or stored on a compact disk. +\fi %%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection {The statistical tests} + +The statistical tests are implemented in the {\tt s} modules, +whose names start by {\tt s}. +They all test one of the two null hypotheses $\cH_0$ defined +previously, using different test statistics. +To apply a test to a specific generator, the generator must first be +created by the appropriate {\tt Create} function in a {\tt u} module, +then it must be passed as a parameter to the function +implementing the appropriate test. + The test results are printed automatically +to the standard output, with a level of detail that can be selected +by the user (see module {\tt swrite}). + +It is also possible to recover information about what has happened +in the tests, via data structures specific to each type of test. +%% (althought this requires a bit of hacking). +These data stuctures, if they are to be used outside of a test, +must always be created by calling the appropriate +{\tt s\ldots\_Create\ldots} function. They +%% are global variables in the corresponding modules. They + are described only in the {\em detailed\/} version of this +user's guide. This could be used, for example, to examine or +post-process the results of a test. +There are also a few public functions that do not appear even +in the {\em detailed\/} version of this guide. They are hidden since +they will be useful only when developing new tests or modifying +existing ones. + +The testing procedures use several functions from the library ProbDist +\cite{iLEC01p}. In particular, they use {\tt statcoll} from that library +to collect statistical observations, and {\tt gofw} to apply the +goodness-of-fit (GOF) tests. + +The module {\tt scatter} does not apply statistical tests per se, +but permits one to draw scatter plots for vectors of points +returned by a generator. + +\iffalse %%%%%%%%%%%%%%% +The tests that will be implemented include those described +by Knuth \cite{rKNU98a} (serial test, gap test, poker test, +coupons collector test, permutation test, run test, max-of-$t$ test, +collision test), those described by Marsaglia \cite{rMAR85b} +(overlapping serial test, overlapping pairs with sparse occupancy, +birthday spacings \cite{rLEC01a}, monkey test, matrix rank), +the modified test of Savir proposed in \cite{rMAR85c}, +the general {\em power divergence\/} family of tests for overlapping +and non-overlapping vectors, studied in \cite{rLEC98h,rLEC02c}, +for both the dense and sparse situations +(this family of tests include chi-square, serial, collision, +loglikelihood ratio, and entropy tests as special cases), +tests based on the sum of the transformed spacings between sorted +observations \cite{rLEC97h}, +tests based on discrete and continuous entropies \cite{rLEC96e}, +tests based on the distance between the closest pairs of points +in space \cite{rLEC00c}, +the Bickel-Breiman multidimensional test of uniformity \cite{tBIC83a}, +the weight distribution test described in \cite{rMAT94a}, +a generalized collision test proposed by Sullivan \cite{rSUL93a}, +the test of Ugrin-Sparac \cite{rUGR91a}, +the so-called universal test proposed by Maurer \cite{rMAU92a} +(which we call {\em appearances spacings\/}), +various independence tests for the Hamming weights of successive +blocks of bits, +tests based on the distribution of correlations in bit strings +studied in \cite{pGUI81a}, +tests based on the linear complexity of sequences \cite{rERD92a} +and on the Lempel-Ziv complexity, +empirical spectral tests based on Fourier transforms, +and several tests based on random walks +\cite{rTAK94a,rTAK96a,rVAT94a,rVAT95a}. +Graphical tools for examining the projections of point sets +(or their truncations) from the multidimensional unit hypercube +to low-dimensional subspaces will be available as well. +\fi %%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection {Batteries of tests} + +Many users find it convenient to have predefined suites (or batteries) +of more or less standard statistical tests, with fixed parameters, +that can be applied to a given RNG. +Different types of tests should be included in such a battery, +in order to detect different types of weaknesses in a given generator. +% There can also be many batteries to cover the different kind of uses +% to which random number generators can be applied. + +A number of predefined batteries of tests, some oriented towards +sequences of uniform floating-point numbers in the interval $[0, 1)$, +others towards sequences of bits, are available in TestU01. +There are small batteries, that run quickly, and larger +(more stringent) batteries that take longer to run. +These batteries are implemented in the {\tt b} modules. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection {Tools for testing families of generators} + +The {\tt f} modules provide a set of tools, built on top of +the modules that implement the generator families and the tests, +designed to perform systematic studies of +the interaction between certain types of tests and the structure +of the point sets produced by given families of RNGs. +Roughly, the idea is to see at which sample size $n_0$ the test starts +to reject the RNG decisively, as a function of its period length $\rho$. +In experiments already performed with certain classes of generators +and specific tests \cite{rLEC98h,rLEC00c,rLEC01a}, +the results were often surprisingly regular, +in the sense that a regression model of the form +$\log n_0 = a \log\rho + \epsilon$, where $a$ is a constant +and $\epsilon$ a small noise, fits very well. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section {History and implementation notes} + +% THIS SECTION MUST BE COMPLETED. + +{TestU01} started as a Pascal program implementing the tests suggested +in the 1981 edition of volume 2 of ``The Art of Computer Programming'' +\cite{rKNU81a}. This was around 1985. +Three or four years later, a Modula-2 implementation was made, in the +form of a library with a modular design. +Other tests were added, as well as some generators implemented in +generic form. Between 1990 and 2001, new generators and new tests were +added regularly to the library and a detailed user's guide (in french) +was kept up to date. The {\tt f} modules, which contain +tools for testing entire families of generators, were introduced in +1997, while the first author was on sabbatical at the University of +Salzburg, Austria. +In 2001 and 2002, we partially redesigned the library, +translated it in the C language, +and translated the user's guide in english. + +These preliminary versions of the library were used for several +articles (co)authored by P.\ L'Ecuyer, starting from his 1986 paper +where he first proposed a combined LCG \cite{rLEC86a}, and including +\cite{rLEC88a,rLEC92a,rLEC97d,rLEC97h,rLEC98h,rLEC02c,rLEC98t,rLEC99e,% +rLEC00c,rLEC01a,rLEC03c,rLEC01d}. + +\iffalse %%%%%%%%%% Most of this is now done. +The way this library was born and grew up certainly had an important +influence on its design. +Things were added layer after layer along the years. +Global variables abound, because this is the way things were made +in the (relatively small) original Pascal and Modula-2 versions, +partly in the interest of speed and reduced memory utilization. +Some have been removed in the C version, but others remain. +It we could afford the luxury of redoing the library entirely from +scratch tomorrow, the design would certainly be somewhat different, +probably more objected-oriented (e.g., the functions that set the +current generator, in modules {\tt u\ldots}, could return a generator +object that would be passed as a parameter to testing functions, +instead of using a global variable for the current generator. +The tests could also return a pointer to a structure (i.e., an object) +that contains their detailed results, instead of just writing them +to the current output). +This may happen in future versions. +\fi %%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section {Other software for testing RNGs} + +Another well-known public-domain testing package for RNGs is +DIEHARD \cite{rMAR96b}. +\index{battery of tests!DIEHARD}\index{DIEHARD}% +It contains a large number of statistical tests. +However, it has some drawbacks and limitations. +Firstly, the sequence of tests to be applied to any generator, +as well as the parameters of these tests (sample size, etc.) are +fixed in the package. The sample sizes are moderate; +all these tests run in a few seconds of CPU time on a desktop computer. +For example, on a PC with an Athlon XP 2100+ processor at 1733 MHz +and running Linux, the entire series of tests take approximately +12 seconds to run. +% As a result, they are not really very stringent and the user has +% little flexibility for changing that. +Secondly, the package requires that the random numbers to be tested +are 32-bit integers, placed in a huge file in binary format. +This file is passed to the testing procedures. +This setup is not always convenient. +Many RNGs produce numbers with less than 32 bits of resolution +(e.g., 31 bits is frequent) and DIEHARD does not care for that. +{TestU01} is more flexible on all these aspects. + +The SPRNG library \cite{rMAS00a} is another public-domain software +that implements the classical tests for RNGs given +in \cite{rKNU98a}, plus a few others. +\index{battery of tests!SPRNG}\index{SPRNG}% +The National Institute of Standards and Technology (NIST), in the USA, +\index{battery of tests!NIST}\index{NIST tests suite}% +has implemented a test suite (16 tests) for RNGs, mainly for the +testing and certification of RNGs used in cryptographic applications +(see \cite{rSOT99a} and \url{http://csrc.nist.gov/rng/}). +The ENT test program (\url{http://www.fourmilab.ch/random/}) +\index{battery of tests!ENT}\index{ENT}% +implements a few elementary tests. +The Information Security Research Center, in Australia, +offers a commercial testing package called Crypt-X, +\index{battery of tests!Crypt-X}\index{Crypt-X}% +which contains a test suite designed for stream +ciphers, block ciphers, and key generators used in cryptology +(see \url{http://www.isrc.qut.edu.au/resource/cryptx/}). +The GNU scientific library {\tt gsl}, currently under development +(see \url{http://sources.redhat.com/gsl/ref/gsl-ref_10.html}), +implements a large set of well-tested RNGs, but so far no statistical +test per se. + +\iffalse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section {Examples} + +Simple examples of programs using {TestU01} are given here. +The goal is to give a quick idea of what the library can do and how +to use it. + \vdots + + + +Two-level tests: + +The software allows also easily two-levels tests: +one replicates the basic test $N$ times, to obtain $N$ +values of the statistic $T$, after which one compares the empirical +distribution function $\hat F_N$ of these $N$ values with the +theoretical distribution function $F$ of statistic $T$ under $\cH_0$. +This comparison may be done by the use of different statistics, +such as those of Kolmogorov-Smirnov, Watson, or Anderson-Darling +\cite{tDAR60a,tDUR73a,tSTE70a,tSTE86b}. + +The final result of such a test is the set of significance levels +of the goodness-of-fit tests between $\hat F_N$ and $F$. +For example, if $F$ is continuous, one may use, in order to test +the fit, the Kolmogorov-Smirnov (KS) statistics: +\begin {eqnarray*} + D_N^+ &=& \sup_{-\infty < t < \infty} \left(\hat F_N(t) - F(t)\right) + = \max_{1\le j\le N} \left(j/N - F(T_{(j)})\right) + \qquad\mbox { and} \\[6pt] + D_N^- &=& \sup_{-\infty < t < \infty} \left(F(t) - \hat F_N(t)\right) + = \max_{1\le j\le N} \left(F(T_{(j)}) - (j-1)/N\right). +\end {eqnarray*} +Let $d_N^+$ and $d_N^-$ be the values of these statistics, +then the significance levels are +\begin {eqnarray*} + \delta^+ &=& \Pr [D_N^+ \ge d_N^+ \mid \cH_0],\\[4pt] + \delta^- &=& \Pr [D_N^- \ge d_N^- \mid \cH_0]. +\end {eqnarray*} +The software will generally print the values of these statistics +and their significance levels. +For more details, see the modules {\tt gofs, gofw} from the +library {\bf ProbDist}. +The generator ``fails'' a test when the value of the significance +level is deemed much too close to 0 or to 1, which means +that the deviation obtained is too unlikely under $\cH_0$. +When the result is unquestionable (for example when $\delta^+ < 10^{-5}$), +one rejects $\cH_0$ and the generator. +When the result is open to doubt (for example when $\delta^+ \approx 0.005$), +one repeats the test (we may increase $n$ or $N$) +and one rejects $\cH_0$ if suspect values occur consistently. +% Les tests statistic decrits dans \cite{rLEC88a} ont ete effectues +% a l'aide d'une version preliminaire de ce logiciel. + +Two-levels tests require the generation of a very large number of + values, which is generally costly in CPU times. On the other hand, +this gives a more powerful test and allows the base test to be +applied many times, on different sub-sequences, instead of being +applied once on the whole sequence. Thus, one will be better able to +detect the defects of a generator whose behaviour, + with respect to a given test, is not too bad if one takes the average +over the whole sequence, but becomes bad when taken independently +over shorter sub-sequences. + For example, let us consider the extreme case of a generator +which generates, in the standard order, the values $i/2^{31}$, + for $i=1,2,\dots,2^{31}-1$. +If we apply a simple test of uniformity over the whole sequence, we +shall have a perfect fit, while if we apply the same test many times +over shorter sub-sequences, the fit will be very bad. + +Sometimes, the two-level test may be done by simply adding +the $N$ values of $T$ +and rejecting $\cH_0$ if the sum is too large or too small. +This is the case, for example, when $T$ obeys (approximately) a normal +or a Poisson law, under $\cH_0$. +For detecting the flaws of random number +generators, the test based on the sum of the values of $T$ is usually more +powerful than the tests comparing $\hat F_N$ and $F$, +according to our experience. + +The module {\tt scatter} allows us to view on a graphics the points +obtained from a generator (i.e.\ the vectors of $t$ +successive values in the sequence of generated values) +in the $t$-dimensionnal hypercube $[0,1]^t$. +We may take a slice of the hypercube, and we may +project the points of this slice onto a 2-dimensionnal face. +The module {\tt scatter} can create a file ready to be processed by + \LaTeX\ or {\tt Gnuplot}, that allow the viewing of this projection. +In this way, the user may view the lattice structure of a linear +congruential generator (LCG). + +Furthermore, each of the tests described in the {\tt s...} modules may +be applied to a whole family of generators of the same + type differing by their period. Thus, one may observe some + systematic behaviour of a whole family of generators with respect to a +given test. + +Let us consider, for example, a family of {LCG} defined by +\begin{eqnarray*} + x_i &=& a x_{i-1} \mod m,\\ + u_i &=& x_i / m, +\end{eqnarray*} +whose modulus is chosen as a prime number +of the form $2^e - q$, where $q$ is very small, and +$a$ is chosen to give the best figure of merit $M_8$ as in + \cite{rLEC99c}. The figure of merit + $M_8$ characterizes the behaviour of a generator +with respect to the spectral test for all dimensions from 1 to 8. +We apply the collisions test (see the modules +{\tt sknuth} and {\tt tknuth}, and \cite{rKNU81a} pp. 68--70), +to all members of this + family while varying the sample size $n$ according to the law + $n=2^{\alpha\, e + \beta}$. By selecting suitable + $\alpha$ and $\beta$, we hope to discover a + regularity characterizing the failure of the +members of this family with respect to this test. +For example, table~\ref{tab:coll1}, created by the program, +gives the expected number of collisions and the + observed number of collisions, for +$$ + n = 2^{f + e/2} +$$ +and a number of cells $k\approx 2^e$, in 2 dimensions. +Under $\cH_0$, this number of collisions is a random variable $C$ which +obeys a Poisson law of mean $\lambda = n^2/(2k)$. +Table~\ref{tab:coll11} shows the $p$-values (as defined in +function {\tt gofw\_pDist} of the module {\tt gofw}), always for this +collisions test. +In this table, $\epsilon$ stands for a value $< 10^{-15}$. + +We see that the generators pass the test for $f=1$, begin to +have suspect values for $f=2$, and fail the test +systematically for $f \ge 3$. +By comparing the corresponding columns of the table~\ref{tab:coll1}, +we see that the observed number of + collisions is much less than the expected number +for $f \ge 3$, and this is the reason those generators +fail the test. + + +\begin {table} +\begin {center} +\caption {Some good LCGs with respect to $M_8$} +\label {tab:lcg1} +\smallskip +\begin {tabular}{|lr|} +\hline +\qquad $m$ & $a$ (good LCG) \\ +\hline +$2^{10}-3 = 1021$ & 65 \\ +$2^{11}-9 = 2039$ & 995 \\ + $2^{12}-3 = 4093$ & 209 \\ + $2^{13}-1 = 8191$ & 884 \\ + $2^{14}-3 = 16381$ & 572 \\ + $2^{15}-19 = 32749$ & 219 \\ + $2^{16}-15 = 65521$ & 17364 \\ + $2^{17}-1 = 131071$ & 43165 \\ + $2^{18}-5 = 262139$ & 92717 \\ + $2^{19}-1 = 524287$ & 283741 \\ + $2^{20}-3 = 1048573$ & 380985 \\ + $2^{21}-9 = 2097143$ & 360889 \\ + $2^{22}-3 = 4194301$ & 914334 \\ + $2^{23}-15 = 8388593$ & 653276 \\ + $2^{24}-3 = 16777213$ & 6423135 \\ + $2^{25}-39 = 33554393$ & 25907312 \\ + $2^{26}-5 = 67108859$ & 26590841 \\ + $2^{27}-39 = 134217689$ & 45576512 \\ + $2^{28}-57 = 268435399$ & 31792125 \\ + $2^{29}-3 = 536870909$ & 16538103 \\ + $2^{30}-35 = 1073741789$ & 5122456 \\ +\hline +\end {tabular} +\end {center} +\end {table} + + +\def\eps {$\quad\epsilon\quad$} +\def\epsm {$\quad 1 - \epsilon\quad$} + + +\begin {table} +\centering +\caption {Expected number of +collisions | Observed number of collisions.} +\label {tab:coll1} +\smallskip +\begin {tabular}{|r|@{\extracolsep{10pt}}rr|rr|rr|rr|rr|} +%% \multicolumn{11}{l}{\makebox[0pt][l]{Expected number of Collisions---Observed number of Collisions}}\\ +\hline + $e$& \multicolumn{2}{c|}{$ f=1$} & \multicolumn{2}{c|}{$ f=2$} & \multicolumn{2}{c|}{$ f=3$} & \multicolumn{2}{c|}{$ f=4 +$} & \multicolumn{2}{c|}{$ f=5$} \\ +\hline + 10 & 1.93 & 2 & 7.62 & 2 & 29.39 & 11 & 108.94 & 58 & 376.52 & 570 \\ + 11 & 1.99 & 1 & 7.81 & 0 & 30.44 & 6 & 115.16 & 17 & 413.38 & 474 \\ + 12 & 1.96 & 0 & 7.81 & 2 & 30.65 & 13 & 117.87 & 44 & 436.20 & 216 \\ + 13 & 1.95 & 1 & 7.78 & 2 & 30.71 & 22 & 119.46 & 57 & 452.06 & 211 \\ + 14 & 1.98 & 1 & 7.90 & 5 & 31.31 & 11 & 122.77 & 52 & 471.77 & 191 \\ + 15 & 1.99 & 1 & 7.93 & 1 & 31.51 & 7 & 124.27 & 41 & 483.20 & 132 \\ + 16 & 1.99 & 1 & 7.95 & 0 & 31.65 & 5 & 125.35 & 20 & 491.26 & 75 \\ + 17 & 1.99 & 0 & 7.97 & 1 & 31.75 & 11 & 126.16 & 23 & 497.29 & 101 \\ + 18 & 2.00 & 0 & 7.98 & 4 & 31.83 & 15 & 126.66 & 45 & 501.47 & 214 \\ + 19 & 2.00 & 0 & 7.98 & 1 & 31.89 & 3 & 127.07 & 19 & 504.60 & 61 \\ + 20 & 2.00 & 0 & 7.99 & 0 & 31.91 & 4 & 127.33 & 14 & 506.69 & 74 \\ + 21 & 2.00 & 0 & 7.99 & 1 & 31.94 & 12 & 127.55 & 48 & 508.35 & 178 \\ + 22 & 2.00 & 0 & 7.99 & 3 & 31.96 & 14 & 127.66 & 59 & 509.34 & 220 \\ + 23 & 2.00 & 0 & 8.00 & 0 & 31.97 & 5 & 127.79 & 16 & 510.22 & 45 \\ + 24 & 2.00 & 0 & 8.00 & 0 & 31.98 & 1 & 127.83 & 15 & 510.67 & 37 \\ + 25 & 2.00 & 0 & 8.00 & 3 & 31.98 & 5 & 127.86 & 29 & 510.99 & 133 \\ + 26 & 2.00 & 2 & 8.00 & 1 & 31.99 & 7 & 127.92 & 24 & 511.33 & 71 \\ + 27 & 2.00 & 1 & 8.00 & 1 & 31.99 & 7 & 127.95 & 38 & 511.55 & 152 \\ + 28 & 2.00 & 0 & 8.00 & 3 & 31.99 & 17 & 127.96 & 41 & 511.67 & 193 \\ + 29 & 2.00 & 1 & 8.00 & 0 & 32.00 & 0 & 127.98 & 8 & 511.78 & 25 \\ + 30 & 2.00 & 0 & 8.00 & 3 & 32.00 & 10 & 127.98 & 29 & 511.83 & 189 \\ +\hline +\end {tabular} \\ +\medskip +\end {table} + + +\begin {table} +\centering +\caption {The $p$-values of $C$ for the LCGs, for $t=2$ +and $k\approx 2^e$.} +\label {tab:coll11} +\smallskip +\begin {tabular}{|r|@{\extracolsep{10pt}}lllcc|} +% \multicolumn{6}{l}{\makebox[0pt][l]{Discrete p-value for Collision test}}\\ +\hline + $e$& $ f=1$ & $ f=2$ & $ f=3$ & $ f=4$ & $ f=5$ \\ +\hline + 10 & & &--1E--5 &--1E--12 & \eps \\ + 11 & &--2E--4 &--6E--9 & \epsm & 1E--6 \\ + 12 & & &--1E--4 & \epsm & \epsm \\ + 13 & & & &--2E--12 & \epsm \\ + 14 & & &--2E--5 &--1E--14 & \epsm \\ + 15 & &--3E--3 &--9E--8 & \epsm & \epsm \\ + 16 & &--4E--4 &--6E--9 & \epsm & \epsm \\ + 17 & &--3E--3 &--2E--5 & \epsm & \epsm \\ + 18 & & &--7E--4 & \epsm & \epsm \\ + 19 & &--3E--3 &--8E--11 & \epsm & \epsm \\ + 20 & &--3E--4 &--7E--10 & \epsm & \epsm \\ + 21 & &--3E--3 &--5E--5 & \epsm & \epsm \\ + 22 & & &--3E--4 &--9E--12 & \epsm \\ + 23 & &--3E--4 &--4E--9 & \epsm & \epsm \\ + 24 & &--3E--4 &--4E--13 & \epsm & \epsm \\ + 25 & & &--4E--9 & \epsm & \epsm \\ + 26 & &--3E--3 &--1E--7 & \epsm & \epsm \\ + 27 & &--3E--3 &--1E--7 & \epsm & \epsm \\ + 28 & & &--3E--3 & \epsm & \epsm \\ + 29 & &--3E--4 &--1E--14 & \epsm & \epsm \\ + 30 & & &--6E--6 & \epsm & \epsm \\ +\hline +\end {tabular} \\ +\end {table} + + +\fi %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/TESTU01/TestU01-1.2.3/testu01/rijndael-alg-fst.c b/TESTU01/TestU01-1.2.3/testu01/rijndael-alg-fst.c new file mode 100644 index 0000000..6d26c61 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/rijndael-alg-fst.c @@ -0,0 +1,1407 @@ +/* Remarks for TestU01: + * The only changes I have made in the authors' code below is to rename the + * types u8, u32. (R. Simard for TestU01) + * + *===========================================================================*/ + + +/** + * rijndael-alg-fst.c + * + * @version 3.0 (December 2000) + * + * Optimised ANSI C code for the Rijndael cipher (now AES) + * + * @author Vincent Rijmen + * @author Antoon Bosselaers + * @author Paulo Barreto + * + * This code is hereby placed in the public domain. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include + +#include "rijndael-alg-fst.h" + +/* +Te0[x] = S [x].[02, 01, 01, 03]; +Te1[x] = S [x].[03, 02, 01, 01]; +Te2[x] = S [x].[01, 03, 02, 01]; +Te3[x] = S [x].[01, 01, 03, 02]; +Te4[x] = S [x].[01, 01, 01, 01]; + +Td0[x] = Si[x].[0e, 09, 0d, 0b]; +Td1[x] = Si[x].[0b, 0e, 09, 0d]; +Td2[x] = Si[x].[0d, 0b, 0e, 09]; +Td3[x] = Si[x].[09, 0d, 0b, 0e]; +Td4[x] = Si[x].[01, 01, 01, 01]; +*/ + +static const uint32_t Te0[256] = { + 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, + 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, + 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, + 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU, + 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U, + 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU, + 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU, + 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU, + 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU, + 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU, + 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U, + 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU, + 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU, + 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U, + 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU, + 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU, + 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU, + 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU, + 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU, + 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U, + 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU, + 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU, + 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU, + 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU, + 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U, + 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U, + 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U, + 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U, + 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU, + 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U, + 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U, + 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU, + 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU, + 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U, + 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U, + 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U, + 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU, + 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U, + 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU, + 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U, + 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU, + 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U, + 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U, + 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU, + 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U, + 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U, + 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U, + 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U, + 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U, + 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U, + 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U, + 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U, + 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU, + 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U, + 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U, + 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U, + 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U, + 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U, + 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U, + 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU, + 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U, + 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U, + 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, + 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, +}; +static const uint32_t Te1[256] = { + 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, + 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, + 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, + 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U, + 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU, + 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U, + 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU, + 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U, + 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U, + 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU, + 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U, + 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U, + 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U, + 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU, + 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U, + 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U, + 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU, + 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U, + 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U, + 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U, + 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU, + 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU, + 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U, + 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU, + 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU, + 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U, + 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU, + 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U, + 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU, + 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U, + 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U, + 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U, + 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU, + 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U, + 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU, + 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U, + 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU, + 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U, + 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U, + 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU, + 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU, + 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU, + 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U, + 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U, + 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU, + 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U, + 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU, + 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U, + 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU, + 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U, + 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU, + 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU, + 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U, + 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU, + 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U, + 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU, + 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U, + 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U, + 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U, + 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU, + 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU, + 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U, + 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, + 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, +}; +static const uint32_t Te2[256] = { + 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, + 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, + 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, + 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U, + 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU, + 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U, + 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU, + 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U, + 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U, + 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU, + 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U, + 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U, + 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U, + 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU, + 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U, + 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U, + 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU, + 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U, + 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U, + 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U, + 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU, + 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU, + 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U, + 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU, + 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU, + 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U, + 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU, + 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U, + 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU, + 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U, + 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U, + 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U, + 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU, + 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U, + 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU, + 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U, + 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU, + 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U, + 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U, + 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU, + 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU, + 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU, + 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U, + 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U, + 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU, + 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U, + 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU, + 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U, + 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU, + 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U, + 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU, + 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU, + 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U, + 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU, + 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U, + 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU, + 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U, + 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U, + 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U, + 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU, + 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU, + 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U, + 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, + 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, +}; +static const uint32_t Te3[256] = { + + 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, + 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, + 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, + 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU, + 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU, + 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU, + 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U, + 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU, + 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU, + 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U, + 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U, + 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU, + 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU, + 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU, + 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU, + 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU, + 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U, + 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU, + 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU, + 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U, + 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U, + 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U, + 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U, + 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U, + 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU, + 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U, + 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU, + 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU, + 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U, + 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U, + 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U, + 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU, + 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U, + 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU, + 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU, + 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U, + 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U, + 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU, + 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U, + 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU, + 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U, + 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U, + 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U, + 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U, + 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU, + 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U, + 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU, + 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U, + 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU, + 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U, + 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU, + 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU, + 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU, + 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU, + 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U, + 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U, + 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U, + 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U, + 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U, + 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U, + 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU, + 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U, + 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, + 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, +}; +static const uint32_t Te4[256] = { + 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, + 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, + 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU, + 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U, + 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU, + 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U, + 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU, + 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U, + 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U, + 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU, + 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U, + 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U, + 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U, + 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU, + 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U, + 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U, + 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU, + 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U, + 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U, + 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U, + 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU, + 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU, + 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U, + 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU, + 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU, + 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U, + 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU, + 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U, + 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU, + 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U, + 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U, + 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U, + 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU, + 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U, + 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU, + 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U, + 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU, + 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U, + 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U, + 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU, + 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU, + 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU, + 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U, + 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U, + 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU, + 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U, + 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU, + 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U, + 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU, + 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U, + 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU, + 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU, + 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U, + 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU, + 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U, + 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU, + 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U, + 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U, + 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U, + 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU, + 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU, + 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U, + 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU, + 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, +}; +static const uint32_t Td0[256] = { + 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, + 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, + 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, + 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU, + 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U, + 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U, + 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU, + 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U, + 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU, + 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U, + 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U, + 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U, + 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U, + 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU, + 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U, + 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU, + 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U, + 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU, + 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U, + 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U, + 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U, + 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU, + 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U, + 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU, + 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U, + 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU, + 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U, + 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU, + 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU, + 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U, + 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU, + 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U, + 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU, + 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U, + 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U, + 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U, + 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU, + 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U, + 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U, + 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU, + 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U, + 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U, + 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U, + 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U, + 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U, + 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU, + 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U, + 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U, + 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U, + 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U, + 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U, + 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU, + 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU, + 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU, + 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU, + 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U, + 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U, + 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU, + 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU, + 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U, + 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU, + 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U, + 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, + 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, +}; +static const uint32_t Td1[256] = { + 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, + 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, + 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, + 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U, + 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U, + 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U, + 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U, + 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U, + 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U, + 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU, + 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU, + 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU, + 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U, + 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU, + 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U, + 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U, + 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U, + 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU, + 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU, + 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U, + 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU, + 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U, + 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU, + 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU, + 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U, + 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U, + 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U, + 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU, + 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U, + 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU, + 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U, + 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U, + 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U, + 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU, + 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U, + 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U, + 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U, + 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U, + 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U, + 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U, + 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU, + 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU, + 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U, + 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU, + 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U, + 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU, + 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU, + 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U, + 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU, + 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U, + 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U, + 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U, + 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U, + 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U, + 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U, + 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U, + 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU, + 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U, + 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U, + 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU, + 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U, + 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U, + 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, + 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, +}; +static const uint32_t Td2[256] = { + 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, + 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, + 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, + 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U, + 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU, + 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U, + 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U, + 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U, + 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U, + 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU, + 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U, + 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U, + 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU, + 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U, + 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U, + 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U, + 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U, + 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, + 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, + 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, + + 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, + 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, + 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U, + 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U, + 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U, + 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU, + 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU, + 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U, + 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU, + 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U, + 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU, + 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU, + 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU, + 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU, + 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U, + 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U, + 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U, + 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U, + 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U, + 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U, + 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U, + 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU, + 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU, + 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U, + 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U, + 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU, + 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU, + 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U, + 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U, + 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U, + 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U, + 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U, + 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U, + 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U, + 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU, + 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U, + 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U, + 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U, + 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U, + 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U, + 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U, + 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU, + 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, + 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, +}; +static const uint32_t Td3[256] = { + 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, + 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, + 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, + 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U, + 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU, + 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU, + 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U, + 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU, + 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U, + 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU, + 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U, + 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U, + 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U, + 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U, + 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U, + 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU, + 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU, + 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U, + 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U, + 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU, + 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU, + 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U, + 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U, + 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U, + 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U, + 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU, + 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U, + 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U, + 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU, + 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU, + 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U, + 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U, + 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U, + 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU, + 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U, + 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U, + 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U, + 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U, + 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U, + 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U, + 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U, + 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU, + 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U, + 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U, + 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU, + 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU, + 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U, + 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU, + 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U, + 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U, + 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U, + 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U, + 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U, + 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U, + 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU, + 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU, + 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU, + 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU, + 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U, + 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U, + 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U, + 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU, + 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, + 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, +}; +static const uint32_t Td4[256] = { + 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, + 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, + 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU, + 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU, + 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U, + 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U, + 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U, + 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU, + 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U, + 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU, + 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU, + 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU, + 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U, + 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U, + 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U, + 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U, + 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U, + 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U, + 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU, + 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U, + 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U, + 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU, + 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U, + 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U, + 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U, + 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU, + 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U, + 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U, + 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU, + 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U, + 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U, + 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU, + 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U, + 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU, + 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU, + 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U, + 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U, + 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U, + 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U, + 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU, + 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U, + 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U, + 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU, + 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU, + 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU, + 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U, + 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU, + 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U, + 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U, + 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U, + 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U, + 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU, + 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U, + 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU, + 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU, + 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU, + 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU, + 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U, + 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU, + 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U, + 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU, + 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U, + 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U, + 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, +}; +static const uint32_t rcon[] = { + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ +}; + +#define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) + +#ifdef _MSC_VER +#define GETU32(p) SWAP(*((uint32_t *)(p))) +#define PUTU32(ct, st) { *((uint32_t *)(ct)) = SWAP((st)); } +#else +#define GETU32(pt) (((uint32_t)(pt)[0] << 24) ^ ((uint32_t)(pt)[1] << 16) ^ ((uint32_t)(pt)[2] << 8) ^ ((uint32_t)(pt)[3])) +#define PUTU32(ct, st) { (ct)[0] = (uint8_t)((st) >> 24); (ct)[1] = (uint8_t)((st) >> 16); (ct)[2] = (uint8_t)((st) >> 8); (ct)[3] = (uint8_t)(st); } +#endif + +/** + * Expand the cipher key into the encryption key schedule. + * + * @return the number of rounds for the given cipher key size. + */ +int rijndaelKeySetupEnc(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) { + int i = 0; + uint32_t temp; + + rk[0] = GETU32(cipherKey ); + rk[1] = GETU32(cipherKey + 4); + rk[2] = GETU32(cipherKey + 8); + rk[3] = GETU32(cipherKey + 12); + if (keyBits == 128) { + for (;;) { + temp = rk[3]; + rk[4] = rk[0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp ) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24) ] & 0x000000ff) ^ + rcon[i]; + rk[5] = rk[1] ^ rk[4]; + rk[6] = rk[2] ^ rk[5]; + rk[7] = rk[3] ^ rk[6]; + if (++i == 10) { + return 10; + } + rk += 4; + } + } + rk[4] = GETU32(cipherKey + 16); + rk[5] = GETU32(cipherKey + 20); + if (keyBits == 192) { + for (;;) { + temp = rk[ 5]; + rk[ 6] = rk[ 0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp ) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24) ] & 0x000000ff) ^ + rcon[i]; + rk[ 7] = rk[ 1] ^ rk[ 6]; + rk[ 8] = rk[ 2] ^ rk[ 7]; + rk[ 9] = rk[ 3] ^ rk[ 8]; + if (++i == 8) { + return 12; + } + rk[10] = rk[ 4] ^ rk[ 9]; + rk[11] = rk[ 5] ^ rk[10]; + rk += 6; + } + } + rk[6] = GETU32(cipherKey + 24); + rk[7] = GETU32(cipherKey + 28); + if (keyBits == 256) { + for (;;) { + temp = rk[ 7]; + rk[ 8] = rk[ 0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp ) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24) ] & 0x000000ff) ^ + rcon[i]; + rk[ 9] = rk[ 1] ^ rk[ 8]; + rk[10] = rk[ 2] ^ rk[ 9]; + rk[11] = rk[ 3] ^ rk[10]; + if (++i == 7) { + return 14; + } + temp = rk[11]; + rk[12] = rk[ 4] ^ + (Te4[(temp >> 24) ] & 0xff000000) ^ + (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(temp ) & 0xff] & 0x000000ff); + rk[13] = rk[ 5] ^ rk[12]; + rk[14] = rk[ 6] ^ rk[13]; + rk[15] = rk[ 7] ^ rk[14]; + + rk += 8; + } + } + return 0; +} + +/** + * Expand the cipher key into the decryption key schedule. + * + * @return the number of rounds for the given cipher key size. + */ +int rijndaelKeySetupDec(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) { + int Nr, i, j; + uint32_t temp; + + /* expand the cipher key: */ + Nr = rijndaelKeySetupEnc(rk, cipherKey, keyBits); + /* invert the order of the round keys: */ + for (i = 0, j = 4*Nr; i < j; i += 4, j -= 4) { + temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; + temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; + temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; + temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; + } + /* apply the inverse MixColumn transform to all round keys but the first and the last: */ + for (i = 1; i < Nr; i++) { + rk += 4; + rk[0] = + Td0[Te4[(rk[0] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[0] ) & 0xff] & 0xff]; + rk[1] = + Td0[Te4[(rk[1] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[1] ) & 0xff] & 0xff]; + rk[2] = + Td0[Te4[(rk[2] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[2] ) & 0xff] & 0xff]; + rk[3] = + Td0[Te4[(rk[3] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[3] ) & 0xff] & 0xff]; + } + return Nr; +} + +void rijndaelEncrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t pt[16], uint8_t ct[16]) { + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; +#ifndef FULL_UNROLL + int r; +#endif /* ?FULL_UNROLL */ + + /* + * map byte array block to cipher state + * and add initial round key: + */ + s0 = GETU32(pt ) ^ rk[0]; + s1 = GETU32(pt + 4) ^ rk[1]; + s2 = GETU32(pt + 8) ^ rk[2]; + s3 = GETU32(pt + 12) ^ rk[3]; +#ifdef FULL_UNROLL + /* round 1: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7]; + /* round 2: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11]; + /* round 3: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15]; + /* round 4: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19]; + /* round 5: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23]; + /* round 6: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27]; + /* round 7: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31]; + /* round 8: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35]; + /* round 9: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39]; + if (Nr > 10) { + /* round 10: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43]; + /* round 11: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47]; + if (Nr > 12) { + /* round 12: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51]; + /* round 13: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55]; + } + } + rk += Nr << 2; +#else /* !FULL_UNROLL */ + /* + * Nr - 1 full rounds: + */ + r = Nr >> 1; + for (;;) { + t0 = + Te0[(s0 >> 24) ] ^ + Te1[(s1 >> 16) & 0xff] ^ + Te2[(s2 >> 8) & 0xff] ^ + Te3[(s3 ) & 0xff] ^ + rk[4]; + t1 = + Te0[(s1 >> 24) ] ^ + Te1[(s2 >> 16) & 0xff] ^ + Te2[(s3 >> 8) & 0xff] ^ + Te3[(s0 ) & 0xff] ^ + rk[5]; + t2 = + Te0[(s2 >> 24) ] ^ + Te1[(s3 >> 16) & 0xff] ^ + Te2[(s0 >> 8) & 0xff] ^ + Te3[(s1 ) & 0xff] ^ + rk[6]; + t3 = + Te0[(s3 >> 24) ] ^ + Te1[(s0 >> 16) & 0xff] ^ + Te2[(s1 >> 8) & 0xff] ^ + Te3[(s2 ) & 0xff] ^ + rk[7]; + + rk += 8; + if (--r == 0) { + break; + } + + s0 = + Te0[(t0 >> 24) ] ^ + Te1[(t1 >> 16) & 0xff] ^ + Te2[(t2 >> 8) & 0xff] ^ + Te3[(t3 ) & 0xff] ^ + rk[0]; + s1 = + Te0[(t1 >> 24) ] ^ + Te1[(t2 >> 16) & 0xff] ^ + Te2[(t3 >> 8) & 0xff] ^ + Te3[(t0 ) & 0xff] ^ + rk[1]; + s2 = + Te0[(t2 >> 24) ] ^ + Te1[(t3 >> 16) & 0xff] ^ + Te2[(t0 >> 8) & 0xff] ^ + Te3[(t1 ) & 0xff] ^ + rk[2]; + s3 = + Te0[(t3 >> 24) ] ^ + Te1[(t0 >> 16) & 0xff] ^ + Te2[(t1 >> 8) & 0xff] ^ + Te3[(t2 ) & 0xff] ^ + rk[3]; + } +#endif /* ?FULL_UNROLL */ + /* + * apply last round and + * map cipher state to byte array block: + */ + s0 = + (Te4[(t0 >> 24) ] & 0xff000000) ^ + (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t3 ) & 0xff] & 0x000000ff) ^ + rk[0]; + PUTU32(ct , s0); + s1 = + (Te4[(t1 >> 24) ] & 0xff000000) ^ + (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t0 ) & 0xff] & 0x000000ff) ^ + rk[1]; + PUTU32(ct + 4, s1); + s2 = + (Te4[(t2 >> 24) ] & 0xff000000) ^ + (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t1 ) & 0xff] & 0x000000ff) ^ + rk[2]; + PUTU32(ct + 8, s2); + s3 = + (Te4[(t3 >> 24) ] & 0xff000000) ^ + (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t2 ) & 0xff] & 0x000000ff) ^ + rk[3]; + PUTU32(ct + 12, s3); +} + +void rijndaelDecrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t ct[16], uint8_t pt[16]) { + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; +#ifndef FULL_UNROLL + int r; +#endif /* ?FULL_UNROLL */ + + /* + * map byte array block to cipher state + * and add initial round key: + */ + s0 = GETU32(ct ) ^ rk[0]; + s1 = GETU32(ct + 4) ^ rk[1]; + s2 = GETU32(ct + 8) ^ rk[2]; + s3 = GETU32(ct + 12) ^ rk[3]; +#ifdef FULL_UNROLL + /* round 1: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7]; + /* round 2: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11]; + /* round 3: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15]; + /* round 4: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19]; + /* round 5: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23]; + /* round 6: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27]; + /* round 7: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31]; + /* round 8: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35]; + /* round 9: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39]; + if (Nr > 10) { + /* round 10: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43]; + /* round 11: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47]; + if (Nr > 12) { + /* round 12: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51]; + /* round 13: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55]; + } + } + rk += Nr << 2; +#else /* !FULL_UNROLL */ + /* + * Nr - 1 full rounds: + */ + r = Nr >> 1; + for (;;) { + t0 = + Td0[(s0 >> 24) ] ^ + Td1[(s3 >> 16) & 0xff] ^ + Td2[(s2 >> 8) & 0xff] ^ + Td3[(s1 ) & 0xff] ^ + rk[4]; + t1 = + Td0[(s1 >> 24) ] ^ + Td1[(s0 >> 16) & 0xff] ^ + Td2[(s3 >> 8) & 0xff] ^ + Td3[(s2 ) & 0xff] ^ + rk[5]; + t2 = + Td0[(s2 >> 24) ] ^ + Td1[(s1 >> 16) & 0xff] ^ + Td2[(s0 >> 8) & 0xff] ^ + Td3[(s3 ) & 0xff] ^ + rk[6]; + t3 = + Td0[(s3 >> 24) ] ^ + Td1[(s2 >> 16) & 0xff] ^ + Td2[(s1 >> 8) & 0xff] ^ + Td3[(s0 ) & 0xff] ^ + rk[7]; + + rk += 8; + if (--r == 0) { + break; + } + + s0 = + Td0[(t0 >> 24) ] ^ + Td1[(t3 >> 16) & 0xff] ^ + Td2[(t2 >> 8) & 0xff] ^ + Td3[(t1 ) & 0xff] ^ + rk[0]; + s1 = + Td0[(t1 >> 24) ] ^ + Td1[(t0 >> 16) & 0xff] ^ + Td2[(t3 >> 8) & 0xff] ^ + Td3[(t2 ) & 0xff] ^ + rk[1]; + s2 = + Td0[(t2 >> 24) ] ^ + Td1[(t1 >> 16) & 0xff] ^ + Td2[(t0 >> 8) & 0xff] ^ + Td3[(t3 ) & 0xff] ^ + rk[2]; + s3 = + Td0[(t3 >> 24) ] ^ + Td1[(t2 >> 16) & 0xff] ^ + Td2[(t1 >> 8) & 0xff] ^ + Td3[(t0 ) & 0xff] ^ + rk[3]; + } +#endif /* ?FULL_UNROLL */ + /* + * apply last round and + * map cipher state to byte array block: + */ + s0 = + (Td4[(t0 >> 24) ] & 0xff000000) ^ + (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t1 ) & 0xff] & 0x000000ff) ^ + rk[0]; + PUTU32(pt , s0); + s1 = + (Td4[(t1 >> 24) ] & 0xff000000) ^ + (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t2 ) & 0xff] & 0x000000ff) ^ + rk[1]; + PUTU32(pt + 4, s1); + s2 = + (Td4[(t2 >> 24) ] & 0xff000000) ^ + (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t3 ) & 0xff] & 0x000000ff) ^ + rk[2]; + PUTU32(pt + 8, s2); + s3 = + (Td4[(t3 >> 24) ] & 0xff000000) ^ + (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t0 ) & 0xff] & 0x000000ff) ^ + rk[3]; + PUTU32(pt + 12, s3); +} + +#ifdef INTERMEDIATE_VALUE_KAT + +void rijndaelEncryptRound(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, uint8_t block[16], int rounds) { + int r; + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; + + /* + * map byte array block to cipher state + * and add initial round key: + */ + s0 = GETU32(block ) ^ rk[0]; + s1 = GETU32(block + 4) ^ rk[1]; + s2 = GETU32(block + 8) ^ rk[2]; + s3 = GETU32(block + 12) ^ rk[3]; + rk += 4; + + /* + * Nr - 1 full rounds: + */ + for (r = (rounds < Nr ? rounds : Nr - 1); r > 0; r--) { + t0 = + Te0[(s0 >> 24) ] ^ + Te1[(s1 >> 16) & 0xff] ^ + Te2[(s2 >> 8) & 0xff] ^ + Te3[(s3 ) & 0xff] ^ + rk[0]; + t1 = + Te0[(s1 >> 24) ] ^ + Te1[(s2 >> 16) & 0xff] ^ + Te2[(s3 >> 8) & 0xff] ^ + Te3[(s0 ) & 0xff] ^ + rk[1]; + t2 = + Te0[(s2 >> 24) ] ^ + Te1[(s3 >> 16) & 0xff] ^ + Te2[(s0 >> 8) & 0xff] ^ + Te3[(s1 ) & 0xff] ^ + rk[2]; + t3 = + Te0[(s3 >> 24) ] ^ + Te1[(s0 >> 16) & 0xff] ^ + Te2[(s1 >> 8) & 0xff] ^ + Te3[(s2 ) & 0xff] ^ + rk[3]; + + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + rk += 4; + + } + + /* + * apply last round and + * map cipher state to byte array block: + */ + if (rounds == Nr) { + t0 = + (Te4[(s0 >> 24) ] & 0xff000000) ^ + (Te4[(s1 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(s2 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(s3 ) & 0xff] & 0x000000ff) ^ + rk[0]; + t1 = + (Te4[(s1 >> 24) ] & 0xff000000) ^ + (Te4[(s2 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(s3 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(s0 ) & 0xff] & 0x000000ff) ^ + rk[1]; + t2 = + (Te4[(s2 >> 24) ] & 0xff000000) ^ + (Te4[(s3 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(s0 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(s1 ) & 0xff] & 0x000000ff) ^ + rk[2]; + t3 = + (Te4[(s3 >> 24) ] & 0xff000000) ^ + (Te4[(s0 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(s1 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(s2 ) & 0xff] & 0x000000ff) ^ + rk[3]; + + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + + PUTU32(block , s0); + PUTU32(block + 4, s1); + PUTU32(block + 8, s2); + PUTU32(block + 12, s3); +} + +void rijndaelDecryptRound(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, uint8_t block[16], int rounds) { + int r; + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; + + /* + * map byte array block to cipher state + * and add initial round key: + */ + s0 = GETU32(block ) ^ rk[0]; + s1 = GETU32(block + 4) ^ rk[1]; + s2 = GETU32(block + 8) ^ rk[2]; + s3 = GETU32(block + 12) ^ rk[3]; + rk += 4; + + /* + * Nr - 1 full rounds: + */ + for (r = (rounds < Nr ? rounds : Nr) - 1; r > 0; r--) { + t0 = + Td0[(s0 >> 24) ] ^ + Td1[(s3 >> 16) & 0xff] ^ + Td2[(s2 >> 8) & 0xff] ^ + Td3[(s1 ) & 0xff] ^ + rk[0]; + t1 = + Td0[(s1 >> 24) ] ^ + Td1[(s0 >> 16) & 0xff] ^ + Td2[(s3 >> 8) & 0xff] ^ + Td3[(s2 ) & 0xff] ^ + rk[1]; + t2 = + Td0[(s2 >> 24) ] ^ + Td1[(s1 >> 16) & 0xff] ^ + Td2[(s0 >> 8) & 0xff] ^ + Td3[(s3 ) & 0xff] ^ + rk[2]; + t3 = + Td0[(s3 >> 24) ] ^ + Td1[(s2 >> 16) & 0xff] ^ + Td2[(s1 >> 8) & 0xff] ^ + Td3[(s0 ) & 0xff] ^ + rk[3]; + + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + rk += 4; + + } + + /* + * complete the last round and + * map cipher state to byte array block: + */ + t0 = + (Td4[(s0 >> 24) ] & 0xff000000) ^ + (Td4[(s3 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(s2 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(s1 ) & 0xff] & 0x000000ff); + t1 = + (Td4[(s1 >> 24) ] & 0xff000000) ^ + (Td4[(s0 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(s3 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(s2 ) & 0xff] & 0x000000ff); + t2 = + (Td4[(s2 >> 24) ] & 0xff000000) ^ + (Td4[(s1 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(s0 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(s3 ) & 0xff] & 0x000000ff); + t3 = + (Td4[(s3 >> 24) ] & 0xff000000) ^ + (Td4[(s2 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(s1 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(s0 ) & 0xff] & 0x000000ff); + + if (rounds == Nr) { + t0 ^= rk[0]; + t1 ^= rk[1]; + t2 ^= rk[2]; + t3 ^= rk[3]; + } + + PUTU32(block , t0); + PUTU32(block + 4, t1); + PUTU32(block + 8, t2); + PUTU32(block + 12, t3); +} + +#endif /* INTERMEDIATE_VALUE_KAT */ diff --git a/TESTU01/TestU01-1.2.3/testu01/rijndael-alg-fst.tex b/TESTU01/TestU01-1.2.3/testu01/rijndael-alg-fst.tex new file mode 100644 index 0000000..84de30e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/rijndael-alg-fst.tex @@ -0,0 +1,50 @@ +\code +/* Remarks for TestU01: + * The only changes I have made in the authors' code below is to rename the + * types u8, u32. I have also removed 3 unused defined constants. + * (R. Simard for TestU01) + * + *===========================================================================*/ + +/** + * rijndael-alg-fst.h + * + * @version 3.0 (December 2000) + * + * Optimised ANSI C code for the Rijndael cipher (now AES) + * + * @author Vincent Rijmen + * @author Antoon Bosselaers + * @author Paulo Barreto + * + * This code is hereby placed in the public domain. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __RIJNDAEL_ALG_FST_H +#define __RIJNDAEL_ALG_FST_H +#include "gdef.h" + + +int rijndaelKeySetupEnc(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits); +int rijndaelKeySetupDec(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits); +void rijndaelEncrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t pt[16], uint8_t ct[16]); +void rijndaelDecrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t ct[16], uint8_t pt[16]); + +#ifdef INTERMEDIATE_VALUE_KAT +void rijndaelEncryptRound(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, uint8_t block[16], int rounds); +void rijndaelDecryptRound(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, uint8_t block[16], int rounds); +#endif /* INTERMEDIATE_VALUE_KAT */ + +#endif /* __RIJNDAEL_ALG_FST_H */ +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/scatfig.tex b/TESTU01/TestU01-1.2.3/testu01/scatfig.tex new file mode 100644 index 0000000..4e8b0b8 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/scatfig.tex @@ -0,0 +1,744 @@ + +\def\fiverm {}% +\input prepictex.tex \input pictex.tex \input postpictex.tex +\begin{figure} \centering \beginpicture +\setcoordinatesystem units < 13.00cm, 13.00cm> +\setplotarea x from 0 to 1, y from 0 to 1 +\axis bottom + label $u_{n}$ + ticks withvalues 0 0.0005 / at 0.0 1.0 / / +\axis left + label \makebox[0pt]{$u_{n+1}$} + ticks withvalues 0 1 / at 0.0 1.0 / / +\axis top / \axis right / +\multiput {\bf .} at + 0.87616656 0.51374291 + 0.11597678 0.78083097 + 0.12949458 0.84721013 + 0.49743501 0.65398160 + 0.02880826 0.35278994 + 0.36784698 0.01763960 + 0.92335414 0.74545749 + 0.46445986 0.49205716 + 0.51628352 0.74653722 + 0.24238984 0.40158230 + 0.93364353 0.79598353 + 0.08661146 0.63663258 + 0.66445768 0.47414646 + 0.19320077 0.16003937 + 0.08088465 0.60851106 + 0.99648726 0.10457771 + 0.62489800 0.27988861 + 0.11073102 0.75507168 + 0.57751533 0.04721604 + 0.61171552 0.21515605 + 0.60461085 0.18026856 + 0.19184528 0.15338324 + 0.16107452 0.00228344 + 0.62273219 0.26925342 + 0.64412910 0.37432296 + 0.22435731 0.31303356 + 0.99223269 0.08368562 + 0.98968829 0.07119135 + 0.73929501 0.84163512 + 0.47844317 0.56072217 + 0.65606070 0.43291307 + 0.61156790 0.21443120 + 0.37375728 0.04666210 + 0.09055600 0.65600225 + 0.50857701 0.70869439 + 0.86687459 0.46811467 + 0.28609050 0.61617442 + 0.27551708 0.56425361 + 0.74290852 0.85937930 + 0.17820616 0.08640836 + 0.17825724 0.08665916 + 0.62686326 0.28953902 + 0.14487474 0.92273443 + 0.38602612 0.10690827 + 0.05471595 0.48000967 + 0.14407185 0.91879181 + 0.03972670 0.40640497 + 0.53357137 0.83142919 + 0.52924655 0.81019221 + 0.59009802 0.10900335 + 0.28860288 0.62851143 + 0.08690092 0.63805398 + 0.27487171 0.56108454 + 0.57883182 0.05368063 + 0.39915617 0.17138339 + 0.09413261 0.67356519 + 0.37652164 0.06023653 + 0.29994341 0.68419911 + 0.91990921 0.72854119 + 0.02997194 0.35850419 + 0.08407675 0.62418588 + 0.43636512 0.35409794 + 0.37548318 0.05513715 + 0.73483251 0.81972204 + 0.19419010 0.16489748 + 0.60147233 0.16485686 + 0.01720539 0.29581404 + 0.08823745 0.64461697 + 0.48748078 0.60510139 + 0.86456106 0.45675409 + 0.67775143 0.53942542 + 0.70269759 0.66192353 + 0.13954072 0.89654171 + 0.20003249 0.19358652 + 0.89359260 0.59931347 + 0.84102376 0.34117418 + 0.81969526 0.23644057 + 0.26669307 0.52092330 + 0.90737643 0.66699898 + 0.63398520 0.32451134 + 0.22585466 0.32038631 + 0.30444989 0.70632816 + 0.12759186 0.83786683 + 0.99191868 0.08214370 + 0.44054365 0.37461659 + 0.39275686 0.13995955 + 0.10560597 0.72990512 + 0.74428622 0.86614450 + 0.53182668 0.82286191 + 0.28773779 0.62426340 + 0.89001582 0.58174969 + 0.01179086 0.26922600 + 0.89834064 0.62262872 + 0.86213437 0.44483784 + 0.90561111 0.65833035 + 0.21362902 0.26035232 + 0.90840445 0.67204706 + 0.82604393 0.26761570 + 0.92157206 0.73670659 + 0.98374023 0.04198342 + 0.26385949 0.50700902 + 0.47454623 0.54158625 + 0.26442799 0.50980063 + 0.54685154 0.89664149 + 0.11259877 0.76424327 + 0.61745083 0.24331929 + 0.94866500 0.86974650 + 0.25202431 0.44889237 + 0.62107337 0.26110780 + 0.36180416 0.98796631 + 0.77704638 0.02701326 + 0.56685876 0.99488692 + 0.77480611 0.01601242 + 0.64442613 0.37578150 + 0.07495666 0.57940170 + 0.41085332 0.22882223 + 0.12045149 0.80280406 + 0.82429790 0.25904185 + 0.64051091 0.35655583 + 0.07043965 0.55722089 + 0.75077620 0.89801355 + 0.74655908 0.87730538 + 0.28722120 0.62172673 + 0.11549042 0.77844272 + 0.94684549 0.86081177 + 0.98708662 0.05841587 + 0.48683682 0.60193922 + 0.94552530 0.85432898 + 0.80918322 0.18482120 + 0.38653079 0.10938643 + 0.61179780 0.21556007 + 0.91028171 0.68126535 + 0.05593833 0.48601217 + 0.99877292 0.11580143 + 0.00279516 0.22505265 + 0.75539458 0.92069211 + 0.70194198 0.65821310 + 0.41491292 0.24875692 + 0.77726040 0.02806420 + 0.77716676 0.02760439 + 0.64874344 0.39698168 + 0.30009883 0.68496230 + 0.85781427 0.42362395 + 0.09644062 0.68489864 + 0.08154701 0.61176361 + 0.81303386 0.20372976 + 0.26151432 0.49549307 + 0.29662715 0.66791460 + 0.75045696 0.89644590 + 0.60447582 0.17960550 + 0.19728634 0.18010159 + 0.37535932 0.05452892 + 0.27148118 0.54443532 + 0.90616787 0.66106431 + 0.82363667 0.25579485 + 0.55395276 0.93151204 + 0.19314272 0.15975434 + 0.99180287 0.08157500 + 0.88276889 0.54616362 + 0.77458146 0.01490927 + 0.20753513 0.23042823 + 0.73393124 0.81529634 + 0.00356888 0.22885199 + 0.93115306 0.78375408 + 0.40719673 0.21086652 + 0.34124454 0.88700831 + 0.62692601 0.28984715 + 0.77909498 0.03707288 + 0.79528184 0.11655850 + 0.70223122 0.65963342 + 0.19267479 0.15745656 + 0.77382031 0.01117161 + 0.79323964 0.10653024 + 0.89710426 0.61655749 + 0.29725510 0.67099815 + 0.67214686 0.51190415 + 0.78231516 0.05288558 + 0.66296137 0.46679881 + 0.56575356 0.98945986 + 0.26228667 0.49928567 + 0.89273630 0.59510859 + 0.10159777 0.71022285 + 0.85696039 0.41943097 + 0.01482588 0.28412949 + 0.82870718 0.28069359 + 0.33661858 0.86429256 + 0.11373696 0.76983232 + 0.82882870 0.28129032 + 0.00223028 0.22227877 + 0.70576453 0.67698373 + 0.87275391 0.49698509 + 0.54999104 0.91205799 + 0.68390808 0.56965762 + 0.25100649 0.44389434 + 0.23462664 0.36346113 + 0.19603267 0.17394541 + 0.16699656 0.03136363 + 0.83878070 0.33015964 + 0.67487387 0.52529516 + 0.98880021 0.06683045 + 0.04947905 0.45429387 + 0.12490166 0.82465659 + 0.71563670 0.72546100 + 0.16766628 0.03465225 + 0.89078076 0.58550594 + 0.00199914 0.22114377 + 0.30624887 0.71516208 + 0.17187712 0.05532958 + 0.59866809 0.15108667 + 0.98830078 0.06437799 + 0.88111926 0.53806313 + 0.76762855 0.98076698 + 0.68209845 0.56077146 + 0.86134457 0.44095950 + 0.48641732 0.59987927 + 0.51246167 0.72777001 + 0.17924630 0.09151595 + 0.03807196 0.39827937 + 0.78107727 0.04680695 + 0.16777204 0.03517160 + 0.39286902 0.14051034 + 0.78267533 0.05465423 + 0.15335386 0.96437112 + 0.06133678 0.51252124 + 0.31268347 0.74675917 + 0.76680373 0.97671673 + 0.42442693 0.29547543 + 0.77533968 0.01863250 + 0.25221118 0.44981001 + 0.06482678 0.52965889 + 0.17478438 0.06960571 + 0.62478138 0.27931595 + 0.41675924 0.25782323 + 0.90506586 0.65565290 + 0.61081472 0.21073268 + 0.86331705 0.45064535 + 0.85081220 0.38924033 + 0.55212905 0.92255671 + 0.19429036 0.16538980 + 0.38615538 0.10754298 + 0.97395731 0.99394438 + 0.16351157 0.01425056 + 0.14675018 0.93194378 + 0.41923624 0.26998656 + 0.58281903 0.07325983 + 0.93518922 0.80357365 + 0.13618805 0.88007842 + 0.48141182 0.57529975 + 0.35742979 0.96648599 + 0.79213568 0.10110925 + 0.44308571 0.38709937 + 0.63113735 0.31052696 + 0.05164863 0.46494759 + 0.56403484 0.98102009 + 0.93787209 0.81674791 + 0.90609535 0.66070823 + 0.05282711 0.47073450 + 0.30705770 0.71913385 + 0.83679651 0.32041624 + 0.51150382 0.72306649 + 0.50284435 0.68054418 + 0.75382900 0.91300430 + 0.43498458 0.34731880 + 0.93751253 0.81498227 + 0.83265186 0.30006398 + 0.43151049 0.33025927 + 0.95209230 0.88657623 + 0.10817377 0.74251429 + 0.59727033 0.14422295 + 0.49089568 0.62187026 + 0.02086084 0.31376415 + 0.07422298 0.57579892 + 0.19676166 0.17752515 + 0.40535406 0.20181813 + 0.30942834 0.73077488 + 0.93216785 0.78873720 + 0.58540637 0.08596499 + 0.44294935 0.38642980 + 0.47849988 0.56100064 + 0.65853141 0.44504550 + 0.83712333 0.32202113 + 0.76047287 0.94562904 + 0.10839717 0.74361128 + 0.34753307 0.91788814 + 0.65774144 0.44116636 + 0.94950457 0.87386921 + 0.84848158 0.37779581 + 0.91073980 0.68351479 + 0.19699673 0.17867944 + 0.75062298 0.89726115 + 0.99361416 0.09046934 + 0.90523238 0.65647059 + 0.26322025 0.50387002 + 0.38677630 0.11059200 + 0.08541019 0.63073375 + 0.23210146 0.35106123 + 0.90971229 0.67846920 + 0.47542342 0.54589368 + 0.30259247 0.69720731 + 0.06151974 0.51341967 + 0.91012974 0.68051908 + 0.38336228 0.09382747 + 0.16295296 0.01150751 + 0.21562621 0.27015951 + 0.21077999 0.24636214 + 0.92873247 0.77186782 + 0.86784391 0.47287451 + 0.52217407 0.77546279 + 0.27591635 0.56621424 + 0.78247192 0.05365535 + 0.90204119 0.64080028 + 0.98006932 0.02395738 + 0.29881510 0.67865855 + 0.40146603 0.18272593 + 0.55016339 0.91290431 + 0.65962143 0.45039803 + 0.16394965 0.01640176 + 0.45697057 0.45528099 + 0.21577089 0.27086995 + 0.98893196 0.06747739 + 0.33926801 0.87730256 + 0.36499953 0.00365718 + 0.29084660 0.63952921 + 0.80379346 0.15835479 + 0.47660588 0.55170019 + 0.09679155 0.68662190 + 0.58498340 0.08388797 + 0.32983864 0.83099963 + 0.84158318 0.34392119 + 0.97278967 0.98821070 + 0.13917200 0.89473112 + 0.35690876 0.96392745 + 0.23692728 0.37475839 + 0.31843373 0.77499584 + 0.99869090 0.11539868 + 0.65021598 0.40421259 + 0.83671054 0.31999410 + 0.52200497 0.77463242 + 0.61770383 0.24456166 + 0.41085625 0.22883662 + 0.96155696 0.93305244 + 0.94148262 0.83447740 + 0.63095241 0.30961880 + 0.38220080 0.08812401 + 0.10094337 0.70700942 + 0.45070770 0.42452715 + 0.97864254 0.01695118 + 0.55660054 0.94451396 + 0.62563362 0.28350089 + 0.30719762 0.71982089 + 0.99256022 0.08529397 + 0.63666998 0.33769494 + 0.15726809 0.98359193 + 0.73616720 0.82627603 + 0.32282387 0.79655362 + 0.97605487 0.00424443 + 0.93210502 0.78842868 + 0.93318707 0.79374211 + 0.65049798 0.40559733 + 0.32225910 0.79378033 + 0.06858995 0.54813793 + 0.17951973 0.09285863 + 0.00310806 0.22658914 + 0.35355088 0.94743858 + 0.42324398 0.28966659 + 0.40009591 0.17599797 + 0.95469634 0.89936339 + 0.59020615 0.10953429 + 0.71298364 0.71243317 + 0.91469092 0.70291675 + 0.11895856 0.79547303 + 0.28983996 0.63458613 + 0.80775884 0.17782678 + 0.05579862 0.48532611 + 0.45490839 0.44515464 + 0.88026086 0.53384796 + 0.32735675 0.81881230 + 0.76958229 0.99036084 + 0.09068579 0.65663958 + 0.76266291 0.95638323 + 0.71412570 0.71804127 + 0.08162688 0.61215578 + 0.99152886 0.08022946 + 0.28459713 0.60884118 + 0.46659535 0.50254348 + 0.60140403 0.16452149 + 0.97929759 0.02016783 + 0.59937226 0.15454450 + 0.11215597 0.76206887 + 0.10791842 0.74126038 + 0.17503957 0.07085882 + 0.93068549 0.78145808 + 0.65559554 0.43062889 + 0.36024118 0.98029134 + 0.89827752 0.62231875 + 0.22427339 0.31262148 + 0.68027785 0.55183139 + 0.08566742 0.63199687 + 0.07071240 0.55856026 + 0.95476122 0.89968195 + 0.82204876 0.24799744 + 0.09691318 0.68721917 + 0.18105067 0.10037633 + 0.72935181 0.79280904 + 0.67867416 0.54395645 + 0.93692028 0.81207405 + 0.79627047 0.12141312 + 0.50545091 0.69334368 + 0.32626180 0.81343559 + 0.27764861 0.57472051 + 0.06820475 0.54624642 + 0.06082856 0.51002562 + 0.55790472 0.95091815 + 0.69231503 0.61093997 + 0.94959689 0.87432255 + 0.08103977 0.60927279 + 0.62007088 0.25618506 + 0.12477788 0.82404879 + 0.39131793 0.13289371 + 0.83135350 0.29368837 + 0.69345871 0.61655601 + 0.37734122 0.06426107 + 0.15074005 0.95153602 + 0.99981703 0.12092851 + 0.27701195 0.57159418 + 0.59169831 0.11686158 + 0.63238177 0.31663768 + 0.07112296 0.56057629 + 0.35866200 0.97253677 + 0.55563689 0.93978193 + 0.29535536 0.66166949 + 0.39834238 0.16738727 + 0.83483302 0.31077456 + 0.78000669 0.04154985 + 0.70088099 0.65300309 + 0.13531572 0.87579484 + 0.99989140 0.12129373 + 0.79816684 0.13072527 + 0.79464968 0.11345425 + 0.45676922 0.45429227 + 0.52924353 0.81017734 + 0.18452311 0.11742776 + 0.67990449 0.54999801 + 0.82780669 0.27627176 + 0.02814900 0.34955264 + 0.71130246 0.70417774 + 0.04298047 0.42238258 + 0.99399599 0.09234432 + 0.49073103 0.62106171 + 0.07100025 0.55997372 + 0.92454399 0.75130026 + 0.71814738 0.73778968 + 0.15552794 0.97504693 + 0.60866674 0.20018504 + 0.63075532 0.30865102 + 0.03436883 0.38009514 + 0.50574078 0.69476711 + 0.75979365 0.94229373 + 0.98553944 0.05081844 + 0.60377155 0.17614719 + 0.63104329 0.31006508 + 0.36628621 0.00997542 + 0.70754295 0.68571666 + 0.79829553 0.13135719 + 0.33355618 0.84925462 + 0.36809450 0.01885506 + 0.76324597 0.95924632 + 0.46696895 0.50437802 + 0.59529295 0.13451303 + 0.24268827 0.40304775 + 0.47723387 0.55478391 + 0.30377191 0.70299896 + 0.55934520 0.95799161 + 0.21216347 0.25315573 + 0.80919234 0.18486597 + 0.78480551 0.06511446 + 0.48583743 0.59703168 + 0.26549137 0.51502236 + 0.89735035 0.61776588 + 0.71471196 0.72092007 + 0.19401895 0.16405705 + 0.41922104 0.26991193 + 0.66102147 0.45727294 + 0.78702416 0.07600916 + 0.64441559 0.37572975 + 0.83346544 0.30405904 + 0.02000843 0.30957839 + 0.51349253 0.73283208 + 0.02377384 0.32806846 + 0.92070470 0.73244742 + 0.97641214 0.00599880 + 0.67876769 0.54441573 + 0.64739691 0.39036952 + 0.51355955 0.73316118 + 0.65275215 0.41666644 + 0.79232944 0.10206070 + 0.57466266 0.03320799 + 0.79893825 0.13451329 + 0.92412280 0.74923200 + 0.26800037 0.52734282 + 0.67468014 0.52434382 + 0.83334187 0.30345228 + 0.36745211 0.01570056 + 0.80802176 0.17911784 + 0.11470773 0.77459929 + 0.68859764 0.59268571 + 0.86353302 0.45170589 + 0.67925392 0.54680335 + 0.84332644 0.35248148 + 0.33861526 0.87409721 + 0.90930168 0.67645290 + 0.88323356 0.54844542 + 0.95119367 0.88216352 + 0.89085534 0.58587212 + 0.91341981 0.69667496 + 0.52161694 0.77272697 + 0.93344395 0.79500354 + 0.20721640 0.22886312 + 0.07615611 0.58529156 + 0.19112062 0.14982482 + 0.99545296 0.09949877 + 0.38789940 0.11610703 + 0.28428183 0.60729294 + 0.10792039 0.74127006 + 0.31066557 0.73685028 + 0.59442494 0.13025067 + 0.96122445 0.93141966 + 0.69709972 0.63443520 + 0.03482008 0.38231098 + 0.11989085 0.80005103 + 0.25506917 0.46384416 + 0.62507215 0.28074379 + 0.63195943 0.31456380 + 0.88280603 0.54634600 + 0.08054726 0.60685433 + 0.79273317 0.10404325 + 0.54432960 0.88425748 + 0.17106847 0.05135874 + 0.13971115 0.89737860 + 0.74033211 0.84672782 + 0.79040073 0.09258980 + 0.88342714 0.54939598 + 0.07967626 0.60257730 + 0.51571719 0.74375627 + 0.90184370 0.63983046 + 0.50051910 0.66912603 + 0.73151138 0.80341363 + 0.41119729 0.23051131 + 0.42261257 0.28656600 + 0.55883198 0.95547144 + 0.15034009 0.94957203 + 0.09583395 0.68191962 + 0.78561813 0.06910483 + 0.72450168 0.76899250 + 0.26149144 0.49538074 + 0.59001217 0.10858174 + 0.84340889 0.35288633 + 0.57710652 0.04520857 + 0.11469954 0.77455912 + 0.03773576 0.39662845 + 0.14220677 0.90963335 + 0.93777331 0.81626285 + 0.08517358 0.62957186 + 0.46409018 0.49024185 + 0.01738618 0.29670186 + 0.20991658 0.24212235 + 0.28860884 0.62854071 + 0.66301205 0.46704767 + 0.40758109 0.21275396 + 0.33829318 0.87251565 + 0.30600341 0.71395677 + 0.57943339 0.05663467 + 0.09948295 0.69983802 + 0.83565622 0.31481685 + 0.20095477 0.19811537 + 0.29790880 0.67420815 + 0.75645643 0.92590629 + 0.63559595 0.33242092 + 0.37459596 0.05078048 + 0.49641084 0.64895245 + 0.71550087 0.72479400 + 0.62054225 0.25849972 + 0.35744151 0.96654356 + 0.45345973 0.43804102 + 0.52545507 0.79157411 + 0.26592605 0.51715685 + 0.47272179 0.53262734 + 0.43008993 0.32328362 + 0.10285541 0.71639848 + 0.72493883 0.77113910 + 0.33552370 0.85891613 + 0.69889168 0.64323460 + 0.87056131 0.48621832 + 0.07501607 0.57969340 + 0.31332458 0.74990737 + 0.38341806 0.09410139 + 0.99152309 0.08020114 + 0.58244207 0.07140878 + 0.84936603 0.38213888 + 0.31376231 0.75205684 + 0.12979132 0.84866726 + 0.73284010 0.80993830 + 0.22990715 0.34028607 + 0.88036297 0.53434935 + 0.62648769 0.28769482 + 0.10896828 0.74641574 + 0.33021253 0.83283562 + 0.83224864 0.29808397 + 0.46604872 0.49985924 + 0.43883675 0.36623485 + 0.50236174 0.67817431 + 0.42933887 0.31959553 + 0.96417546 0.94591058 + 0.95573780 0.90447748 + 0.78133378 0.04806652 + 0.93394271 0.79745267 + 0.13550819 0.87673995 + 0.05747969 0.49358103 + 0.28345193 0.60321769 + 0.46073978 0.47378969 + 0.42552309 0.30085812 + 0.64755833 0.39116219 + 0.73440831 0.81763901 + 0.82973021 0.28571718 + 0.47139846 0.52612912 + 0.67039789 0.50331584 + 0.56765977 0.99882030 + 0.44719800 0.40729277 + 0.84513242 0.36134974 + 0.22925024 0.33706029 + 0.82403565 0.25775407 + 0.21596035 0.27180030 + 0.98208411 0.03385104 + 0.78998154 0.09053135 + 0.51592206 0.74476229 + 0.69441408 0.62124735 + 0.15188452 0.95715595 + 0.32811556 0.82253848 + 0.37295961 0.04274515 + 0.85676924 0.41849233 + 0.60257371 0.17026518 + 0.12016127 0.80137894 + 0.75870664 0.93695593 + 0.46148853 0.47746645 + 0.04946444 0.45422213 + 0.56433489 0.98249349 + 0.09491687 0.67741628 + 0.62163138 0.26384791 + 0.85816149 0.42532901 + 0.41931267 0.27036189 + 0.39600030 0.15588646 + 0.08169485 0.61248955 + 0.84136604 0.34285495 + 0.93005864 0.77837993 + 0.02500689 0.33412331 + 0.89769605 0.61946344 + 0.56151527 0.96864774 + 0.94796439 0.86630615 + 0.03530731 0.38470353 + 0.97672205 0.00752062 + 0.39642188 0.15795662 + 0.27854417 0.57911815 + 0.47591836 0.54832410 + 0.97099060 0.97937635 + 0.42808718 0.31344909 + 0.43368644 0.34094428 + 0.97908234 0.01911081 + 0.28834971 0.62726823 + 0.83296502 0.30160172 + 0.02434801 0.33088793 + 0.26518421 0.51351404 + 0.75066930 0.89748862 + 0.66979974 0.50037860 + 0.81726878 0.22452536 + 0.93589458 0.80703735 + 0.78654944 0.07367802 + 0.99672742 0.10575698 + 0.30252211 0.69686184 + 0.12030378 0.80207874 + 0.70828630 0.68936688 + 0.24976132 0.43777995 + 0.84067978 0.33948504 + 0.72412495 0.76714258 + 0.07998279 0.60408247 + 0.41964898 0.27201333 + 0.10692779 0.73639591 + 0.69582565 0.62817887 + 0.37556329 0.05553054 + 0.13158975 0.85749845 + 0.87948548 0.53004045 + 0.92268117 0.74215289 + 0.27313517 0.55255727 + 0.65152330 0.41063218 + 0.74889110 0.88875672 + 0.53089501 0.81828694 + 0.48245304 0.58041267 + 0.84226956 0.34729166 + 0.03284273 0.37260124 + 0.87849060 0.52515512 + 0.99696339 0.10691573 + 0.11120898 0.75741871 + 0.66776863 0.49040484 + 0.51475537 0.73903323 + 0.41582471 0.25323425 + 0.23456056 0.36313662 + 0.50977254 0.71456505 + 0.11646293 0.78321821 + 0.34617193 0.91120425 + 0.22834263 0.33260348 + 0.69872324 0.64240747 + 0.80626615 0.17049692 +/ \endpicture + +\def\bornes#1#2#3 {$\null\ \ \ #2 < u_{n+#1} < #3$\\ } +\def\bornez#1#2 {$\null\ \ \ #1 < u_{n} < #2$\\ } +\def\stat#1#2 { +Number of vectors generated: \hbox to 1in {\hfil #1.}\\ +Number of points plotted: \hbox to 1in {\hfil #2.}\\ } + +\bigskip\noindent {\bf Generator:} +ufile\_CreateReadText: excel.pts + +Hypercube in 2 dimensions.\\ + Over = TRUE\\ +\bornez { 0}{ 0.0005} +\stat { 1500000}{ 711} +Total CPU time : 5.98 seconds. +\caption{ Scatter plot for the Microsoft Excel 97 generator + \label {dispers}} +\end {figure} diff --git a/TESTU01/TestU01-1.2.3/testu01/scatter.c b/TESTU01/TestU01-1.2.3/testu01/scatter.c new file mode 100644 index 0000000..3820003 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/scatter.c @@ -0,0 +1,742 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: scatter.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "chrono.h" +#include "mystr.h" + +#include "scatter.h" +#include "unif01.h" + +#include +#include + + + +#define NUM_CHAR 100 /* Maximum length of file names */ + +#define LEN 250 /* Maximum length of strings */ + + + +/*---------------------------- extern variables ---------------------------*/ + +long scatter_N; +int scatter_t; +lebool scatter_Over; +int scatter_x; +int scatter_y; +double scatter_L [scatter_MAXDIM + 1]; +double scatter_H [scatter_MAXDIM + 1]; +lebool scatter_Lacunary; +long scatter_LacI [scatter_MAXDIM + 1]; +double scatter_Width = -1.0; +double scatter_Height = -1.0; +scatter_OutputType scatter_Output; +long scatter_Nkept; + + + + + +/*---------------------------- module variables ---------------------------*/ + +static double V [scatter_MAXDIM + 1]; /* A point */ + +static char Nin [NUM_CHAR + 1] = {0}; /* Name of data file */ + +static char Nout1[NUM_CHAR + 1] = { 0 }; +static char Nout2[NUM_CHAR + 1] = { 0 }; +static char Nout3[NUM_CHAR + 1] = { 0 }; /* Names of results file */ + +static char S[NUM_CHAR + 1] = { 0 }; +static char str[NUM_CHAR + 1] = { 0 }; /* Working strings */ + +static char Title[LEN + 1] = { 0 }; + +static int precision; /* Number of decimals for the points */ + +static chrono_Chrono *chro; /* Timer */ + + + + + + +/*-------------------------------- functions ------------------------------*/ + +static unif01_Gen * scatter_ReadData ( + unif01_Gen *gen, + char *F /* Input file name without its extension .dat */ + ) +/* + * Reads the data in file .dat for scatter_PlotUnif, according to the + * format of the figure in the documentation scatter.tex. + */ +{ + FILE *fin; /* Input file */ + int i, j; + double xa, xb; + unif01_Gen *genL; + + strncpy (Nin, F, (size_t) NUM_CHAR - 5); + /* Add the extension .dat to input data file */ + strcat (Nin, ".dat"); + fin = util_Fopen (Nin, "r"); + + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %ld", &scatter_N); + util_Assert (j > 0, "scatter_ReadData: on reading scatter_N"); + + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %d", &scatter_t); + util_Assert (j > 0, "scatter_ReadData: on reading scatter_t"); + util_Assert (scatter_t <= scatter_MAXDIM, + "scatter_ReadData: scatter_t > scatter_MAXDIM"); + util_Assert (scatter_t > 1, "scatter_ReadData: scatter_t < 2"); + + fgets (S, NUM_CHAR, fin); + util_ReadBool (S, &scatter_Over); + + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %d %d", &scatter_x, &scatter_y); + util_Assert (j > 0, + "scatter_ReadData: on reading scatter_x or scatter_y"); + util_Assert (scatter_x <= scatter_t, + "scatter_ReadData: scatter_x > scatter_t"); + util_Assert (scatter_y <= scatter_t, + "scatter_ReadData: scatter_y > scatter_t"); + + /* By default, bounds are [0, 1] */ + for (i = 1; i < scatter_t; i++) { + scatter_L[i] = 0.0; + scatter_H[i] = 1.0; + } + + do { + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %d %lf %lf", &i, &xa, &xb); + util_Assert (j > 0, + "scatter_ReadData: on reading r, scatter_L[r], scatter_H[r]"); + util_Assert (i <= scatter_t, + "scatter_ReadData: r > scatter_t"); + scatter_L[i] = xa; + scatter_H[i] = xb; + util_Assert (scatter_L[i] >= 0.0, + "scatter_ReadData: scatter_L[r] < 0"); + util_Assert (scatter_H[i] <= 1.0, + "scatter_ReadData: scatter_H[r] > 1"); + util_Assert (scatter_L[i] < scatter_H[i], + "scatter_ReadData: scatter_H[r] <= scatter_L[r]"); + } while (i != scatter_t); + + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %lf %lf", &scatter_Width, &scatter_Height); + util_Assert (j > 0, + "scatter_ReadData: on reading scatter_Width, scatter_Height"); + + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %12s", str); + if (!strcmp (str, "latex")) + scatter_Output = scatter_latex; + else if (!strcmp (str, "gnu_term")) + scatter_Output = scatter_gnu_term; + else if (!strcmp (str, "gnu_ps")) + scatter_Output = scatter_gnu_ps; + else { + util_Error ("scatter_ReadData: on reading scatter_Output"); + } + + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %d", &precision); + util_Assert (j > 0, "scatter_ReadData: on reading Precision"); + + fgets (S, NUM_CHAR, fin); + util_ReadBool (S, &scatter_Lacunary); + + if (scatter_Lacunary) { + for (i = 0; i < scatter_t; i++) { + fgets (S, NUM_CHAR, fin); + j = sscanf (S, " %ld", &scatter_LacI[i]); + util_Assert (j > 0, + "scatter_ReadData: on reading scatter_LacI[]"); + } + genL = unif01_CreateLacGen (gen, scatter_t, scatter_LacI); + } else + genL = gen; + + util_Fclose (fin); + return genL; +} + + +/*=========================================================================*/ + +static unif01_Gen * scatter_ReadDataInterac ( + unif01_Gen *gen + ) +/* + * Reads the data for scatter_PlotUnifInterac, interactively on the terminal + */ +{ + char rep; + int i, j; + lebool erreur; + char format[12]; + unif01_Gen *genL; + + do { + erreur = FALSE; + printf ("What kind of output?\n" + "latex: (l)\n" + "gnu_ps: (p)\n" + "gnu_term: (t)\n"); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %1s", str); + + rep = str[0]; + switch ((unsigned) rep) { + case 'l': + case 'L': + scatter_Output = scatter_latex; + break; + case 'p': + case 'P': + scatter_Output = scatter_gnu_ps; + break; + case 't': + case 'T': + scatter_Output = scatter_gnu_term; + break; + default: + printf ("Please, answer with one letter amongst l, p, t.\n"); + erreur = TRUE; + break; + } + } while (erreur); + + sprintf (S, "%1d", NUM_CHAR - 5); + strcpy (format, " %"); + strcat (format, S); + strcat (format, "s"); + printf ("Name of output file (without extension): "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, format, Nin); + util_Assert (j > 0, "scatter_ReadDataInterac"); + + printf ("Number of points: "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %ld", &scatter_N); + util_Assert (j > 0, "scatter_ReadDataInterac"); + + printf ("Number of dimensions: "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %d", &scatter_t); + util_Assert (j > 0, "scatter_ReadDataInterac"); + + printf ("Overlapping:\n TRUE (t)\n FALSE (f)\n "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %1s", str); + if (str[0] == 't') + scatter_Over = TRUE; + else + scatter_Over = FALSE; + + printf ("Which dimension for the x-axis: "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %d", &scatter_x); + util_Assert (j > 0, "scatter_ReadDataInterac"); + + printf ("Which dimension for the y-axis: "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %d", &scatter_y); + util_Assert (j > 0, "scatter_ReadDataInterac"); + + for (i = 1; i <= scatter_t; i++) { + printf ("Lower bound for x%1d: ", i); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %lf", &scatter_L[i]); + util_Assert (j > 0, "scatter_ReadDataInterac"); + + printf ("Upper bound for x%1d: ", i); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %lf", &scatter_H[i]); + util_Assert (j > 0, "scatter_ReadDataInterac"); + util_Assert (scatter_L[i] >= 0.0, + "scatter_ReadDataInterac: scatter_L[r] < 0"); + util_Assert (scatter_H[i] <= 1.0, + "scatter_ReadDataInterac: scatter_H[r] > 1"); + util_Assert (scatter_L[i] < scatter_H[i], + "scatter_ReadDataInterac: scatter_H[r] >= scatter_L[r]"); + } + scatter_Height = 13.0; + scatter_Width = 13.0; + + + printf ("Lacunary:\n TRUE (t)\n FALSE (f)\n "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %1s", str); + if (str[0] == 't') + scatter_Lacunary = TRUE; + else + scatter_Lacunary = FALSE; + + if (scatter_Lacunary) { + for (i = 0; i < scatter_t; i++) { + printf ("Lacunary index %1d: ", i + 1); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %ld", &scatter_LacI[i]); + util_Assert (j > 0, + "scatter_ReadDataInterac: on reading scatter_LacI[]"); + } + genL = unif01_CreateLacGen (gen, scatter_t, scatter_LacI); + } else + genL = gen; + + printf ("Number of decimals of precision : "); + fgets (S, NUM_CHAR, stdin); + j = sscanf (S, " %d", &precision); + util_Assert (j > 0, "scatter_ReadDataInterac: on reading Precision"); + return genL; +} + + +/*=========================================================================*/ + +static lebool Retenu (void) +/* + * Returns TRUE if the point with coordinates V[1],..., V[scatter_t] is + * inside the bounds to be plotted; FALSE otherwise. + */ +{ + int j; + for (j = 1; j <= scatter_t; j++) { + if (V[j] < scatter_L[j] || V[j] > scatter_H[j]) + return FALSE; + } + return TRUE; +} + + +/*=========================================================================*/ + +static void HeadGraphTex ( + FILE *f /* Latex output file */ + ) +/* + * Write the Latex commands before the points to be plotted. + */ +{ + fprintf (f, "\\documentclass [11pt]{article}\n" + "\\begin {document}\n\n" + "\\def\\fiverm {}%%\n" + "\\input prepictex.tex \\input pictex.tex " + "\\input postpictex.tex\n"); + fprintf (f, "\\begin{figure} \\centering \\beginpicture\n" + "\\setcoordinatesystem units <%6.2fcm,%6.2fcm>\n", + scatter_Width, scatter_Height); + fprintf (f, "\\setplotarea x from 0 to 1, y from 0 to 1\n" + "\\axis bottom\n" + " label $u_{n}$\n" + " ticks withvalues %8.4g %8.4g ", + scatter_L[scatter_x], scatter_H[scatter_x]); + fprintf (f, " / at 0.0 1.0 / / \n" + "\\axis left\n" + " label \\makebox[0pt]{$u_{n+%1d}$}\n", scatter_y - scatter_x); + fprintf (f, " ticks withvalues %8.4g %8.4g ", + scatter_L[scatter_y], scatter_H[scatter_y]); + fprintf (f, " / at 0.0 1.0 / / \n" + "\\axis top / \\axis right /\n" + "\\multiput {\\bf .} at\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void BottomGraphTex ( + unif01_Gen *gen, + FILE *f /* Latex output file */ + ) +/* + * Write the Latex commands after the points have been written. + */ +{ + const double Epsilon = 1.0E-32; + int j; + char *p; + size_t len; + + fprintf (f, "/ \\endpicture\n\n"); + /* fprintf (f, "\\parindent=0pt\n"); */ + fprintf (f, + "\\def\\bornes#1#2#3 {$\\null\\ \\ \\ #2 < u_{n+#1} < #3$\\\\ }\n" + "\\def\\bornez#1#2 {$\\null\\ \\ \\ #1 < u_{n} < #2$\\\\ }\n" + "\\def\\stat#1#2 {\n" + "Number of vectors generated: \\hbox to 1in {\\hfil #1.}\\\\\n" + "Number of points plotted: \\hbox to 1in {\\hfil #2.}\\\\ }\n\n" + "\\bigskip\\noindent {\\bf Generator:} \n"); + + if ((p = strstr (gen->name, "Read"))) { + /* This generator is from ufile. Write complete generator's name */ + strncpy (Title, gen->name, (size_t) LEN); + p = strchr (gen->name, '\n'); + if (p) + mystr_Subst (Title, "\n", "\n\n"); + } else { + /* Remove initial seeds from gen name, but write filter if any */ + p = strchr (gen->name, ':'); + len = p - gen->name; + strncpy (Title, gen->name, (size_t) len); + Title[len] = '\0'; + p = strchr (gen->name, '\n'); + if (p) { + strcat (Title, "\n"); + strcat (Title, p); + } + } + + /* Replace the _ in the generator name by \_ for Latex */ + mystr_Subst (Title, "_", "\\_"); + mystr_Subst (Title, "01_", "01\\_"); + fprintf (f, Title); + + fprintf (f, "\n\nHypercube in %1d dimensions.\\\\\n", scatter_t); + fprintf (f, " Over = "); + if (scatter_Over) + fprintf (f, "TRUE"); + else + fprintf (f, "FALSE"); + + fprintf (f, "\\\\\n"); + for (j = 1; j <= scatter_t; j++) { + if (scatter_L[j] > Epsilon || 1.0 - scatter_H[j] > Epsilon) { + if (j == 1) { + fprintf (f, "\\bornez {%9.4G}{%9.4G}\n", + scatter_L[j], scatter_H[j]); + } else { + fprintf (f, "\\bornes {%1d}{%9.4G}{%9.4G}\n", + j - 1, scatter_L[j], scatter_H[j]); + } + } + } + /* + if (scatter_Lacunary) { + fprintf (f, "Lacunary indices = \\{"); + for (j = 0; j < scatter_t; j++) { + if (j < scatter_t - 1) + fprintf (f, " %ld,", scatter_LacI[j]); + else + fprintf (f, " %ld", scatter_LacI[j]); + } + fprintf (f, " \\}\\\\\n"); + } + */ + fprintf (f, "\\stat {%10ld}{%10ld}\n", scatter_N, scatter_Nkept); + fprintf (f, "Total CPU time : %12.2f", chrono_Val (chro, chrono_sec)); + fprintf (f, " seconds.\n" + "\\end {figure}\n" + "\\end {document}\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void PutPointsTex ( + unif01_Gen *gen, + FILE *f, /* Latex output file */ + int Prec /* Write the points with Prec decimals */ + ) +{ + int j; + long Npoints; /* Number of points */ + + sprintf (S, "%%%1d", Prec + 5); + sprintf (str, ".%1df", Prec); + strcat (S, str); + for (j = 1; j <= scatter_t; j++) + V[j] = unif01_StripD (gen, 0); + Npoints = 0; + scatter_Nkept = 0; + while (Npoints < scatter_N) { + ++Npoints; + if (Retenu ()) { + ++scatter_Nkept; + fprintf (f, S, (V[scatter_x] - scatter_L[scatter_x]) / + (scatter_H[scatter_x] - scatter_L[scatter_x])); + fprintf (f, S, (V[scatter_y] - scatter_L[scatter_y]) / + (scatter_H[scatter_y] - scatter_L[scatter_y])); + fprintf (f, "\n"); + } + if (scatter_Over) { + for (j = 1; j < scatter_t; j++) + V[j] = V[j + 1]; + V[scatter_t] = unif01_StripD (gen, 0); + } else { + for (j = 1; j <= scatter_t; j++) + V[j] = unif01_StripD (gen, 0); + } + } +} + + +/*=========================================================================*/ + +static void HeadGraphGnu ( + unif01_Gen *gen, + char *F /* File name without extension */ + ) +/* + * Creates the following output file names for gnuplot: + * .gnu contains the gnuplot commands to create the plot, + * .gnu.points contains the points to be plotted, + * .ps contains the plot figure in PostScript format. + * Write gnuplot commands for plot. + */ +{ + FILE *f; + char *p, *q; + size_t len; + + /* File of commands for gnuplot */ + strcpy (Nout1, F); + strcat (Nout1, ".gnu"); + f = util_Fopen (Nout1, "w"); + + /* File of points for gnuplot */ + strcpy (Nout2, Nout1); + strcat (Nout2, ".points"); + + fprintf (f, "set nokey\n" "set title \""); + + if ((p = strstr (gen->name, "Read"))) { + /* This generator is from ufile. Write complete generator's name */ + strncpy (Title, gen->name, (size_t) LEN); + } else { + /* Remove initial seeds from gen name */ + p = strchr (gen->name, ':'); + len = p - gen->name; + strncpy (Title, gen->name, (size_t) len); + Title[len] = '\0'; + } + /* Search for '\n' in title. If it is there, it will not be understood by + gnuplot. Process it specially to print the generator name */ + p = strchr (gen->name, '\n'); + if (p) { + strncat (Title, p, (size_t) LEN); + p = strchr (Title, '\n'); + q = Title; + while (p) { + *p = '\0'; + len = strlen (q); + if (len > 0) { + fprintf (f, q); + fprintf (f, ";\\n"); + } + p++; + q = p; + p = strchr (q, '\n'); + } + fprintf (f, q); + } else + fprintf (f, Title); + + fprintf (f, ";\\n N = %1ld", scatter_N); + fprintf (f, "; t = %1d", scatter_t); + if (scatter_Over) + fprintf (f, "; Over"); + /* + if (scatter_Lacunary) { + int j; + fprintf (f, "; LacI = {"); + for (j = 0; j < scatter_t; j++) { + fprintf (f, " %ld", scatter_LacI[j]); + } + fprintf (f, " }"); + } + */ + fprintf (f, "\"\nset xlabel \"u(n)\"\n" + "set ylabel \"u(n+%1d)\"\n", scatter_y - scatter_x); + fprintf (f, "set xrange [%4.2g:%4.2g]\n", + scatter_L[scatter_x], scatter_H[scatter_x]); + fprintf (f, "set yrange [%4.2g:%4.2g]\n", + scatter_L[scatter_y], scatter_H[scatter_y]); + fprintf (f, "set size square\n"); + if (scatter_Output == scatter_gnu_ps) { + /* Set the size of the figure */ + /* fprintf (f, "set size %6.2f, %6.2f\n", Width/25.4, Height/17.8); */ + strcpy (Nout3, F); + strcat (Nout3, ".ps"); + /* Postscript file for figure */ + fprintf (f, "set output \""); + fprintf (f, Nout3); + fprintf (f, "\"\nset term postscript"); + } else if (scatter_Output == scatter_gnu_term) { + fprintf (f, "set output\n"); + fprintf (f, "set term x11"); + } + fprintf (f, "\nplot \""); + fprintf (f, Nout2); + fprintf (f, "\"\n"); + if (scatter_Output == scatter_gnu_term) { + fprintf (f, "pause -1 \"Hit return to continue \"\n"); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void PutPointsGnu ( + unif01_Gen *gen, + FILE *f, /* Output file for the points in gnuplot format */ + int Prec /* Write the points with Prec decimals */ + ) +{ + int j; + long Npoints; /* Number of points */ + + sprintf (S, "%%%1d", Prec + 5); + sprintf (str, ".%1df", Prec); + strcat (S, str); + for (j = 1; j <= scatter_t; j++) + V[j] = unif01_StripD (gen, 0); + Npoints = 0; + scatter_Nkept = 0; + while (Npoints < scatter_N) { + ++Npoints; + if (Retenu ()) { + ++scatter_Nkept; + fprintf (f, S, V[scatter_x]); + fprintf (f, S, V[scatter_y]); + fprintf (f, "\n"); + } + if (scatter_Over) { + for (j = 1; j < scatter_t; j++) + V[j] = V[j + 1]; + V[scatter_t] = unif01_StripD (gen, 0); + } else { + for (j = 1; j <= scatter_t; j++) + V[j] = unif01_StripD (gen, 0); + } + } +} + + +/*=========================================================================*/ + +static void Plot (unif01_Gen * gen, char *Nin, int Prec) +{ + FILE *f; + + if (scatter_Output == scatter_latex) { + strcpy (Nout1, Nin); + strcat (Nout1, ".tex"); + f = util_Fopen (Nout1, "w"); + HeadGraphTex (f); + PutPointsTex (gen, f, Prec); + BottomGraphTex (gen, f); + util_Fclose (f); + + } else if (scatter_Output == scatter_gnu_ps || + scatter_Output == scatter_gnu_term) { + HeadGraphGnu (gen, Nin); + f = util_Fopen (Nout2, "w"); + PutPointsGnu (gen, f, Prec); + util_Fclose (f); + + } else + util_Error ("Plot: scatter_Output has invalid value"); +} + + +/*=========================================================================*/ + +void scatter_PlotUnif (unif01_Gen *gen, char *Nin) +{ + unif01_Gen *genL; + genL = scatter_ReadData (gen, Nin); + chro = chrono_Create (); + Plot (genL, Nin, precision); + chrono_Delete (chro); +} + + +/*=========================================================================*/ + +void scatter_PlotUnifInterac (unif01_Gen *gen) +{ + unif01_Gen *genL; + genL = scatter_ReadDataInterac (gen); + chro = chrono_Create (); + Plot (genL, Nin, precision); + chrono_Delete (chro); +} + + +/*=========================================================================*/ + +void scatter_PlotUnif1 (unif01_Gen * gen, long N, int Dim, lebool Over, + int Proj[2], double Lower[], double Upper[], scatter_OutputType Output, + int Prec, lebool Lac, long LacI[], char *Name) +{ + int j; + unif01_Gen *genL; + chro = chrono_Create (); + scatter_N = N; + scatter_t = Dim; + scatter_Over = Over; + scatter_x = Proj[0]; + scatter_y = Proj[1]; + for (j = 1; j <= scatter_t; j++) { + scatter_L[j] = Lower[j - 1]; + scatter_H[j] = Upper[j - 1]; + util_Assert (scatter_L[j] >= 0.0, "scatter_PlotUnif1: Lower[r] < 0"); + util_Assert (scatter_H[j] <= 1.0, "scatter_PlotUnif1: Upper[r] > 1"); + util_Assert (scatter_L[j] < scatter_H[j], + "scatter_PlotUnif1: Upper[r] <= Lower[r]"); + } + if (scatter_Width <= 0.0) + scatter_Width = 13.0; /* cm */ + if (scatter_Height <= 0.0) + scatter_Height = 13.0; /* cm */ + scatter_Output = Output; + scatter_Lacunary = Lac; + if (scatter_Lacunary) { + for (j = 0; j < scatter_t; j++) + scatter_LacI[j] = LacI[j]; + genL = unif01_CreateLacGen (gen, scatter_t, scatter_LacI); + } else + genL = gen; + strncpy (Nin, Name, (size_t) NUM_CHAR - 5); + Plot (genL, Nin, Prec); + chrono_Delete (chro); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/scatter.tex b/TESTU01/TestU01-1.2.3/testu01/scatter.tex new file mode 100644 index 0000000..5a61452 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/scatter.tex @@ -0,0 +1,320 @@ +\defmodule {scatter} + +% \newcommand{\Fsc}{$<\!\!F\!\!>$} + +This module is useful for producing 2-dimensionnal scatter\index{scatter plot} +plots of $N$ points obtained from a uniform random number generator. +The $N$ points are generated in the $t$-dimensional unit hypercube $[0,1]^t$, +either by taking vectors of $t$ successive output values from the generator, +or by taking $t$ {\em non-successive\/} values at pre-specified lags. +The vectors can overlap or not. +Thus, in the case of successive values for overlapping vectors, +for instance, $N+t-1$ uniforms are needed. + +A rectangular box $R$ is defined in $[0,1]^t$ by defining bounds $L_i < H_i$ +for each coordinate $i$, for $1\le i\le t$. +All the points falling outside that box are discarded. +Two coordinate numbers are selected in $\{1,\dots,t\}$, say +$r_x$ and $r_y$, then all the points are projected on the two-dimensional +subspace determined by these two coordinates, +and these projected points are shown on the plot. + +The plots can appear directly on the computer screen (using {\it Gnuplot}) +or can be stored in a file, in a format chosen by the user +(currently, the format is either for \LaTeX\ or for {\it Gnuplot}). +Three different functions are available for producing the scatter plots: +{\tt scatter\_PlotUnif} reads the data in a file, +{\tt scatter\_PlotUnif1} receives all the data in its parameters, and +{\tt scatter\_PlotUnifInterac} gets the data interactively from the user. + + +\begin{figure} +\begin{center} +\fbox { +\begin {tabular}{l@{\extracolsep{10mm}}l} +\\ + $N$ & Number of points \\ + $t$ & Dimension of vectors\\ + {\it Over} & {\tt TRUE} if we want overlapping vectors, + {\tt FALSE} otherwise\\ + $r_x$ $r_y$ & Components to be plotted\\ + $r_1$ $L_{r_1}$ $H_{r_1}$ & Axis number and bounds for $x_{r_1}$\\ + \vdots\ \ \ \vdots & \\ + $t$ $L_t$ $H_t$ & Dimension and bounds for $x_t$\\ + {\it Width Height}\qquad & Physical dimensions of plot (in cm)\\ + {\it Output} & Output format: {\tt latex, gnu\_ps, gnu\_term }\\ + {\it Precision} & Number of decimal digits for the points\\ + {\it Lacunary} & {\tt TRUE} if we want lacunary indices, + {\tt FALSE} otherwise\\ + $i_1$ & First lacunary index\\ + \vdots & \vdots \\ + $i_t$ & $t$th lacunary index\\ +\\ +\end {tabular} +} +\end{center} +\caption { General format of the data file for {\tt scatter}.} +\label{formatdon} +\end{figure} + + +Figure~\ref{formatdon} gives the general format of the data file +needed by {\tt scatter\_PlotUnif}. +This file must have the extension ``{\tt .dat}''. +% When the data is read in a file by {\tt scatter\_ReadData}, +The right side (in the figure and in the file) contains optional +(but useful) comments that are disregarded by the program. +The values of the variables on the left must appear in the file, +in the same format. +There should be no blank line. +The name of the file is passed as an argument to the function, +without the ``{\tt .dat}'' extention. + + +The first line contains an integer $N$, the total number +of points to generate. +The second line gives the dimension $t$ of the hypercube. +In the third line, {\it Over} is a boolean indicating whether +the vector coordinates overlap ({\tt TRUE\/}) or not ({\tt FALSE\/}). +The next line gives the two coordinate numbers $r_x$ and $r_y$ +selected for the plot. +Each of the following lines contains a coordinate number $r_i$ (an integer +from 1 to $t$), and the lower and upper boundaries $L_{r_i}$ and $H_{r_i}$ +(real) of the box $R$ along the coordinate $x_{r_i}$. +One must have $0 \le L_i < H_i \le 1$. +For the coordinates that do not appear here, the boundaries are set to +0.0 and 1.0 by default. The last coordinate $(r_i=t)$ must always appear. +On the next line, {\it Width} and {\it Height} (real) +specify the physical dimensions (in {\it cm}) +of the rectangle for the plot (on paper). +The variable {\em Output\/} specifies the format of the output file. +The values currently allowed are {\tt latex, gnu\_ps, gnu\_term}, +and they correspond to creating a file for \LaTeX, creating a file +for {\it Gnuplot}, and showing the plot on the screen using {\it Gnuplot}, +respectively. The variable {\em Precision\/} specifies the number of +decimal digits to be printed for the points coordinates. +If the boolean variable {\it Lacunary\/} is {\tt FALSE}, +the vectors are constructed from successive output values of the +generator, and all the lines that follow are discarded. +If {\it Lacunary\/} is {\tt TRUE}, the $t$ lines that follow must give the +values of the $t$ lacunary indices $i_1 < \cdots < i_t$ (integers). +The points used in the plot are $\{(u_{i_1+n},\dots,u_{i_t+n}),\; +n=0,\dots,N-1\}$ in the overlapping case. + +As an illustration, suppose the data file is called {\tt dice.dat}. +If the output format is {\tt latex}, the output file + {\tt dice.tex} will be created by the program. + The command {\tt latex dice.tex} can then produce a file +{\tt dice.dvi} that contains the plot. +If the output format is {\tt gnu\_ps} or {\tt gnu\_term}, +the two files {\tt dice.gnu} and {\tt dice.gnu.points} are +created. The file {\tt dice.gnu} contains a set of gnuplot +commands to plot the points, which are kept in {\tt dice.gnu.points}. +The command {\tt gnuplot dice.gnu} can then produce the scatter plot +either on the terminal (if the output format was {\tt gnu\_term}) or +in a PostScript file (if the output format was {\tt gnu\_ps}). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\paragraph* {An example.} \ +% +Figure \ref{proggraph} gives an example of a small program that creates a +scatter plot of numbers produced by the random number generator +{\tt RAND()} of {Microsoft Excel 1997}. +A long sequence of numbers was previously generated by {Excel} and +saved in the ASCII file {\tt excel.pts}. +In the program, the instruction +{\tt gen = ufile\_CreateReadText ("excel.pts")} +says that the generator {\tt gen} will now simply reads its +numbers from that file. +Then, the instruction {\tt scatter\_PlotUnif (gen, "excel")} +calls a function that plots the points after reading the data related +to the plot in file {\tt excel.dat}. +Figure \ref{excel.dat} show this data file. + +The program will generate $N =$ 1.5 million points $(u_i, u_{i+1})$, +with overlapping, and show those whose first coordinate is between +0 and 0.0005. The output will be in the \LaTeX\ file {\tt excel.tex}. +Figure \ref{dispers} shows the scatter plot created by \LaTeX. + +The values produced by this generator obey the linear recurrence +$u_{i} = (9821.0\, u_{i-1} + 0.211327) \bmod 1$, where the numbers +$u_i$ are represented with 15 decimal digits of precision. +This linear relationship shows up very well in the graph: +All the points are on equidistant parallel lines with slope 9821. +This is obviously a bad generator. + + +\setbox1=\vbox {\hsize = 6.2in +\smallc +\verbatiminput{../examples/scat.c} +} + +\begin{figure}[ht] \centering \myboxit{\box1} +\caption{ Example of a program to create a scatter plot. +\label{proggraph} } +\end{figure} + + +\setbox2=\vbox {\hsize = 6.2in +\smallc +\verbatiminput{../examples/excel.dat} +} + +\begin{figure}[ht] \centering \myboxit{\box2} +\caption{The data file {\tt excel.dat}. \label{excel.dat} } +\end{figure} + + +%%%%%%%%%%%%%% +\input scatfig.tex %%% Graphique pour le generator du VAX. + + +\setbox3=\vbox {\hsize = 6.2in +\smallc +\verbatiminput{../examples/scat2.c} +} + +\begin{figure}[ht] \centering \myboxit{\box3} +\caption{Example, with lacunary indices, for creating a scatter plot.} + \label{proggraph2} +\end{figure} + +Figure \ref{proggraph2} shows another example using the +random number generator in Microsoft VisualBasic. The example +shows how to plot a scatter diagram without reading any data file. +Here, the parameters are passed directly to the function +{\tt scatter\_PlotUnif1}. +We use the hypercube in 3 dimensions, and the + plotting procedure is called for coordinates $x_1$ and $x_{3}$. + Since the Lacunary flag is TRUE, +the procedure will not use every random number generated, but will +use only those selected by the lacunary indices \{1, 2, 6\} +(see the documentation in {\tt unif01\_CreateLacGen}). +The results will be written in file {\tt bone.tex}. + +%%% \newpage %%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\vspace{10mm} +\bigskip +\hrule +\code +\hide +/* scatter.h for ANSI C */ +#ifndef SCATTER_H +#define SCATTER_H +\endhide +#include "gdef.h" +#include "unif01.h" +\endcode + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Types} +\code + +typedef enum { + scatter_latex, /* Latex format */ + scatter_gnu_ps, /* gnuplot format for Postscript file */ + scatter_gnu_term /* Interactive gnuplot format */ + } scatter_OutputType; +\endcode + \tab + Possible formats for the output files containing the plots. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Constant} +\code + +#define scatter_MAXDIM 64 +\endcode + \tab + Maximal number of dimensions. + \endtab + +\ifdetailed %%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Variables} +\code + +extern long scatter_N; /* Number of points generated */ +extern long scatter_Nkept; /* Number of points kept for plot */ +extern int scatter_t; /* Dimension of points */ +extern lebool scatter_Over; /* = TRUE: overlapping points */ +extern int scatter_x; +extern int scatter_y; /* The 2 coordinates to plot */ +extern double scatter_L [scatter_MAXDIM + 1]; +extern double scatter_H [scatter_MAXDIM + 1]; + /* Lower and upper bounds for coordinates + of points to plot */ +\endcode +\code +extern lebool scatter_Lacunary; /* = TRUE: lacunary case */ +extern long scatter_LacI [scatter_MAXDIM + 1]; /* Lacunary indices */ +extern double scatter_Width; +extern double scatter_Height; /* Physical dimensions (in cm) of plot */ +extern scatter_OutputType scatter_Output; /* Kind of output */ +\endcode + +\fi %%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The plotting functions} + +\code + +void scatter_PlotUnif (unif01_Gen *gen, char *F); +\endcode + \tab Creates a scatter plot, using the generator + {\tt gen} and the parameters $N, t, \ldots$ given in file + {\tt F.dat}, in the format specified in Figure~\ref{formatdon}. + (The data file must have the extension {\tt .dat}, but + the argument {\tt F} must be the file name without the extension.) + The results are written in file {\tt F.tex} or {\tt F.gnu}, + depending on the value of the field {\tt scatter\_Output} in the + data file. + For example, the instruction {\tt scatter\_PlotUnif (gen, "dice")} + will read the data in file {\tt dice.dat} and plot the figure using the + parameters in this file. + \endtab +\code + + +void scatter_PlotUnif1 (unif01_Gen *gen, long N, int t, lebool Over, + int Proj[2], double Lower[], double Upper[], scatter_OutputType Output, + int Prec, lebool Lac, long LacI[], char *Name); +\endcode + \tab + Similar to {\tt scatter\_PlotUnif}, except that the data are + passed as arguments to the function instead of being read in a file. + Here, {\tt N} is the number of points to generate, + {\tt t} is the dimension, + {\tt Proj[0..1]} are the two values of the coordinates to be projected, + {\tt Lower[0..(t-1)]} gives the lower bounds of the values to be considered, + {\tt Upper[0..(t-1)]} gives the upper bounds of the values to be considered, + {\tt Over} is {\tt TRUE} iff the coordinates of the points overlap, + {\tt Lac} is {\tt TRUE} iff we consider lacunary values of the generator, + {\tt LacI[0..(t-1)]} gives the {\tt t} lacunary indices, + {\tt Name} is the name (without extension) of the output file, and + {\tt Prec} is the number of decimal digits required for each written value. + The constraints on these values are as explained earlier. + \endtab +\code + + +void scatter_PlotUnifInterac (unif01_Gen *gen); +\endcode + \tab Similar to {\tt scatter\_PlotUnif}, except that the data are + given interactively on the terminal. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/scomp.c b/TESTU01/TestU01-1.2.3/testu01/scomp.c new file mode 100644 index 0000000..3503cba --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/scomp.c @@ -0,0 +1,642 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: scomp.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "chrono.h" +#include "num.h" +#include "tables.h" + +#include "scomp.h" +#include "sres.h" +#include "swrite.h" +#include "unif01.h" + +#include "fbar.h" +#include "wdist.h" +#include "gofw.h" +#include "gofs.h" +#include "statcoll.h" + +#include +#include +#include + + +#define LENGTH 100 + +/* Empirical Mean for Lempel-Ziv test for 2^3 <= n <= 2^28. Obtained by + simulation with N = 1000 */ +static const double LZMu[] = { + 0.0, 0.0, 0.0, 4.44, 7.64, + 12.5, 20.8, 34.8, 58.9, 101.1, + 176.0, 310.0, 551.9, 992.3, 1799., + 3286.2, 6041.5, 11171.5, 20761.8, 38760.4, + 72654., 136677., 257949., 488257., 926658., + 1762965., 3361490., 6422497., 12293930. +}; + +/* Empirical Standard Deviation for Lempel-Ziv test for 2^3 <= n <= 2^28 */ +static const double LZSigma[] = { + 0.0, 0.0, 0.0, 0.49, 0.51, + 0.62, 0.75, 0.78, 0.86, 0.94, + 1.03, 1.19, 1.43, 1.68, 2.09, + 2.46, 3.36, 4.2, 5.4, 6.8, + 9.1, 10.9, 14.7, 19.1, 25.2, + 33.5, 44.546, 58.194, 75.513 +}; + + + +/*--------------------------------- Types ---------------------------------*/ + +/* Bit trie used in Lempel-Ziv test. If left != NULL, this means a 0 bit. + If right != NULL, this means a 1 bit. The word is the sequence obtained + by following the tree until a NULL pointer is met. */ + +struct BitTrie_t { + struct BitTrie_t *left; + struct BitTrie_t *right; +}; +typedef struct BitTrie_t BitTrie_t; + + + + +/*-------------------------------- Functions ------------------------------*/ + +static void DeleteBitTrie (BitTrie_t *tree) +{ + if (tree == NULL) + return; + DeleteBitTrie (tree->left); + DeleteBitTrie (tree->right); + util_Free (tree); +} + + +/*=========================================================================*/ + + +static void InitRes ( + scomp_Res *res, /* Results holder */ + long N, /* Number of replications */ + int jmax, /* Max class index for size of jumps */ + int tmax /* Max class index for linear complexity */ +) +/* + * Initializes the scomp_Res structure + */ +{ + sres_InitBasic (res->JumpNum, N, + "scomp_LinearComp: Number of Jumps"); + sres_InitChi2 (res->JumpSize, N, jmax, + "scomp_LinearComp: Size of Jumps"); + sres_InitChi2 (res->LinComp, N, tmax, + "scomp_LinearComp: Linear Complexity"); +} + + +/*-------------------------------------------------------------------------*/ + +scomp_Res * scomp_CreateRes (void) +{ + scomp_Res *res; + res = util_Malloc (sizeof (scomp_Res)); + res->JumpNum = sres_CreateBasic (); + res->JumpSize = sres_CreateChi2 (); + res->LinComp = sres_CreateChi2 (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void scomp_DeleteRes (scomp_Res *res) +{ + if (res == NULL) + return; + sres_DeleteBasic (res->JumpNum); + sres_DeleteChi2 (res->JumpSize); + sres_DeleteChi2 (res->LinComp); + util_Free (res); +} + + +/*=========================================================================*/ + +static void WriteDataJumps (unif01_Gen *gen, char *TestName, long N, long n, + int r, int s, double muComp, double mu, double sigma) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d\n", s); + if (swrite_Parameters) { + printf ("\n muComp = "); + num_WriteD (muComp, 12, 4, 2); + printf ("\n Mu = "); + num_WriteD (mu, 12, 4, 2); + printf ("\n Sigma = "); + num_WriteD (sigma, 12, 4, 2); + } + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void BerlekampMassey ( + scomp_Res *res, + long n, /* Number of bits */ + double *pComp, /* Linear complexity */ + double *pNumJ, /* Number of jumps */ + int *Bits, + int *Polyb, + int *Polyc, + int *PolycOld + ) +/* + * Berlekamp-Massey algorithm to calculate the linear complexity. + */ +{ + int b; + long Loc; + long i; + long m; + long k; + long L; /* Linear complexity */ + long NumJ; /* Number of jumps */ + sres_Chi2 *resl = res->JumpSize; + + for (k = 0; k <= resl->jmax; k++) + resl->Count[k] = 0; + + Polyc[0] = 1; + Polyb[0] = 1; + L = 0; + NumJ = 0; + k = 0; + m = -1; + + while (k < n) { + /* Return the value of the current polynomial to see if it can + generate the next bit */ + b = 0; + for (i = 1; i <= L; i++) + /* b ^= Polyc[i] * Bits[k + 1 - i]; */ + b = (b + Polyc[i] * Bits[k + 1 - i]) & 1; + + if (Bits[k + 1] != b) { + /* Update c(x)_old and c(x) */ + for (i = 0; i <= L; i++) + PolycOld[i] = Polyc[i]; + + for (i = 0; i <= L; i++) { + if (Polyb[i] == 1) + Polyc[k - m + i] = (++Polyc[k - m + i]) & 1; + } + if (2 * L <= k) { + L = k + 1 - L; + NumJ++; + Loc = labs (k + 1 - 2 * L); + if (Loc <= resl->jmax) + ++resl->Count[Loc]; + else + ++resl->Count[resl->jmax]; + /* Update B */ + for (i = 0; i <= L; i++) + Polyb[i] = PolycOld[i]; + m = k; + } + } + ++k; + } + *pNumJ = NumJ; + *pComp = L; +} + + +/*=========================================================================*/ + +void scomp_LinearComp (unif01_Gen *gen, scomp_Res *res, + long N, long n, int r, int s) +{ + const double epsilon = 1.0E-10; + const int tt = 1 - 0.5 * num_Log2 (3 * epsilon); /* Dimension */ + const long K0 = n/s; + long i, Seq; + int j, k; + int M0; + double NumJ; /* Number of Jumps */ + double sigma, mu; /* Parameters of number of jumps */ + double comp; /* Linear complexity */ + double muComp; /* Mean of linear complexity */ + unsigned long Nombre; /* Random number */ + int Parite; + double *Prob; + long *Loca; + long tmin, tmax, NbClasses; + double X2; + double temp; + int *Bits; /* 4 Arrays of bits */ + int *Polyb; + int *Polyc; + int *PolycOld; + double Param[1]; + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "scomp_LinearComp test"; + sres_Basic *resJN; + sres_Chi2 *resJL; + sres_Chi2 *resLC; + lebool JL_OK = TRUE; /* If TRUE do the JL test, otherwise not */ + lebool LC_OK = FALSE; /* If TRUE do the LC test, otherwise not */ + + Timer = chrono_Create (); + n = K0 * s; + Parite = n & 1; + if (n >= DBL_MAX_EXP) + temp = 0.0; + else + temp = pow (2.0, -(double) n); + + mu = n / 4.0 + (4 + Parite) / 12.0 - temp / 3.0; + sigma = n / 8.0 - (2 - Parite)/(9.0 - Parite) + n * temp / 6.0 + + (6 + Parite) * temp / 18.0 - temp * temp / 9.0; + sigma = sqrt (sigma); + muComp = n / 2.0 + (4 + Parite) / 18.0; + M0 = num_Log2 (mu / gofs_MinExpected); + if (M0 < 2) { + /* 0 degree of freedom for the chi2, do not do the test JL. */ + JL_OK = FALSE; + } + + if (swrite_Basic) + WriteDataJumps (gen, TestName, N, n, r, s, muComp, mu, sigma); + + /* util_Assert (M0 > 1, "scomp_LinearComp: n*s is too small"); */ + util_Assert (M0 <= num_MaxTwoExp, "scomp_LinearComp: M0 > num_MaxTwoExp"); + + Prob = util_Calloc (1 + (size_t) tt, sizeof (double)); + Bits = util_Calloc ((size_t) n + 1, sizeof (int)); + Polyb = util_Calloc ((size_t) n + 1, sizeof (int)); + Polyc = util_Calloc ((size_t) n + 1, sizeof (int)); + PolycOld = util_Calloc ((size_t) n + 1, sizeof (int)); + + if (res == NULL) { + localRes = TRUE; + res = scomp_CreateRes (); + } + M0 = util_Max (M0, 1); + InitRes (res, N, M0, tt); + resJN = res->JumpNum; + resJL = res->JumpSize; + resLC = res->LinComp; + Loca = resLC->Loc; + + if (N > 2.0 * gofs_MinExpected) { + /* Compute the expected probabilities for the linear complexity. */ + /* We put in Prob[k] the probabilities for i = k and i = -k of */ + /* the statistic defined in the NIST document 800-22, p. 86. */ + temp = Prob[0] = 0.5; + for (k = 1; k < tt; k++) { + Prob[k] = 1.5 * pow (4.0, -(double) k); + temp += Prob[k]; + } + Prob[tt] = 1.0 - temp; + for (k = 0; k <= tt; k++) { + resLC->Count[k] = 0; + resLC->NbExp[k] = N * Prob[k]; + } + tmin = 0; + tmax = tt; + if (swrite_Classes) { + printf ("Classes for the linear complexity:\n"); + gofs_WriteClasses (resLC->NbExp, Loca, tmin, tmax, 0); + } + gofs_MergeClasses (resLC->NbExp, Loca, &tmin, &tmax, &NbClasses); + resLC->jmax = tmax; + resLC->jmin = tmin; + resLC->degFree = NbClasses - 1; + if (NbClasses < 2) { + /* 0 degree of freedom for the chi2, do not do the test LC. */ + LC_OK = FALSE; + } else + LC_OK = TRUE; + } + + statcoll_SetDesc (resJN->sVal1, + "The number of jumps: the N statistic values (a standard normal):"); + sprintf (str, "The jumps size: the N statistic values (a ChiSquare" + " with %1d degrees of freedom):", M0 - 1); + statcoll_SetDesc (resJL->sVal1, str); + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i < K0; i++) { + Nombre = unif01_StripB (gen, r, s); + for (j = s; j >= 1; j--) { + Bits[s * i + j] = Nombre & 1; + Nombre >>= 1; + } + } + + BerlekampMassey (res, n, &comp, &NumJ, Bits, Polyb, Polyc, PolycOld); + + /* Value of the statistic for the linear complexity */ + if (LC_OK) { + comp = comp - muComp; + if (Parite) + comp = -comp; + comp += 2.0 / 9.0; + /* comp is now an integer: truncate correctly and avoid off-by-1 + error because of small floating-point inaccuracies. */ + if (comp >= 0.0) + k = comp + 0.5; + else + k = comp - 0.5; + if (k < 0) + k = -k; + if (k >= tt) + ++resLC->Count[Loca[tt]]; + else + ++resLC->Count[Loca[k]]; + } + + /* Value of the normal statistic for the number of jumps */ + statcoll_AddObs (resJN->sVal1, (NumJ - mu) / sigma); + + /* Value of the statistic for the size of the jumps */ + if (JL_OK) { + for (k = 1; k < M0; k++) { + resJL->NbExp[k] = NumJ / num_TwoExp[k]; + resJL->Loc[k] = k; + } + resJL->NbExp[M0] = NumJ / num_TwoExp[M0 - 1]; + resJL->Loc[M0] = M0; + resJL->jmax = M0; + resJL->jmin = 1; + resJL->degFree = M0 - 1; + + X2 = gofs_Chi2 (resJL->NbExp, resJL->Count, 1, M0); + statcoll_AddObs (resJL->sVal1, X2); + if (swrite_Classes) { + printf ("\n\nClasses for the size of the jumps:\n"); + gofs_WriteClasses (resJL->NbExp, (long *) NULL, 1, M0, 0); + } + if (swrite_Counters) + tables_WriteTabL (resJL->Count, 1, M0, 5, 10, + "Size of the jumps: observed numbers"); + } + } + + gofw_ActiveTests2 (resJN->sVal1->V, resJN->pVal1->V, N, wdist_Normal, + (double *) NULL, resJN->sVal2, resJN->pVal2); + resJN->pVal1->NObs = N; + sres_GetNormalSumStat (resJN); + + if (JL_OK) { + Param[0] = M0 - 1; + gofw_ActiveTests2 (resJL->sVal1->V, resJL->pVal1->V, N, + wdist_ChiSquare, Param, resJL->sVal2, resJL->pVal2); + resJL->pVal1->NObs = N; + sres_GetChi2SumStat (resJL); + } + + if (LC_OK) { + X2 = gofs_Chi2 (resLC->NbExp, resLC->Count, tmin, tmax); + resLC->sVal2[gofw_Mean] = X2; + resLC->pVal2[gofw_Mean] = fbar_ChiSquare2 (NbClasses - 1, 8, X2); + } + + if (swrite_Basic) { + if (JL_OK) { + printf ("\n-----------------------------------------------\n"); + if (N == 1) { + printf ("Number of degrees of freedom : %4ld\n", + resJL->degFree); + printf ("Chi2 statistic for size of jumps :"); + gofw_Writep2 (resJL->sVal2[gofw_Mean], resJL->pVal2[gofw_Mean]); + } else { + printf ("Test results for the size of jumps:\n"); + gofw_WriteActiveTests0 (N, resJL->sVal2, resJL->pVal2); + swrite_Chi2SumTest (N, resJL); + } + if (swrite_Collectors) + statcoll_Write (resJL->sVal1, 5, 14, 4, 3); + } + + printf ("\n-----------------------------------------------\n"); + if (N == 1) { + printf ("Normal statistic for number of jumps :"); + gofw_Writep2 (resJN->sVal2[gofw_Mean], resJN->pVal2[gofw_Mean]); + } else { + printf ("Test results for the number of jumps:\n"); + gofw_WriteActiveTests0 (N, resJN->sVal2, resJN->pVal2); + swrite_NormalSumTest (N, resJN); + } + if (swrite_Collectors) + statcoll_Write (resJN->sVal1, 5, 14, 4, 3); + + if (LC_OK) { + printf ("\n-----------------------------------------------\n"); + printf ("Test results for the linear complexity:\n\n"); + printf ("Number of degrees of freedom : %4ld\n", + resLC->degFree); + printf ("Chi2 statistic on the N replications :"); + gofw_Writep2 (resLC->sVal2[gofw_Mean], resLC->pVal2[gofw_Mean]); + if (swrite_Classes) + gofs_WriteClasses (resLC->NbExp, Loca, tmin, tmax, NbClasses); + if (swrite_Counters) + tables_WriteTabL (resLC->Count, tmin, tmax, 5, 10, + "Linear Complexity: observed numbers"); + } + + printf ("\n\n"); + swrite_Final (gen, Timer); + } + + util_Free (Prob); + util_Free (Bits); + util_Free (Polyb); + util_Free (Polyc); + util_Free (PolycOld); + if (localRes) + scomp_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataLZ ( + unif01_Gen *gen, /* generator */ + char *Test, /* Test name */ + long N, /* Number of replications */ + int k, /* Sample size n = 2^k */ + int r, /* r first bits of each random number dropped */ + int s /* s bits of each random number used */ +) +{ + long n; + n = num_TwoExp[k]; + swrite_Head (gen, Test, N, n, r); + printf (", s = %4d, k = %4d\n\n", s, k); +} + + +/*-------------------------------------------------------------------------*/ + +static long LZ78 (unif01_Gen * gen, long n, int r, int s) +/* + * The parameters are the same as in scomp_LempelZiv. The trie contains + * a left (right) branch if a word with a 0 (1) bit after the prefix has + * been seen before. We descend one level in the trie with each bit until + * a leaf is met. Add a branch for a new word, and restart at root. + */ +{ + const unsigned long kMAX = 1UL << (s - 1); + unsigned long Y, k; + long i; /* Count the number of bits overall */ + long W; /* Count the number of words */ + lebool done = FALSE; /* Start a new word */ + BitTrie_t *trie, *root; + + W = i = 0; + trie = root = util_Malloc (sizeof (BitTrie_t)); + trie->left = trie->right = NULL; + Y = unif01_StripB (gen, r, s); + k = kMAX; + + while (i < n) { + /* Start a new word: match it as far as possible in the trie */ + done = FALSE; + trie = root; + while (!done) { + if ((Y & k) == 0) { /* Bit 0 */ + if (trie->left) { + /* We have seen it before: descend in branch */ + trie = trie->left; + } else { + /* A leaf: this is a new word */ + W++; + done = TRUE; + trie->left = util_Malloc (sizeof (BitTrie_t)); + trie = trie->left; + trie->left = trie->right = NULL; + } + + } else { /* Bit 1 */ + if (trie->right) { + trie = trie->right; + } else { + W++; + done = TRUE; + trie->right = util_Malloc (sizeof (BitTrie_t)); + trie = trie->right; + trie->left = trie->right = NULL; + } + } + i++; + if (i >= n) { + done = TRUE; + if ((trie->left != NULL) || (trie->right != NULL)) + W++; + break; + } + k >>= 1; + if (k == 0) { + /* Have used the s bits in the number; generate a new number */ + Y = unif01_StripB (gen, r, s); + k = kMAX; + } + } + } + DeleteBitTrie (root); + return W; +} + + +/*-------------------------------------------------------------------------*/ + +void scomp_LempelZiv (unif01_Gen *gen, sres_Basic *res, + long N, int t, int r, int s) +{ + long Seq, n; + double X; + /* const double lg_n = num_Log2 ((double) n); */ + long W; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "scomp_LempelZiv test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataLZ (gen, TestName, N, t, r, s); + util_Assert (r + s <= 32, "scomp_LempelZiv: r + s > 32"); + util_Assert (t <= 28, "scomp_LempelZiv: k > 28"); + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + n = num_TwoExp[t]; + sres_InitBasic (res, N, "scomp_LempelZiv"); + statcoll_SetDesc (res->sVal1, "sVal1: a standard normal"); + + for (Seq = 1; Seq <= N; Seq++) { + W = LZ78 (gen, n, r, s); + /* X = (W - n / lg_n) / sqrt (0.266 * n / (lg_n * lg_n * lg_n)); */ + X = (W - LZMu[t]) / LZSigma[t]; + statcoll_AddObs (res->sVal1, X); + if (swrite_Counters) { + printf ("%12ld ", W); + if (Seq % 5 == 0) + printf ("\n"); + if (Seq >= N) + printf ("\n\n"); + } + } + + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetNormalSumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 12, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/scomp.tex b/TESTU01/TestU01-1.2.3/testu01/scomp.tex new file mode 100644 index 0000000..17a8e32 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/scomp.tex @@ -0,0 +1,178 @@ +\defmodule {scomp} + +This module contains three tests based on the evolution of the +{\em linear complexity\/} of a sequence of bits as it grows,% +\index{complexity!linear} +and a test based on the compressibility of the bit sequence, +as measured by the Lempel-Ziv complexity.% +\index{compression} +% The first two linear complexity tests are taken from +% Erdmann \cite{rERD92a} and the third from \cite {rRUK01a}. +For the compressibility test, we use the Lempel-Ziv compression +algorithm of 1978 (see \cite{iZIV78a}). +A similar test is implemented in \cite{rERD92a,rRUK01a}, +but according to the authors, it uses a version of +the Lempel-Ziv algorithm of 1977 instead \cite{iZIV77a}. +\resdef + + +\bigskip +\hrule +\code\hide +/* scomp.h for ANSI C */ +#ifndef SCOMP_H +#define SCOMP_H +\endhide +#include "unif01.h" +#include "sres.h" +\endcode + +\ifdetailed %%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} +\code +typedef struct { + + sres_Basic *JumpNum; + sres_Chi2 *JumpSize; + sres_Chi2 *LinComp; + +} scomp_Res; +\endcode + \tab + Structure for keeping the results of the tests on linear complexity + in this module. The results for the number of jumps are kept in + {\tt JumpNum}, for the size of the jumps in {\tt JumpSize}, and for the + linear complexity itself in {\tt LinComp}. + \endtab +\code + + +scomp_Res * scomp_CreateRes (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt scomp\_LinearComp} test. + \endtab +\code + + +void scomp_DeleteRes (scomp_Res *res); +\endcode + \tab + Frees the memory allocated by {\tt scomp\_CreateRes}. + \endtab + +\fi %%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code +void scomp_LinearComp (unif01_Gen *gen, scomp_Res *res, + long N, long n, int r, int s); +\endcode +\tab \index{Test!LinearComp} % + \index{Test!linear complexity|see{LinearComp}} % + This procedure applies simultaneously the jump complexity test and the jump + size test, two tests based on the linear complexity of a sequence of bits and + described in \cite{rCAR89a,rERD92a}. A sequence of $n$ bits is constructed by + taking $s$ bits from each random number. For each $\ell$, $1\le \ell\le n$, + the linear complexity of the subsequence formed by the first $\ell$ bits is + computed by the Berlekamp-Massey algorithm \cite{mBER84a,mMAS69a}. + \index{Berlekamp-Massey algorithm} + + The {\em jump complexity test\/} counts the number of jumps occurring in the + linear complexity of the sequence. A {\em jump\/} occurs whenever adding + the next bit to the sequence increases its linear complexity. + Under $\cH_0$, for $n$ sufficiently large, the number of jumps, say $J$, + is approximately normally distributed with mean and variance + given by \cite{rWAN97a}: + \begin{eqnarray} + E(J) & = & \frac n 4 + \frac{4 + R_n}{12} - \frac 1 {3(2^n)} \\[6pt] + \Var(J) & = & \frac n 8 - \frac{2 - R_n}{9 - R_n} + \frac n {6(2^n)} + + \frac{6 + R_n}{18(2^n)} - \frac 1 {9(2^{2n})}, + \end{eqnarray} + where $R_n$ is the parity of $n$ (= 0 for even $n$, 1 for odd $n$). + The test compares the standardized value of the observed number + of jumps to the standard normal distribution. + + \hpierre{Should be called ``jump sizes'', I believe.} + The {\em jump size test\/} looks at the + {\em size\/} of the jumps (there is a jump of size $h$ if the + complexity increases by $h$ when we consider the next bit of the + sequence), and counts how many jumps of each size have occurred. + It then compares these countings with the expected values via a chi-square test. + Carter has shown \cite{rCAR89a} that under $\cH_0$, the jump sizes are i.i.d. + random variables which obey a geometric law with parameter 1/2. +% It finally applies a Kolmogorov-Smirnov test comparing the distribution of +% the $N$ chi-square values to the chi-square distribution. + + When $N$ is large enough, the procedure also applies a third test, + taken from \cite{rRUK01a}. It is a chi-square + test based on the $N$ replications of the statistic + \begin{eqnarray} + T_n & = & (-1)^n (L_n - \xi_n) + 2/9, \nonumber + \end{eqnarray} + where $L_n$ is the linear complexity of the sequence, and + $\xi_n = n/2 + (4 + R_n)/18$ is an approximation of $E[L_n]$ under $\cH_0$. + The statistic $T_n$ takes only integer values, with probabilities + given by (see \cite{rRUK01a}): + % Nist Special publication 800-22, May 15, + % 2001, p. 86, at \url{http://csrc.nist.gov/rng/index.html}. + \begin{eqnarray*} + P[T = k] & = & \left\{\begin{array}{ll} + 0.5 & \mbox{ for } k=0, \\[4pt] + \displaystyle {2^{-2k}} & \mbox{ for } k = 1, 2, 3, + \ldots \\[4pt] + \displaystyle { 2^{-2|k| - 1}} & \mbox{ for } k = -1, -2, + -3, \ldots + \end{array} \right. + \end{eqnarray*} +% Restriction: $ns/16 \ge$ {\tt gofs\_MinExpected}. + Recommendation: take $N=1$ and $n$ large (however, computing the + linear complexity takes $O(n^2 \log n)$ time). +\endtab +\code + + +void scomp_LempelZiv (unif01_Gen *gen, sres_Basic *res, + long N, int k, int r, int s); +\endcode +\tab + Given a string of $n= 2^k$ bits, this test \cite{rRUK01a,rERD92a} + counts the number $W$ of distinct patterns in the string in order to + determine% +\index{Test!LempelZiv} \index{Lempel-Ziv compression} % + \index{Test!compression|see{LempelZiv}} + its compressibility by the Lempel-Ziv compression + algorithm of 1978 (see \cite{iZIV78a}). + According to \cite{iKIR94a}, under $\cH_0$, + $$ + Z = \frac{W - {n}/{\log_2 n}}{\sqrt{{0.266\,n} / + {(\log_2 n)^3}}}, + $$ + has approximately the standard normal distribution for large $n$. + However, our tests show that even for $n$ as large as $2^{24}$, + the approximation is not very good. +\hrichard {An interesting problem: To examine the exact distribution + for small or finite n. What is the right correction for finite n? + Why the correction calculated in \cite{iKIR94a} (and in other papers) + does not seem to work?} +% does not seem to obey this distribution, which +% seem to indicate that the asymptotic regime is attained only for much +% larger values of $n$ because of the logarithmic factor. + Our implementation of the test assumes that $W$ has approximately + the normal distribution, but uses estimates of its mean and + standard deviation that have been obtained through simulation + with two differents reliable generators. + Restriction: $k \le 28$ and $N$ not too large. +\endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/sentrop.c b/TESTU01/TestU01-1.2.3/testu01/sentrop.c new file mode 100644 index 0000000..eed2209 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sentrop.c @@ -0,0 +1,1025 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: sentrop.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "gdef.h" +#include "util.h" +#include "tables.h" +#include "chrono.h" +#include "num.h" + +#include "sentrop.h" +#include "smultin.h" +#include "unif01.h" +#include "swrite.h" +#include "wdist.h" + +#include "statcoll.h" +#include "gofw.h" +#include "fbar.h" + +#include +#include +#include + + +/*------------------------------ Constants --------------------------------*/ + +/* We use a numerically stable algorithm to compute the variance and the + correlation in sentrop_EntropyDiscOver and sentrop_EntropyDiscOver2. + If it is undefined, we use the naive unstable method. */ +#define STABLE + + /* Euler constant */ +static const double Euler = 0.57721566490153286; + +/* Necessary so that the multiplication of a large number of U01 will + not underflow in sentrop_EntropyDM and sentrop_EntropyDMCirc; + the precise value is not so important: it could be bigger. */ +static const double Epsilon = 1.0e-50; + + +/* We may choose n >>> NLIM in the tests where xLgx is used, because + * the probabilities will be concentrated near i = 0, and large values of + * -i/n * Lg (i/n) will never occur if n/2^L is not too large */ +#define NLIM 16384 + + + + +/*------------------------------ Functions --------------------------------*/ + + +static double FoncMNEntropie (double junk, double n, long j) +/* + * One term of entropy when there are j balls in an urn + */ +{ + double x; + if (j == 0) + return 0.0; + x = j / n; + return -x * num_Log2 (x); +} + + +/*=========================================================================*/ + +static void CalcLgx (double xLgx[], long n) +{ + long i, nLim; + double nLR = n; + double temp; + + if (n < NLIM) + nLim = n; + else + nLim = NLIM; + + for (i = 1; i <= nLim; i++) { + temp = i / nLR; + xLgx[i] = -temp * num_Log2 (temp); + } + xLgx[0] = 0.0; +} + + +/*=========================================================================*/ + +static void InitRes ( + sentrop_Res *res, /* Results holder */ + long N, /* Number of replications */ + int jmax, /* Maximal index for Count */ + char *nam +) +/* + * Initializes res + */ +{ + sres_InitBasic (res->Bas, N, nam); + if (jmax > res->jmax) + res->Count = util_Realloc (res->Count, (jmax + 1) * sizeof (long)); + res->jmax = jmax; +} + + +/*-------------------------------------------------------------------------*/ + +sentrop_Res * sentrop_CreateRes (void) +{ + sentrop_Res *res; + res = util_Malloc (sizeof (sentrop_Res)); + memset (res, 0, sizeof (sentrop_Res)); + res->Bas = sres_CreateBasic (); + res->Count = util_Calloc (1, sizeof (long)); + res->jmax = 0; + res->jmin = 0; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sentrop_DeleteRes (sentrop_Res *res) +{ + if (res == NULL) + return; + sres_DeleteBasic (res->Bas); + util_Free (res->Count); + util_Free (res); +} + + +/*=========================================================================*/ + +static void InitExactOver ( + long n, /* Sample size */ + long L, /* Blocks of L bits */ + double *Mu, /* Mean */ + double *Sigma /* Standard deviation */ + ) +/* + * Initializes the exact values of the mean and the standard deviation + * for the entropy, if these are known (precomputed). Otherwise, sets + * the standard deviation to -1. + */ +{ + long j; + long i; + double ExactVar[23][3]; + double ExactMean[23][3]; + + *Mu = 0.0; + *Sigma = -1.0; + if (n <= 30 && n >= 8 && L <= 5 && L >= 3) { + for (i = 8; i <= 30; i++) { + for (j = 3; j <= 5; j++) { + ExactVar[i - 8][j - 3] = -1.0; + } + } + ExactMean[0][0] = 2.29977; ExactVar[0][0] = 1.86729e-1; + ExactMean[8][1] = 3.23872; ExactVar[8][1] = 1.00739e-1; + ExactMean[12][2] = 3.817; ExactVar[12][2] = 8.1539e-2; + ExactMean[17][2] = 4.01429; ExactVar[17][2] = 6.9463e-2; + ExactMean[22][2] = 4.160005; ExactVar[22][2] = 5.91489e-2; + if (ExactVar[n - 8][L - 3] > 0.0) { + *Mu = ExactMean[n - 8][L - 3]; + *Sigma = sqrt (ExactVar[n - 8][L - 3]); + } + } +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteDataDisc (unif01_Gen * gen, char *TestName, + long N, long n, int r, int s, int L, double Mu, double Sigma) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d, L = %1d\n", s, L); + + if (Sigma > 0.0) { + printf (" Mu = "); + num_WriteD (Mu, 15, 7, 7); + printf ("\n Sigma = "); + num_WriteD (Sigma, 15, 7, 7); + printf ("\n"); + } else { + printf (" Mu and Sigma are unknown.\n"); + } + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteResultsDiscOver (sentrop_Res *res, double NLR, double Sum2, + double SumSq, double Mu, double Sigma, double Mean, double Var, + double Corr) +{ + printf ("\nEmpirical mean :"); + num_WriteD (Mean, 12, 8, 2); + printf ("\nEmpirical variance :"); + num_WriteD (Var, 12, 8, 2); + printf ("\n"); + +#ifndef STABLE + if (swrite_Basic) { + printf ("\nInformation on the numerical error in the computation\n" + " of the variance and the correlation:\n" + " Mean * Mean :"); + num_WriteD (Mean * Mean, 20, 16, 2); + printf ("\n Sum2 / N :"); + num_WriteD (Sum2 / NLR, 20, 16, 2); + printf ("\n SumSq / (N-1) :"); + num_WriteD (SumSq / (NLR - 1.0), 20, 16, 2); + printf ("\n\n"); + } +#endif + + if (Sigma > 0.0) { + printf ("\nDeviation from the theoretical mean :"); + num_WriteD (Mean - Mu, 12, 8, 2); + printf ("\nStandardized standard deviation :"); + gofw_Writep2 (res->Bas->sVal2[gofw_Mean], res->Bas->pVal2[gofw_Mean]); + printf ("\n"); + } else { + printf ("\n\n"); + } + printf ("Empirical correlation :"); + num_WriteD (Corr, 12, 8, 2); + printf ("\nEmpirical correlation * sqrt(N) :"); + gofw_Writep2 (res->Bas->sVal2[gofw_Cor], res->Bas->pVal2[gofw_Cor]); + printf ("\n"); +} + + +/*-------------------------------------------------------------------------*/ + +void sentrop_EntropyDiscOver (unif01_Gen * gen, sentrop_Res * res, + long N, long n, int r, int s, int L) +{ + + long i; /* Index */ + unsigned long Block1, Block0; /* Blocks of bits */ + long Seq; /* Replication number */ + double Entropy; /* Value of the entropy S */ + double tempPrev; /* Previous value of entropy */ + double SumSq; /* To compute the covariance */ + double Corr; /* Empirical correlation */ + double Var; /* Empirical variance */ + double Mean; /* Empirical mean */ + double Sigma, Mu; /* Parameters of the normal law */ + double Sum2, Sum; /* Temporary variables */ + long d; /* 2^s */ + long C; /* 2^L */ + long nSurs; /* n / s */ + double xLgx[NLIM + 1]; /* = -i/n * Lg (i/n) */ + double NLR = N; + double temp, E1; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sentrop_EntropyDiscOver test"; + + Timer = chrono_Create (); + InitExactOver (n, L, &Mu, &Sigma); + if (swrite_Basic) + WriteDataDisc (gen, TestName, N, n, r, s, L, Mu, Sigma); + + util_Assert (L <= n - L, "sentrop_EntropyDiscOver: L > n-L"); + util_Assert (n <= 31, "sentrop_EntropyDiscOver: n > 31"); + util_Assert (r <= 31, "sentrop_EntropyDiscOver: r > 31"); + util_Assert (s <= 31, "sentrop_EntropyDiscOver: s > 31"); + util_Assert (n % s == 0, "sentrop_EntropyDiscOver: n % s != 0"); + util_Assert (N > 1, "sentrop_EntropyDiscOver: N <= 1"); + + d = num_TwoExp[s]; + C = num_TwoExp[L]; + nSurs = n / s; + + if (res == NULL) { + localRes = TRUE; + res = sentrop_CreateRes (); + } + InitRes (res, N, C - 1, "sentrop_EntropyDiscOver"); + CalcLgx (xLgx, n); + tempPrev = SumSq = Sum2 = Sum = 0.0; + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i < C; i++) + res->Count[i] = 0; + + Block0 = unif01_StripB (gen, r, s); + for (i = 2; i <= nSurs; i++) + Block0 = Block0 * d + unif01_StripB (gen, r, s); + + /* Compute entropy of the block of n bits = Block0. */ + /* This block has less than 31 bits. */ + Block1 = Block0; + for (i = 0; i <= n - L - 1; i++) { + ++res->Count[Block1 % C]; + Block1 >>= 1; + } + Block1 = (Block1 % C) + C * (Block0 % C); + for (i = n - L; i < n; i++) { + ++res->Count[Block1 % C]; + Block1 >>= 1; + } + + Entropy = 0.0; + for (i = 0; i < C; i++) { + util_Assert (res->Count[i] <= NLIM, + "sentrop_EntropyDiscOver: NLIM is too small"); + Entropy += xLgx[res->Count[i]]; + } + +#ifdef STABLE + /* Ideally, we should use the moving average for numerical stability. + But we shall use the first observed value instead; it should be + typical and will prevent loss of precision (unless it is 0). */ + if (1 == Seq) + E1 = Entropy; + temp = Entropy - E1; + Sum += temp; + Sum2 += temp * temp; + SumSq += temp * tempPrev; + tempPrev = temp; + +#else + /* The naive method: it is simple but numerically unstable. It can be + used for debugging and testing the more stable calculation in the + case of small samples. */ + Sum += Entropy; + Sum2 += Entropy * Entropy; + SumSq += Entropy * tempPrev; + tempPrev = Entropy; +#endif + + if (swrite_Counters) + tables_WriteTabL (res->Count, 0, C - 1, 5, 10, "Counters:"); + + if (swrite_Collectors) { + printf ("Entropy = "); + num_WriteD (Entropy, 15, 6, 1); + printf ("\n"); + } + } + + /* We now test the correlation between successive values of the entropy. + Corr should have mean 0 and variance 1. We use a numerically stable + calculation. */ + +#ifdef STABLE + Mean = Sum / NLR + E1; + Var = Sum2 / NLR - (E1 - Mean) * (E1 - Mean); + Var *= NLR / (NLR - 1.0); + temp = (Entropy + E1 * NLR - 2.0 * NLR * Mean) * E1 / (NLR - 1.0); + Corr = SumSq / (NLR - 1.0) - temp - Mean * Mean; + if (Var <= 0.0) { + Corr = 1.0e100; + util_Warning (TRUE, + "Empirical variance <= 0. Correlation set to 1e100."); + } else + Corr /= Var; + +#else + /* Naive calculations. Here, there could be huge losses of precision + because Mean*Mean, Sum2/NLR, and SumSq/(NLR - 1.0) may be very close. */ + Mean = Sum / NLR; + Var = (Sum2 / NLR - Mean * Mean) * NLR / (NLR - 1.0); + Corr = (SumSq / (NLR - 1.0) - Mean * Mean) / Var; + +#endif + + + if (Sigma > 0.0) { + /* We know the true values of Mu and Sigma */ + res->Bas->sVal2[gofw_Mean] = (Mean - Mu) * sqrt (NLR) / Sigma; + res->Bas->pVal2[gofw_Mean] = fbar_Normal1 (res->Bas->sVal2[gofw_Mean]); + } else + res->Bas->pVal2[gofw_Mean] = -1.0; + + res->Bas->sVal2[gofw_Cor] = Corr * sqrt (NLR); + res->Bas->pVal2[gofw_Cor] = fbar_Normal1 (res->Bas->sVal2[gofw_Cor]); + + if (swrite_Basic) { + WriteResultsDiscOver (res, NLR, Sum2, SumSq, Mu, Sigma, Mean, Var, + Corr); + swrite_Final (gen, Timer); + } + if (localRes) + sentrop_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sentrop_EntropyDiscOver2 (unif01_Gen * gen, sentrop_Res * res, + long N, long n, int r, int s, int L) +{ + long i, j; /* Indices */ + unsigned long B2, B1, B0; /* Blocks of bits */ + long Seq; /* Replication number */ + double Entropy; /* Value of the entropy S */ + double tempPrev; /* Previous value of the entropy */ + double SumSq; /* To compute the covariance */ + double Corr; /* Empirical correlation */ + double Var; /* Empirical variance */ + double Mean; /* Empirical mean */ + double Sigma, Mu; /* Parameters of the normal law */ + double Sum2, Sum; /* Temporary variables */ + unsigned long d; /* 2^s */ + long C; /* 2^L */ + unsigned long CLC; /* 2^L */ + long m0; /* m0 = ceil (L/s) */ + long m; /* m = n/s */ + double xLgx[NLIM + 1]; /* = -i/n * Lg (i/n) */ + double NLR = N; + double temp, E1; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sentrop_EntropyDiscOver2 test"; + + Timer = chrono_Create (); + InitExactOver (n, L, &Mu, &Sigma); + if (swrite_Basic) + WriteDataDisc (gen, TestName, N, n, r, s, L, Mu, Sigma); + + util_Assert (L <= n, "sentrop_EntropyDiscOver2: L > n"); + util_Assert (L <= 15, "sentrop_EntropyDiscOver2: L > 15"); + util_Assert (r <= 31, "sentrop_EntropyDiscOver2: r > 31"); + util_Assert (s <= 31, "sentrop_EntropyDiscOver2: s > 31"); + util_Assert (L + s <= 31, "sentrop_EntropyDiscOver2: L+s > 31"); + util_Assert (n % s == 0, "sentrop_EntropyDiscOver2: n % s != 0"); + + d = num_TwoExp[s]; + m = n / s; + m0 = L / s; + if (m0 * s < L) + ++m0; + /* B0 must not be larger than LONG_MAX (31 bits) */ + util_Assert (m0 * s <= 31, "sentrop_EntropyDiscOver2: m0 * s > 31"); + C = num_TwoExp[L]; + CLC = num_TwoExp[L]; + + if (res == NULL) { + localRes = TRUE; + res = sentrop_CreateRes (); + } + InitRes (res, N, C - 1, "sentrop_EntropyDiscOver2"); + tempPrev = SumSq = Sum2 = Sum = 0.0; + CalcLgx (xLgx, n); + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i < C; i++) + res->Count[i] = 0; + + B0 = unif01_StripB (gen, r, s); + for (j = 2; j <= m0; j++) + B0 = B0 * d + unif01_StripB (gen, r, s); + + /* B0 now contains the bits 0,...,0,b_1,...,b_{m0*s} */ + B2 = B0; + + /* Count the blocks of L bits in b_1,...,b_{m0*s} */ + for (i = 0; i <= m0 * s - L; i++) { + ++res->Count[B2 % CLC]; + B2 >>= 1; + } + B1 = B0 % CLC; + B0 = B2 % CLC; + /* B1 contains 0,...,0,b_{m0*s-L+1},...,b_{m0*s} */ + /* B0 contains 0,...,0,b_1,...,b_{L-1} */ + for (j = 1; j <= m - m0; j++) { + B1 = B1 * d + unif01_StripB (gen, r, s); + B2 = B1; + B1 %= CLC; + /* B1 and B2 contain L bits and L+s bits, resp. */ + for (i = 1; i <= s; i++) { + ++res->Count[B2 % CLC]; + B2 >>= 1; + } + } + + /* B1 contains 0,...,0,b_{m*s-L+1},...,b_{m*s}. */ + /* Her we must have 2 * L <= 31. */ + B2 = B0 + B1 * (CLC / 2); + /* B2 contains 0,..,0,b_{m*s-L+1},..,b_{m*s},b_1,...,b_{L-1}. */ + /* Now count blocks with overlap. */ + for (i = 1; i < L; i++) { + ++res->Count[B2 % CLC]; + B2 >>= 1; + } + + /* Compute entropy */ + Entropy = 0.0; + for (i = 0; i < C; i++) { + util_Assert (res->Count[i] <= NLIM, + "sentrop_EntropyDiscOver2: NLIM is too small"); + Entropy += xLgx[res->Count[i]]; + } + +#ifdef STABLE + /* Ideally, we should use the moving average for numerical stability. + But we shall use the first observed value of instead; it should be + typical and will prevent loss of precision (unless it is 0). */ + + if (1 == Seq) + E1 = Entropy; + temp = Entropy - E1; + Sum += temp; + Sum2 += temp * temp; + SumSq += temp * tempPrev; + tempPrev = temp; + +#else + /* The naive unstable method */ + Sum += Entropy; + Sum2 += Entropy * Entropy; + SumSq += Entropy * tempPrev; + tempPrev = Entropy; +#endif + + if (swrite_Counters) + tables_WriteTabL (res->Count, 0, C - 1, 5, 10, "Counters:"); + + if (swrite_Collectors) { + printf ("Entropy = "); + num_WriteD (Entropy, 15, 6, 1); + printf ("\n"); + } + } + + /* We now test the correlation between successive values of the */ + /* entropy. Corr should have mean 0 and variance 1. */ + +#ifdef STABLE + Mean = Sum / NLR + E1; + Var = Sum2 / NLR - (E1 - Mean) * (E1 - Mean); + Var *= NLR / (NLR - 1.0); + temp = (Entropy + E1 * NLR - 2.0 * NLR * Mean) * E1 / (NLR - 1.0); + Corr = SumSq / (NLR - 1.0) - temp - Mean * Mean; + if (Var <= 0.0) { + Corr = 1.0e100; + util_Warning (TRUE, + "Empirical variance <= 0. Correlation set to 1e100."); + } else + Corr /= Var; + +#else + /* Naive calculations. Here, there could be huge losses of precision + because Mean*Mean, Sum2/NLR, and SumSq/(NLR - 1.0) may be very close. */ + Mean = Sum / NLR; + Var = (Sum2 / NLR - Mean * Mean) * NLR / (NLR - 1.0); + Corr = (SumSq / (NLR - 1.0) - Mean * Mean) / Var; +#endif + + if (Sigma > 0.0) { + /* We know the true values of Mu and Sigma */ + res->Bas->sVal2[gofw_Mean] = (Mean - Mu) * sqrt (NLR) / Sigma; + res->Bas->pVal2[gofw_Mean] = fbar_Normal1 (res->Bas->sVal2[gofw_Mean]); + } else + res->Bas->sVal2[gofw_Mean] = -1.0; + + res->Bas->sVal2[gofw_Cor] = Corr * sqrt (NLR); + res->Bas->pVal2[gofw_Cor] = fbar_Normal1 (res->Bas->sVal2[gofw_Cor]); + + if (swrite_Basic) { + WriteResultsDiscOver (res, NLR, Sum2, SumSq, Mu, Sigma, Mean, Var, + Corr); + swrite_Final (gen, Timer); + } + if (localRes) + sentrop_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteResultsDisc (long N, gofw_TestArray sVal2, gofw_TestArray pVal2, + sres_Basic *res) +{ + if (N > 1) { + gofw_WriteActiveTests0 (N, sVal2, pVal2); + swrite_NormalSumTest (N, res); + printf ("Standardized empirical correlation :"); + gofw_Writep2 (sVal2[gofw_Cor], pVal2[gofw_Cor]); + } else { + printf ("Standardized statistic value :"); + gofw_Writep2 (sVal2[gofw_Mean], pVal2[gofw_Mean]); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void EntropyDisc00 (unif01_Gen * gen, sentrop_Res * res, + long N, long n, int r, int s, int L) +/* + * Test based on the discrete entropy, proposed by Compagner and L'Ecuyer + */ +{ + long Seq; + long j; + long i; + double EntropyNorm; /* Normalized entropy */ + double Entropy; /* Value of entropy S */ + double EntropyPrev; /* Previous value of entropy */ + double SumSq; /* To compute the covariance */ + double Sigma, Mu; /* Parameters of the normal law */ + double tem; + double nLR = n; + long d; /* 2^s */ + long C; /* 2^L */ + long LSurs; /* L / s */ + long sSurL; /* s / L */ + long nLSurs; /* nL / s */ + double xLgx[NLIM + 1]; /* = -i/n * Lg (i/n) */ + unsigned long Block; + unsigned long Number; + unsigned int LL = L; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sentrop_EntropyDisc test"; + + Timer = chrono_Create (); + if (s <= L && L % s) { + util_Error ("EntropyDisc00: s <= L and L % s != 0"); + } + if (s > L && s % L) { + util_Error ("EntropyDisc00: s > L and s % L != 0"); + } + + d = num_TwoExp[s]; + C = num_TwoExp[L]; + + if (s <= L) + LSurs = L / s; + else { + sSurL = s / L; + nLSurs = n / sSurL; + if (n % sSurL) + ++nLSurs; + } + + util_Assert (n / num_TwoExp[L] < NLIM, + "sentrop_EntropyDisc: n/2^L is too large"); + smultin_MultinomMuSigma (n, num_TwoExp[L], 0.0, (double) n, + FoncMNEntropie, &Mu, &Sigma); + + if (swrite_Basic) + WriteDataDisc (gen, TestName, N, n, r, s, L, Mu, Sigma); + + if (res == NULL) { + localRes = TRUE; + res = sentrop_CreateRes (); + } + InitRes (res, N, C - 1, "sentrop_EntropyDisc"); + CalcLgx (xLgx, n); + + statcoll_SetDesc (res->Bas->sVal1, "EntropyDisc sVal1"); + statcoll_SetDesc (res->Bas->pVal1, "EntropyDisc pVal1"); + SumSq = EntropyPrev = 0.0; + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i < C; i++) + res->Count[i] = 0; + + if (s <= L) { + for (i = 1; i <= n; i++) { + Block = unif01_StripB (gen, r, s); + for (j = 2; j <= LSurs; j++) + Block = Block * d + unif01_StripB (gen, r, s); + ++res->Count[Block]; + } + + } else { /* s > L */ + for (i = 1; i <= nLSurs; i++) { + Number = unif01_StripB (gen, r, s); + for (j = 1; j <= sSurL; j++) { + Block = Number % C; + ++res->Count[Block]; + Number >>= LL; + } + } + } + + /* Compute entropy */ + Entropy = 0.0; + for (i = 0; i < C; i++) { + if (res->Count[i] > NLIM) { + tem = res->Count[i] / nLR; + tem *= -num_Log2 (tem); + Entropy += tem; + } else if (res->Count[i] > 0) { + Entropy += xLgx[res->Count[i]]; + } + } + EntropyNorm = (Entropy - Mu) / Sigma; + statcoll_AddObs (res->Bas->sVal1, EntropyNorm); + SumSq += EntropyNorm * EntropyPrev; + EntropyPrev = EntropyNorm; + + if (swrite_Counters) + tables_WriteTabL (res->Count, 0, C - 1, 5, 10, "Counters:"); + + if (swrite_Collectors) { + printf ("Entropy = "); + num_WriteD (Entropy, 15, 6, 1); + printf ("\n"); + } + } + + gofw_ActiveTests2 (res->Bas->sVal1->V, res->Bas->pVal1->V, N, wdist_Normal, + (double *) NULL, res->Bas->sVal2, res->Bas->pVal2); + res->Bas->pVal1->NObs = N; + sres_GetNormalSumStat (res->Bas); + + /* We now test the correlation between successive values of the entropy. + The next SumSq should have mean 0 and variance 1. */ + if (N > 1) { + res->Bas->sVal2[gofw_Cor] = SumSq / sqrt ((double) N); + res->Bas->pVal2[gofw_Cor] = fbar_Normal1 (res->Bas->sVal2[gofw_Cor]); + } + if (swrite_Collectors) { + statcoll_Write (res->Bas->sVal1, 5, 14, 4, 3); + } + if (swrite_Basic) { + WriteResultsDisc (N, res->Bas->sVal2, res->Bas->pVal2, res->Bas); + swrite_Final (gen, Timer); + } + + if (localRes) + sentrop_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteDataEnt (long N, long n, int r, int s, int L) +{ + printf ("***********************************************************\n" + "Test sentrop_EntropyDisc calling smultin_Multinomial\n\n"); + printf (" N = %2ld, n = %8ld, r = %2d", N, n, r); + printf (", s = %1d, L = %1d\n\n", s, L); +} + + +/*-------------------------------------------------------------------------*/ + +void sentrop_EntropyDisc (unif01_Gen * gen, sentrop_Res * res, + long N, long n, int r, int s, int L) +/* + * Use smultin_Multinomial to replace sentrop_EntropyDisc + */ +{ + int i; + int t; + long d; + double x; + smultin_Param *par; + double ValDelta[] = { 0.0 }; + + if (s > L) { + EntropyDisc00 (gen, res, N, n, r, s, L); + return; /* <--- Case "s > L" end up here. */ + } + + if (swrite_Basic) + WriteDataEnt (N, n, r, s, L); + util_Assert (L % s == 0, "sentrop_EntropyDisc: L % s != 0"); + + d = num_TwoExp[s]; + t = L / s; + + x = d; + for (i = 2; i <= t; i++) + x *= d; + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, 3); + if (NULL == res) { + if (n / x <= 8.0) + smultin_Multinomial (gen, par, NULL, N, n, r, d, t, TRUE); + else + smultin_Multinomial (gen, par, NULL, N, n, r, d, t, FALSE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + if (n / x <= 8.0) + smultin_Multinomial (gen, par, resm, N, n, r, d, t, TRUE); + else + smultin_Multinomial (gen, par, resm, N, n, r, d, t, FALSE); + InitRes (res, N, 0, "sentrop_EntropyDisc"); + statcoll_SetDesc (res->Bas->sVal1, "EntropyDisc sVal1"); + res->Bas->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->Bas->sVal1->V, 1, N); + tables_CopyTabD (resm->sVal2[0], res->Bas->sVal2, 0, gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->Bas->pVal2, 0, gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} + + +/*=========================================================================*/ + +static void WriteDataDM (unif01_Gen * gen, char *TestName, + long N, long n, int r, long m) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", m = %1ld\n\n", m); +} + + +/*-------------------------------------------------------------------------*/ + +void sentrop_EntropyDM (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r, long m) +{ + long i; /* Index */ + double I0, x; + long Seq; /* Replication number */ + double Entropy; /* Value of the statistic H(m, n) */ + double LnEntropy; + double SumR; /* 1 + 1/2 + ... + 1/(2m-1) */ + double nLR = n; + double Twom; /* 2m */ + double *AU; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sentrop_EntropyDM test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataDM (gen, TestName, N, n, r, m); + + Twom = 2 * m; + I0 = Twom - 1.0; + SumR = 0.0; + for (i = 2 * m - 1; i >= 1; i--) { + SumR += 1.0 / I0; + I0 -= 1.0; + } + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "sentrop_EntropyDM"); + AU = util_Calloc ((size_t) (n + 1), sizeof (double)); + statcoll_SetDesc (res->sVal1, + "The N statistic values (a standard normal)"); + + for (Seq = 1; Seq <= N; Seq++) { + + /* Generate the sample and sort */ + for (i = 1; i <= n; i++) + AU[i] = unif01_StripD (gen, r); + tables_QuickSortD (AU, 1, n); + + /* Compute empirical entropy */ + Entropy = 1.0; + LnEntropy = 0.0; + for (i = 1; i <= n; i++) { + if (i - m < 1) { + Entropy *= (AU[i + m] - AU[1]); + } else if (i + m > n) { + Entropy *= (AU[n] - AU[i - m]); + } else + Entropy *= (AU[i + m] - AU[i - m]); + + /* Avoid underflow */ + if (Entropy < Epsilon) { + LnEntropy += log (Entropy); + Entropy = 1.0; + } + } + + Entropy = (LnEntropy + log (Entropy)) / nLR + log (nLR / Twom); + + /* Compute standardized statistic */ + x = sqrt (3.0 * Twom * nLR) * (Entropy + log (Twom) + Euler - SumR); + statcoll_AddObs (res->sVal1, x); + } + + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetNormalSumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res); + swrite_Final (gen, Timer); + } + + util_Free (AU); + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sentrop_EntropyDMCirc (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r, long m) +{ + long i; /* Index */ + double I0, x; + long Seq; /* Replication number */ + double Entropy; /* Value of the statistic H(m, n) */ + double LnEntropy; + double SumR; /* 1 + 1/2 + ... + 1/(2m-1) */ + double nLR = n; + double Twom; /* 2m */ + double *AU; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sentrop_EntropyDMCirc test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataDM (gen, TestName, N, n, r, m); + + Twom = 2 * m; + I0 = Twom - 1.0; + SumR = 0.0; + for (i = 2 * m - 1; i >= 1; i--) { + SumR += 1.0 / I0; + I0 -= 1.0; + } + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "sentrop_EntropyDMCirc"); + AU = util_Calloc ((size_t) (n + 1), sizeof (double)); + statcoll_SetDesc (res->sVal1, + "The N statistic values (a standard normal)"); + + for (Seq = 1; Seq <= N; Seq++) { + /* Generate the sample and sort */ + for (i = 1; i <= n; i++) + AU[i] = unif01_StripD (gen, r); + tables_QuickSortD (AU, 1, n); + + /* Compute empirical entropy */ + Entropy = 1.0; + LnEntropy = 0.0; + for (i = 1; i <= n; i++) { + if (i - m < 1) { + Entropy *= (AU[i + m] - AU[n + i - m] + 1.0); + } else if (i + m > n) { + Entropy *= (AU[i + m - n] - AU[i - m] + 1.0); + } else + Entropy *= (AU[i + m] - AU[i - m]); + + if (Entropy < Epsilon) { + LnEntropy += log (Entropy); + Entropy = 1.0; + } + } + + Entropy = (LnEntropy + log (Entropy)) / nLR + log (nLR / Twom); + + /* Compute standardized statistic */ + x = sqrt (3.0 * Twom * nLR) * ((Entropy + log (Twom) + Euler) - SumR); + statcoll_AddObs (res->sVal1, x); + } + + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetNormalSumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res); + swrite_Final (gen, Timer); + } + + util_Free (AU); + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/sentrop.tex b/TESTU01/TestU01-1.2.3/testu01/sentrop.tex new file mode 100644 index 0000000..098a2de --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sentrop.tex @@ -0,0 +1,186 @@ +\defmodule {sentrop} + +This module implements tests based on discrete and continuous +empirical entropies\index{entropy}, defined and studied by +Dudewicz and van der Meulen \cite{rDUD81b,rDUD95a} +and L'Ecuyer, Compagner, and Cordeau \cite{rLEC96e}. +The tests of \cite{rDUD81b,rDUD95a} are actually superseded by the +tests with $\delta=0$ in module {\tt smultin}, where a much better +approximation is used for the distribution of the test statistic. + \resdef + + +\bigskip\hrule +\code\hide +/* sentrop.h for ANSI C */ +#ifndef SENTROP_H +#define SENTROP_H +\endhide +#include "statcoll.h" +#include "gofw.h" +#include "unif01.h" +#include "sres.h" +\endcode + + +\ifdetailed %%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Test results} +\code + +typedef struct { + + long *Count; +\endcode +\tabb + Block counters used in the tests {\tt sentrop\_EntropyDisc}, + {\tt sentrop\_EntropyDiscOver}, and {\tt sentrop\_EntropyDiscOver2}. +\endtabb +\code + + long jmin; + long jmax; +\endcode +\tabb + Lowest and highest valid indices for array {\tt Count}. +\endtabb +\code + + sres_Basic *Bas; +\endcode + \tabb + The statistical collectors and the resulting $s$ and $p$-values. + \endtabb +\code + +} sentrop_Res; +\endcode + \tab + Structure used to keep the results of the tests in this module. + For some tests, the array {\tt Count} is unused. + \endtab +\code + + +sentrop_Res * sentrop_CreateRes (void); +\endcode + \tab + Creates and returns a structure that will hold the results of a test. + \endtab +\code + + +void sentrop_DeleteRes (sentrop_Res *res); +\endcode + \tab + Frees the memory allocated by {\tt sentrop\_CreateRes}. + \endtab +\fi %%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code + +void sentrop_EntropyDisc (unif01_Gen *gen, sentrop_Res *res, + long N, long n, int r, int s, int L); +\endcode +\tab + Applies\index{Test!EntropyDisc} the entropy-based test + proposed in \cite{rLEC96e}. + It builds $n$ blocks of $L$ bits by taking $s$-bit strings + (the $s$ most significant bits after dropping the first $r$) from each of + $NL/s$ successive output values from the generator, and concatenating + these strings. + There are $k=2^L$ possible $L$-bit blocks, which can be numbered + from 0 to $k-1$. Let $X_i$ be the observed frequency of occurrence + of the $i$th possibility, for $i=0,\dots,k-1$. + The test is based on the {\em empirical entropy\/} + $$ T = -\sum_{i = 0}^{k-1} X_i \log_2 X_i, $$ + whose distribution is approximated by the normal if $n/2^L \le 8$ + (the sparse case) and by a chi-square distribution if $n/2^L > 8$ + (the dense case). + This test is equivalent to {\tt smultin\_Multino\-mial\-Bits} with the + power divergence test statistic, using $\delta=0$ only. +\iffalse %%% + If $s$ divides $L$, it is equivalent to calling + {\tt smultin\_Multinomial} with $d=2^s$, $t= L/s$, and + looking at the result for $\delta=0$. +\fi %%% + Restrictions: Either $L$ divides $s$ or $s$ divides $L$. +\endtab +\code + + +void sentrop_EntropyDiscOver (unif01_Gen *gen, sentrop_Res *res, + long N, long n, int r, int s, int L); +\endcode +\tab + Applies\index{Test!EntropyDiscOver} an entropy-based test + described in \cite{rLEC96e}, similar + to {\tt sentrop\_EntropyDisc}, but with overlap of the blocks. + It constructs a sequence of $n$ bits, by taking $s$ bits from each + of $n/s$ output values, puts these $n$ bits on a circle, + and examines all $n$ blocks of $L$ successive bits on this circle. + The test computes the empirical entropy, defined by + $$ T = -\sum_{i = 0}^{k-1} X_i \log_2 X_i, $$ + where the $X_i$ are the observed frequencies of the $L$-bit strings. + This test is equivalent to {\tt smultin\_MultinomialBitsOver} with the + power divergence test statistic, using $\delta=0$ only. +% Note: This is different from {\tt smultin\_MultinomialOver} +% unless $s=1$, because here the overlapping is for sequences of {\em bits}. + + For $N>1$, the function also tests the empirical correlation + between pairs of successive values of $T$, as well as the average + of these values. This average is compared with the exact expectation + in the cases where it is known. + Restrictions: $r\le 31$, $s\le 31$, $n\le 31$, $L \le n/2$, + $n \mod s = 0$, and $N \gg n$. +\endtab +\code + + +void sentrop_EntropyDiscOver2 (unif01_Gen *gen, sentrop_Res *res, + long N, long n, int r, int s, int L); +\endcode +\tab + A version\index{Test!EntropyDiscOver2} + of {\tt sentrop\_EntropyDiscOver} that accepts $n > 31$. + For $n > 30$, it tests only the correlation between successive values + of $T$. + Restrictions: $L \le 15$, $r \le 31$, $ s \le 31$, $L + s \le 31$, + $n \mod s =0$, $\lceil L/s\rceil s \le 31$, and $N \gg n$. +\endtab +\code + + +void sentrop_EntropyDM (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, long m); +\endcode +\tab + Applies the entropy test\index{Test!EntropyDM} + described by Dudewicz and van der Meulen \cite{rDUD81b,rDUD95a}. + It uses $n$ successive output values from the generator and computes + the empirical entropy $H_{m,n}$ defined in \cite{rDUD81b,rDUD95a}, + whose theoretical distribution is approximated by a normal distribution. +\endtab +\code + + +void sentrop_EntropyDMCirc (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, long m); +\endcode +\tab + Similar\index{Test!EntropyDMCirc} to {\tt sentrop\_EntropyDM}, except + that a circular + definition of the $Y_i$'s (defined in \cite{rDUD81b,rDUD95a}) is used. + This function defines $Y_i = Y_{n+i} - 1$ for $i < 1$, and + $Y_i = Y_{i-n} + 1$ for $i > n$. +\endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/sintro.tex b/TESTU01/TestU01-1.2.3/testu01/sintro.tex new file mode 100644 index 0000000..755cf5f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sintro.tex @@ -0,0 +1,375 @@ +\chapter{STATISTICAL TESTS} + +This chapter describes the different statistical tests available +in TestU01 and how they can be applied. +These tests are organized in different modules, +sometimes according to their similarity and +sometimes according to the author of the book/article from which they +were taken. +Each test looks, in its own way, for empirical evidence against +the null hypothesis $\cH_0$ defined in the introduction. +It computes a test statistic $Y$ whose distribution under $\cH_0$ +is known (or for which a good approximation is available). + +%%%%%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{Single-level tests.} \ + +A {\em first-order\/} (or {\em single-level\/}) test +observes the value of $Y$, say $y$,\index{single-level tests} +and rejects $\cH_0$ if the {\em $p$-value\/} +(or {\em significance level\/}) + $$ p = P[Y \ge y \mid \cH_0] $$ +is much too close to either 0 or 1. +If the distribution of $Y$ is [approximately] continuous, +$p$ is [approximately] +a $U(0,1)$ random variable under $\cH_0$. +Sometimes, this $p$ can be viewed as a {\em measure of uniformity}, +in the sense that it will be close to 1 if the generator produces +its values with excessive uniformity, and close to 0 in the opposite +situation (see, e.g., the module {\tt smultin}). + +In the case where $Y$ has a + {\em discrete distribution\/}\index{discrete distribution} +under $\cH_0$, we distinguish the {\em right $p$-value\/} +$p_R = P[Y \ge y \mid \cH_0]$ and the {\em left $p$-value\/} +$p_L = P[Y \le y \mid \cH_0]$. We then define the $p$-value as +\begin{eqnarray*} + p & = & \left\{ + \begin{array}{l@{\qquad}l} + p_R, & \mbox{if } p_R < p_L \\[6pt] + 1 - p_L, & \mbox{if } p_R \ge p_L \mbox{ and } p_L < 0.5 \\[6pt] + 0.5 & \mbox{otherwise.} + \end{array}\right. +\end{eqnarray*} +Why such a definition? +Consider for example a Poisson random variable $Y$ with mean 1 +under $\cH_0$. If $Y$ takes the value 0, the right $p$-value is +$p_R = P[Y \ge 0 \mid \cH_0] = 1$. In the uniform case, this would +obviously lead to rejecting $\cH_0$ on the basis that the +$p$-value is too close to 1. +However, $P[Y = 0 \mid \cH_0] = 1/e \approx 0.368$, so it does not +really make sense to reject $\cH_0$ in this case. +In fact, the left $p$-value here is $p_L = 0.368$, and the $p$-value +computed with the above definition is $p = 1 - p_L \approx 0.632$. +Note that if $p_L$ is very small, with this definition, $p$ becomes +close to 1. +If the left $p$-value was defined as +$p_L = 1 - p_R = P[Y < y \mid \cH_0]$, this would also lead to problems; +in the example, one would have $p_L = 0$. + +%%%%%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{Two-level tests.} \ + +In a {\em second-order\/} (or {\em two-level\/}) test, one generates +$N$ ``independent'' copies of $Y$, say $Y_1,\dots,Y_N$, by replicating +the first-order test $N$ times.\index{two-levels tests} +Let $F$ be the theoretical distribution function of $Y$ under $\cH_0$. +In the case where $F$ is {\em continuous}, the transformed observations +$U_1 = F(Y_1),\dots, U_N = F(Y_N)$ should behave as i.i.d.\ uniform +random variables. +One way of performing the two-level test is to compare the empirical +distribution of these $U_j$'s to the uniform\index{goodness-of-fit tests} +distribution, via a {\em goodness-of-fit\/} (GOF) test such as +those of Kolmogorov-Smirnov, Anderson-Darling, Cr\'amer-von Mises, etc. +These GOF test statistics are defined in module {\tt gofs} and their +$p$-values are computed by the functions of module {\tt gofw} +(these two modules are in library ProbDist). +For example, if $d_N^+$ is the sample value taken by the Kolmogorov-Smirnov +statistic $D_N^+$ (defined in module {\tt gofs}), the corresponding +$p$-value at the second level is $\delta^+ = P[D_N^+ > d_N^+ | \cH_0]$. +Under $\cH_0$, $\delta^+$ has the $U(0,1)$ distribution. + +In TestU01, several of these GOF tests can actually be applied +simultaneously, and all their $p$-values are reported in the results. +Those that are too close to 0 or 1 are marked by special indicators +in the printouts. %% The symbol {\tt eps} in the printout stands for a +%% value smaller than $10^{-15}$. +The GOF tests that are applied are those that belong to the set +{\tt gofw\_ActiveTests}. +This kind of flexibility is sometimes convenient for comparing the +power of these GOF tests to detect the weaknesses of specific classes +of generators. + +This type of two-level testing procedure has been widely applied for +testing RNGs \cite{sFIS96a,rKNU98a,rLEC92a,rLEE97a,rMAR85a}. +The arguments supporting it are that +(i) it sometimes permits one to apply the test with a larger total +sample size to increase its power +(for example, if the memory size of the computer +limits the sample size of a single-level test), and +(ii) it tests the RNG sequence at the local level, +not only at the global level (i.e., there could be very bad behavior +over short subsequences, which cancels out when averaging +over larger subsequences). +As an example of this, consider the extreme case of a generator +whose output values are $i/2^{31}$, for $i=1,2,\dots,2^{31}-1$, +in this order. +A simple test of uniformity over the entire sequence would give +a perfect fit, whereas the same test applied repeatedly over +(disjoint) shorter sub-sequences would easily detect the anomaly. + +Another way of performing the test at the second level is to simply add +the $N$ observations of the first level +and reject $\cH_0$ if the sum is too large or too small. +For the great majority of the tests in this library, the distribution +of $Y$ is either chi-square, normal, or Poisson. +In these three cases, the sum $\tilde Y = Y_1 + \cdots + Y_N$ has the +same type of distribution. That is, if $Y$ is chi-square with $k$ degrees +of freedom [resp., normal with mean $\mu$ and variance $\sigma^2$, +Poisson with mean $\lambda$], $\tilde Y$ is chi-square with $Nk$ degrees +of freedom [resp., normal with mean $N\mu$ and variance $N^2\sigma^2$, +Poisson with mean $N\lambda$]. +TestU01 usually +\hrichard {Not yet fully implemented everywhere, but will be done very soon.} +reports the results of the test based on $\tilde Y$ in +these situations, in addition to the second-order GOF tests specified +by {\tt gofs\_ActiveTests} (for the Poisson case, where the +second-order GOF tests are not valid unless $\lambda$ is large enough +for the Poisson distribution to be well approximated by a normal, +only the results of the tests base on $\tilde Y$ are reported). + +Our empirical investigations indicate that for a fixed total +sample size $Nn$, when testing RNGs, a test with $N=1$ is often +more efficient than the corresponding test with $N > 1$. +\hrichard{Il y a des tests pour lesquels $N > 1$ est plus sensible + que $N=1$: au moins + {\tt sstring\_HammingWeight, sstring\_AutoCor, + sstring\_LongestHeadRun, sknuth\_MaxOft}}. +This means that for typical RNGs, the type of structure found in +one (reasonably long) subsequence is usually found in (practically) +all subsequences of the same length. +In other words, when a RNG started from a +given seed fails spectacularly a certain test, it usually fails +that test for {\em most\/} admissible seeds, though +there are some exceptions. +In the case where $N > 1$, the test based on $\tilde Y$ is usually +more powerful than the second-order GOF tests comparing the empirical +distribution of $F(Y_1),\dots,F(Y_N)$ to the uniform, +according to our experience. + + +%%%%%%%%%%%%%%%%%%%% +\paragraph*{Rejecting $\cH_0$.} \ + +In statistical studies where a limited amount of data is available, +people sometimes fix the significance level $\alpha$ in advance +to arbitrary values such as 0.05 or 0.01, +and reject $H_0$ if and only if the $p$-value is below $\alpha$. +However, statisticians often recommend to just report the $p$-value, +because this provides more information than reporting a ``reject'' or +``do not reject'' verdict based on a fixed $\alpha$. + +When a $p$-value is extremely close to 0 or to 1 (for example, +if it is less than $10^{-10}$), one can obviously conclude that +the generator {\em fails\/} the test. +If the $p$-value is suspicious but failure is not clear enough, +($p=0.0005$, for example), then the test can be replicated independently +until either failure becomes obvious or suspicion disappears +(i.e., one finds that the suspect $p$-value was obtained only by chance). +This approach is possible because there is no limit (other than CPU time) +on the amount of data that can be produced by a RNG to increase the +sample size and the power of the test. + +%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{Common parameters and tools.} \ + +Three parameters, called $N$, $n$, and $r$, are common to all the +functions that apply a test in the {\tt s} modules. +The parameter $N$ gives the number of independent replications of the +base test, i.e. the number of distinct subsequences on which it is applied, +and $n$ is the sample size for each replication. +The parameter $r$ gives the number of bits that are discarded +from each generated random number. +That is, each real-valued random number is multiplied by $2^r$ modulo 1, +to drop its $r$ most significant bits. +These three parameters are not re-explained in each test description. +It is implicit that the first $r$ bits of each uniform are always +discarded, that the test explained in the function description +is always replicated $N$ times, and that a two-level test is applied +whenever $N > 1$. +% In many cases, it is best to choose $N=1$ and $n$ as large as possible. + +For the tests based on bit strings, another parameter that usually +appears is $s$. It represents the number +of bits of each uniform that are effectively used by the test. +That is, when $s$ appears, the test drops the $r$ most significant bits +and takes the $s$ bits that follow. +In this case, it is important to make sure that $r+s$ does not exceed +the number of bits of precision provided by the RNG. +For example, if the RNG's output is always a multiple of $1/2^{31}$, +$r+s$ should not exceed 31. +% There are also other situations (e.g., the tests in {\tt snpair}) +% where the test would detect the discretization error when the sample +% size is large and the RNG does not return enough bits. + +\ifdetailed %%% +Modules {\tt swrite} and {\tt sres} +provide basic tools used inside the other +{\tt s} modules, which implement the tests. +Typical users do not need to use them directly. +In the majority of cases, it suffices to create the generator +to be tested and pass it as a parameter to +the function that applies the desired test. +The test results are then printed automatically +to the standard output, with a level of detail that can be modified +by the user (see module {\tt swrite}). +\fi %%%%% + +%%%%%%%%%%%%%%%%%%%% +\paragraph*{Reports.} \ + +By default, each test prints a report, on standard output, +giving the name of the test, the name of the tested generator, +the test parameters, the values of the statistics, +the significance level of those statistics +and the CPU time used by the test. +This report may also contain information specific to a given test. + +It is possible to print more or less detailed statistical reports +by setting one or more of the {\tt lebool} flags defined in module {\tt swrite}. +One may wish to see, for example, the value of the test +statistic $Y$ for each of the $N$ replications, +% (usually the values in the statistical collectors), +the values of the counters, the groupings of the classes, their +expected and observed numbers for the chi-square test, etc. +For some of the tests, printing the counters would generate huge reports +and is not practically useful. For other tests (for example those +based on a chi-square test), seeing the counters and the classes may be +enlightening as to why a given generator fails a test. +It is even possible to have no output at all from any of the {\tt s} +modules of TestU01 by setting all the {\tt lebool} flags in module {\tt swrite} + to {\tt FALSE}. + +The test functions automatically print the state of the generator +at the beginning of an experiment and at the end of each test. +If more than one test are called in a program, the initial state +of the generator at the beginning of a test will be the final state +of the generator at the end of the preceding test. This permits one to +keep track of which segment of the stream of random numbers has been +used by each test. + +A more flexible way of examining detailed information +about what has happened in the tests, to have a closer look at +specific details or perhaps for post-processing the results of the tests, +is via the {\tt ...\_Res} structures. +These data structures are specific to each type of test and +are described explicitly in the detailed version of this guide +(see also module {\tt sres}). +Each function implementing a test has a parameter {\tt \ldots\_Res *} +pointing to a structure that keeps the results. + +Perhaps in the majority of situations, the automatic printout made +by the testing function suffices and there is no need to +examine the {\tt ...\_Res} structure(s) after the test(s). +In this case, it suffices to pass +a {\tt NULL} pointer for the {\tt ...\_Res *} parameter. +The structure will then be created internally and destroyed automatically +after the results are printed. +% , inside the function that applies the test. + + +\ifdetailed %%%% + +To examine or process the results of a test after its completion, +one must create a +{\tt \ldots\_Res} structure by calling the appropriate {\tt Create...} +function, and pass it as a parameter to the test. Failing to call the +appropriate {\tt Create...} function before using a {\tt \ldots\_Res} +structure will result in a memory fault because each such +function creates inner sub-structures used in the tests. +The same structure can be used for many successive tests of the same type. +When the structure is no longer needed, it should be destroyed by +calling the appropriate {\tt Delete} function. +These structures are explained in the {\em detailed\/} +version of this user's guide. + +\fi %%%% + +%%%%%%%%%%%%%%%%%%%% +\paragraph*{Scatter plots.} \ + +There is a module {\tt scatter} that permits one to plot points produced +by a generator in the $t$-dimensional hypercube $[0,1)^t$. +A rectangular box is defined in this hypercube, and the points lying +in this box are projected on a selected two-dimensional subspace +and placed on a 2-dimensional scatter plot. +The plot is put in a file ready to be processed by +\LaTeX\ or {\it Gnuplot}. + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\paragraph*{An example: The birthday spacings tests applied to an LCG.} \ + +Figure~\ref{fig:progstat} shows how to apply a test to a generator. +The call to {\tt ulcg\_CreateLCG} creates and initializes the generator +{\tt gen} to the LCG with modulus $m$ = 2147483647, +multiplier $a$ = 397204094, additive constant $c=0$, and initial +state $x_0 = 12345$. This LCG is used in the SAS statistical + software \cite{iSAS90a}. +Then the birthday spacings test is applied twice to this generator, +with $N=1$, $r=0$, in $t=2$ dimensions. +The sample sizes are $n=10^3$ and $n=10^4$, and the number $d$ of +divisions along each coordinate is chosen so that the expected number +of collisions $\lambda = n^3/(4d^t)$ is 2.5 in the first case and 0.25 +in the second case (the values of $d$ are $10^4$ and $10^6$, respectively). +Under $\cH_0$, the number of collisions is approximately a Poisson +random variable with mean $\lambda$. + + +\setbox0=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/birth1.c} +} + +\begin{figure}[htb] \centering \myboxit{\box0} +\caption{Applying two birthday spacings tests to a LCG.} + \label{fig:progstat} +\end{figure} + + +The results are in Figure~\ref{fig:resstat}. +These results are printed to the standard output, which may be redirected +to a file if desired. +%% Here, the symbol {\tt eps} means a $p$-value smaller than $10^{-15}$. +At sample size $n=10^3$, there are 6 collisions and the $p$-value is 0.04, +which is not extreme enough to reject $\cH_0$. +At sample size $n=10^4$, there are 44 collisions and the $p$-value is +close to $10^{-81}$ (i.e., if $Y$ is Poisson with mean 0.25, +$P[Y\ge 44] < 10^{-81}$). +The generator fails miserably in this case, with a sample size as +small as ten thousands. This test took approximately 0.02 second to run. + + +\ifdetailed %%% + +One may also want to examine or post-process the results of the tests in +some way. In this case, one would create a {\tt res} structure as shown +in the code segment of Figure~\ref{fig:progstat2}, and delete the +structure when it is no longer needed. By setting the flag + {\tt swrite\_Basic} to {\tt FALSE}, no output will be automatically +printed by the testing function. + + + +\setbox0=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/birth2.c} +} + +\begin{figure}[htb] \centering \myboxit{\box0} +\caption{Two birthday spacings tests and post-processing the results.} + \label{fig:progstat2} +\end{figure} + +\fi %%% + +\setbox1=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/birth1.res} +} + +\begin{figure}[ht] \centering \myboxit{\box1} +\caption{Results of the two birthday spacings tests. + \label{fig:resstat} } +\end{figure} diff --git a/TESTU01/TestU01-1.2.3/testu01/sknuth.c b/TESTU01/TestU01-1.2.3/testu01/sknuth.c new file mode 100644 index 0000000..5554a1c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sknuth.c @@ -0,0 +1,1159 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: sknuth.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "tables.h" +#include "chrono.h" +#include "num2.h" + +#include "sknuth.h" +#include "sres.h" +#include "smultin.h" +#include "wdist.h" +#include "swrite.h" +#include "unif01.h" + +#include "gofs.h" +#include "gofw.h" + +#include +#include + + +#define LENGTH 200 + + + + +/*-------------------------------- Functions ------------------------------*/ + + +static void InitRes1 ( + sknuth_Res1 *res, /* Results holder */ + long N, /* Number of replications */ + int d /* Max class index for chi2 */ +) +/* + * Initializes the sknuth_Res structure + */ +{ + sres_InitBasic (res->Bas, N, "sknuth_MaxOft: Anderson-Darling"); + sres_InitChi2 (res->Chi, N, d, "sknuth_MaxOft: Chi2"); +} + + +/*-------------------------------------------------------------------------*/ + +sknuth_Res1 * sknuth_CreateRes1 (void) +{ + sknuth_Res1 *res; + res = util_Malloc (sizeof (sknuth_Res1)); + res->Bas = sres_CreateBasic (); + res->Chi = sres_CreateChi2 (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sknuth_DeleteRes1 (sknuth_Res1 *res) +{ + if (res == NULL) + return; + sres_DeleteBasic (res->Bas); + sres_DeleteChi2 (res->Chi); + util_Free (res); +} + + +/*=========================================================================*/ + +static void InitRes2 ( + sknuth_Res2 *res, /* Results holder */ + long N, /* Number of replications */ + double Lambda, /* Poisson mean */ + char *nam /* Test name */ +) +/* + * Initializes res + */ +{ + sres_InitBasic (res->Bas, N, nam); + sres_InitPoisson (res->Pois, N, Lambda, nam); +} + + +/*-------------------------------------------------------------------------*/ + +sknuth_Res2 * sknuth_CreateRes2 (void) +{ + sknuth_Res2 *res; + res = util_Malloc (sizeof (sknuth_Res2)); + res->Bas = sres_CreateBasic (); + res->Pois = sres_CreatePoisson (); + res->Pois->pLeft = -1.0; + res->Pois->pRight = -1.0; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sknuth_DeleteRes2 (sknuth_Res2 *res) +{ + if (res == NULL) + return; + sres_DeleteBasic (res->Bas); + sres_DeletePoisson (res->Pois); + util_Free (res); +} + + +/*=========================================================================*/ + +void sknuth_Serial (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long d, int t) +{ + double ValDelta[] = { 1.0 }; + smultin_Param *par; + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test sknuth_Serial calling smultin_Multinomial\n\n"); + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, 3); + if (NULL == res) { + smultin_Multinomial (gen, par, NULL, N, n, r, d, t, FALSE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_Multinomial (gen, par, resm, N, n, r, d, t, FALSE); + sres_InitChi2 (res, N, -1, "sknuth_Serial"); + statcoll_SetDesc (res->sVal1, "Serial sVal1"); + res->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->sVal1->V, 1, N); + tables_CopyTabD (resm->sVal2[0], res->sVal2, 0, gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->pVal2, 0, gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} + + +/*=========================================================================*/ + +void sknuth_SerialSparse (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long d, int t) +{ + double ValDelta[] = { 1.0 }; + smultin_Param *par; + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test sknuth_SerialSparse calling smultin_Multinomial\n\n"); + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, 3); + if (NULL == res) { + smultin_Multinomial (gen, par, NULL, N, n, r, d, t, TRUE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_Multinomial (gen, par, resm, N, n, r, d, t, TRUE); + sres_InitChi2 (res, N, -1, "sknuth_SerialSparse"); + statcoll_SetDesc (res->sVal1, "Serial sVal1"); + res->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->sVal1->V, 1, N); + tables_CopyTabD (resm->sVal2[0], res->sVal2, 0, gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->pVal2, 0, gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} + + +/*=========================================================================*/ + +static void WriteDataGap (unif01_Gen *gen, char *TestName, + long N, long n, int r, double Alpha, double Beta) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", Alpha = %8.6g, Beta = %8.6g\n\n", Alpha, Beta); +} + + +/*-------------------------------------------------------------------------*/ + +void sknuth_Gap (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, double Alpha, double Beta) +{ + int len; + int t; + long m; /* Number of observed Gaps */ + long Seq; /* Current replication number */ + double p; /* Probability of U01 in (Alpha, Beta) */ + double X2; + double U; + double Mult; + double V[1]; /* Number of degrees of freedom for Chi2 */ + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sknuth_Gap test"; + + Timer = chrono_Create (); + p = Beta - Alpha; + t = log (gofs_MinExpected / n) / num2_log1p (-p); + len = 1 + log (gofs_MinExpected / (n*p)) / num2_log1p (-p); + t = util_Min(t, len); + t = util_Max(t, 0); + + Mult = p * n; + if (swrite_Basic) + WriteDataGap (gen, TestName, N, n, r, Alpha, Beta); + + util_Assert (Alpha >= 0.0 && Alpha <= 1.0, + "sknuth_Gap: Alpha outside interval [0..1]"); + util_Assert (Beta <= 1.0 && Beta > Alpha, + "sknuth_Gap: Beta outside interval (Alpha..1]"); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, t, "sknuth_Gap"); + + sprintf (str, "The N statistic values (a ChiSquare with %1d degrees" + " of freedom):", t); + statcoll_SetDesc (res->sVal1, str); + res->degFree = t; + if (res->degFree < 1) { + util_Warning (TRUE, "Chi-square with 0 degree of freedom."); + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); + return; + } + + /* Compute the probabilities for each gap length */ + res->NbExp[0] = Mult; + res->Loc[0] = 0; + for (len = 1; len < t; len++) { + Mult *= 1.0 - p; + res->NbExp[len] = Mult; + res->Loc[len] = len; + } + res->NbExp[t] = Mult * (1.0 - p) / p; + res->Loc[t] = t; + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, res->Count, 0, t, 0); + + /* Beginning of test */ + for (Seq = 1; Seq <= N; Seq++) { + for (len = 0; len <= t; len++) + res->Count[len] = 0; + for (m = 1; m <= n; m++) { + /* Process one gap */ + len = 0; + U = unif01_StripD (gen, r); + while ((U < Alpha || U >= Beta) && len < n) { + ++len; + U = unif01_StripD (gen, r); + } + if (len >= n) { + util_Warning (TRUE, + "sknuth_Gap: one gap of length > n\n********* Interrupting the test\n"); + printf ("\n\n"); + res->pVal2[gofw_Mean] = res->pVal2[gofw_AD] + = res->pVal2[gofw_KSM] = res->pVal2[gofw_KSP] = 0.0; + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); + return; + } + if (len >= t) + ++res->Count[t]; + else + ++res->Count[len]; + } + if (swrite_Counters) + tables_WriteTabL (res->Count, 0, t, 5, 10, "Observed numbers:"); + + X2 = gofs_Chi2 (res->NbExp, res->Count, 0, t); + statcoll_AddObs (res->sVal1, X2); + } + + V[0] = t; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataPoker (unif01_Gen * gen, char *TestName, + long N, long n, int r, int d, int k) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", d = %4d, k = %4d\n\n", d, k); +} + + +/*-------------------------------------------------------------------------*/ + +#define Maxkd 127 + +void sknuth_SimpPoker (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int d, int k) +{ + long Seq; /* Replication number */ + long NbGroups; /* Number of classes */ + long jhigh; + long jlow; + long Groupe; + long L; + int Minkd; + int s, j; + double X2; + double Mult; + double *NbExp; + long *Loca; + long *Nb; + lebool Occurs[1 + Maxkd]; + double **M; + double V[1]; /* Number degrees of freedom for Chi2 */ + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sknuth_SimpPoker test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataPoker (gen, TestName, N, n, r, d, k); + + util_Assert (d <= Maxkd, "sknuth_SimpPoker: d > 127"); + util_Assert (k <= Maxkd, "sknuth_SimpPoker: k > 127"); + util_Assert (d > 1, "sknuth_SimpPoker: d < 2"); + util_Assert (k > 1, "sknuth_SimpPoker: k < 2"); + if (k < d) + Minkd = k; + else + Minkd = d; + + num2_CalcMatStirling (&M, Minkd, k); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, Minkd, "sknuth_SimpPoker"); + NbExp = res->NbExp; + Nb = res->Count; + Loca = res->Loc; + + /* NbExp[s] = n * d * (d-1) * ... * (d-s+1) * M [s,k] / d^k. */ + Mult = n * pow ((double) d, -(double) k); + for (s = 1; s <= Minkd; s++) { + Mult *= d - s + 1; + NbExp[s] = Mult * M[s][k]; + } + jlow = 1; + jhigh = Minkd; + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, 0); + gofs_MergeClasses (NbExp, Loca, &jlow, &jhigh, &NbGroups); + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, NbGroups); + res->jmin = jlow; + res->jmax = jhigh; + res->degFree = NbGroups - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbGroups - 1); + statcoll_SetDesc (res->sVal1, str); + + for (Seq = 1; Seq <= N; Seq++) { + for (s = 1; s <= Minkd; s++) + Nb[s] = 0; + for (Groupe = 1; Groupe <= n; Groupe++) { + /* Draw one poker hand */ + for (j = 0; j < d; j++) + Occurs[j] = FALSE; + s = 0; /* s = number of different values */ + for (j = 1; j <= k; j++) { + L = unif01_StripL (gen, r, d); + if (!Occurs[L]) { + Occurs[L] = TRUE; + ++s; + } + } + ++Nb[Loca[s]]; + } + if (swrite_Counters) + tables_WriteTabL (Nb, jlow, jhigh, 5, 10, "Observed numbers:"); + + X2 = gofs_Chi2 (NbExp, Nb, jlow, jhigh); + statcoll_AddObs (res->sVal1, X2); + } + + V[0] = NbGroups - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) { + statcoll_Write (res->sVal1, 5, 14, 4, 3); + } + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + num2_FreeMatStirling (&M, Minkd); + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +#define MAXT 62 + +static void WriteDataCoupCol (unif01_Gen *gen, char *TestName, + long N, long n, int r, int d) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", d = %4d\n\n", d); +} + + +/*-------------------------------------------------------------------------*/ + +static long NRepet ( + unif01_Gen *gen, + int dInt, /* d */ + int r, + lebool Occurs[] + ) +/* + * Used by CouponCollector. Counts the number of values generated before + * each possible value of d appears at least once. + */ +{ + int u, j; + int s = 0; + + for (j = 1; j <= dInt; j++) { + do { + ++s; + if (s >= MAXT) + return MAXT; + u = unif01_StripL (gen, r, dInt); + } while (Occurs[u]); + Occurs[u] = TRUE; + } + /* j is the number of different values observed up to now */ + return s; +} + + +/*-------------------------------------------------------------------------*/ + +void sknuth_CouponCollector (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, int d) +{ + long Seq; /* Replication number */ + long Segm; + const int t = MAXT; + long tt = t; + int dInt = d; + long dd = d; + int s, k; + long NbGroups; + double Moydes; + double Mult; + double dReal = d; + double **M; + double *NbExp; + long *Loca; + long *Nb; + lebool Occurs[1 + MAXT]; + double X2; + double V[1]; /* Number degrees of freedom for Chi2 */ + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sknuth_CouponCollector test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataCoupCol (gen, TestName, N, n, r, d); + + util_Assert (d < MAXT, "sknuth_CouponCollector: d >= 62"); + util_Assert (d > 1, "sknuth_CouponCollector: d < 2"); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, MAXT, "sknuth_CouponCollector"); + NbExp = res->NbExp; + Nb = res->Count; + Loca = res->Loc; + + /* Compute the expected number of segments of each length */ + /* NbExp [s] = n * d! * Stirling (d-1, s-1) / d^s for d <= s <= t - 1 */ + /* NbExp [t] = n * (1 - d! * Stirling (d, t-1) / d^{t-1}) */ + dInt = d; + num2_CalcMatStirling (&M, d, t - 1); + Mult = n; + for (s = 1; s <= d; s++) { + Mult *= s / dReal; + } + NbExp[d] = Mult; + Moydes = d * Mult; + for (s = d + 1; s < t; s++) { + Mult /= dReal; + NbExp[s] = Mult * M[d - 1][s - 1]; + Moydes += s * NbExp[s]; + } + NbExp[t] = n - Mult * M[d][t - 1]; + Moydes += t * NbExp[t]; + Moydes /= n; + /* + if (swrite_Basic) { + printf (" Expected value of s = "); + num_WriteD (Moydes, 10, 2, 2); + printf ("\n\n"); + } + */ + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, d, t, 0); + gofs_MergeClasses (NbExp, Loca, &dd, &tt, &NbGroups); + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, dd, tt, NbGroups); + res->jmin = dd; + res->jmax = tt; + res->degFree = NbGroups - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbGroups - 1); + statcoll_SetDesc (res->sVal1, str); + + /* Beginning of test */ + for (Seq = 1; Seq <= N; Seq++) { + for (s = dInt; s <= MAXT; s++) + Nb[s] = 0; + for (Segm = 1; Segm <= n; Segm++) { + /* One collection of values. */ + for (k = 0; k < dInt; k++) + Occurs[k] = FALSE; + ++Nb[Loca[NRepet (gen, dInt, r, Occurs)]]; + } + if (swrite_Counters) + tables_WriteTabL (Nb, dd, tt, 5, 10, "Observed numbers:"); + + X2 = gofs_Chi2 (NbExp, Nb, dd, tt); + statcoll_AddObs (res->sVal1, X2); + } + + V[0] = NbGroups - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) { + statcoll_Write (res->sVal1, 5, 14, 4, 3); + } + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + num2_FreeMatStirling (&M, d); + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sknuth_Permutation (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, int t) +{ + double ValDelta[] = { 1.0 }; + smultin_Param *par; + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test sknuth_Permutation calling smultin_Multinomial\n\n"); + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellPermut, 3); + if (NULL == res) { + smultin_Multinomial (gen, par, NULL, N, n, r, 1, t, FALSE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_Multinomial (gen, par, resm, N, n, r, 1, t, FALSE); + sres_InitChi2 (res, N, -1, "sknuth_Permutation"); + statcoll_SetDesc (res->sVal1, "Serial sVal1"); + res->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->sVal1->V, 1, N); + tables_CopyTabD (resm->sVal2[0], res->sVal2, 0, gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->pVal2, 0, gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} + + +/*=========================================================================*/ + +static void WriteDataRun (unif01_Gen * gen, char *TestName, + long N, long n, int r, lebool Up) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", Up = %5s\n\n", Up ? "TRUE" : "FALSE"); +} + + +/*-------------------------------------------------------------------------*/ + +void sknuth_Run (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, lebool Up) +{ + long Seq; /* Replication number */ + double U; + double UPrec; /* Preceding value of U */ + double nReal = n; + double A[6][6]; + double B[6]; + double *NbExp; + long k; + int j, i; + long Longueur; /* Current length of the sequence */ + double Khi; + long *Count; + char str[LENGTH + 1]; + double V[1]; /* Number degrees of freedom for Chi2 */ + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sknuth_Run test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataRun (gen, TestName, N, n, r, Up); + + if (n < 600) + return; + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, 6, "sknuth_Run"); + NbExp = res->NbExp; + Count = res->Count; + res->jmin = 1; + res->jmax = 6; + + A[0][0] = 4529.35365; + A[0][1] = 9044.90208; + A[0][2] = 13567.9452; + A[0][3] = 18091.2672; + A[0][4] = 22614.7139; + A[0][5] = 27892.1588; + A[1][1] = 18097.0254; + A[1][2] = 27139.4552; + A[1][3] = 36186.6493; + A[1][4] = 45233.8198; + A[1][5] = 55788.8311; + A[2][2] = 40721.3320; + A[2][3] = 54281.2656; + A[2][4] = 67852.0446; + A[2][5] = 83684.5705; + A[3][3] = 72413.6082; + A[3][4] = 90470.0789; + A[3][5] = 111580.110; + A[4][4] = 113261.815; + A[4][5] = 139475.555; + A[5][5] = 172860.170; + + for (i = 2; i <= 6; i++) { + for (j = 1; j < i; j++) + A[i - 1][j - 1] = A[j - 1][i - 1]; + } + + B[0] = 1.0 / 6.0; + B[1] = 5.0 / 24.0; + B[2] = 11.0 / 120.0; + B[3] = 19.0 / 720.0; + B[4] = 29.0 / 5040.0; + B[5] = 1.0 / 840.0; + for (i = 1; i <= 6; i++) { + NbExp[i] = nReal * B[i - 1]; + res->Loc[i] = i; + } + + if (swrite_Classes) + /* gofs_Classes (NbExp, NULL, 1, 6, 0); */ + tables_WriteTabD (NbExp, 1, 6, 1, 20, 2, 1, "Expected numbers:"); + + statcoll_SetDesc (res->sVal1, + "The N statistic values (a ChiSquare with 6 degrees of freedom):"); + res->degFree = 6; + + /* Beginning of test */ + for (Seq = 1; Seq <= N; Seq++) { + for (i = 1; i <= 6; i++) + Count[i] = 0; + Longueur = 1; + UPrec = unif01_StripD (gen, r); + /* Generate n numbers */ + for (k = 1; k < n; k++) { + U = unif01_StripD (gen, r); + if ((Up && U < UPrec) || (!Up && U > UPrec)) { + /* The end of a "Run" */ + ++Count[Longueur]; + Longueur = 1; + } else if (Longueur < 6) + ++Longueur; + UPrec = U; + } + ++Count[Longueur]; + + if (swrite_Counters) + tables_WriteTabL (Count, 1, 6, 5, 10, "Observed numbers:"); + + /* Compute modified Chi2 for a sequence */ + Khi = 0.0; + for (i = 1; i <= 6; i++) { + for (j = 1; j <= 6; j++) { + Khi += A[i-1][j-1]*(Count[i] - NbExp[i])*(Count[j] - NbExp[j]); + } + } + statcoll_AddObs (res->sVal1, Khi / (nReal - 6.0)); + } + + V[0] = 6; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sknuth_RunIndep (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, lebool Up) +{ + long Seq; /* Replication number */ + double U; + double UPrec; /* Preceding value of U */ + double X2; + long Nb; + long k; + int i; + long Longueur; /* Current length of the sequence */ + long *Count; + double *NbExp; + double Prob[7]; + char str[LENGTH + 1]; + double V[1]; /* Number degrees of freedom for Chi2 */ + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sknuth_RunIndep test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataRun (gen, TestName, N, n, r, Up); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, 6, "sknuth_RunIndep"); + NbExp = res->NbExp; + Count = res->Count; + res->jmin = 1; + res->jmax = 6; + sprintf (str, "NumExpected[6] < %.1f", gofs_MinExpected); + + for (i = 1; i <= 5; i++) { + Prob[i] = 1.0 / num2_Factorial (i) - 1.0 / num2_Factorial (i + 1); + } + Prob[6] = 1.0 / num2_Factorial (6); + + statcoll_SetDesc (res->sVal1, + "The N statistic values (a ChiSquare with 5 degrees of freedom):"); + res->degFree = 5; + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 1; i <= 6; i++) + Count[i] = 0; + Longueur = 1; + UPrec = unif01_StripD (gen, r); + for (k = 1; k <= n; k++) { + U = unif01_StripD (gen, r); + if ((Up && U < UPrec) || (!Up && U > UPrec)) { + /* The end of a "Run" */ + ++Count[Longueur]; + Longueur = 1; + U = unif01_StripD (gen, r); + } else if (Longueur < 6) + ++Longueur; + UPrec = U; + } + ++Count[Longueur]; + + Nb = 0; + for (i = 1; i <= 6; i++) + Nb += Count[i]; + for (i = 1; i <= 6; i++) + NbExp[i] = Nb * Prob[i]; + + if (swrite_Counters) { + tables_WriteTabD (NbExp, 1, 6, 1, 20, 2, 1, "Expected numbers:"); + tables_WriteTabL (Count, 1, 6, 1, 17, "Observed numbers:"); + } + /* util_Warning (NbExp[6] < gofs_MinExpected, str); */ + + X2 = gofs_Chi2 (NbExp, Count, 1, 6); + statcoll_AddObs (res->sVal1, X2); + } + + V[0] = 5; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataMaxOft (unif01_Gen * gen, char *TestName, + long N, long n, int r, int d, int t, double NbExp) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", d = %4d, t = %2d\n\n", d, t); + printf (" Number of categories = %d\n", d); + printf (" Expected number per category = %.2f\n\n", NbExp); +} + + +/*-------------------------------------------------------------------------*/ + +static double FDistMax ( + double Par[], /* The parameter t = Par[0] */ + double x /* The argument */ + ) +/* + * Distribution function for the maximum of t random variables U01 = x^t + */ +{ + /* double Prod; + int j; + const int t = Par[0] + 0.5; + */ + if (x >= 1.0) + return 1.0; + if (x <= 0.0) + return 0.0; + return pow (x, Par[0]); + /* + Prod = x; + for (j = 1; j < t; j++) + Prod *= x; + return Prod; + */ +} + + +/*-------------------------------------------------------------------------*/ + +void sknuth_MaxOft (unif01_Gen * gen, sknuth_Res1 * res, + long N, long n, int r, int d, int t) +{ + long Seq; /* Replication number */ + double tReal = t; + double dReal = d; + double NbExp; /* Expected number in each class */ + double MaxU; + double U; + long Groupe; + int j, Indice; + double *P; + double Par[1]; + double X2; + double V[1]; /* Number degrees of freedom for Chi2 */ + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sknuth_MaxOft test"; + sres_Basic *Bas; + sres_Chi2 *Chi; + + Timer = chrono_Create (); + Par[0] = t; + + NbExp = n / dReal; + if (swrite_Basic) + WriteDataMaxOft (gen, TestName, N, n, r, d, t, NbExp); + util_Assert (NbExp >= gofs_MinExpected, + "MaxOft: NbExp < gofs_MinExpected"); + if (res == NULL) { + localRes = TRUE; + res = sknuth_CreateRes1 (); + } + InitRes1 (res, N, d); + Bas = res->Bas; + Chi = res->Chi; + Chi->jmin = 0; + Chi->jmax = d - 1; + for (j = 0; j < d; j++) { + Chi->Loc[j] = j; + Chi->NbExp[j] = NbExp; + } + + sprintf (str, "The N statistic values (a ChiSquare with %1d degrees" + " of freedom):", d - 1); + statcoll_SetDesc (Chi->sVal1, str); + Chi->degFree = d - 1; + statcoll_SetDesc (Bas->sVal1, + "The N statistic values (the Anderson-Darling p-values):"); + P = util_Calloc ((size_t) n + 1, sizeof (double)); + + for (Seq = 1; Seq <= N; Seq++) { + for (Indice = 0; Indice < d; Indice++) + Chi->Count[Indice] = 0; + for (Groupe = 1; Groupe <= n; Groupe++) { + /* Generate a vector and find the max value */ + MaxU = unif01_StripD (gen, r); + for (j = 1; j < t; j++) { + U = unif01_StripD (gen, r); + if (U > MaxU) + MaxU = U; + } + /* For the chi2 */ + Indice = pow (MaxU, tReal) * dReal; + ++Chi->Count[Indice]; + + /* For the Anderson-Darling */ + P[Groupe] = MaxU; + } + if (swrite_Counters) + tables_WriteTabL (Chi->Count, 0, d - 1, 5, 10, "Observed numbers:"); + + /* Value of the chi2 statistic */ + X2 = gofs_Chi2Equal (NbExp, Chi->Count, 0, d - 1); + statcoll_AddObs (Chi->sVal1, X2); + + /* Value of the Anderson-Darling statistic */ + gofw_ActiveTests1 (P, n, FDistMax, Par, Bas->sVal2, Bas->pVal2); + statcoll_AddObs (Bas->sVal1, Bas->pVal2[gofw_AD]); + } + util_Free (P); + + V[0] = d - 1; + gofw_ActiveTests2 (Chi->sVal1->V, Chi->pVal1->V, N, wdist_ChiSquare, V, + Chi->sVal2, Chi->pVal2); + Chi->pVal1->NObs = N; + sres_GetChi2SumStat (Chi); + + gofw_ActiveTests2 (Bas->sVal1->V, Bas->pVal1->V, N, wdist_Unif, + (double *) NULL, Bas->sVal2, Bas->pVal2); + Bas->pVal1->NObs = N; + + if (swrite_Collectors) { + statcoll_Write (Chi->sVal1, 5, 14, 4, 3); + statcoll_Write (Bas->sVal1, 5, 14, 4, 3); + } + if (swrite_Basic) { + if (N == 1) { + swrite_AddStrChi (str, LENGTH, Chi->degFree); + gofw_WriteActiveTests2 (N, Chi->sVal2, Chi->pVal2, str); + } else { + printf ("\n-----------------------------------------------\n"); + printf ("Test results for chi2 with %2ld degrees of freedom:\n", + Chi->degFree); + gofw_WriteActiveTests0 (N, Chi->sVal2, Chi->pVal2); + swrite_Chi2SumTest (N, Chi); + } + + if (N == 1) { + gofw_WriteActiveTests2 (N, Bas->sVal2, Bas->pVal2, + "Anderson-Darling statistic :"); + } else { + printf ("\n-----------------------------------------------\n"); + printf ("Test results for Anderson-Darling:\n"); + gofw_WriteActiveTests0 (N, Bas->sVal2, Bas->pVal2); + } + printf ("\n"); + swrite_Final (gen, Timer); + } + if (localRes) + sknuth_DeleteRes1 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sknuth_Collision (unif01_Gen * gen, sknuth_Res2 * res, + long N, long n, int r, long d, int t) +{ + double ValDelta[] = { -1.0 }; + smultin_Param *par; + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test sknuth_Collision calling smultin_Multinomial\n\n"); + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, -3); + if (NULL == res) { + smultin_Multinomial (gen, par, NULL, N, n, r, d, t, TRUE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_Multinomial (gen, par, resm, N, n, r, d, t, TRUE); + InitRes2 (res, N, resm->Mu[0], "sknuth_Collision"); + statcoll_SetDesc (res->Bas->sVal1, "Collision sVal1"); + statcoll_SetDesc (res->Pois->sVal1, "Collision sVal1"); + res->Pois->sVal1->NObs = resm->Collector[0]->NObs; + res->Bas->sVal1->NObs = resm->Collector[0]->NObs; + res->Pois->pLeft = resm->pCollLeft; + res->Pois->pRight = resm->pCollRight; + tables_CopyTabD (resm->Collector[0]->V, res->Bas->sVal1->V, 1, N); + tables_CopyTabD (resm->Collector[0]->V, res->Pois->sVal1->V, 1, N); + res->Pois->pVal2 = resm->pColl; + res->Pois->sVal2 = resm->NbCollisions; + tables_CopyTabD (resm->sVal2[0], res->Bas->sVal2, 0, + gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->Bas->pVal2, 0, + gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} + + +/*=========================================================================*/ + +void sknuth_CollisionPermut (unif01_Gen * gen, sknuth_Res2 * res, + long N, long n, int r, int t) +{ + double ValDelta[] = { -1.0 }; + smultin_Param *par; + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test sknuth_CollisionPermut calling smultin_Multinomial\n\n"); + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellPermut, -3); + if (NULL == res) { + smultin_Multinomial (gen, par, NULL, N, n, r, 0, t, TRUE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_Multinomial (gen, par, resm, N, n, r, 0, t, TRUE); + InitRes2 (res, N, resm->Mu[0], "sknuth_CollisionPermut"); + statcoll_SetDesc (res->Bas->sVal1, "CollisionPermut sVal1"); + statcoll_SetDesc (res->Pois->sVal1, "CollisionPermut sVal1"); + res->Pois->pLeft = resm->pCollLeft; + res->Pois->pRight = resm->pCollRight; + res->Pois->sVal1->NObs = resm->Collector[0]->NObs; + res->Bas->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->Bas->sVal1->V, 1, N); + tables_CopyTabD (resm->Collector[0]->V, res->Pois->sVal1->V, 1, N); + res->Pois->pVal2 = resm->pColl; + res->Pois->sVal2 = resm->NbCollisions; + tables_CopyTabD (resm->sVal2[0], res->Bas->sVal2, 0, + gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->Bas->pVal2, 0, + gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/sknuth.tex b/TESTU01/TestU01-1.2.3/testu01/sknuth.tex new file mode 100644 index 0000000..1d66631 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sknuth.tex @@ -0,0 +1,336 @@ +\defmodule {sknuth} + +This module implements the classical statistical tests for RNGs +described in Knuth's book \cite{rKNU81a}. +(They were actually taken from the 1981 edition, and implemented +some years before the 1998 edition \cite{rKNU98a} appeared.) +Some of these tests are special cases of the {\em multinomial\/} +tests described and implemented in module {\tt smultin}. +In these cases, the functions here simply call the appropriate +functions in {\tt smultin}. +\resdef + +\bigskip\hrule + +\code\hide +/* sknuth.h for ANSI C */ +#ifndef SKNUTH_H +#define SKNUTH_H +\endhide +#include "gdef.h" +#include "unif01.h" +#include "sres.h" +\endcode + + +\ifdetailed %%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} + +The detailed test results can be recovered in a structure of type +{\tt sres\_Basic}, {\tt sres\_Chi2} or in one of the structures +defined in this module, depending on the test. + +\code + +typedef struct { + + sres_Chi2 *Chi; + sres_Basic *Bas; + +} sknuth_Res1; +\endcode + \tab + Structure for keeping the results of the tests in {\tt sknuth\_MaxOft}. + The results for the chi-square test are kept in + {\tt Chi}, and for the Anderson-Darling test in {\tt Bas}. + \endtab +\code + + +sknuth_Res1 * sknuth_CreateRes1 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt sknuth\_MaxOft} test. + \endtab +\code + + +void sknuth_DeleteRes1 (sknuth_Res1 *res); +\endcode + \tab + Frees the memory allocated by {\tt sknuth\_CreateRes1}. + \endtab + +\bigskip\hrule\bigskip + +\code +typedef struct { + + sres_Poisson *Pois; + sres_Basic *Bas; + +} sknuth_Res2; +\endcode + \tab + Structure for keeping the results of the tests {\tt sknuth\_Collision} + and {\tt sknuth\_CollisionPermut}. + The results for the Poisson approximation are kept in + {\tt Pois}, and for the normal approximation in {\tt Bas}. + \endtab +\code + + +sknuth_Res2 * sknuth_CreateRes2 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt sknuth\_Collision} or a {\tt sknuth\_CollisionPermut} test. + \endtab +\code + + +void sknuth_DeleteRes2 (sknuth_Res2 *res); +\endcode + \tab + Frees the memory allocated by {\tt sknuth\_CreateRes2}. + \endtab + + + + +\fi %%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code + +void sknuth_Serial (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long d, int t); +\endcode + \tab + Applies\index{Test!Serial} the {\em serial test\/} of uniformity + in $t$ dimensions, + using a chi-square, as described by Knuth \cite{rKNU98a}, p.62. + It divides the interval $[0,1)$ in $d$ equal segments, thus dividing + the unit hypercube $[0,1)^t$ in $d^{t}$ small hypercubes. + It generates $n$ points ($t$-dimensional vectors) in $[0,1)^t$, + using $n$ non-overlapping vectors of $t$ successive output values + from the generator, counts the number of points falling into + each small hypercube, and compares those counts with the expected + values via a chi-square test. + This test is a special case of {\tt smultin\_Multinomial} with + {\tt Sparse = FALSE} (see \cite{rLEC02c}). + It assumes that we are in the {\em dense\/} case, where + $n > k = d^t$. + Restriction: $n / d^{t}\ge$ {\tt gofs\_MinExpected}. + \endtab +\code + + +void sknuth_SerialSparse (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long d, int t); +\endcode + \tab + Similar\index{Test!SerialSparse} + to {\tt sknuth\_Serial}, except that a normal approximation + is used for the distribution of the chi-square statistic. + This is valid asymptotically when $n / d^t$ is bounded and + $n\to\infty$. + The implementation uses a hashing table in order to allow for + larger values of $d^t$. + This test is a special case of {\tt smultin\_Multinomial} with + {\tt Sparse = TRUE} (see \cite{rLEC02c}). + It corresponds to the sparse case of the serial test, where we assume + that $n$ is large and $n \le k = d^t$. + Restrictions: $d^t < 2^{53}$ and $d^{t}/n < 2^{31}$. + \endtab +\code + + +void sknuth_Permutation (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int t); +\endcode + \tab + Applies\index{Test!Permutation} + the {\em permutation test\/} (Knuth \cite{rKNU98a}, page 65). + It generates $n$ non-overlapping vectors of $t$ values, each vector + using $t$ successive values obtained from the generator, + and determines to which permutation each vector corresponds + (the permutation that would place the values in increasing order). + The test counts the number of times each permutation has appeared + and compares these counts with the expected values ($n/t!$) + via a chi-square test. + This is a special case of {\tt smultin\_Multinomial} with + {\tt Sparse = FALSE} and +% a special way of choosing the cell number, that is with + {\tt smultin\_Gener\-Cell = smultin\_GenerCellPermut}. + It corresponds to the dense case, where $n$, + the number of points, should be larger than $t!$, the number of cells. + Restrictions: $n/t! \ge$ {\tt gofs\_MinExpected} and $2 \le t \le 18$. + \endtab +\code + + +void sknuth_Gap (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, double Alpha, double Beta); +\endcode + \tab Applies\index{Test!Gap} + the {\em gap test\/} described by Knuth \cite{rKEN38a,rKEN39a,rKNU98a}. + Let $\alpha=$ {\tt Alpha}, $\beta=$ {\tt Beta}, and $p=\beta-\alpha$. + The test generates $n$ values in $[0,1)$ and, for $s=0,1,2,\dots$, + counts the number of times that a sequence of exactly $s$ successive + values fall outside the interval $[\alpha,\beta]$ + (this is the number of {\em gaps\/} of length $s$ between visits to + $[\alpha,\beta]$). It then applies a chi-square test + to compare the expected and observed number of observations for the + different values of $s$. + Restrictions: $0\le\alpha < \beta\le 1$. + \endtab +\code + + +void sknuth_SimpPoker (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int d, int k); +\endcode + \tab Applies\index{Test!Poker} + the simplified {\rm poker test\/} described by + Knuth \cite{rKEN38a,rKEN39a,rKNU98a}. + It generates $n$ groups of $k$ integers from 0 to $d-1$, + by making $nk$ calls to the generator, and for each group it computes + the number $s$ of distinct integers in the group. +\hrichard{Pourquoi ne pas l'appeler simplement Poker test? Dixit Pierre: +parce qu'il y a un autre test dans Knuth qui est le poker test; +celui-ci est appel\'e poker test simplifi\'e par Knuth.} + It then applies a chi-square test + to compare the expected and observed number of observations for the + different values of $s$. + Restrictions: $d < 128$ and $k < 128$. + \endtab +\code + + +void sknuth_CouponCollector (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int d); +\endcode + \tab Applies the {\em coupon collector test\/} proposed in \cite{rGRE55a} + and described in \cite{rKNU98a}. \index{Test!CouponCollector} + The test generates a sequence of random integers in $\{0,\dots,d-1\}$, + and counts how many must be generated before each of the + $d$ possible values appears at least once. + This is repeated $n$ times. The test counts how many times exactly + $s$ integers were needed, for each $s$, and compares these counts + with the expected values via a chi-square test. + Restriction: $1 1$, the empirical distribution of the $p$-values of the + AD test is compared with the AD distribution. + Restriction: $n/d \ge$ {\tt gofs\_MinExpected}. +\endtab +\code + + +void sknuth_Collision (unif01_Gen *gen, sknuth_Res2 *res, + long N, long n, int r, long d, int t); +\endcode + \tab + Applies\index{Test!Collision} the {\em collision test\/} + (Knuth \cite{rKNU98a}, pp.~70--71, and \cite{rLEC02c}). + Similar to {\tt sknuth\_Serial}, except that the test computes the + number of {\em collisions\/} (the number of times a point hits a cell + already occupied) instead of computing the chi-square statistic. + This is a special case of {\tt smultin\_Multinomial} with + {\tt Sparse = TRUE}. This test is meaningfull only in the sparse case, + with $n$ smaller than $k$. See the documentation in {\tt smultin}. + Restrictions: $d^t < 2^{53}$ (assuming that a {\tt double's} mantissa + uses 53 bits of precision) and $d^{t}/n < 2^{31}$. + \endtab +\code + + +void sknuth_CollisionPermut (unif01_Gen *gen, sknuth_Res2 *res, + long N, long n, int r, int t); +\endcode + \tab + Similar\index{Test!CollisionPermut} to {\tt sknuth\_Collisions}, + except that\index{permutations} + instead of generating vectors as in {\tt sknuth\_Serial}, + it generates permutations as in {\tt sknuth\_Permutation}. + It then computes the number of collisions between these permutations. + This is a special case of {\tt smultin\_Multinomial} with + {\tt Sparse = TRUE} and +% a special way of choosing the cell number, that is with + {\tt smultin\_Gener\-Cell = smultin\_GenerCellPermut}. + It corresponds to the sparse case where $n$, the number of points, + should be much smaller than $t!$, the number of cells. + Restrictions: $2 \le t \le 18 $ and $ t!/n < 2^{31}$. + \endtab + +\code +\hide +#endif +\endhide +\endcode + + diff --git a/TESTU01/TestU01-1.2.3/testu01/smarsa.c b/TESTU01/TestU01-1.2.3/testu01/smarsa.c new file mode 100644 index 0000000..a1fa2a5 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/smarsa.c @@ -0,0 +1,1664 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: smarsa.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "tables.h" +#include "chrono.h" +#include "num.h" + +#include "smarsa.h" +#include "smultin.h" +#include "wdist.h" +#include "swrite.h" +#include "unif01.h" + +#include "vectorsF2.h" + +#include "gofs.h" +#include "gofw.h" +#include "fdist.h" +#include "fbar.h" +#include "fmass.h" +#include "statcoll.h" + +#include +#include +#include + + +#define LENGTH 200 + +/* MAXK = 2^64 */ +#define STR_MAXK "18446744073709551616" + + + +/*---------------------------- Extern variables ---------------------------*/ + +#ifdef USE_LONGLONG +double smarsa_Maxk = 18446744073709551616.0; /* 2^64 */ +#else +double smarsa_Maxk = num_MaxIntDouble; /* 2^53 */ +#endif + + + + +/*------------------------------- Functions -------------------------------*/ + +static void WriteResultsPoisson (sres_Poisson *res, long N) +{ + printf ("\n----------------------------------------------------" + "\nTotal expected number = N*Lambda : "); + num_WriteD (N * res->Lambda, 10, 2, 2); + printf ("\nTotal observed number : %7ld\n", + (long) res->sVal2); + gofw_Writep1 (res->pVal2); + printf ("\n"); +} + + +/*=========================================================================*/ + +static void InitRes ( + smarsa_Res *res, /* Results holder */ + long N, /* Number of replications */ + double Lambda, /* Poisson mean */ + char *nam /* Test name */ +) +/* + * Initializes res + */ +{ + sres_InitBasic (res->Bas, N, nam); + sres_InitPoisson (res->Pois, N, Lambda, nam); +} + + +/*-------------------------------------------------------------------------*/ + +smarsa_Res * smarsa_CreateRes (void) +{ + smarsa_Res *res; + res = util_Malloc (sizeof (smarsa_Res)); + res->Bas = sres_CreateBasic (); + res->Pois = sres_CreatePoisson (); + res->Pois->pLeft = -1.0; + res->Pois->pRight = -1.0; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void smarsa_DeleteRes (smarsa_Res *res) +{ + if (res == NULL) + return; + sres_DeleteBasic (res->Bas); + sres_DeletePoisson (res->Pois); + util_Free (res); +} + + +/*=========================================================================*/ + +static void InitRes2 ( + smarsa_Res2 *res, /* Results holder */ + long N, /* Number of replications */ + int jmax, /* Max class index for GCD */ + int tmax /* Max class index for NumIter */ +) +/* + * Initializes the smarsa_Res2 structure + */ +{ + sres_InitChi2 (res->GCD, N, jmax, "smarsa_GCD: GCD"); + sres_InitChi2 (res->NumIter, N, tmax, "smarsa_GCD: NumIter"); +} + + +/*-------------------------------------------------------------------------*/ + +smarsa_Res2 *smarsa_CreateRes2 (void) +{ + smarsa_Res2 *res; + res = util_Malloc (sizeof (smarsa_Res2)); + res->GCD = sres_CreateChi2 (); + res->NumIter = sres_CreateChi2 (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void smarsa_DeleteRes2 (smarsa_Res2 *res) +{ + if (res == NULL) + return; + sres_DeleteChi2 (res->GCD); + sres_DeleteChi2 (res->NumIter); + util_Free (res); +} + + +/*=========================================================================*/ + +void smarsa_SerialOver (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, long d, int t) +{ + double ValDelta[] = { 1.0 }; + smultin_Param *par; + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test smarsa_SerialOver calling smultin_MultinomialOver\n\n"); + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, 0); + if (NULL == res) { + smultin_MultinomialOver (gen, par, NULL, N, n, r, d, t, FALSE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_MultinomialOver (gen, par, resm, N, n, r, d, t, FALSE); + sres_InitBasic (res, N, "smarsa_SerialOver"); + statcoll_SetDesc (res->sVal1, "SerialOver sVal1"); + res->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->sVal1->V, 1, N); + tables_CopyTabD (resm->sVal2[0], res->sVal2, 0, gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->pVal2, 0, gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} + + +/*=========================================================================*/ + +void smarsa_CollisionOver (unif01_Gen *gen, smarsa_Res *res, + long N, long n, int r, long d, int t) +{ + double ValDelta[] = { -1.0 }; + smultin_Param *par; + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test smarsa_CollisionOver calling smultin_MultinomialOver\n\n"); + + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellSerial, 3); + if (NULL == res) { + smultin_MultinomialOver (gen, par, NULL, N, n, r, d, t, TRUE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_MultinomialOver (gen, par, resm, N, n, r, d, t, TRUE); + InitRes (res, N, resm->Mu[0], "smarsa_CollisionOver"); + statcoll_SetDesc (res->Bas->sVal1, "CollisionOver sVal1"); + statcoll_SetDesc (res->Pois->sVal1, "CollisionOver sVal1"); + res->Pois->sVal1->NObs = resm->Collector[0]->NObs; + res->Bas->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->Bas->sVal1->V, 1, N); + tables_CopyTabD (resm->Collector[0]->V, res->Pois->sVal1->V, 1, N); + res->Pois->pVal2 = resm->pColl; + if (resm->CollApprox == smultin_CollPoissonSparse) + res->Pois->sVal2 = resm->NbCollisions; + else + res->Pois->sVal2 = resm->NbCells[0]; + tables_CopyTabD (resm->sVal2[0], res->Bas->sVal2, 0, + gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->Bas->pVal2, 0, + gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); +} + + +/*=========================================================================*/ + +void smarsa_Opso (unif01_Gen * gen, smarsa_Res * res, long N, int r, int p) +{ + int d; + long NBalls; + + switch (p) { + case 1: + NBalls = 2097152; + d = 1024; + break; + case 2: + NBalls = 4194304; + d = 2048; + break; + case 3: + NBalls = 8388608; + d = 2048; + break; + default: + util_Error ("smarsa_Opso: p must be in {1, 2, 3}"); + } + + if (swrite_Basic) + printf ("***********************************************************\n" + "Test smarsa_Opso calling smarsa_CollisionOver\n\n"); + smarsa_CollisionOver (gen, res, N, NBalls, r, d, 2); +} + + +/*=========================================================================*/ +/* + * The CPU time needed for BirthdaySpacings is 6 times longer when I used + * the standard function qsort of stdlib.h. Thus we use our own QuickSort. + */ + +#undef QSORT +#ifdef QSORT +static int compareD (const void *p0, const void *q0) +{ + double x = *((const double *) p0); + double y = *((const double *) q0); + return (x < y) ? -1 : (x > y) ? 1 : 0; +} +/* qsort ((void *)(DatDiff + 1), (size_t) n, sizeof (double), compareD); */ +#endif + + +/*=========================================================================*/ + +static void WriteDataBirth (unif01_Gen * gen, char *TestName, long N, long n, + int r, long d, int t, int p, double k, smultin_CellType kc, + double Lambda) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", d = %1ld, t = %1d, p = %1d\n\n", d, t, p); +#ifdef USE_LONGLONG + if (kc == 0 && d > 1) /* kc = 2^64 */ + printf ("\n Number of cells = d^t = " STR_MAXK "\n"); + else + printf ("\n Number of cells = d^t = %18" PRIuLEAST64 "\n", kc); +#else + printf ("\n Number of cells = d^t = %16.0f\n", k); +#endif + printf (" Lambda = Poisson mean = "); + num_WriteD (Lambda, 12, 4, 2); + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +void smarsa_BirthdaySpacings (unif01_Gen *gen, sres_Poisson *res, + long N, long n, int r, long d, int t, int Order) +{ + long Seq; /* Replication number */ + long j; + long Sum; + double Y; /* Number of collisions */ + double k; + smultin_CellType kc; + double Lambda; /* Poisson mean */ + smultin_CellType *Dates, *DatDiff; + fmass_INFO Mass; + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "smarsa_BirthdaySpacings test"; + + Timer = chrono_Create (); + kc = k = d; + for (j = 2; j <= t; j++) { + k *= d; + kc *= d; + } + Lambda = (double) n * n / k * (n / 4.0); + + if (swrite_Basic) + WriteDataBirth (gen, TestName, N, n, r, d, t, Order, k, kc, Lambda); + + if (d <= 1) { + util_Warning (TRUE, + "smarsa_BirthdaySpacings: d <= 1. The test is not done."); + return; + } + if (k > smarsa_Maxk) { + util_Warning (TRUE, + "smarsa_BirthdaySpacings: d^t > smarsa_Maxk. The test is not done."); + return; + } + if (8.0 * N * Lambda > sqrt (sqrt (k))) { + util_Warning (TRUE, + "smarsa_BirthdaySpacings: 8N Lambda > k^(1/4). The test is not done."); + return; + } + if (res == NULL) { + localRes = TRUE; + res = sres_CreatePoisson (); + } + sres_InitPoisson (res, N, Lambda, "smarsa_BirthdaySpacings"); + + Dates = util_Calloc (1 + (size_t) n, sizeof (smultin_CellType)); + DatDiff = util_Calloc (1 + (size_t) n, sizeof (smultin_CellType)); + + sprintf (str, "The N statistic values (a Poisson with mean %g):", Lambda); + statcoll_SetDesc (res->sVal1, str); + + Sum = 0; + for (Seq = 1; Seq <= N; Seq++) { + /* Generate and sort the "birth dates" */ + if (Order == 2) { + for (j = 1; j <= n; j++) { + Dates[j] = smultin_GenerCellSerial2 (gen, r, t, d); + } + } else { + for (j = 1; j <= n; j++) { + Dates[j] = smultin_GenerCellSerial (gen, r, t, d); + } + } +#ifdef USE_LONGLONG + tables_QuickSortULL (Dates, 1, n); + /* Compute the differences between adjacent dates */ + gofs_DiffULL (Dates, DatDiff, 1, n, 0ULL, 1ULL); + /* The last cell is a special case */ + DatDiff[n] = kc - Dates[n] + Dates[1]; + tables_QuickSortULL (DatDiff, 1, n); +#else + tables_QuickSortD (Dates, 1, n); + /* Compute the differences between adjacent dates */ + gofs_DiffD (Dates, DatDiff, 1, n, 0.0, 1.0); + /* The last cell is a special case */ + DatDiff[n] = kc - Dates[n] + Dates[1]; + tables_QuickSortD (DatDiff, 1, n); +#endif + + /* Count the number of collisions in DatDiff */ + Y = 0.0; + for (j = 2; j <= n; j++) { + if (DatDiff[j] == DatDiff[j - 1]) + Y += 1.0; + } + Sum += Y; + statcoll_AddObs (res->sVal1, Y); + if (swrite_Counters) { +#ifdef USE_LONGLONG + tables_WriteTabULL (Dates, 1, n, 3, 21, "Birthdates:"); + tables_WriteTabULL (DatDiff, 1, n, 3, 21, "Birthdate differences:"); +#else + tables_WriteTabD (Dates, 1, n, 4, 17, 0, 0, "Birthdates:"); + tables_WriteTabD (DatDiff, 1, n, 4, 17, 0, 0, + "Birthdate differences:"); +#endif + } + } + + res->sVal2 = Sum; + Mass = fmass_CreatePoisson (N * Lambda); + res->pLeft = fdist_Poisson2 (Mass, Sum); + res->pRight = fbar_Poisson2 (Mass, Sum); + fmass_DeletePoisson (Mass); + res->pVal2 = gofw_pDisc (res->pLeft, res->pRight); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 1, 1); + if (swrite_Basic) { + WriteResultsPoisson (res, N); + swrite_Final (gen, Timer); + } + util_Free (Dates); + util_Free (DatDiff); + if (localRes) + sres_DeletePoisson (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataCAT (unif01_Gen *gen, char *TestName, + long N, long n, int r, long d, int t, long S[], double Lambda) +{ + int i; + swrite_Head (gen, TestName, N, n, r); + printf (", d = %1ld, t = %1d\n\n", d, t); + for (i = 0; i < t; i++) { + printf (" S[%1d] = %1ld\n", i, S[i]); + } + printf ("\n Lambda = Poisson mean = "); + num_WriteD (Lambda, 12, 4, 2); + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void TestCATData (long d, int t, long S1[]) +/* + * Test that the key to search for has no overlap, that is cannot be + * written as ABA, where A and B are parts of the key. + */ +{ + int i, j, s; + long k1, k2; + i = 0; + j = t - 1; + k1 = k2 = 0; + while (i < j) { + k1 = k1 * d + S1[i]; + k2 = 0; + for (s = j; s < t; s++) + k2 = k2 * d + S1[s]; + util_Assert (k1 != k2, + "CATData: target cell number of the form ABA"); + i++; + j--; + } +} + + +/*-------------------------------------------------------------------------*/ +#if 0 +static void CATGenere1 ( + unif01_Gen *gen, + long n, /* Number of points */ + int r, /* Drop the first r bits of each U01 */ + long d, /* Number of segments on the 1-dim. line */ + int t, /* Dimension */ + long Key, /* Key to search for */ + long k1, /* = d^(t-1) */ + long *Count /* Number of times Key appears */ + ) +/* + * Generate the n points in the dense case and count the number of times + * cell Key appears. This is the circular version with n points. It also + * correspond to the case of aperiodic Key. + */ +{ + int j, i; + long Indice = 0; + long Y = 0; /* Counter */ + long Premier[32]; + + util_Assert (t <= 32, "smarsa_CAT.Genere: t > 32"); + + /* Generation of the first (t - 1) elements of the first tuple */ + for (j = 1; j < t; j++) { + Premier[j] = unif01_StripL (gen, r, d); + Indice = Indice * d + Premier[j]; + } + + /* Generation of the n - (tt - 1) tuples */ + for (j = 1; j <= n - (t - 1); j++) { + /* Remove the leftmost component ... */ + Indice %= k1; + /* ... shift and get another for the rightmost one */ + Indice = Indice * d + unif01_StripL (gen, r, d); + if (Indice == Key) { + ++Y; + /* Key found: jump over the whole Indice and restart */ + Indice = 0; + for (i = 1; i < t; i++) { + Indice = Indice * d + unif01_StripL (gen, r, d); + j++; + } + } + } + + /* Generation of the last (t - 1) tuples. We use numbers in array */ + /* Premier[] so that the sequence is in fact circular */ + for (j = 1; j < t; j++) { + Indice %= k1; + Indice = Indice * d + Premier[j]; + if (Indice == Key) + ++Y; + } + + *Count = Y; +} +#endif + +/*-------------------------------------------------------------------------*/ + +static void CATGenere ( + unif01_Gen *gen, + long n, /* Number of points */ + int r, /* Drop the first r bits of each U01 */ + long d, /* Number of segments on the 1-dim. line */ + int t, /* Dimension */ + long Key, /* Key to search for */ + long k1, /* = d^(t-1) */ + long *Count /* Number of times Key appears */ + ) +/* + * Generate the n points in the dense case and count the number of times + * cell Key appears. This is the non-circular version with n - t + 1 points. + * It also correspond to the case of aperiodic Key. + */ +{ + int j, i; + long Indice; + long Y = 0; /* Counter */ + + /* Generation of the first (t - 1) elements of the first tuple */ + Indice = 0; + for (j = 1; j < t; j++) + Indice = Indice * d + unif01_StripL (gen, r, d); + + /* Generation of the n - (tt - 1) tuples */ + for (j = 1; j <= n - (t - 1); j++) { + /* Remove the leftmost component ... */ + Indice %= k1; + /* ... shift and get another for the rightmost one */ + Indice = Indice * d + unif01_StripL (gen, r, d); + if (Indice == Key) { + ++Y; + /* Key found: jump over the whole Indice and restart */ + Indice = 0; + for (i = 1; i < t; i++) { + Indice = Indice * d + unif01_StripL (gen, r, d); + j++; + } + } + } + + *Count = Y; +} + + +/*-------------------------------------------------------------------------*/ + +void smarsa_CAT (unif01_Gen *gen, sres_Poisson *res, + long N, long n, int r, long d, int t, long S[]) +{ + long Seq; + long i; + double k; + long k1; /* d^(t-1) */ + long Key; /* Cell number to search for */ + double Lambda; /* Poisson mean */ + long Sum; + long Co; + fmass_INFO Mass; + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "smarsa_CAT test"; + + Timer = chrono_Create (); + k1 = d; + for (i = 2; i < t; i++) + k1 *= d; + k = k1 * d; + Lambda = (n - t + 1) / k; + if (swrite_Basic) + WriteDataCAT (gen, TestName, N, n, r, d, t, S, Lambda); + util_Assert (d > 1, "smarsa_CAT: d <= 1"); + + Key = 0; + for (i = 0; i < t; i++) { + if (S[i] < 0 || S[i] >= d) { + util_Error ("smarsa_CAT: S[i] must be in [0, d - 1]"); + } + Key = Key * d + S[i]; + } + TestCATData (d, t, S); + if (res == NULL) { + localRes = TRUE; + res = sres_CreatePoisson (); + } + sres_InitPoisson (res, N, Lambda, "smarsa_CAT"); + sprintf (str, "The N statistic values (a Poisson with mean %g):", Lambda); + statcoll_SetDesc (res->sVal1, str); + + Sum = 0; + for (Seq = 1; Seq <= N; Seq++) { + CATGenere (gen, n, r, d, t, Key, k1, &Co); + statcoll_AddObs (res->sVal1, (double) Co); + Sum += Co; + } + + res->sVal2 = Sum; + Mass = fmass_CreatePoisson (res->Mu); + res->pLeft = fdist_Poisson2 (Mass, Sum); + res->pRight = fbar_Poisson2 (Mass, Sum); + fmass_DeletePoisson (Mass); + res->pVal2 = gofw_pDisc (res->pLeft, res->pRight); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 1, 1); + if (swrite_Basic) { + WriteResultsPoisson (res, N); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeletePoisson (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataCATBits (unif01_Gen *gen, char *TestName, + long N, long n, int r, int s, int L, unsigned long Key, double Lambda) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d, L = %1d, Key = %lu\n\n", s, L, Key); + printf (" Lambda = Poisson mean = "); + num_WriteD (Lambda, 12, 4, 2); + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void TestCATBitsData (int L, unsigned long Key) +/* + * Test that the key to search for has no overlap, that is cannot be + * written as ABA, where A and B are parts of the key. + */ +{ + int i; + unsigned long mask = 1, shift = L - 1; + i = 0; + while (i < L / 2) { + if ((Key & mask) == (Key >> shift)) { + bitset_WriteSet ("Key = ", Key, L); + util_Error ("CATBitsData: Key of the form ABA"); + } + i++; + shift--; + mask = num_TwoExp[i + 1] - 1.0; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void CATGenerBits (unif01_Gen *gen, long n, int r, int s, + int L, unsigned long KEY0, long *Count) +{ +/* + * Generate the bits in the CATBits test. Points are generated with + * overlapping. We have a window of size L bits, and we slide it 1 bit + * forward at each step to generate a point. We then check whether it + * equals the L bits Key. + */ + const unsigned long MASK0 = num_TwoExp[L] - 1.0; + unsigned long Mask, Key, Z0, Z; + int j0, j, k; + long i; + long co; + + util_Assert (L <= 32, "CATBits: GenerBits: L > 32"); + co = 0; + + if ((s >= L) && (L <= 16)) { + const int q = s - L; + + /* Make sure to skip the first half of the loop for the first number + since there is no previous Z */ + j0 = L; + Z = 0; + + for (i = 0; i < n / s; i++) { + Z0 = unif01_StripB (gen, r, s); + + /* The last L - j0 bits of the previous number */ + Mask = MASK0 << (L - j0); + Key = KEY0 << (L - j0); + Z |= (Z0 >> q); + j = j0; + while (j < L) { + if (Key == (Z & Mask)) { + co++; + j += L; + Mask >>= L; + Key >>= L; + } else { + j++; + Mask >>= 1; + Key >>= 1; + } + } + j0 = j % L; + + /* The first s - L bits of the current number */ + Z = Z0; + Mask = MASK0 << (q - j0); + Key = KEY0 << (q - j0); + j = j0; + while (j < q) { + if (Key == (Z & Mask)) { + co++; + j += L; + Mask >>= L; + Key >>= L; + } else { + j++; + Mask >>= 1; + Key >>= 1; + } + } + j0 = j - q; + Z = Z0 << L; + } + + } else if (s >= L) { +#ifdef USE_LONGLONG + const ulonglong MASK0 = num_TwoExp[L] - 1.0; + ulonglong Z, Z0; + ulonglong Mask, Key; + const int q = s - L; + + /* Make sure to skip the first half of the loop for the first number + since there is no previous Z */ + j0 = L; + Z = 0; + + for (i = 0; i < n / s; i++) { + Z0 = unif01_StripB (gen, r, s); + + /* The last L - j0 bits of the previous number */ + Mask = MASK0 << (L - j0); + Key = KEY0 << (L - j0); + Z |= (Z0 >> q); + j = j0; + while (j < L) { + if (Key == (Z & Mask)) { + co++; + j += L; + Mask >>= L; + Key >>= L; + } else { + j++; + Mask >>= 1; + Key >>= 1; + } + } + j0 = j % L; + + /* The first s - L bits of the current number */ + Z = Z0; + Mask = MASK0 << (q - j0); + Key = KEY0 << (q - j0); + j = j0; + while (j < q) { + if (Key == (Z & Mask)) { + co++; + j += L; + Mask >>= L; + Key >>= L; + } else { + j++; + Mask >>= 1; + Key >>= 1; + } + } + j0 = j - q; + Z = Z0 << L; + } +#else + if (L <= s) + util_Error ("CATGenerBits: L <= s and L > 16"); +#endif + + } else if ((s < L) && (L + s <= 32)) { + const int t = L / s; + util_Assert (L % s == 0, "CATBits: L > s but L % s not 0"); + + /* Generation of the first L random bits */ + Z = 0; + for (j = 0; j < t; j++) { + Z <<= s; + Z |= unif01_StripB (gen, r, s); + } + j0 = 0; + + /* Generation of the rest of the random bits */ + for (i = 0; i < (n - L) / s; i++) { + Z = (Z << s) | unif01_StripB (gen, r, s); + Mask = MASK0 << (s - j0); + Key = KEY0 << (s - j0); + j = j0; + while (j < s) { + if (Key == (Z & Mask)) { + co++; + j += L; + i += t - 1; + for (k = 1; k < t; k++) { + Z <<= s; + Z |= unif01_StripB (gen, r, s); + } + } else { + j++; + Mask >>= 1; + Key >>= 1; + } + } + j0 = j % s; + } + + } else { +#ifdef USE_LONGLONG + const ulonglong MASK0 = num_TwoExp[L] - 1.0; + const int t = L / s; + ulonglong Z; + ulonglong Mask, Key, Key0 = KEY0; + + if (L > s) { + util_Assert (L % s == 0, "CATBits: L > s but L % s not 0"); + } + + /* Generation of the first L random bits */ + Z = 0; + for (j = 0; j < t; j++) { + Z <<= s; + Z |= unif01_StripB (gen, r, s); + } + j0 = 0; + + /* Generation of the rest of the random bits */ + for (i = 0; i < (n - L) / s; i++) { + Z = (Z << s) | unif01_StripB (gen, r, s); + Mask = MASK0 << (s - j0); + Key = Key0 << (s - j0); + j = j0; + while (j < s) { + if (Key == (Z & Mask)) { + co++; + j += L; + i += t - 1; + for (k = 1; k < t; k++) { + Z <<= s; + Z |= unif01_StripB (gen, r, s); + } + } else { + j++; + Mask >>= 1; + Key >>= 1; + } + } + j0 = j % s; + } +#else + if (L == s) + util_Error ("CATGenereBits: L = s and s > 16"); + else + util_Error ("CATGenereBits: L > s and L + s > 32"); +#endif + } + + *Count = co; +} + + +/*-------------------------------------------------------------------------*/ + +void smarsa_CATBits (unif01_Gen *gen, sres_Poisson *res, + long N, long n, int r, int s, int L, unsigned long Key) +{ + long Seq; + double Lambda; /* Poisson mean */ + long Sum; + long Co; + fmass_INFO Mass; + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "smarsa_CATBits test"; + + Timer = chrono_Create (); + Lambda = (n - L + 1) / num_TwoExp[L]; + if (swrite_Basic) + WriteDataCATBits (gen, TestName, N, n, r, s, L, Key, Lambda); + util_Assert (L > 1, "smarsa_CATBits: L <= 1"); + + TestCATBitsData (L, Key); + if (res == NULL) { + localRes = TRUE; + res = sres_CreatePoisson (); + } + sres_InitPoisson (res, N, Lambda, "smarsa_CATBits"); + sprintf (str, "The N statistic values (a Poisson with mean %g):", Lambda); + statcoll_SetDesc (res->sVal1, str); + + Sum = 0; + for (Seq = 1; Seq <= N; Seq++) { + CATGenerBits (gen, n, r, s, L, Key, &Co); + statcoll_AddObs (res->sVal1, (double) Co); + Sum += Co; + } + + res->sVal2 = Sum; + Mass = fmass_CreatePoisson (res->Mu); + res->pLeft = fdist_Poisson2 (Mass, Sum); + res->pRight = fbar_Poisson2 (Mass, Sum); + fmass_DeletePoisson (Mass); + res->pVal2 = gofw_pDisc (res->pLeft, res->pRight); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 1, 1); + if (swrite_Basic) { + WriteResultsPoisson (res, N); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeletePoisson (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataMatRank (unif01_Gen * gen, char *TestName, + long N, long n, int r, int s, int L, int k) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d, L = %1d, k = %1d\n\n", s, L, k); +} + + +/*-------------------------------------------------------------------------*/ +#if 0 + +static int RankOfBitMatrix (bitset_BitSet M[], int maxrow) +/* + * Calculation of the rank of the bit-matrix M + */ +{ + const int MaxBit = 31; /* number of bits in a word - 1 */ + bitset_BitSet Swap; + int rank = 0; + int i; + int CL = 1; + + while (CL <= MaxBit) { + /* All components of M shift their bits 1 position to the left */ + for (i = 0; i < maxrow; i++) + M[i] <<= 1; + + /* Search of the first M[i] with 1 as the major bit */ + i = rank; + for (;;) { + if ((bitset_TestBit (M[i], MaxBit)) || (i == maxrow - 1)) + break; + ++i; + } + /* Diagonalization of matrix M */ + if (i < maxrow - 1) { + Swap = M[rank]; + M[rank] = M[i]; + M[i] = Swap; + for (i = rank + 1; i < maxrow; i++) { + if (bitset_TestBit (M[i], MaxBit)) + M[i] ^= M[rank]; + } + ++rank; + if (rank == MaxBit) + return rank; + } + ++CL; + } + return rank; +} + + +/*-------------------------------------------------------------------------*/ + +#define lmax 64 + +void smarsa_MatrixRank (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int s, int l, int k) +{ + long Seq; + long Rep; + int j; + int i; + long L; /* One line of bits */ + int c; /* Number-1 of U01 used to build a line */ + long d; /* Get s bits of a generated U01 */ + long a; /* Get b bits of a generated U01 */ + int b; /* Number of bits of last U01 of a line */ + int Minkl; /* Min (k, l) */ + long NbGroups; /* Number of classes for ChiSquare */ + long jhigh; /* Index of the highest class */ + long jlow; /* Index of the lowest class */ + int Rank; /* Rank of matrix */ + double X2; + double Prod; + long *Loca; /* Redirections in merging Chi2 classes */ + long *Count; /* Observed numbers */ + double *NbExp; /* Expected numbers */ + bitset_BitSet M[lmax]; /* Matrix */ + double V[1]; /* Number of degrees of freedom for Chi2 */ + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "smarsa_MatrixRank test"; + + Timer = chrono_Create (); + /* We shall need c + 1 random numbers to build a line of the matrix */ + c = k / s; + b = k % s; + a = num_TwoExp[b]; + d = num_TwoExp[s]; + if (swrite_Basic) + WriteDataMatRank (gen, TestName, N, n, r, s, l, k); + if (k <= l) + Minkl = k; + else + Minkl = l; + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, Minkl, "smarsa_MatrixRank"); + NbExp = res->NbExp; + Count = res->Count; + Loca = res->Loc; + + Prod = n * pow (2.0, -(double) (l * k)); + NbExp[0] = Prod; + for (j = 1; j <= Minkl; j++) { + Prod = Prod * pow (2.0, (double) (l + k - 2*j + 1)) * + (1.0 - 1.0 / num_TwoExp[l - j + 1]) * + (1.0 - 1.0 / num_TwoExp[k - j + 1]) / + (1.0 - 1.0 / num_TwoExp[j]); + NbExp[j] = Prod; + } + + jlow = 0; + jhigh = Minkl; + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, 0); + gofs_MergeClasses (NbExp, Loca, &jlow, &jhigh, &NbGroups); + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, NbGroups); + res->jmin = jlow; + res->jmax = jhigh; + res->degFree = NbGroups - 1; + + util_Assert (n > 2.0 * gofs_MinExpected, + "smarsa_MatrixRank: n <= 2*gofs_MinExpected"); + util_Assert (k <= 31, "smarsa_MatrixRank: k > 31"); + util_Assert (l <= lmax, "smarsa_MatrixRank: L > 64"); + util_Assert (l * k <= 1020, "smarsa_MatrixRank: L*k > 1020"); + util_Assert (NbGroups > 1, + "smarsa_MatrixRank: number of classes = 1." + " Increase n or decrease |L - k|"); + + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbGroups - 1); + statcoll_SetDesc (res->sVal1, str); + + for (Seq = 1; Seq <= N; Seq++) { + for (i = jlow; i <= jhigh; i++) + Count[i] = 0; + for (Rep = 1; Rep <= n; Rep++) { + /* Generate the l x k matrix and compute its rank */ + for (i = 0; i < l; i++) { + /* Build one line of bits L */ + L = 0; + for (j = 1; j <= c; j++) + /* Generate s bits */ + L = d * L + unif01_StripB (gen, r, s); + /* The last b bits of a line of the matrix */ + if (a > 1) + L = a * L + unif01_StripB (gen, r, b); + M[i] = L; + } + /* Set all remaining lines to 0 */ + for (i = l; i < lmax; i++) + M[i] = 0; + + Rank = RankOfBitMatrix (M, lmax); + ++Count[Loca[Rank]]; + } + + X2 = gofs_Chi2 (NbExp, Count, jlow, jhigh); + statcoll_AddObs (res->sVal1, X2); + if (swrite_Counters) + tables_WriteTabL (Count, jlow, jhigh, 5, 12, "Observed Numbers"); + } + + V[0] = NbGroups - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + /* !!!! Attention, this Write must use the right pVal */ + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH + 1, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + +#endif + +/*=========================================================================*/ +#if 0 +static void ZeroMat (Matrix * M) +{ + int i; + + for (i = 0; i < M->nblignes; i++) + PutBVToZero (&(M->lignes[i][0])); +} +#endif + +/*-------------------------------------------------------------------------*/ + +void smarsa_MatrixRank (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int s, int l, int k) +{ + long Seq; + long Rep; + int j; + int i; + int c; /* Number-1 of U01 used to build a line */ + int b; /* Number of bits of last U01 of a line */ + unsigned long bmask; /* b bits mask */ + unsigned long smask; /* s bits mask */ + int Minkl; /* Min (k, l) */ + long NbGroups; /* Number of classes for ChiSquare */ + long jhigh; /* Index of the highest class */ + long jlow; /* Index of the lowest class */ + int Rank; /* Rank of matrix */ + double X2; + double temp; + long *Loca; /* Redirections in merging Chi2 classes */ + long *Count; /* Observed numbers */ + double *NbExp; /* Expected numbers */ + double Par[1]; /* Number of degrees of freedom for Chi2 */ + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "smarsa_MatrixRank test"; + Matrix *M; + BitVect *V; + + Timer = chrono_Create (); + /* We shall need ceiling(c) random numbers to build a line of the matrix */ + c = k / s; + b = k % s; + bmask = num_TwoExp[b] - 1.0; + /* The b most significant bits are set */ + bmask <<= vectorsF2_WL - b; + smask = num_TwoExp[s] - 1.0; + /* The s most significant bits are set */ + smask <<= vectorsF2_WL - s; + + if (swrite_Basic) + WriteDataMatRank (gen, TestName, N, n, r, s, l, k); + Minkl = util_Min (k, l); + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, Minkl, "smarsa_MatrixRank"); + NbExp = res->NbExp; + Count = res->Count; + Loca = res->Loc; + + temp = num_Log2((double) n) - l * k; + NbExp[0] = pow (2.0, temp); + for (j = 1; j <= Minkl; j++) { + temp += l + k - 2*j + 1 + + num_Log2(1.0 - pow (2.0, -(double) (l - j + 1))) + + num_Log2(1.0 - pow (2.0, -(double) (k - j + 1))) - + num_Log2(1.0 - pow (2.0, -(double) j)); + NbExp[j] = pow (2.0, temp); + } + + jlow = 0; + jhigh = Minkl; + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, 0); + gofs_MergeClasses (NbExp, Loca, &jlow, &jhigh, &NbGroups); + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, NbGroups); + res->jmin = jlow; + res->jmax = jhigh; + res->degFree = NbGroups - 1; + + util_Warning (NbGroups <= 1, + "smarsa_MatrixRank: number of Chi2 classes = 1.\n" + " Increase n or decrease |L - k|."); + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + util_Assert (n >= 2.0 * gofs_MinExpected, + "smarsa_MatrixRank: n <= 2*gofs_MinExpected"); + + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbGroups - 1); + statcoll_SetDesc (res->sVal1, str); + + M = util_Malloc (sizeof (Matrix)); + AllocMat (M, l, k, 1); + + for (Seq = 1; Seq <= N; Seq++) { + for (i = jlow; i <= jhigh; i++) + Count[i] = 0; + + for (Rep = 1; Rep <= n; Rep++) { + /* Generate the l x k matrix and compute its rank */ + for (i = 0; i < l; i++) { + V = &(M->lignes[i][0]); + /* Build one line of bits */ + for (j = 0; j < c; j++) { + /* Shift by s and generate s new bits */ + BVRShiftSelf (V, s); + V->vect[0] |= (smask & + (gen->GetBits (gen->param, gen->state) << r)); + } + /* The last b bits of a line of the matrix */ + if (b > 0) { + BVRShiftSelf (V, b); + V->vect[0] |= (bmask & + (gen->GetBits (gen->param, gen->state) << r)); + } + } + Rank = GaussianElimination (M, l, k, 1); + ++Count[Loca[Rank]]; + } + + X2 = gofs_Chi2 (NbExp, Count, jlow, jhigh); + statcoll_AddObs (res->sVal1, X2); + if (swrite_Counters) + tables_WriteTabL (Count, jlow, jhigh, 5, 12, "Observed Numbers"); + } + + FreeMat (M); + util_Free (M); + + Par[0] = NbGroups - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, Par, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + /* !!!! Attention, this Write must use the right pVal */ + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataSavir2 (unif01_Gen * gen, char *TestName, + long N, long n, int r, long m, int t) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", m = %1ld, t = %1d\n\n", m, t); +} + + +/*-------------------------------------------------------------------------*/ + +void smarsa_Savir2 (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long m, int t) +{ + const double eps = 1.0E-15; + long I; + long msup; /* Dimension - 1 of arrays */ + long Seq; + long Rep; + long j; + int i; + long NbGroups; /* Number of classes for ChiSquare */ + long jhigh; /* Index of the highest class */ + long jlow; /* Index of the lowest class */ + double X2; /* ChiSquare Statistic */ + double UnSurm = 1.0 / m; + double *Prob; /* Probabilities */ + long *Loca; + double V[1]; /* Number degrees of freedom for Chi2 */ + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "smarsa_Savir2 test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataSavir2 (gen, TestName, N, n, r, m, t); + + Prob = util_Calloc ((size_t) m + 2, sizeof (double)); + Prob[m + 1] = 0.0; + for (j = 1; j <= m; j++) + Prob[j] = UnSurm; + for (i = 2; i <= t; i++) { + for (j = m; j >= 1; j--) + Prob[j] = Prob[j + 1] + Prob[j] / j; + } + j = 1; + while (Prob[j] > eps) + ++j; + msup = j - 1; + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, msup, "smarsa_Savir2"); + + for (j = 1; j <= msup; j++) + res->NbExp[j] = Prob[j] * n; + util_Free (Prob); + Loca = res->Loc; + + jlow = 1; + jhigh = msup; + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loca, jlow, jhigh, 0); + gofs_MergeClasses (res->NbExp, Loca, &jlow, &jhigh, &NbGroups); + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loca, jlow, jhigh, NbGroups); + res->jmin = jlow; + res->jmax = jhigh; + res->degFree = NbGroups - 1; + + util_Warning (NbGroups < 2, + "smarsa_Savir2: Number of classes = 1.\n Decrease t or increase n."); + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + util_Assert (n >= 2.0 * gofs_MinExpected, + "smarsa_Savir2: n <= 2*gofs_MinExpected"); + + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbGroups - 1); + res->sVal1 = statcoll_Create (N, str); + + for (Seq = 1; Seq <= N; Seq++) { + for (j = jlow; j <= jhigh; j++) + res->Count[j] = 0; + for (Rep = 1; Rep <= n; Rep++) { + I = m; + for (i = 1; i <= t; i++) + I = 1 + unif01_StripD (gen, r) * I; + if (I > msup) + ++res->Count[Loca[msup]]; + else + ++res->Count[Loca[I]]; + } + + if (swrite_Counters) + tables_WriteTabL (res->Count, jlow, jhigh, 5, 12, + "Observed Numbers"); + + X2 = gofs_Chi2 (res->NbExp, res->Count, jlow, jhigh); + statcoll_AddObs (res->sVal1, X2); + } + + V[0] = NbGroups - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataGCD (unif01_Gen * gen, char *TestName, + long N, long n, int r, int s) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d\n\n", s); +} + + +/*-------------------------------------------------------------------------*/ + +void smarsa_GCD (unif01_Gen *gen, smarsa_Res2 *res, + long N, long n, int r, int s) +{ + /* + The theoretical distribution for the number of iterations is unknown. + The binomial is a very rough approximation: thus the printing of the + results is commented out. + */ + const double C1 = 6 / (num_Pi * num_Pi); + const double P1 = 0.376; + const int KMAX = 50; + unsigned long U, V, temp; + double X; + double Param[1]; + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "smarsa_GCD test"; + sres_Chi2 *GCD; + sres_Chi2 *NumIter; + int jmax, j, k; + long Seq, i; + double *NbExp; + long *Loc; + long NbClasses; + fmass_INFO Q; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataGCD (gen, TestName, N, n, r, s); + if (n < 30) { + util_Warning (TRUE, "n < 30"); + return; + } + if (n > pow (2.0, 1.5*s)) { + util_Warning (TRUE, "n > 2^(1.5s)"); + return; + } + if (res == NULL) { + localRes = TRUE; + res = smarsa_CreateRes2 (); + } + jmax = 1 + sqrt (C1 * n / gofs_MinExpected); + util_Assert (jmax > 1, "smarsa_GCD: jmax < 2"); + InitRes2 (res, N, jmax, KMAX); + + GCD = res->GCD; + GCD->jmin = 1; + GCD->jmax = jmax; + GCD->degFree = jmax - 1; + sprintf (str, "GCD; the N statistic values (a ChiSquare with %1d degrees" + " of freedom):", jmax - 1); + statcoll_SetDesc (GCD->sVal1, str); + + /* Compute the probabilities for the GCD values */ + NbExp = GCD->NbExp; + Loc = GCD->Loc; + X = 0.0; + for (j = 1; j < jmax; j++) { + NbExp[j] = n * C1 / ((double) j * j); + X += NbExp[j]; + Loc[j] = j; + } + NbExp[jmax] = n - X; + + if (swrite_Classes) { + printf ("Classes for the GCD values:\n"); + gofs_WriteClasses (GCD->NbExp, GCD->Count, 1, jmax, 0); + } + + NumIter = res->NumIter; + /* Compute expected numbers for number of iterations */ + Q = fmass_CreateBinomial (KMAX, P1, 1.0 - P1); + for (i = 0; i <= KMAX; i++) + NumIter->NbExp[i] = n * fmass_BinomialTerm2 (Q, i); + fmass_DeleteBinomial (Q); + + NumIter->jmin = 0; + NumIter->jmax = KMAX; + if (swrite_Classes) { + printf ("\nClasses for the number of iterations:\n"); + gofs_WriteClasses (NumIter->NbExp, NumIter->Loc, NumIter->jmin, + NumIter->jmax, 0); + } + gofs_MergeClasses (NumIter->NbExp, NumIter->Loc, &NumIter->jmin, + &NumIter->jmax, &NbClasses); + + if (swrite_Classes) + gofs_WriteClasses (NumIter->NbExp, NumIter->Loc, NumIter->jmin, + NumIter->jmax, NbClasses); + + sprintf (str, "NumIter; the N statistic values (a ChiSquare with %1ld" + " degrees of freedom):", NbClasses - 1); + statcoll_SetDesc (NumIter->sVal1, str); + NumIter->degFree = NbClasses - 1; + util_Assert (NumIter->degFree >= 1, "NumIter->degFree < 1"); + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i <= KMAX; i++) + NumIter->Count[i] = 0; + for (i = 0; i <= GCD->jmax; i++) + GCD->Count[i] = 0; + for (i = 1; i <= n; i++) { + k = 0; + do { + U = unif01_StripB (gen, r, s); + V = unif01_StripB (gen, r, s); + } while (0 == U || 0 == V); + do { + temp = U % V; + U = V; + V = temp; + k++; + } while (V > 0); + if ((long) U > GCD->jmax) + U = GCD->jmax; + (GCD->Count[U])++; + if (k > KMAX) + k = KMAX; + (NumIter->Count[NumIter->Loc[k]])++; + } + if (swrite_Counters) { + tables_WriteTabL (GCD->Count, GCD->jmin, GCD->jmax, 5, 10, + "Observed numbers for GCD values:"); + /* tables_WriteTabL (NumIter->Count, NumIter->jmin, NumIter->jmax, 5, + 10, "Observed numbers for number of iterations:"); + */ + } + + X = gofs_Chi2 (GCD->NbExp, GCD->Count, GCD->jmin, GCD->jmax); + statcoll_AddObs (GCD->sVal1, X); + X = gofs_Chi2 (NumIter->NbExp, NumIter->Count, NumIter->jmin, + NumIter->jmax); + statcoll_AddObs (NumIter->sVal1, X); + } + + Param[0] = GCD->degFree; + gofw_ActiveTests2 (GCD->sVal1->V, GCD->pVal1->V, N, wdist_ChiSquare, + Param, GCD->sVal2, GCD->pVal2); + GCD->pVal1->NObs = N; + sres_GetChi2SumStat (GCD); +/* + Param[0] = NumIter->degFree; + gofw_ActiveTests2 (NumIter->sVal1->V, NumIter->pVal1->V, N, + wdist_ChiSquare, Param, NumIter->sVal2, NumIter->pVal2); + NumIter->pVal1->NObs = N; +*/ + + if (swrite_Basic) { + if (swrite_Collectors) + statcoll_Write (GCD->sVal1, 5, 14, 4, 3); + printf ("\n-----------------------------------------------\n"); + if (N == 1) { + printf ("Number of degrees of freedom : %4ld\n", + GCD->degFree); + printf ("Chi2 statistic for GCD values :"); + gofw_Writep2 (GCD->sVal2[gofw_Mean], GCD->pVal2[gofw_Mean]); + } else { + printf ("Test results for GCD values:\n"); + gofw_WriteActiveTests0 (N, GCD->sVal2, GCD->pVal2); + swrite_Chi2SumTest (N, GCD); + } + /* + if (swrite_Collectors) + statcoll_Write (NumIter->sVal1, 5, 14, 4, 3); + printf ("\n-----------------------------------------------\n"); + if (N == 1) { + printf ("Number of degrees of freedom : %4ld\n", + NumIter->degFree); + printf ("Chi2 statistic for NumIter :"); + gofw_Writep2 (NumIter->sVal2[gofw_Mean], NumIter->pVal2[gofw_Mean]); + } else { + printf ("Test results for NumIter:\n"); + gofw_WriteActiveTests0 (N, NumIter->sVal2, NumIter->pVal2); + swrite_SumTest (N, NumIter->sVal2[gofw_Sum], NumIter->pVal2[gofw_Sum], + N*NumIter->degFree); + } + */ + printf ("\n\n"); + swrite_Final (gen, Timer); + } + + if (localRes) + smarsa_DeleteRes2 (res); + chrono_Delete (Timer); + +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/smarsa.tex b/TESTU01/TestU01-1.2.3/testu01/smarsa.tex new file mode 100644 index 0000000..247dd74 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/smarsa.tex @@ -0,0 +1,414 @@ +\defmodule {smarsa} + +Implements the statistical tests suggested by George Marsaglia and his +collaborators in \cite{rMAR85a} and other places.\index{Marsaglia} +Some of these tests are special cases of the overlapping versions of the +tests implemented in module {\tt smultin} and in these cases, the +functions here simply call {\tt smultin\_MultinomialOver}. +\resdef + + + +\iffalse %%%%% +For all these tests, when $N>1$, we may apply a two-level test +over the $N$ $p$-values obtained at the first level. +For $N=1$, we simply compute the $p$-value of the first level test; +$n$ is the sample size of the first level test. +We also drop the first $r$ bits (the most significant, +$r \ge 0$) of each generated random number and apply the tests on + the remaining bits. +\fi %%%%% + +\bigskip\hrule + +\code\hide +/* smarsa.h for ANSI C */ +#ifndef SMARSA_H +#define SMARSA_H +\endhide +#include "unif01.h" +#include "sres.h" +\endcode + +\ifdetailed %%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\guisec{Environment variables} +\code + +extern double smarsa_Maxk; +\endcode +\tab + Maximal value of the number of cells $k = d^t$ in + {\tt smarsa\_BirthdaySpacings}. + The default value is set to $2^{64}$ if 64-bit integers are available + on this platform (see the constant {\tt USE\_LONGLONG} in module + {\tt gdef} of library MyLib), and $2^{53}$ otherwise. +\endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} + +Depending on the test, the detailed test results can be recovered in the +structures defined below, or in the common structures defined in module + {\tt sres}. + +\code + +typedef struct { + sres_Basic *Bas; + sres_Poisson *Pois; +} smarsa_Res; +\endcode + \tab + Structure used to keep the results of the tests + {\tt smarsa\_CollisionOver} and {\tt smarsa\_Opso}. + Depending on the approximation, the results will be in either {\tt Bas} + or {\tt Pois}. + \endtab +\code + + +smarsa_Res * smarsa_CreateRes (void); +\endcode + \tab + Creates and returns a structure to hold the results of a test. + \endtab +\code + + +void smarsa_DeleteRes (smarsa_Res *res); +\endcode + \tab + Frees the memory allocated by {\tt smarsa\_CreateRes}. + \endtab + +\bigskip\hrule\bigskip + +\code + +typedef struct { + sres_Chi2 *GCD; + sres_Chi2 *NumIter; +} smarsa_Res2; +\endcode + \tab + Structure used to keep the results of the test {\tt smarsa\_GCD}. + The field {\tt GCD} holds the results for the greatest common divisor and + {\tt NumIter} holds the results for the number of iterations used to + find the GCD. + \endtab +\code + + +smarsa_Res2 * smarsa_CreateRes2 (void); +\endcode + \tab + Creates and returns a structure to hold the results of a + {\tt smarsa\_GCD} test. + \endtab +\code + + +void smarsa_DeleteRes2 (smarsa_Res2 *res); +\endcode + \tab + Frees the memory allocated by {\tt smarsa\_CreateRes2}. + \endtab + +\fi %%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} +\code + + +void smarsa_SerialOver (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, long d, int t); +\endcode + \tab + Implements the {\em overlapping $t$-tuple\/} + test\index{Test!SerialOver} described in + \cite {rALT88a,rMAR85a}. + It is similar to {\tt sknuth\_Serial}, except that the $n$ vectors + are generated with overlap, as follows. + A sequence of uniforms $u_0,\dots,u_{n-1}$ is generated, and the + $n$ points are defined as $(u_0,\dots,u_{t-1})$, $(u_1,\dots,u_t)$, + \dots, $(u_{n-1},u_n,u_0,\dots,u_{t-3})$, $(u_n,u_0,\dots,u_{t-2})$. +\iffalse %%% + This function generates $n$ points in + the unit hypercube in $t$ dimensions, using $t$ successive values + returned by the generator, which will make the + components of a vector in $t$ dimensions, the $i$-th generated + value being the first component of the $i$-th vector. + It generates only $n$ values which form a + circular sequence: for $i > n-t+1$, the last $i-n+t-1$ components + of vector $i$ are the first $i-n+t-1$ values. + Then it divides the interval $[0,1)$ in $d$ equal segments; this gives + a partition of the hypercube $[0,1)^t$ in $k = d^{t}$ cells. +\fi %%% + This test is a special case of {\tt smultin\_Multino\-mial\-Over}, + with {\tt Sparse = FALSE} (see also \cite{rLEC02c}). +% It corresponds to the dense case of the test, where $n > k = d^t$. + Restriction: $n/d^{t} \ge$ {\tt gofs\_MinExpected}. + \endtab +\code + + +void smarsa_CollisionOver (unif01_Gen *gen, smarsa_Res *res, + long N, long n, int r, long d, int t); +\endcode + \tab + Similar to the collision test, except\index{Test!CollisionOver} + that the vectors are generated + with overlap, exactly as in {\tt smarsa\_SerialOver}. + This test corresponds to the test {\em overlapping pairs sparse + occupancy\/} (OPSO) test described in \cite {rMAR85a} and studied by + Marsaglia and Zaman \cite{rMAR93a}. + Let $\lambda = (n-t+1)/d^t$, called the {\em density}. + If $n$ (the number of points) and $d^t$ (the number of cells) + are very large and have the same order of magnitude, + then, under $\cH_0$,\index{overlapping pairs sparse occupancy} + the number of collisions $C$ is a random variable which is + approximately normally distributed with mean + $\mu \approx d^t (\lambda - 1 + e^{-\lambda})$ + (this follows from Theorem 2 of \cite{rPER95a}), + and variance $\sigma^2 \approx d^t e^{-\lambda}(1-3e^{-\lambda})$, + according to the speculations of \cite{rMAR93a} (see {\tt smultin}). + However, Rukhin \cite{rRUK02a} gave a better approximation for the variance as + $\sigma^2 \approx d^t e^{-\lambda}(1-(1+\lambda) e^{-\lambda})$ and this + is the formula that is used. + When $n \ll d^t$, the number of collisions should be + approximately Poisson with mean $\mu$, + whereas if $\lambda$ is large enough (e.g., $\lambda> 6$), then the + number of empty cells ($d^t - n + C$) + should be approximately Poisson with mean $d^t e^{-\lambda}$. + This test is a special case of {\tt smultin\_MultinomialOver}. + \endtab +\code + + +void smarsa_Opso (unif01_Gen *gen, smarsa_Res *res, + long N, int r, int p); +\endcode + \tab + Three special cases of {\tt smarsa\_CollisionOver}. + Implements the OPSO\index{Test!OPSO} + test with the same three sets of parameters + as in the examples + of \cite{rMAR85a}.\index{overlapping pairs sparse occupancy} + The parameters $(n, d, t)$ are $(2^{21}, 2^{10}, 2)$, + $(2^{22}, 2^{11}, 2)$, + and $(2^{23}, 2^{11}, 2)$, for $p = 1$, 2, and 3, respectively. + + Restriction: $p\in \{1, 2, 3\}$. + \endtab +\code + + +void smarsa_CAT (unif01_Gen *gen, sres_Poisson *res, + long N, long n, int r, long d, int t, long S[]); +\endcode +\tab + Applies the {\em CAT test\/}, one of the {\em monkey test\/} proposed by + Marsaglia in \cite{rMAR93b} and analyzed by Percus and Whitlock in + \cite{rPER95a}.\index{Test!CAT} + This test is a variation of the collision test with overlapping + ({\tt smarsa\_CollisionOver}), except that only {\em one\/} cell is + observed. For this reason, this test is typically less powerful than + {\tt smarsa\_CollisionOver} unless the target cell happens to be visited + very frequently due to a particular weakness of the generator. + This target cell is specified by the vector {\tt S[0..t-1]}. + For each point, the generator provides $t$ integers + $y_0,\dots,y_{t-1}$ in $\{0,\dots,d-1\}$ and the target cell is hit + whenever $(y_0, \dots, y_{t-1}) =$ {\tt (S[0],\dots,S[t-1])}. The + target cell number should make an aperiodic pattern, i.e., it should not + be possible to write it as {\em ABA} where {\em A} is a prefix of the + pattern. + + The test generates $n$ numbers (giving $n-t+1$ points with overlapping + coordinates) and computes $Y$, the number of points that hit the target + cell. Under $\cH_0$, $Y$ is approximately Poisson with mean + $\lambda = (n-t+1)/d^t$, + and the sum of all values of $Y$ for the + $N$ replications is approximately Poisson with mean $N\lambda$. + The test computes this sum and the corresponding $p$-value, + using the Poisson distribution. + Note: The pair $(N,n)$ may be replaced by $(1, nN)$, as this is equivalent. + Normally, $\lambda$ should be larger than 1, + so this corresponds to the dense case, where $n > k$. + \endtab +\code + + +void smarsa_CATBits (unif01_Gen *gen, sres_Poisson *res, long N, long n, + int r, int s, int L, unsigned long Key); +\endcode +\tab + Similar to {\tt smarsa\_CAT}, except that the cell is generated + from a string of bits.\index{Test!CATBits} + This test is a variation of the multinomial test on bits with overlapping + ({\tt smultin\_MultinomialBitsOver}), except that only {\em one\/} cell is + observed (for this reason, this test is typically less powerful than + {\tt smultin\_MultinomialBitsOver}). + This target cell is specified by {\tt Key}. + Each point is made of $L$ bits and the target cell is hit + whenever the $L$ bits are numerically equal to {\tt Key}. + The test compares each group of $L$ bits to the key in a sequence of + $n$ bits. When the key is not found, one moves 1 bit forward + in the sequence. But when the key is found, one jumps $L$ bits forward. + The bits of {\tt Key} + should make an aperiodic pattern, i.e., it should not + be possible to write {\tt Key} (in binary form) as {\em ABA} where + {\em A} is a binary prefix of {\tt Key}. + + The test generates $n$ bits and computes $Y$, the number of points + that hit the target cell. + Under $\cH_0$, $Y$ is approximately Poisson with mean + $\lambda = (n-L+1)/2^L$, and the sum of all values of $Y$ for the + $N$ replications is approximately Poisson with mean $N\lambda$. + The test computes this sum and the corresponding $p$-value, + using the Poisson distribution. + Normally, $\lambda$ should be larger than 1, + so this corresponds to the dense case, where $n > 2^L$. + Restrictions: $L \le 32$, $r+s \le 32$, and if $L > s$ then $L \mod s = 0$. + \endtab +\code + + +void smarsa_BirthdaySpacings (unif01_Gen *gen, sres_Poisson *res, + long N, long n, int r, long d, int t, int p); +\endcode + \tab + Implements the {\em birthday spacings\/} test proposed in \cite{rMAR85a} + and studied further by Knuth \cite{rKNU98a} and + L'Ecuyer and Simard \cite{rLEC01a}.\index{Test!BirthdaySpacings} +% Results in L'Ecuyer-Simard's article uses p = 1. + This is a variation of the collision test, in which + $n$ points are thrown into $k = d^t$ cells in $t$ dimensions as in + {\tt smultin\_Multinomial}. + The cells are numbered from 0 to $k-1$. + To generate a point, $t$ integers $y_0,\dots,y_{t-1}$ in $\{0,\dots,d-1\}$ + are generated from $t$ successive uniforms. + The parameter $p$ decides in which order these $t$ integers are used + to determine the cell number: The cell number is + $c = y_0 d^{t-1} + \cdots + y_{t-2} d + y_{t-1}$ if $p=1$ and + $c = y_{t-1} d^{t-1} + \cdots + y_{1} d + y_0$ if $p=2$. + This corresponds to using {\tt smultin\_GenerCellSerial} for $p=1$ + and {\tt smultin\_GenerCellSerial2} for $p=2$. + + The points obtained can be viewed as + $n$ birth dates in a year of $k$ days \cite {rALT88a,rMAR85a}. + Let $I_1 \le I_2\le \cdots \le I_n$ be the $n$ cell numbers obtained, + sorted in increasing order. The test computes the differences + $I_{j+1} - I_{j}$, for $1\le j < n$, + and count the number $Y$ of collisions between these differences. + Under $\cH_0$, $Y$ is approximately Poisson with mean + $\lambda = n^3/(4k)$, and the sum of all values of $Y$ for the + $N$ replications (the total number of collisions) is + approximately Poisson with mean $N\lambda$. + The test computes this total number of collisions and computes the + corresponding $p$-value using the Poisson distribution. + Recommendation: $k$ should be very large and $\lambda$ relatively small. + Restrictions: $k \le {}${\tt smarsa\_Maxk}, +%% $n < \frac12\sqrt{\frac{k}{N}}$; + $8 N \lambda \le k^{1/4}$ or $4n \le k^{5/12}/ N^{1/3}$, and + $p\in \{1, 2\}$. +\richard{Ce test est beaucoup plus sensible pour un tr\`es grand nombre de + cellules avec $n$ grand. Pour $Nn$ constant, choisir $n$ aussi grand que + possible et $N$ petit. Mais on est limit\'e par la valeur maximale d'un entier + pour num\'eroter les cases, et aussi par le fait que la densit\'e doit \^etre + suffisamment petite pour que l'approximation de Poisson soit valide.} + \endtab +\code + + +void smarsa_MatrixRank (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int s, int L, int k); +\endcode + \tab + Applies the test based on the {\em rank of a random binary matrix\/}, + as\index{Test!MatrixRank}\index{random binary matrix} + suggested in \cite {rMAR85a,rMAR85b}. + It fills a $L\times k$ matrix with random bits as follows. + A sequence of uniforms are generated and $s$ bits are taken from each. + The matrix is filled one row at a time, using + $\lceil k/s\rceil$ uniforms per row. + \hpierre{Should take blocks of $L$ bits instead, for better uniformity + with the other tests.} + The test then computes the rank of the matrix + (the number of linearly independent rows). + It thus generates $n$ matrices and counts how many + there are of each rank. + Finally it compares this empirical distribution + with the theoretical distribution of the rank of a random matrix, + via a chi-square test, after merging classes if neeeded (as usual). + The probability that the rank $R$ of a random matrix is $x$ is given by + \begin{eqnarray*} + P[R=0] & =& {2^{-Lk}} \\ + P[R=x] & =& 2^{x(L+k-x)-Lk} \prod_{i=0}^{x-1} + { (1-2^{i-L})(1-2^{i-k}) \over 1-2^{i-x} }, + \qquad 1 \le x \le \min (L, k). + \end{eqnarray*} + Restrictions: $n/2 > $ {\tt gofs\_MinExpected}. Recommendation: $L = k$. + The difference $|L - k|$ should be small, otherwise almost all the + probability will be lumped in a single class of the chi-square. +\hpierre {Il serait bon d'avoir une id\'ee de la valeur de $n$ qu'il + faut prendre pour que ce soit raisonnable, en fonction de $k$ et $L$.} +\hrichard{Le nombre de classes ne d\'epend presque pas de n, mais seulement + de la diff\'erence $|L - k|$. Donc n'importe quel n >= 100 fera l'affaire.} + \endtab +\code + + +void smarsa_Savir2 (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long m, int t); +\endcode + \tab + Applies a modified version of the Savir test, as proposed by + Marsaglia\index{Test!Savir2} \cite{rMAR85c}. + The test generates a random integer $I_1$ uniformly in $\{1,\dots,m\}$, + then a random integer $I_2$ uniformly in $\{1,\dots,I_1\}$, + then a random integer $I_3$ uniformly in $\{1,\dots,I_2\}$, + and so on until $I_t$. + It thus generates $n$ values of $I_t$ and compares their empirical + distribution with the theoretical one, via a chi-square test. + The algorithm given in \cite{rMAR85c} is used to compute the + theoretical distribution of $I_t$ under the null hypothesis. + Restrictions: $n/2 > $ {\tt gofs\_MinExpected}. + Recommendation: $m \approx 2^t$. + \endtab +\code + + +void smarsa_GCD (unif01_Gen *gen, smarsa_Res2 *res, + long N, long n, int r, int s); +\endcode + \tab Applies the tests based on the greatest common divisor (GCD) between +\index{Test!GCD}% + two random integers in $[1, 2^s]$ as proposed by Marsaglia \cite{rMAR02b}. + The first test considers the value of the GCD itself for which the + probability that the GCD takes the value $j$ is $P_j = 6/(\pi^2 j^2)$ + (see \cite{rKNU98a}). + A chi-square test is applied on the values obtained. + The second test considers the number of iterations needed to find the + GCD. The theoretical distribution is unknown and the binomial + approximation proposed by Marsaglia has to be corrected by an empirical + factor. This second test is not used for the moment and is left as a + future project. + Restrictions: $n \ge 30$ and $\log_2 n \le 3s/2$. +% I have set the domain of the approximation error by using the 3 good +% generators: ugfsr_CreateMT19937_02, ulec_CreateMRG32k3a and +% ulec_Createlfsr113. They start failing the test GCD at about the +% same values of n for a given s, at 2 or 4 times the above limit n. +% Thus the above restriction. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/smultin.c b/TESTU01/TestU01-1.2.3/testu01/smultin.c new file mode 100644 index 0000000..0d09af8 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/smultin.c @@ -0,0 +1,3674 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: smultin.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "util.h" +#include "chrono.h" +#include "num.h" +#include "num2.h" +#include "tables.h" + +#include "smultin.h" +#include "wdist.h" +#include "swrite.h" +#include "unif01.h" + +#include "statcoll.h" +#include "gofw.h" +#include "fmass.h" +#include "fdist.h" +#include "fbar.h" + +#include +#include +#include +#include + + + + + + +/*============================= constants ===============================*/ + +/* Max string length */ +#define LENGTH 100 + +/* Max dimension t */ +#define MAX_DIM 64 + +/* Used for secondary hashing */ +#define HACHE2 41 + +/* Upper Limit of precomputed tables of 2nI, when SPARSE = TRUE */ +static const long LIM_SPARSE = 64; + +/* LIM_DENSE*n/k = upper limit of the precomputed tables for 2nI, when */ +/* SPARSE = FALSE and 6n/k < k */ +static const double LIM_DENSE = 6.0; + +/* Precision with which we measure specific values of ValDelta */ +static const double EPS_LAM = 1.0E-14; + +#ifdef USE_LONGLONG +#define MAXK 9223372036854775808.0 /* 2^63 */ +#else +#define MAXK 9007199254740992.0 /* 2^53 */ +#endif + +/* Our gamma distribution is not good for parameters larger than this. */ +#define EMPTYLIM 200000000000000.0 + +#define MASK64 0x8000000000000000ULL /* 2^63: set bit 64 to 1 */ + +#define TRACE(N) printf ("********* "#N"%13ld\n", N); + + + +/*=============================== Types =================================*/ + +/* Index for the different values of ValDelta */ +typedef int DeltaIndex; + + + + +/*========================= Extern variables ============================*/ + +smultin_Envir smultin_env = { + MAXK, + 1024 * 1024, /* SeuilHash */ + 0.75, /* HashLoad */ + 5.0E+6, /* SeuilEColl */ + + 12.0, /* SeuilCOverDense */ + 5.0, /* SeuilCOverNorSup */ + 1.999, /* SeuilCOverNorInf */ + 1.0001 /* SeuilCOverSparse */ +}; + + +/* The stable parameters values used by default */ +smultin_Param smultin_ParamDefault = { + 2, /* NbDelta */ + {-1, 1}, /* ValDelta */ + smultin_GenerCellSerial, /* GenerCell */ + -3 /* bmax */ +}; + + + +/*============================== Functions ==============================*/ + + +smultin_Param *smultin_CreateParam (int NbDelta, double ValDelta[], + smultin_GenerCellType GenerCell, int bmax) +{ + smultin_Param *par; + int j; + + par = util_Malloc (sizeof (smultin_Param)); + par->NbDelta = NbDelta; + for (j = 0; j < NbDelta; j++) { + util_Assert (ValDelta[j] >= -1.0, + "smultin_CreateParam: ValDelta[j] < -1"); + par->ValDelta[j] = ValDelta[j]; + } + util_Assert (bmax <= smultin_MAXB, + "smultin_CreateParam: bmax > smultin_MAXB"); + par->bmax = bmax; + par->GenerCell = GenerCell; + return par; +} + +/*-------------------------------------------------------------------------*/ + +void smultin_DeleteParam (smultin_Param *par) +{ + if (par == NULL) + return; + util_Free (par); +} + + +/*=========================================================================*/ + +static void CleanPD (smultin_Res *res) +{ + DeltaIndex s; + + if (res == NULL) + return; + + for (s = 0; s < res->NbDeltaOld; s++) { + res->TabFj[s] = util_Free (res->TabFj[s]); + } + + res->Count = util_Free (res->Count); + res->Count1 = util_Free (res->Count1); + res->Cell = util_Free (res->Cell); + res->Cell1 = util_Free (res->Cell1); + res->Nb = util_Free (res->Nb); + res->Nb1 = util_Free (res->Nb1); +} + + +/*=========================================================================*/ + +static void InitRes ( + smultin_Param *par, + smultin_Res *res, /* Results holder */ + long N /* Number of replications */ +) +/* + * Initializes the smultin_Res structure. The old NbDelta is in res, the + * new NbDelta is in par. Delete the unused collectors if old NbDelta > new + * NbDelta, and create the needed collectors if old NbDelta < new NbDelta. + */ +{ + DeltaIndex s; + + if (par == NULL) + par = &smultin_ParamDefault; + CleanPD (res); + + for (s = par->NbDelta; s < res->NbDeltaOld; s++) + res->Collector[s] = statcoll_Delete (res->Collector[s]); + + for (s = res->NbDeltaOld; s < par->NbDelta; s++) + res->Collector[s] = statcoll_Create (N, ""); + + for (s = 0; s < par->NbDelta; s++) { + statcoll_Init (res->Collector[s], N); + gofw_InitTestArray (res->sVal2[s], -1.0); + gofw_InitTestArray (res->pVal2[s], -1.0); + } + + res->NbDeltaOld = par->NbDelta; + res->flagTab = FALSE; + res->nLimit = 1; + res->pColl = res->pEmpty = -1.0; + res->pCollLeft = -1.0; + res->pCollRight = -1.0; +} + + +/*-------------------------------------------------------------------------*/ + +smultin_Res * smultin_CreateRes (smultin_Param *par) +{ + smultin_Res *res; + DeltaIndex s; + + res = util_Malloc (sizeof (smultin_Res)); + memset (res, 0, sizeof (smultin_Res)); + + if (par == NULL) + par = &smultin_ParamDefault; + + for (s = 0; s < par->NbDelta; s++) { + res->Collector[s] = statcoll_Create (1, ""); + res->TabFj[s] = NULL; + } + + res->Count = NULL; + res->Count1 = NULL; + res->Cell = NULL; + res->Cell1 = NULL; + res->NbDeltaOld = 0; + res->Nb = NULL; + res->Nb1 = NULL; + + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void smultin_DeleteRes (smultin_Res * res) +{ + DeltaIndex s; + + if (res == NULL) + return; + + for (s = 0; s < res->NbDeltaOld; s++) + res->Collector[s] = statcoll_Delete (res->Collector[s]); + + CleanPD (res); + util_Free (res); +} + + +/*=========================================================================*/ + +double smultin_MNTermeKhi2 (double junk, double NbEsp, long j) +/* + * One term of Chi2 = 2nI1; there are j balls in this urn. + */ +{ + double Diff; + Diff = j - NbEsp; + return Diff * Diff / NbEsp; +} + + +/*=======================================================================*/ + +double smultin_MNTermePowDiv (double Delta, double NbEsp, long j) +/* + * One term of Power Divergence = 2nI; there are j balls in this urn. + */ +{ + double y; + if (j == 0) + return 0.0; + y = pow (j / NbEsp, Delta) - 1.0; + return (2.0 * j * y) / (Delta * (Delta + 1.0)); +} + + +/*=======================================================================*/ + +double smultin_MNTermeLogLikhood (double junk, double NbEsp, long j) +/* + * One term of loglikelihood ratio = 2nI0; there are j balls in this urn + */ +{ + if (j == 0) + return 0.0; + return 2.0 * j * log (j / NbEsp); +} + + +/*=======================================================================*/ + +double smultin_MNTermeColl (double junk1, double junk2, long j) +/* + * Number of collisions when there are j balls in this urn + */ +{ + if (j <= 1) + return 0.0; + return (double) (j - 1); +} + + +/*=======================================================================*/ + +static void MNCalcMuSigma ( + double V[], /* Contains the terms of the statistic */ + long nlim, /* Limit on the non negligible terms */ + long n, /* Number of balls */ + double k, /* Number of urns */ + double *Mu, /* Mean */ + double *Sigma /* Standard deviation */ + ) +/* + * Compute the mean Mu and the standard deviation Sigma. For some values + * of n and k, some of the terms to be subtracted will be huge and loss + * of precision may give negative variance. We shall then stop the tests + * and exit in WriteDataPowDiv. + */ +{ + const double Epsilon = 1.0E-100; /* To avoid division by 0 */ + const double Eps = 1.0E-18; + long i, j, Mid; + double cond2, cond1, temp; + double Sum3, Sum2, Sum1; + double muk, Var; + double km; + double Terme2, TermeMid, Terme1; + double x, nr = n; + + util_Assert (nlim <= n, "MNCalcMuSigma; nlim > n"); + Mid = n / k; + while (Mid < nlim && fabs (V[Mid]) < Eps) + ++Mid; + util_Assert (Mid <= nlim, "MNCalcMuSigma; Mid > nlim"); + + /******* Compute Mean x = *Mu */ + TermeMid = fmass_BinomialTerm3 (n, 1.0 / k, Mid) * k; + x = V[Mid] * TermeMid; + Terme1 = x; + i = Mid; + km = k - 1; + while (i < n && fabs (Terme1 / x) > Eps) { + util_Assert (i < nlim, "MNCalcMuSigma: nlim too small --> Espion001"); + Terme1 *= V[i + 1] * (n - i) / (V[i] * (i + 1) * km); + x += Terme1; + ++i; + } + Terme1 = V[Mid] * TermeMid; + i = Mid; + while (i > 0 && fabs (Terme1) / x > Eps) { + Terme1 *= V[i - 1] * i * km / (V[i] * (n - i + 1)); + x += Terme1; + --i; + } + /* The cases when |Terme[i]| < Eps, but |Terme[i-1]| > Eps */ + /* these terms must be included also. */ + --i; + if (i >= 0) { + Terme1 = V[i] * fmass_BinomialTerm3 (n, 1.0 / k, i) * k; + x += Terme1; + while (i > 0 && fabs (Terme1 / x) > Eps) { + Terme1 = Terme1 * V[i - 1] * i * km / (V[i] * (n - i + 1)); + x += Terme1; + --i; + } + } + + /****** Calculate variance: first series of terms */ + muk = x / k; + Terme1 = (V[Mid] - muk) * (V[Mid] - muk) * TermeMid; + cond2 = TermeMid * V[Mid] * V[Mid]; + Sum1 = Terme1; + Terme2 = Terme1; + i = Mid; + km = k - 1; + while (i < n && fabs (cond2 / Sum1) + fabs (Terme2 / Sum1) > Eps) { + util_Assert (i < nlim, "MNCalcMuSigma: nlim too small --> Espion002"); + temp = V[i + 1] / (V[i] + Epsilon); + cond2 *= temp * temp * (n - i) / ((i + 1) * km); + temp = (V[i + 1] - muk) / (V[i] - muk); + Terme2 *= temp * temp * (n - i) / ((i + 1) * km); + Sum1 += Terme2; + ++i; + } + Terme2 = Terme1; + cond2 = TermeMid * V[Mid] * V[Mid]; + i = Mid; + while (i > 0 && fabs (cond2 / Sum1) + fabs (Terme2 / Sum1) > Eps) { + temp = V[i - 1] / (V[i] + Epsilon); + cond2 *= temp * temp * i * km / (n - i + 1); + temp = (V[i - 1] - muk) / (V[i] - muk); + Terme2 *= temp * temp * i * km / (n - i + 1); + Sum1 += Terme2; + --i; + } + + /****** Calculate variance: terms i = j */ + temp = fmass_BinomialTerm4 (n - Mid, 1.0 / k, 2.0 / k, Mid) * + fmass_BinomialTerm4 (n, 1.0 / k, 0.0, Mid) * k * (k - 1); + TermeMid = temp * (V[Mid] - muk) * (V[Mid] - muk); + cond1 = TermeMid * V[Mid] * V[Mid] + / ((V[Mid] - muk) * (V[Mid] - muk) + Epsilon); + Terme1 = TermeMid; + Sum2 = Terme1; + i = Mid; + km = k - 2; + while ((i < n / 2) + && fabs (cond1 / Sum2) + fabs (Terme1 / Sum2) > Eps) { + util_Assert (i < nlim, "MNCalcMuSigma: nlim too small --> Espion003"); + temp = V[i + 1] / ((V[i] + Epsilon) * (i + 1) * km); + cond1 *= (nr - 2 * i) * (nr - 2 * i - 1) * temp * temp; + temp = (V[i + 1] - muk) / ((V[i] - muk) * (i + 1) * km); + Terme1 *= (nr - 2 * i) * (nr - 2 * i - 1) * temp * temp; + Sum2 += Terme1; + ++i; + } + i = Mid; + Terme1 = TermeMid; + cond1 = TermeMid * V[Mid] * V[Mid] / ((V[Mid] - muk) * (V[Mid] - muk)); + while (i > 0 && fabs (cond1 / Sum2) + fabs (Terme1 / Sum2) > Eps) { + temp = (V[i - 1] * i * km) / (V[i] + Epsilon); + cond1 *= temp * temp / ((nr - 2 * i + 2) * (nr - 2 * i + 1) + Epsilon); + temp = (V[i - 1] - muk) * i * km / (V[i] - muk); + Terme1 *= temp * temp / ((nr - 2 * i + 2) * (nr - 2 * i + 1) + Epsilon); + Sum2 += Terme1; + --i; + } + /****** Calculate variance: terms i <> j */ + i = Mid + 1; + Sum3 = 1.0E-40; + cond1 = 1.0; + Terme1 = 1.0; + while (i <= n && fabs (cond1 / Sum3) + fabs (Terme1 / Sum3) > Eps) { + util_Assert (i <= nlim, "MNCalcMuSigma: nlim too small --> Espion004"); + j = Mid; + if (j > n - i) + j = n - i; + temp = fmass_BinomialTerm4 (n, 1.0 / k, 0.0, i) * + fmass_BinomialTerm4 (n - i, 1.0 / k, 2.0 / k, j); + Terme1 = temp * (V[i] - muk) * (V[j] - muk) * k * (k - 1); + cond1 = Terme1 * V[i] * V[j] / ((V[i] - muk) * (V[j] - muk)); + Sum3 += Terme1; + Terme2 = Terme1; + cond2 = cond1; + while (j > 0 && fabs (cond2 / Sum3) + fabs (Terme2 / Sum3) > Eps) { + cond2 *= V[j - 1] * j * km / (V[j] * (n - i - j + 1) + Epsilon); + Terme2 *= (V[j - 1] - muk) * j * km / + ((V[j] - muk) * (n - i - j + 1) + Epsilon); + Sum3 += Terme2; + --j; + } + Terme2 = Terme1; + cond2 = cond1; + j = Mid; + while ((j < i - 1 && i + j < n) + && fabs (cond2 / Sum3) + fabs (Terme2 / Sum3) > Eps) { + util_Assert (j < nlim, "MNCalcMuSigma: nlim too small --> Espion005"); + cond2 *= V[j + 1] * (n - i - j) / (V[j] * (j + 1) * km + Epsilon); + Terme2 *= (V[j + 1] - muk) * (n - i - j) + / ((V[j] - muk) * (j + 1) * km + Epsilon); + Sum3 += Terme2; + ++j; + } + ++i; + } + i = Mid; + cond1 = Sum3 + 1.0; + Terme1 = 1.0; + while (i > 0 && fabs (cond1 / Sum3) + fabs (Terme1 / Sum3) > Eps) { + j = i - 1; + temp = fmass_BinomialTerm4 (n, 1.0 / k, 0.0, i) * + fmass_BinomialTerm4 (n - i, 1.0 / k, 2.0 / k, j); + Terme1 = temp * (V[i] - muk) * (V[j] - muk) * k * (k - 1.0); + cond1 = (Terme1 * V[i] * V[j]) / ((V[i] - muk) * (V[j] - muk)); + Sum3 += Terme1; + Terme2 = Terme1; + cond2 = cond1; + while (j > 0 && fabs (cond2 / Sum3) + fabs (Terme2 / Sum3) > Eps) { + cond2 *= V[j - 1] * j * km / (V[j] * (n - i - j + 1) + Epsilon); + Terme2 *= (V[j - 1] - muk) * j * km / + ((V[j] - muk) * (n - i - j + 1) + Epsilon); + Sum3 += Terme2; + --j; + } + --i; + } + Var = Sum1 + Sum2 + 2.0 * Sum3; + util_Warning (Var < 0.0, "MNCalcMuSigma: negative variance"); + if (Var >= 0.0) + *Sigma = sqrt (Var); + else + *Sigma = -1.0; + *Mu = x; +} + + +/*=======================================================================*/ + +void smultin_MultinomMuSigma ( + long n, /* Number of balls */ + double k, /* Number of urns */ + double Theta1, /* First parameter of the term F */ + double Theta2, /* Second parameter of the term F */ + smultin_MNTermeType F, /* One term of the statistic */ + double *Mu, /* Mean */ + double *Sigma /* Standard deviation */ + ) +/* + * Compute the mean Mu and the standard deviation Sigma + */ +{ + + /* For densities n/k < 8, only the ~ 25 first terms will contribute */ + /* significantly to the normal approximation; thus we precompute only */ + /* elements [0..LIM_SPARSE] of the tables in the case Sparse = TRUE */ + + long nlim; + long j; + double densite; + double *PV; + + /* We may choose n >>> nlim because the probabilities will be concen- */ + /* trated near j = 0 for low densites ( < 8). Large values of j will */ + /* practically never occur. It is not necessary to compute all the */ + /* PV[0..n]. For high densities n/k, nlim will have to be increased. */ + + densite = n / (double) k; + nlim = 8 * densite; + if (nlim < LIM_SPARSE) + nlim = LIM_SPARSE; /* Sparse = TRUE */ + if (nlim > n) + nlim = n; /* Sparse = FALSE */ + PV = util_Calloc ((size_t) nlim + 2, sizeof (double)); + for (j = 0; j <= nlim; j++) + PV[j] = F (Theta1, Theta2, j); + MNCalcMuSigma (PV, nlim, n, k, Mu, Sigma); + util_Free (PV); +} + + +/*=======================================================================*/ + +static void CalcTabFj ( + smultin_Param *par, + smultin_Res *res, + lebool Sparse, + double k, /* Number of cells or urns */ + double NbExp /* Expected number per cell */ + ) +/* + * May pre-calculate all terms. Will then calculate all non negligible + * terms for all values of s, and keep them in tables TabFj[s][]. + */ +{ + long i; + DeltaIndex s; + double delta; + double c; + double temp; + double *F; + + if (!Sparse && LIM_DENSE * NbExp > k) { + /* Do not precompute tables when Sparse = FALSE and we have a very */ + /* small number k of cells */ + res->flagTab = FALSE; + return; + } + + /* Precompute the values and keep them in arrays */ + res->flagTab = TRUE; + if (Sparse) + res->nLimit = LIM_SPARSE; + else { + res->nLimit = LIM_DENSE * NbExp; + if (res->nLimit < 1) + res->nLimit = 2; + } + + for (s = 0; s < par->NbDelta; s++) { + res->TabFj[s] = util_Calloc (2 + (size_t) res->nLimit, sizeof (double)); + delta = par->ValDelta[s]; + util_Assert (delta >= -1.0 - EPS_LAM, + "CalcTabFj: par->ValDelta[s] < -1"); + F = res->TabFj[s]; + F[0] = 0.0; + + if (fabs (delta - 1.0) < EPS_LAM) { + /* ChiSquare */ + for (i = 0; i <= res->nLimit; i++) { + temp = i - NbExp; + F[i] = temp * temp / NbExp; + } + + } else if (fabs (delta) < EPS_LAM) { + /* LogLikelyhood */ + for (i = 1; i <= res->nLimit; i++) { + temp = i; + F[i] = 2.0 * temp * log (temp / NbExp); + } + + } else if (fabs (delta + 1.0) < EPS_LAM) { + /* Collision */ + for (i = 1; i <= res->nLimit; i++) { + F[i] = i - 1; + } + + } else { + /* PowerDivergence, delta > -1 */ + c = 2.0 / (delta * (delta + 1.0)); + for (i = 1; i <= res->nLimit; i++) { + temp = i; + F[i] = c * temp * (pow (temp / NbExp, delta) - 1.0); + } + } + } +} + + +/*=======================================================================*/ + +static void ReCalcTabFj ( + smultin_Param *par, + smultin_Res *res, + double NbExp /* Expected number per cell */ + ) +/* + * Update tables TabFj when one of the Count becomes larger than res->nLimit + */ +{ + long i; + DeltaIndex s; + double delta; + double c; + double temp; + double *F; + long i0 = res->nLimit; + res->nLimit *= 2; + + for (s = 0; s < par->NbDelta; s++) { + delta = par->ValDelta[s]; + res->TabFj[s] = util_Realloc (res->TabFj[s], + (res->nLimit + 1) * sizeof (double)); + F = res->TabFj[s]; + + if (fabs (delta - 1.0) < EPS_LAM) { + /* ChiSquare */ + for (i = i0 + 1; i <= res->nLimit; i++) { + temp = i - NbExp; + F[i] = temp * temp / NbExp; + } + + } else if (fabs (delta) < EPS_LAM) { + /* LogLikelyhood */ + for (i = i0 + 1; i <= res->nLimit; i++) { + temp = i; + F[i] = 2.0 * temp * log (temp / NbExp); + } + + } else if (fabs (delta + 1.0) < EPS_LAM) { + /* Collision Test */ + for (i = i0 + 1; i <= res->nLimit; i++) { + F[i] = i - 1; + } + + } else { + c = 2.0 / (delta * (delta + 1.0)); + for (i = i0 + 1; i <= res->nLimit; i++) { + temp = i; + F[i] = c * temp * (pow (temp / NbExp, delta) - 1.0); + } + } + } +} + + +/*=======================================================================*/ + +void smultin_PowDivMomCorChi ( + double Delta, + long n, /* Number of balls */ + double k, /* Number of urns */ + double *MuC, /* Corrected mean */ + double *SigmaC /* Corrected standard deviation */ + ) +/* + * Compute the corrected mean and standard deviation in the dense case + * for the ChiSquare approximation. (See Read and Cressie) + */ +{ + double t = k * k; + double temp; + if (Delta < EPS_LAM - 1.0) { + *MuC = -1.0; + *SigmaC = -1.0; + return; + } + temp = (8.0 - 12.0 * k - 2.0 * k * k + 6.0 * t + + (Delta - 1.0) * (4.0 - 6.0 * k - 3.0 * k * k + 5.0 * t) / 3.0 + + 2.0 * (Delta - 2.0) * (1.0 - 2.0 * k + t)); + *SigmaC = 2.0 - 2.0 * k - (double) k * k + t + (Delta - 1.0) * temp; + *SigmaC = sqrt (1.0 + *SigmaC / (2.0 * n * (k - 1.0))); + temp = (2.0 - 3.0 * k + t) / 3.0 + + (Delta - 2.0) * (1.0 - 2.0 * k + t) / 4.0; + *MuC = (k - 1.0) * (1.0 - *SigmaC) + (Delta - 1.0) * temp / n; +} + + +/*=======================================================================*/ + +void smultin_PowDivMom ( + double Delta, /* Which Power Divergence */ + long n, /* Number of balls */ + double k, /* Number of urns */ + double NbExp, /* Expected number per urn */ + double *Mu, /* Mean */ + double *Sigma /* Standard deviation */ + ) +/* + * Compute the mean and standard deviation in the sparse case + */ +{ + + if ((double) n / k > 8.0) { + printf ("************* Call of smultin_PowDivMom with n/k > 8\n"); + *Mu = -1.0; + *Sigma = -1.0; + return; + } + if (k <= 2) { + printf ("************* Call of smultin_PowDivMom with k <= 2\n"); + *Mu = -1.0; + *Sigma = -1.0; + return; + } + + util_Assert ((double) n / k <= 8.0, + "smultin: Call of PowDivMom with n/k > 8"); + util_Assert (k > 2, "smultin: Call of PowDivMom with k <= 2"); + + if (fabs (Delta - 1.0) < EPS_LAM) { + /* ChiSquare test */ + *Mu = k - 1; + *Sigma = sqrt (2.0 * (k - 1) * (n - 1.0) / n); + + } else if (fabs (Delta + 1.0) < EPS_LAM) { + /* Collision test */ + smultin_MultinomMuSigma (n, k, 0.0, 0.0, smultin_MNTermeColl, Mu, Sigma); + + } else if (fabs (Delta) < EPS_LAM) { + /* Delta = 0, LogLikelyhood */ + smultin_MultinomMuSigma (n, k, 0.0, NbExp, smultin_MNTermeLogLikhood, + Mu, Sigma); + + } else if (Delta > -1.0) { + smultin_MultinomMuSigma (n, k, Delta, NbExp, smultin_MNTermePowDiv, + Mu, Sigma); + + } else + util_Error ("smultin_PowDivMom: Delta < -1.0"); +} + + +/*=======================================================================*/ +#if 0 + +static void CalcPowDiv (double Delta, double NbExp[], long Count[], + long smin, long smax, double *X) +/* + * Compute the statistic $2n I^\delta$ defined in (\ref{powdiv}), + * for $\delta = {\tt Delta}$, and return its value in $X$. + * We assume that the expected values $n p_i$ in cell $i$ are in + * {\tt NbExp[smin..smax]}, the observed values $X_i$ are in + * {\tt Count[smin..smax]}, {\tt smin} and {\tt smax} are the indices + * of the first and the last cell, + * and the number of cells is $k = {\tt smax} - {\tt smin} + 1$. + * The $p_i$ are not necessarily equal. + */ +{ + double temp; + long s; + *X = 0.0; + + if (fabs (Delta - 1.0) < EPS_LAM) { + /* ChiSquare */ + for (s = smin; s <= smax; s++) { + temp = Count[s] - NbExp[s]; + *X += (temp * temp) / NbExp[s]; + } + + } else if (fabs (Delta) < EPS_LAM) { + /* Loglikelihood */ + for (s = smin; s <= smax; s++) { + if (Count[s] > 0) { + temp = Count[s]; + *X += temp * log (temp / NbExp[s]); + } + } + *X *= 2.0; + + } else if (Delta <= EPS_LAM - 1.0) { + util_Error ("smultin_CalcPowDiv: Delta <= -1.0"); + /* We do the collisions test only when probabilities are equal. See + smultin_CalcPowDivEqual. */ + + } else { + /* Other values of Delta. */ + for (s = smin; s <= smax; s++) { + if (Count[s] > 0) { + temp = Count[s]; + *X += temp * (pow (temp / NbExp[s], Delta) - 1.0); + } + } + *X = 2.0 * *X / (Delta * (Delta + 1.0)); + } +} + +#endif + +/*=======================================================================*/ + +static void CalcPowDivEqual ( + smultin_Param *par, + smultin_Res *res, + DeltaIndex s, + double NbExp, /* Expected number per cell */ + long Count[], /* Counters */ + long jmin, /* First cell */ + long jmax, /* Last cell */ + lebool flagTab, /* TRUE: use precomputed table */ + double *X /* Computed statistic */ + ) +/* + * This function is called only when we do not use hashing. + * + * As in CalcPowDiv, except that the values of np_i are all equal to + * np = NbExp. The lebool flagTab indicates if the values of + * $2 i ln (i/np)$ and + * $ {2\over \delta(1+\delta)} + * i \left[\left(i/np\right)^\delta -1\right]$ have already been + * pre-computed and kept in the arrays + * F (it is so if {\tt flagTab = TRUE}). + */ +{ + double temp; + double *F = res->TabFj[s]; /* The precomputed table */ + double Delta = par->ValDelta[s]; + long j; + *X = 0.0; + + if (flagTab) { + /* For low densities, we use precomputed tables since the observed */ + /* values will all be very small. We shall thus need only a few */ + /* terms (expensive to compute) of the statistics. */ + util_Assert (res->nLimit > 0, + "smultin_CalcPowDivEqual BUG: res->nLimit <= 0"); + + for (j = jmin; j <= jmax; j++) { + /* A larger than expected counter needs terms that have not been */ + /* precomputed: Recompute missing terms. */ + while (Count[j] > res->nLimit) { + ReCalcTabFj (par, res, NbExp); + F = res->TabFj[s]; + } + *X += F[Count[j]]; + } + return; + } + + /* High densities: no precomputed tables */ + if (fabs (Delta - 1.0) < EPS_LAM) { + /* ChiSquare: Delta = 1 */ + for (j = jmin; j <= jmax; j++) { + temp = Count[j] - NbExp; + *X += temp * temp; + } + *X /= NbExp; + + } else if (fabs (Delta) < EPS_LAM) { + /* Loglikelihood ratio */ + for (j = jmin; j <= jmax; j++) { + if (Count[j] > 0) { + temp = Count[j]; + *X += temp * log (temp / NbExp); + } + } + *X *= 2.0; + + } else if (fabs (Delta + 1.0) < EPS_LAM) { + /* Collision test */ + for (j = jmin; j <= jmax; j++) { + if (Count[j] > 1) + *X += Count[j] - 1; + } + + } else if (Delta > (-1.0)) { + for (j = jmin; j <= jmax; j++) { + if (Count[j] > 0) { + temp = Count[j]; + *X += temp * (pow (temp / NbExp, Delta) - 1.0); + } + } + *X = (2.0 * *X) / (Delta * (Delta + 1.0)); + + } else + util_Error ("smultin_CalcPowDivEqual: Delta < -1"); +} + + +/*=======================================================================*/ + +static void CalcPoDiEqHache ( + smultin_Param *par, + smultin_Res *res, + DeltaIndex i, + double NbExp, /* Expected number per cell */ + smultin_CellType Nb[], /* Number of cells with s balls */ + long CountMax, /* Max number of balls in any cell */ + lebool flagTab, /* TRUE if use precomputed table */ + double *X /* Computed statistic */ + ) +/* + * Compute the Power Divergence statistic or the number of collisions in + * the sparse case. We use a hashing table of smultin_CellType. + */ +{ + double temp; + double *F = res->TabFj[i]; /* The precomputed table */ + double Delta = par->ValDelta[i]; + long s; + *X = 0.0; + + if (flagTab) { + /* For low densities, we use precomputed tables since the observed */ + /* values will all be very small. We shall thus need only a few */ + /* terms (expensive to compute) of the statistics. */ + util_Assert (res->nLimit > 0, "CalcPoDiEqHache BUG: res->nLimit <= 0"); + + /* A larger than expected counter needs terms that have not been */ + /* precomputed: Recompute missing terms. */ + while (CountMax > res->nLimit) { + ReCalcTabFj (par, res, NbExp); + F = res->TabFj[i]; + } + + for (s = 0; s <= CountMax; s++) { + *X += F[s] * Nb[s]; + } + return; + } + + /* High densities: no precomputed tables */ + if (fabs (Delta - 1.0) < EPS_LAM) { + /* ChiSquare: Delta = 1 */ + for (s = 1; s <= CountMax; s++) { + temp = s - NbExp; + *X += temp * temp * Nb[s]; + } + *X = *X / NbExp + NbExp * Nb[0]; + + } else if (fabs (Delta) < EPS_LAM) { + /* Delta = 0: Loglikelihood ratio */ + for (s = 1; s <= CountMax; s++) { + temp = s; + *X += temp * log (temp / NbExp) * Nb[s]; + } + *X *= 2.0; + + } else if (fabs (Delta + 1.0) < EPS_LAM) { + /* Collision test */ + for (s = 2; s <= CountMax; s++) { + *X += (s - 1.0) * Nb[s]; + } + + } else if (Delta > -1.0) { + for (s = 1; s <= CountMax; s++) { + temp = s; + *X += temp * (pow (temp / NbExp, Delta) - 1.0) * Nb[s]; + } + *X = 2.0 * *X / (Delta * (Delta + 1.0)); + + } else + util_Error ("CalcPoDiEqHache: Delta < -1"); +} + + +/*=======================================================================*/ + +static void CalcNbCells ( + smultin_Param *par, + smultin_Res *res, + long jmin, /* First cell */ + long jmax, /* Last cell */ + long CoMax /* Maximum number of balls in any cell */ + ) +/* + * Compute the number of cells containing j balls or more. + */ +{ + + long j; + smultin_CellType wb[smultin_MAXB + 1]; + long *Count = res->Count; /* Counters */ + smultin_CellType *Nb = res->Nb; /* Nb[j] = number of cells with j balls */ + + util_Assert (par->bmax <= smultin_MAXB, + "CalcNbCells: smultin_MAXB is too small"); + + for (j = 0; j <= smultin_MAXB; j++) + wb[j] = 0; + + if (res->Hashing) { + for (j = smultin_MAXB; j <= CoMax; j++) + wb[smultin_MAXB] += Nb[j]; + for (j = smultin_MAXB - 1; j >= 0; j--) + wb[j] = wb[j + 1] + Nb[j]; + + } else { + Nb[0] = 0; + for (j = jmin; j <= jmax; j++) { + if (Count[j] > smultin_MAXB) { + wb[smultin_MAXB] += 1; + } else + Nb[Count[j]] += 1; + } + wb[smultin_MAXB] += Nb[smultin_MAXB]; + for (j = smultin_MAXB - 1; j >= 0; j--) + wb[j] = wb[j + 1] + Nb[j]; + } + + /* the local array wb is necessary in the case N > 1 and Poisson since */ + /* then, the statistic used is the sum of the N Poisson statistics; */ + /* we are here summing the numbers for the N replications of the test. */ + + for (j = 0; j <= smultin_MAXB; j++) { + res->WbCells[j] += wb[j]; + res->NbCells[j] += Nb[j]; + } +} + + +/*=======================================================================*/ + +smultin_CellType smultin_GenerCellSerial (unif01_Gen *gen, + int r, int t, long d) +{ + int j; + smultin_CellType dr = d; + smultin_CellType Cell; + + Cell = unif01_StripL (gen, r, d); + for (j = 2; j <= t; j++) + Cell = Cell * dr + unif01_StripL (gen, r, d); + return Cell; +} + + +/*=======================================================================*/ + +smultin_CellType smultin_GenerCellSerial2 (unif01_Gen *gen, + int r, int t, long d) +{ + int j; + smultin_CellType dr = d; + smultin_CellType Cell; + + Cell = unif01_StripL (gen, r, d); + for (j = 2; j <= t; j++) { + Cell += dr * unif01_StripL (gen, r, d); + dr *= d; + } + return Cell; +} + + +/*=======================================================================*/ + +smultin_CellType smultin_GenerCellPermut (unif01_Gen *gen, + int r, int t, long junk) +{ + int s, i, j; + smultin_CellType Cell = 0; + double U[64]; + + for (j = 1; j <= t; j++) + U[j] = unif01_StripD (gen, r); + + for (i = t; i >= 2; i--) { + /* Find the U[s] = max (U[1],...,U[i]) */ + s = 1; + for (j = 2; j <= i; j++) { + if (U[j] > U[s]) + s = j; + } + Cell = Cell * i + (s - 1); + U[s] = U[i]; + } + return Cell; +} + + +/*=======================================================================*/ + +smultin_CellType smultin_GenerCellMax (unif01_Gen *gen, + int r, int t, long junk) +{ + int i, MaxI; + double U, MaxU = -1.0; + + /* Don't forget that cells are numbered from 0 to k - 1 */ + for (i = 0; i < t; i++) { + U = unif01_StripD (gen, r); + if (U > MaxU) { + MaxU = U; + MaxI = i; + } + } + return (smultin_CellType) MaxI; +} + + +/*=======================================================================*/ + +smultin_CellType smultin_GenerCellSerialBits (unif01_Gen * gen, + int r, int s, long L) +{ + const int t = L / s; + const smultin_CellType dr = num_TwoExp[s]; + smultin_CellType Cell; + int j; + + Cell = unif01_StripB (gen, r, s); + for (j = 2; j <= t; j++) + Cell = Cell * dr + unif01_StripB (gen, r, s); + return Cell; +} + + +/*=======================================================================*/ + +fmass_INFO smultin_CreateCollisions (long n, smultin_CellType k) +{ + const long nLim = 100000; + const int MaxIter = 32; + const double Epsilon = DBL_EPSILON; + const double DensityLim = 1.0001; + long J1, J0, j, i, Dim; + double terme, v, u, mu, sigma, x; + double kinv = 1.0 / k; + double *A; + fmass_INFO W; + + util_Assert (k > 0, "smultin_CreateCollisions: k <= 0"); + util_Assert (n > 0, "smultin_CreateCollisions: n <= 0"); + + /* Poisson Approximation */ + if ((n > nLim) && ((double) n / k <= DensityLim)) { + if ((double) n / k <= 0.1) { + int jj; + /* To avoid loss of precision when n/k --> 0, we expand the */ + /* formula below in a MacLaurin series */ + + jj = 3; + u = n - 1; + v = 2.0; + terme = (n * u) / (2.0 * k * k); + mu = terme; + while (fabs (terme / mu) > Epsilon && jj < MaxIter) { + u -= 1.0; + v += 1.0; + terme = -terme * u / (k * v); + mu += terme; + ++jj; + } + util_Assert (jj < MaxIter, + "smultin_CreateCollisions: limit MaxIter hit"); + + } else if (n <= 100) { + mu = ((double) n / k - 1.0) + pow (1.0 - 1.0 / k, (double) n); + + } else { + const int ITER = 10; + int i; + terme = kinv; + mu = terme; + + /* Compute the log of pow(1 - 1/k, n) by Maclaurin series */ + for (i = 2; i < ITER; i++) { + terme *= kinv; + mu += terme / i; + } + mu = ((double) n / k - 1.0) + exp (-n * mu); + } + + mu *= k; + W = fmass_CreatePoisson (mu); + /* W->paramR[0] now contains the Poisson parameter mu */ + W->paramR = util_Realloc (W->paramR, 3 * sizeof (double)); + W->paramR[1] = n; + W->paramR[2] = k; + W->paramI = util_Malloc (sizeof (long)); + W->paramI[0] = smultin_CollPoissonSparse; + return W; + } + + W = util_Malloc (sizeof (struct fmass_INFO_T)); + W->paramI = util_Malloc (sizeof (long)); + W->paramR = util_Calloc (5, sizeof (double)); + W->paramR[1] = n; + W->paramR[2] = k; + + + /* Normal Approximation */ + if (n > nLim) { + smultin_MultinomMuSigma (n, (double) k, 0.0, 0.0, smultin_MNTermeColl, + &mu, &sigma); + W->paramR[3] = mu; + W->paramR[4] = sigma; + W->paramI[0] = smultin_CollNormal; + W->pdf = NULL; + W->cdf = NULL; + W->smin = -1; + W->smax = -1; + return W; + } + + + /* Exact Distribution */ + A = util_Calloc ((size_t) n + 2, sizeof (double)); + for (j = 0; j <= n; j++) + A[j] = 0.0; + A[1] = 1.0; + J1 = J0 = 1; + for (j = 1; j <= n - 1; j++) { + ++J1; + i = J1; + while (i >= J0) { + x = i * kinv; + A[i] = x * A[i] + (1.0 + kinv - x) * A[i - 1]; + if (A[i] <= Epsilon) { + A[i] = 0.0; + if (i == J1) + --J1; + else if (i == J0) + ++J0; + } + --i; + } + } + Dim = n - J0 + 1; + W->pdf = util_Calloc ((size_t) Dim + 1, sizeof (double)); + W->cdf = util_Calloc ((size_t) Dim + 1, sizeof (double)); + + W->pdf[0] = A[n]; + W->cdf[0] = A[n]; + j = 0; + while (j < Dim && W->cdf[j] < 1.0) { + ++j; + W->pdf[j] = A[n - j]; + W->cdf[j] = W->pdf[j] + W->cdf[j - 1]; + } + while (j <= Dim) { + W->pdf[j] = A[n - j]; + W->cdf[j] = 1.0; + ++j; + } + util_Free (A); + W->paramI[0] = smultin_CollExact; + W->smin = 0; + W->smax = Dim; + return W; +} + + +/*-------------------------------------------------------------------------*/ + +void smultin_DeleteCollisions (fmass_INFO W) +{ + if (W == NULL) + return; + util_Free (W->paramI); + util_Free (W->paramR); + util_Free (W->pdf); + util_Free (W->cdf); + util_Free (W); +} + + +/*-------------------------------------------------------------------------*/ + +double smultin_CollisionsTerm (fmass_INFO W, long s) +{ + int par; + double z; + double Mu; + double Sigma; + + util_Assert (W != NULL, + "smultin_CollisionsTerm: fmass_INFO is NULL pointer"); + if (s < 0) + return 0.0; + par = W->paramI[0]; + + switch (par) { + case smultin_CollPoissonSparse: + return fmass_PoissonTerm2 (W, s); + case smultin_CollNormal: + Mu = W->paramR[3]; + Sigma = W->paramR[4]; + z = fdist_Normal2 ((s - Mu) / Sigma) - + fdist_Normal2 ((s - 1 - Mu) / Sigma); + return z; + case smultin_CollExact: + if (s > W->smax) + return 0.0; + return W->pdf[s]; + default: + util_Error ("smultin_CollisionsTerm: Not initialized"); + return 0.0; + } +} + + +/*-------------------------------------------------------------------------*/ + +double smultin_FDistCollisions (fmass_INFO W, long s) +{ + int par; + + util_Assert (W != NULL, + "smultin_FDistCollisions: fmass_INFO is NULL pointer"); + if (s < 0) + return 0.0; + par = W->paramI[0]; + + switch (par) { + case smultin_CollPoissonSparse: + return fdist_Poisson2 (W, s); + case smultin_CollNormal: + /* W->paramR[3] = Mu, W->paramR[4] = Sigma */ + return fdist_Normal2 ((s - W->paramR[3]) / W->paramR[4]); + case smultin_CollExact: + if (s > W->smax) + return 1.0; + return W->cdf[s]; + default: + util_Error ("smultin_FDistCollisions: Not initialized"); + return 0.0; + } +} + + +/*-------------------------------------------------------------------------*/ + +double smultin_FBarCollisions (fmass_INFO W, long s) +{ + return 1.0 - smultin_FDistCollisions (W, s - 1); +} + + +/*=======================================================================*/ + +static void InitPowDiv ( + smultin_Param *par, + smultin_Res *res, + long N, /* Number of replications */ + lebool Sparse, + long n, /* Number of balls */ + smultin_CellType z /* Number of urns (not quite for PowDivOver) */ + ) +/* + * Initialize the multinomial tests + */ +{ + + DeltaIndex s; + long j; + double NbExp; + char chaine[LENGTH + 1]; + char Str[LENGTH + 1]; + double Mu; /* Mean */ + double Sigma; /* Standard Deviation */ + + NbExp = (double) n / z; + if (z >= smultin_env.SeuilHash && NbExp < 1.0) + res->Hashing = TRUE; + else + res->Hashing = FALSE; + + res->EsCells[0] = N * (double) z * exp (-NbExp); + res->EsEmpty = res->EsCells[0]; + res->NbCells[0] = 0; + res->WbCells[0] = 0; + + util_Assert (par->NbDelta <= smultin_MAX_DELTA, + "par->NbDelta > smultin_MAX_DELTA"); + for (s = 0; s < par->NbDelta; s++) { + + if (Sparse) { + smultin_PowDivMom (par->ValDelta[s], n, (double) z, (double) n / z, + &Mu, &Sigma); + + } else if (fabs (par->ValDelta[s] + 1.0) > EPS_LAM) { + /* Non collision tests */ + smultin_PowDivMomCorChi (par->ValDelta[s], n, (double) z, &Mu, + &Sigma); + + } else { + /* Meaningless values as flags */ + Mu = -1.0; + Sigma = -1.0; + } + res->Mu[s] = Mu; + res->Sigma[s] = Sigma; + + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) { + /* Collision test */ + strncpy (Str, "The N statistic values for Collision:", (size_t) 64); + res->NbCollisions = 0.0; + for (j = 1; j <= smultin_MAXB; j++) { + res->NbCells[j] = 0; + res->WbCells[j] = 0; + } + /* The exact expected numbers (from Knuth) + temp = n * log ((z - 1.0)/z); + res->EsCells[0] = z * exp (temp); + res->EsCells[1] = n * res->EsCells[0] / (z - 1.0); + res->EsCells[2] = (n - 1.0) * res->EsCells[1] / (2.0*(z - 1.0)); + res->EsCells[>=3] = z - res->EsCells[0] - res->EsCells[1] - + res->EsCells[2]; + */ + + /* Expected numbers of urns with exactly j balls in the Poisson */ + /* approximation */ + for (j = 1; j <= smultin_MAXB; j++) { + res->EsCells[j] = (res->EsEmpty * pow (NbExp, (double) j)) + / num2_Factorial (j); + } + /* Expected numbers of urns with >= j balls */ + for (j = smultin_MAXB - 1; j >= 0; j--) { + res->EsCells[j] += res->EsCells[j + 1]; + } + + } else { + /* Non Collision tests */ + strncpy (Str, "The N statistic values for Delta = ", (size_t) 64); + sprintf (chaine, "%4.2f:", par->ValDelta[s]); + strncat (Str, chaine, (size_t) 10); + } + + statcoll_SetDesc (res->Collector[s], Str); + } +} + + +/*=======================================================================*/ + +static void WriteDataPowDiv ( + unif01_Gen *gen, + smultin_Param *par, + smultin_Res *res, + char *TestName, + long N, /* Number of replications */ + long n, /* Number of balls */ + int r, /* Drop r bits from each random number */ + long d, /* Number of segments on 1-dimensional line */ + int t, /* Dimension */ + lebool Sparse, + smultin_CellType k /* Number of urns */ +) +/* + * Write the parameters of the test + */ +{ + double EC; + double NbExp; + DeltaIndex s; + + swrite_Head (gen, TestName, N, n, r); + + if (par->GenerCell == smultin_GenerCellSerial) { + printf (", d = %4ld, t = %2d,\n Sparse = ", d, t); + util_WriteBool (Sparse, 6); + printf ("\n\n"); + printf (" GenerCell = smultin_GenerCellSerial\n"); + printf (" Number of cells = d^t = "); + } else if (par->GenerCell == smultin_GenerCellSerial2) { + printf (", d = %4ld, t = %2d,\n Sparse = ", d, t); + util_WriteBool (Sparse, 6); + printf ("\n\n"); + printf (" GenerCell = smultin_GenerCellSerial2\n"); + printf (" Number of cells = d^t = "); + } else if (par->GenerCell == smultin_GenerCellPermut) { + printf (", t = %2d,\n Sparse = ", t); + util_WriteBool (Sparse, 6); + printf ("\n\n"); + printf (" GenerCell = smultin_GenerCellPermut\n"); + util_Assert (!res->Over, + "MultinomialOver: non implemented for smultin_GenerCasePermut"); + printf (" Number of cells = t! = "); + } else if (par->GenerCell == smultin_GenerCellMax) { + printf (", k = %2d,\n Sparse = ", t); + util_WriteBool (Sparse, 6); + printf ("\n\n"); + printf (" GenerCell = smultin_GenerCellMax\n"); + printf (" Number of cells = k = "); + } + +#ifdef USE_LONGLONG + printf ("%18" PRIuLEAST64 "\n", k); +#else + printf ("%18.0f\n", k); +#endif + + util_Assert (k <= smultin_env.Maxk, "Multinomial: k is too large"); + printf (" Expected number per cell = "); + NbExp = (double) n / k; + if (NbExp < 1.0) + printf ("1 / %10.8g\n", 1.0 / NbExp); + else + printf ("%10.8g\n", NbExp); + + EC = (double) n * n / (2.0 * k); + if (Sparse) + printf (" EColl = n^2 / (2k) = %12.10g\n", EC); + printf (" Hashing = "); + util_WriteBool (res->Hashing, 6); + printf ("\n\n"); + if (par->NbDelta == 1 && par->ValDelta[0] == -1) + ; + else { + if (Sparse) { + printf (" For Delta > -1, we use the normal approximation\n"); + printf (" Mean and standard deviation: \n"); + } else { + printf (" For Delta > -1, we use the ChiSquare approximation\n"); + printf (" Correction factor of the ChiSquare: \n"); + } + } + + for (s = 0; s < par->NbDelta; s++) { + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) { + if ((Sparse == FALSE) && (res->Over == FALSE)) { + /* The collision test is meaningless when Sparse = FALSE */ + continue; + } + printf (" Collision test"); + } else { + printf (" Delta = %5.2g", par->ValDelta[s]); + } + if (!res->Over || fabs (par->ValDelta[s] + 1.0) > EPS_LAM) { + printf (", Mu = %14.8g", res->Mu[s]); + printf (", Sigma = %10.6g", res->Sigma[s]); + util_Assert (res->Sigma[s] > 0.0, "Negative Variance"); + } + printf ("\n"); + } + printf ("\n"); +} + + +/*=======================================================================*/ + +static void WriteDataMNBits ( + unif01_Gen *gen, + smultin_Param *par, + smultin_Res *res, + char *TestName, + long N, /* Number of replications */ + long n, /* Number of balls */ + int r, /* Drop r bits from each random number */ + long L, /* Number of bits for a cell */ + int s, /* Number of bits taken from each rand. num. */ + lebool Sparse, + smultin_CellType k, /* Number of cells = 2^L */ + lebool Over /* Overlapping case = TRUE */ +) +/* + * Write the parameters of the test + */ +{ + + double EC; + double NbExp; + DeltaIndex j; + + swrite_Head (gen, TestName, N, n, r); + + printf (", s = %2d, L = %4ld,\n Sparse = ", s, L); + util_WriteBool (Sparse, 6); + if (Over) + printf ("\n\n Number of bits = n = %1ld\n", n); + else + printf ("\n\n Number of bits = n*L = %1ld\n", L * n); + + /* printf (" GenerCell = smultin_GenerCellSerialBits\n"); */ + +#ifdef USE_LONGLONG + printf (" Number of cells = 2^L = %18" PRIuLEAST64 "\n", k); +#else + printf (" Number of cells = 2^L = %18.0f\n", k); +#endif + util_Assert (k <= smultin_env.Maxk, "Multinom: k is too large"); + + printf (" Expected number per cell = "); + NbExp = (double) n / k; + if (NbExp < 1.0) + printf ("1 / %10.8g\n", 1.0 / NbExp); + else + printf ("%10.8g\n", NbExp); + + EC = (double) n * n / (2.0 * k); + if (Sparse) + printf (" EColl = n^2 / (2k) = %12.10g\n", EC); + printf (" Hashing = "); + util_WriteBool (res->Hashing, 6); + printf ("\n\n"); + if (par->NbDelta == 1 && par->ValDelta[0] == -1) + ; + else { + if (Sparse) { + printf (" For Delta > -1, we use the normal approximation\n"); + printf (" Mean and standard deviation: \n"); + } else { + printf (" For Delta > -1, we use the ChiSquare approximation\n"); + printf (" Correction factor of the ChiSquare: \n"); + } + } + + for (j = 0; j < par->NbDelta; j++) { + if (fabs (par->ValDelta[j] + 1.0) < EPS_LAM) { + if ((Sparse == FALSE) && (res->Over == FALSE)) { + /* The collision test is meaningless when Sparse = FALSE */ + continue; + } + printf (" Collision test"); + } else { + printf (" Delta = %5.2g", par->ValDelta[j]); + } + if (!res->Over || fabs (par->ValDelta[j] + 1.0) > EPS_LAM) { + printf (", Mu = %14.8g", res->Mu[j]); + printf (", Sigma = %10.6g\n", res->Sigma[j]); + util_Assert (res->Sigma[j] > 0.0, "Negative Variance"); + } + } + printf ("\n"); +} + + +/*=======================================================================*/ + +static void CalcResultsPowDiv ( + smultin_Param *par, + smultin_Res *res, + DeltaIndex s, /* Which statistic */ + long n, /* Number of balls */ + lebool Sparse, + smultin_CellType DegreLib, /* Number of degrees of freedom */ + double Mu, /* Mean */ + double SumX[], + double SumX2[] + ) +{ + + double pR, pL; + double pCollLeft; /* Left p-value of Collision test */ + double pCollRight; /* Right p-value of Collision test */ + int j; + statcoll_Collector *SC = res->Collector[s]; + fmass_INFO Mass1, Mass2; + double V[1]; + long N = SC->NObs; + double racN; + + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) { + /* Collision Test */ + if (!Sparse) { + res->pColl = -1.0; + res->pCollLeft = -1.0; + res->pCollRight = -1.0; + return; + } + /* The total number of collisions of N replications is NbCollisions */ + Mass1 = smultin_CreateCollisions (n, DegreLib + 1); + if (N == 1) { + pCollLeft = smultin_FDistCollisions (Mass1, (long) res->NbCollisions); + pCollRight = smultin_FBarCollisions (Mass1, (long) res->NbCollisions); + res->pCollLeft = pCollLeft; + res->pCollRight = pCollRight; + res->sVal2[s][gofw_Mean] = SumX[s]; + res->pVal2[s][gofw_Mean] = fbar_Normal1 (res->sVal2[s][gofw_Mean]); + } else { + if (Mu < smultin_env.SeuilEColl) { + Mass2 = fmass_CreatePoisson (N * Mu); + pCollLeft = fdist_Poisson2 (Mass2, (long) res->NbCollisions); + pCollRight = fbar_Poisson2 (Mass2, (long) res->NbCollisions); + fmass_DeletePoisson (Mass2); + } + } + smultin_DeleteCollisions (Mass1); + res->pColl = gofw_pDisc (pCollLeft, pCollRight); + + /* Total number of empty urns of the N replications: res->NbCells[0] + Mass2 = fmass_CreatePoisson (res->EsEmpty); + pL = fdist_Poisson2 (Mass2, res->NbCells[0]); + pR = fbar_Poisson2 (Mass2, res->NbCells[0]); + fmass_DeletePoisson (Mass2); + res->pEmpty = gofw_pDisc (pL, pR); */ + + /* Since we can have very large values of res->EsEmpty (2^63), we + compute the Poisson pL, pR by calling the Gamma distribution, since + our Poisson takes a long argument */ + + if (res->NbCells[0] <= EMPTYLIM && res->EsEmpty <= EMPTYLIM) { + pL = fbar_Gamma (res->NbCells[0] + 1.0, 12, res->EsEmpty); + if ((res->NbCells[0] <= 0) || (res->NbCells[0] > res->NbCellsTotal)) + pR = 1.0; + else + pR = fdist_Gamma ((double) (res->NbCells[0]), 12, res->EsEmpty); + res->pEmpty = gofw_pDisc (pL, pR); + } + /* The total number of urns containing >= j balls */ + for (j = 2; j <= par->bmax; j++) { + Mass2 = fmass_CreatePoisson ((double) (res->EsCells[j])); + pL = fdist_Poisson2 (Mass2, (long) res->WbCells[j]); + pR = fbar_Poisson2 (Mass2, (long) res->WbCells[j]); + fmass_DeletePoisson (Mass2); + res->pWb[j] = gofw_pDisc (pL, pR); + } + + } else if (Sparse) { + /* Tests other than Collision test */ + gofw_ActiveTests1 (SC->V, N, wdist_Normal, (double *) NULL, + res->sVal2[s], res->pVal2[s]); + + } else { + V[0] = DegreLib; + gofw_ActiveTests1 (SC->V, N, wdist_ChiSquare, V, + res->sVal2[s], res->pVal2[s]); + } + + /* Now compute the mean and the correlation with their p-values. */ + if (N > 1) { + racN = sqrt ((double) N); + res->sVal2[s][gofw_Mean] = SumX[s] / racN; + res->pVal2[s][gofw_Mean] = fbar_Normal1 (res->sVal2[s][gofw_Mean]); + res->sVal2[s][gofw_Cor] = racN * SumX2[s] / (N - 1); + res->pVal2[s][gofw_Cor] = fbar_Normal1 (res->sVal2[s][gofw_Cor]); + } +} + + +/*=======================================================================*/ + +static void WriteResultsPowDiv ( + smultin_Param *par, + smultin_Res *res, + DeltaIndex s, + long N, + double EColl, /* Approximate expected number of collisions */ + smultin_CellType DegreLib, /* Number of degrees of freedom */ + lebool Sparse, + double Mu /* Exact expected mean */ + ) +{ + long j; + printf ("-----------------------------------------------\n"); + printf ("Test Results for "); + + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) + printf ("Collisions\n\n"); + else { + printf ("Delta = %8.4f\n\n", par->ValDelta[s]); + if (N == 1) { + if (!Sparse) { +#ifdef USE_LONGLONG + printf ("Number of degrees of freedom : %4" PRIuLEAST64 + "\n", DegreLib); +#else + printf ("Number of degrees of freedom : %4.0f\n", + DegreLib); +#endif + + } + printf ("Value of the statistic :"); + gofw_Writep2 (res->sVal2[s][gofw_Mean], res->pVal2[s][gofw_Mean]); + + } else { + gofw_WriteActiveTests0 (N, res->sVal2[s], res->pVal2[s]); + printf ("For the sum of the N observations, we use\n"); + printf (" the Normal approximation:\n"); + printf ("Standardized empirical mean :"); + gofw_Writep2 (res->sVal2[s][gofw_Mean], res->pVal2[s][gofw_Mean]); + printf ("Standardized empirical correlation :"); + gofw_Writep2 (res->sVal2[s][gofw_Cor], res->pVal2[s][gofw_Cor]); + } + } + + if (swrite_Collectors) { + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) + statcoll_Write (res->Collector[s], 5, 14, 0, 0); + else + statcoll_Write (res->Collector[s], 5, 14, 4, 3); + } + + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) { + if (N > 1 && Mu < smultin_env.SeuilEColl) { + printf ("For the total number of collisions, we use\n" + " the Poisson approximation:\n"); + /* "Value of N * EColl : "); num_WriteD(N * EColl, 11, 2, 2); */ + printf ("Expected number of collisions = N*Mu : "); + num_WriteD (N * Mu, 11, 2, 2); + printf ("\nObserved number of collisions : %8ld\n", + (long) res->NbCollisions); + gofw_Writep1 (res->pColl); + printf ("\n"); + } + if (N == 1) { + /* printf ("Value of EColl : "); + num_WriteD(EColl, 11, 2, 2);*/ + printf ("Expected number of collisions = Mu : "); + num_WriteD (Mu, 11, 2, 2); + printf ("\nObserved number of collisions : %8ld\n", + (long) res->NbCollisions); + gofw_Writep1 (res->pColl); + } + printf ("-----------------------------\n"); + printf ("Total number of cells containing j balls\n\n"); + for (j = 0; j <= smultin_MAXB / 2; j++) { + printf (" j = %2ld", j); + +#ifdef USE_LONGLONG + printf (" : %16" PRIuLEAST64 "\n", + res->NbCells[j]); +#else + printf (" : %16.0f\n", res->NbCells[j]); +#endif + } + + if (par->bmax >= 0 && res->NbCells[0] <= EMPTYLIM && + res->EsEmpty <= EMPTYLIM) { + printf ("\n-----------------------------\n" + "Results for the number of empty cells\n\n" + "Expected number : "); + num_WriteD (res->EsEmpty, 19, 2, 2); + printf ("\nObserved number :"); +#ifdef USE_LONGLONG + printf (" %16" PRIuLEAST64 "\n", res->NbCells[0]); +#else + printf (" %16.0f\n", res->NbCells[0]); +#endif + gofw_Writep1 (res->pEmpty); + } + if (par->bmax >= 1) { + printf ("\n-----------------------------\n"); + printf ("Results for the number of cells containing at least" + " j balls\n\n"); + for (j = 2; j <= par->bmax; j++) { + printf (" j = %2ld\n", j); + printf ("Expected number : %11.2f\n", + (double) (res->EsCells[j])); + printf ("Observed number : %8.0f\n", + (double) (res->WbCells[j])); + gofw_Writep1 (res->pWb[j]); + } + } + } + printf ("\n"); +} + + +/*=======================================================================*/ + +static void UpdateCountHash ( + smultin_Res *res, + smultin_CellType Ind, + long Hache, + double UnSurHache, + long *CoMax, + lebool DimFlag /* TRUE for t-1 dimension, FALSE for t dim. */ + ) +/* + * We use hashing. A ball falls in cell Ind: update counters + * Speed is essential here. + */ +{ + long *Count; + smultin_CellType *Cell; + smultin_CellType *Nb; + long Decal, Pos, Tem; + + if (DimFlag == FALSE) { + Count = res->Count; /* Counters in t dimensions */ + Cell = res->Cell; /* Cell numbers in t dimensions */ + Nb = res->Nb; + } else { + Count = res->Count1; /* Counters in t - 1 dimensions */ + Cell = res->Cell1; /* Cell numbers in t - 1 dimensions */ + Nb = res->Nb1; + } + +#ifdef USE_LONGLONG + Pos = Ind % Hache; +#else + Tem = Ind * UnSurHache; + Pos = Ind - (double) Hache * Tem; +#endif + + Decal = HACHE2 + Pos % HACHE2; + + /* Insert in hashing table; if sign bit is 1, cell is empty. */ + for (;;) { +#ifdef USE_LONGLONG + if (Cell[Pos] & MASK64) { +#else + if (Cell[Pos] < 0.0) { +#endif + Cell[Pos] = Ind; + break; + } + if (Cell[Pos] == Ind) + break; + Pos = (Pos + Decal) % Hache; + } + + Nb[Count[Pos]] -= 1; + ++(Count[Pos]); + if (Count[Pos] > *CoMax) + ++(*CoMax); + if (DimFlag == FALSE) { + if (*CoMax > res->NbSize) { + int i; + res->NbSize *= 2; + res->Nb = util_Realloc (res->Nb, + (res->NbSize + 1) * sizeof (smultin_CellType)); + Nb = res->Nb; + for (i = res->NbSize / 2 + 1; i <= res->NbSize; i++) + Nb[i] = 0; + } + } else { + if (*CoMax > res->Nb1Size) { + int i; + res->Nb1Size *= 2; + res->Nb1 = util_Realloc (res->Nb1, + (res->Nb1Size + 1) * sizeof (smultin_CellType)); + Nb = res->Nb1; + for (i = res->Nb1Size / 2 + 1; i <= res->Nb1Size; i++) + Nb[i] = 0; + } + } + Nb[Count[Pos]] += 1; +} + + +/*=======================================================================*/ + +static void GenerAllPointsHash (unif01_Gen * gen, smultin_Param * par, + smultin_Res * res, long n, int r, long d, int t, long *pCoMax, + long Hache, double UnSurHache) +/* + * Generate all n points in hashing case + */ +{ + smultin_CellType Indice; /* Cell number */ + long i; + + for (i = 0; i <= Hache; i++) +#ifdef USE_LONGLONG + res->Cell[i] = MASK64; /* Empty cells */ +#else + res->Cell[i] = -1.0; /* Empty cells */ +#endif + *pCoMax = 0; + for (i = 1; i <= n; i++) { + Indice = par->GenerCell (gen, r, t, d); + UpdateCountHash (res, Indice, Hache, UnSurHache, pCoMax, FALSE); + } +} + + +/*=======================================================================*/ + +static void GenerAllPoints2 (unif01_Gen * gen, smultin_Param * par, + smultin_Res * res, long n, int r, long d, int t) +/* + * Generate all n points; no hashing + */ +{ + smultin_CellType Indice; /* Cell number */ + long i; + for (i = 1; i <= n; i++) { + Indice = par->GenerCell (gen, r, t, d); + ++res->Count[(long) Indice]; + } +} + + +/*=======================================================================*/ + +static void GenerAllPointsHashBits (unif01_Gen *gen, smultin_Res *res, + long n, int r, long L, int s, long *pCoMax, long Hache, + double UnSurHache) +/* + * Generate all n points of L bits each in hashing case + */ +{ + smultin_CellType Indice; /* Cell number */ + long i; + int j; + unsigned long Z; + const int t = s / L; /* Number of points in a U01 */ + const long Last = n % t; + const unsigned long MASK = num_TwoExp[L] - 1.0; + + for (i = 0; i <= Hache; i++) +#ifdef USE_LONGLONG + res->Cell[i] = MASK64; /* Empty cells */ +#else + res->Cell[i] = -1.0; /* Empty cells */ +#endif + *pCoMax = 0; + + for (i = 1; i <= n / t; i++) { + Z = unif01_StripB (gen, r, s); + for (j = 1; j <= t; j++) { + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache, UnSurHache, pCoMax, FALSE); + Z >>= L; + } + } + /* The last points */ + if (Last > 0) { + Z = unif01_StripB (gen, r, s); + /* The most significant bits make the points */ + for (j = 1; j <= t - Last; j++) + Z >>= L; + for (j = 1; j <= Last; j++) { + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache, UnSurHache, pCoMax, FALSE); + Z >>= L; + } + } +} + + +/*=======================================================================*/ + +static void GenerAllPoints2Bits (unif01_Gen * gen, smultin_Res * res, + long n, int r, long L, int s) +/* + * Generate all n points of L bits each; no hashing + */ +{ + long i; + int j; + unsigned long Z; + const int t = s / L; + const long Last = n % t; + const unsigned long MASK = num_TwoExp[L] - 1.0; + + for (i = 1; i <= n / t; i++) { + Z = unif01_StripB (gen, r, s); + for (j = 1; j <= t; j++) { + ++res->Count[Z & MASK]; + Z >>= L; + } + } + /* The last points */ + if (Last > 0) { + Z = unif01_StripB (gen, r, s); + /* The most significant bits make the points */ + for (j = 1; j <= t - Last; j++) + Z >>= L; + for (j = 1; j <= Last; j++) { + ++res->Count[Z & MASK]; + Z >>= L; + } + } +} + + +/*=======================================================================*/ + +static void Multinom (unif01_Gen * gen, smultin_Param * par, + smultin_Res * res, long N, long n, int r, long d, int t, lebool Sparse, + smultin_CellType k, char *TestName, chrono_Chrono * Timer, lebool BitFlag) +/* + * If BitFlag = TRUE, this procedure was called from smultin_MultinomialBits, + * otherwise from smultin_Multinomial. + * In the case BitFlag = TRUE, t stand for s, d for L. Otherwise, all + * parameters are as in smultin_Multinomial. + * + * Sparse: normal approximation for Delta != -1. + * Non sparse: chi-square approximation. + * Collisions test meaningfull only in Sparse case. + */ +{ + long Seq; /* Replication number */ + double NbExp; /* Expected number per cell */ + double EColl; /* Approx. expected number of collisions */ + long Hache; /* Hashing module */ + double UnSurHache; + double HacheLR; /* Dimension of hashing table */ + long i; + long CoMax; /* Maximum number of balls in any cell */ + double X0, X; /* Statistics */ + DeltaIndex j; /* Which power divergence case */ + double SumX2[smultin_MAX_DELTA]; + double SumX[smultin_MAX_DELTA]; + double X0Pre[smultin_MAX_DELTA]; /* For empirical mean and correlation */ + lebool localRes = FALSE; + + NbExp = (double) n / k; + EColl = (double) n / (2.0 * k) * n; + + if (par == NULL) + par = &smultin_ParamDefault; + if (res == NULL) { + localRes = TRUE; + res = smultin_CreateRes (par); + } else + /* Clean memory from a previous call */ + CleanPD (res); + + InitRes (par, res, N); + res->NbCellsTotal = k; + res->Over = FALSE; + InitPowDiv (par, res, N, Sparse, n, k); + + if (swrite_Basic) { + if (BitFlag) + /* Here t stand for s, d for L */ + WriteDataMNBits (gen, par, res, TestName, N, n, r, d, t, Sparse, k, + FALSE); + else + WriteDataPowDiv (gen, par, res, TestName, N, n, r, d, t, Sparse, k); + } + /* Initialize the hashing constants and tables */ + CalcTabFj (par, res, Sparse, (double) k, NbExp); + for (j = 0; j < par->NbDelta; j++) { + SumX[j] = 0.0; + SumX2[j] = 0.0; + X0Pre[j] = 0.0; + } + if (res->Hashing) + Hache = tables_HashPrime (n, smultin_env.HashLoad); + else + Hache = k; + HacheLR = Hache; + UnSurHache = 1.0 / HacheLR; + res->CountSize = Hache; + res->Count = util_Calloc ((size_t) Hache + 2, sizeof (long)); + res->Cell = util_Calloc ((size_t) Hache + 2, sizeof (smultin_CellType)); + res->NbSize = 8000; + res->Nb = util_Calloc ((size_t) res->NbSize + 2, sizeof (smultin_CellType)); + + /* Generate the points or balls */ + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i <= Hache; i++) + res->Count[i] = 0; + res->Nb[0] = k; + for (i = 1; i <= res->NbSize; i++) + res->Nb[i] = 0; + + if (BitFlag) { + /* Here, d stands for L, and t for s */ + if (res->Hashing) + GenerAllPointsHashBits (gen, res, n, r, d, t, &CoMax, Hache, + UnSurHache); + else + GenerAllPoints2Bits (gen, res, n, r, d, t); + } else { + if (res->Hashing) + GenerAllPointsHash (gen, par, res, n, r, d, t, &CoMax, Hache, + UnSurHache); + else + GenerAllPoints2 (gen, par, res, n, r, d, t); + } + + if (swrite_Counters) { + if (res->Hashing) +#ifdef USE_LONGLONG + tables_WriteTabULL (res->Nb, 0, CoMax, 5, 12, + "Observed numbers in res->Nb"); +#else + tables_WriteTabD (res->Nb, 0, CoMax, 5, 12, 0, 0, + "Observed numbers in res->Nb"); +#endif + else if (!Sparse) + tables_WriteTabL (res->Count, 0, res->CountSize - 1, 5, 10, + "Observed numbers in res->Count"); + } + + /* The points have been generated; now compute the statistics */ + /* if (par->bmax >= 0) */ + CalcNbCells (par, res, 0, Hache - 1, CoMax); + + for (j = 0; j < par->NbDelta; j++) { + if (res->Hashing) { + CalcPoDiEqHache (par, res, j, NbExp, res->Nb, CoMax, TRUE, &X); + } else if (res->flagTab) { + CalcPowDivEqual (par, res, j, NbExp, res->Count, + 0, (long) k - 1, TRUE, &X); + } else { + CalcPowDivEqual (par, res, j, NbExp, res->Count, + 0, (long) k - 1, FALSE, &X); + } + X0 = (X - res->Mu[j]) / res->Sigma[j]; + if (fabs (par->ValDelta[j] + 1.0) < EPS_LAM) { + res->Nb[0] = k + X - n; + res->NbCollisions += X; + statcoll_AddObs (res->Collector[j], X); + } else { + statcoll_AddObs (res->Collector[j], X0); + if (!Sparse) + X0 = (X0 - k + 1.0) / sqrt (2.0 * k - 2.0); + } + /* Now, X0 is standardized, with mean 0 and variance 1. */ + /* The following is to compute the mean and correlation. */ + SumX[j] += X0; + SumX2[j] += X0 * X0Pre[j]; + X0Pre[j] = X0; + } + } + + for (j = 0; j < par->NbDelta; j++) { + if ((Sparse == FALSE) && (fabs (par->ValDelta[j] + 1.0) < EPS_LAM)) + continue; + CalcResultsPowDiv (par, res, j, n, Sparse, k - 1, res->Mu[j], + SumX, SumX2); + } + + if (swrite_Basic) { + for (j = 0; j < par->NbDelta; j++) { + if ((Sparse == FALSE) && (fabs (par->ValDelta[j] + 1.0) < EPS_LAM)) { + util_Warning (TRUE, + "The collision test is meaningless when Sparse = FALSE"); + continue; + } + WriteResultsPowDiv (par, res, j, N, EColl, k - 1, Sparse, res->Mu[j]); + } + swrite_Final (gen, Timer); + } + if (localRes) + smultin_DeleteRes (res); +} + + +/*=======================================================================*/ + +void smultin_Multinomial (unif01_Gen * gen, smultin_Param * par, + smultin_Res * res, long N, long n, int r, long d, int t, lebool Sparse) +/* + * Sparse: normal approximation for Delta != -1. + * Non sparse: chi-square approximation. + * Collisions test meaningfull only in Sparse case. + */ +{ + smultin_CellType k; /* Number of cells */ + int i; + chrono_Chrono *Timer; + char *TestName = "smultin_Multinomial test"; + + Timer = chrono_Create (); + if (NULL == par) + par = &smultin_ParamDefault; + + if (par->GenerCell == smultin_GenerCellSerial || + par->GenerCell == smultin_GenerCellSerial2) { + util_Assert (d > 1, "smultin_Multinomial: d <= 1"); + util_Assert (t > 0, "smultin_Multinomial: t < 1"); + k = d; + for (i = 2; i <= t; i++) + k *= d; + + } else if (par->GenerCell == smultin_GenerCellPermut) { + util_Assert (t > 1, "Permutation... smultin_Multinomial: t < 2"); +#ifdef USE_LONGLONG + /* longlong has more bits of precision than double */ + util_Assert (t <= 20, "smultin_GenerCellPermut: t > 20"); + if (t == 20) { + k = num2_Factorial (18) * 19 * 20; + } else if (t == 19) { + k = num2_Factorial (18) * 19; + } else + k = num2_Factorial (t); +#else + util_Assert (t <= 18, "smultin_GenerCellPermut: t > 18"); + k = num2_Factorial (t); +#endif + + } else if (par->GenerCell == smultin_GenerCellMax) { + util_Assert (t > 1, "GenerCellMax... smultin_Multinomial: t < 2"); + k = t; + + } else + util_Error ("smultin_Multinomial: par->GenerCell not initialized"); + + util_Assert (k <= smultin_env.Maxk, + "smultin_Multinomial: k > smultin_env.Maxk"); + util_Assert (n > 4, "smultin_Multinomial: n <= 4"); +#ifndef USE_LONGLONG + util_Assert ((double) n / k > 1.0 / num_TwoExp[31], + "smultin_Multinomial: NbExp <= 1/2^31"); +#endif + Multinom (gen, par, res, N, n, r, d, t, Sparse, k, TestName, Timer, FALSE); + chrono_Delete (Timer); +} + + +/*=======================================================================*/ + +static void InitCollOver ( + smultin_Res *res, + long n, /* Number of balls */ + smultin_CellType k, /* Number of cells = d^t */ + long d, /* One-dim. segment */ + int t, /* dimension */ + double *Esperance, /* Expectation value */ + double *StandDev /* Standard deviation */ + ) +/* + * Initialize the collisionOver test + */ +{ + const double Epsilon = 1.0E-20; + const int MaxIter = 32; + long j; + double terme; + double v; + double COverDelta; + + res->NbCollisions = 0.0; + res->NbCells[0] = 0; + res->CollApprox = smultin_CollNotInit; + *Esperance = -1.0; + *StandDev = -1.0; + COverDelta = (double) (n - t + 1)/ k; + + if (COverDelta > smultin_env.SeuilCOverNorSup && + COverDelta < smultin_env.SeuilCOverDense) { + res->CollApprox = smultin_CollPoissonDense; + *Esperance = k * exp (-COverDelta); + + } else if (COverDelta >= smultin_env.SeuilCOverNorInf && + COverDelta <= smultin_env.SeuilCOverNorSup) { + res->CollApprox = smultin_CollNormal; + *Esperance = k * (COverDelta - 1.0 + exp (-COverDelta)); + terme = k * exp (-COverDelta) * (1.0 - (1.0 + COverDelta) * + exp (-COverDelta)); + /* The general formula given by Marsaglia is not very good; the above + formula used Rukhin's correction. The following values were obtained + by Marsaglia by simulation for the special cases: */ + if (n == 2097152 && k == 1048576) { + if ((d == 32) && (t == 4)) { + terme = 295.0 * 295.0; /* OQSO test */ + } + if ((d == 4) && (t == 10)) { + terme = 339.0 * 339.0; /* DNA test */ + } + } + if (terme < 0.0) { + util_Warning (TRUE, "***** InitCollOver ******* VARIANCE < 0 !!"); + *Esperance = -1.0; + *StandDev = -1.0; + } else + *StandDev = sqrt (terme); + + } else if (COverDelta < smultin_env.SeuilCOverSparse) { + res->CollApprox = smultin_CollPoissonSparse; + if (COverDelta < 0.1) { + /* Avoid loss of precision when COverDelta --> 0 */ + j = 3; + v = 2.0; + terme = COverDelta * COverDelta / 2.0; + *Esperance = terme; + while (fabs (terme / *Esperance) > Epsilon && j < MaxIter) { + v += 1.0; + terme = -terme * COverDelta / v; + *Esperance += terme; + ++j; + } + *Esperance *= k; + } else + *Esperance = k * (COverDelta - 1.0 + exp (-COverDelta)); + } +} + + +/*=======================================================================*/ + +static void WriteDataCollOver ( + smultin_Res *res, + long n, /* Number of balls */ + smultin_CellType k, /* Number of cells */ + double Esperance, /* Expectation value */ + double StandDev /* Standard deviation */ + ) +{ + double COverDelta = (double) (n) / k; + printf (" CollisionOver: density = n / k = "); + if (COverDelta >= 1.0) + num_WriteD (COverDelta, 10, 2, 2); + else { + printf (" 1 / "); + num_WriteD (1.0 / COverDelta, 10, 2, 1); + } + printf ("\n"); + if (res->CollApprox == smultin_CollPoissonDense) { + printf (" Expected number of empty cells = Mu = "); + num_WriteD (Esperance, 10, 2, 2); + printf ("\n"); + } else if (res->CollApprox == smultin_CollNormal) { + printf (" Expected number of collisions = "); + num_WriteD (Esperance, 10, 2, 2); + printf ("\n"); + printf (" Expected standard deviation = "); + num_WriteD (StandDev, 10, 2, 2); + } else if (res->CollApprox == smultin_CollPoissonSparse) { + printf (" Expected number of collisions = Mu = "); + num_WriteD (Esperance, 10, 2, 2); + } else { + printf (" NO TEST FOR THIS DENSITY n/k"); + } + printf ("\n\n"); +} + + +/*=======================================================================*/ + +static void CalcResCollOver ( + smultin_Res *res, + DeltaIndex s, + long N, /* Number of replications */ + double Esperance, /* Expectation value */ + double SumX, + double SumX2 + ) +/* + * Compute results for CollisionOver test + */ +{ + double pCollLeft; /* Left p-value of Collision test */ + double pCollRight; /* Right p-value of Collision test */ + double racN; + fmass_INFO W; + statcoll_Collector *Q = res->Collector[s]; + + res->Mu[s] = Esperance; + if (Esperance < 0.0) { + res->pVal2[s][gofw_KSP] = -1.0; + res->pVal2[s][gofw_Mean] = -1.0; + res->pColl = -1.0; + return; + } + + switch (res->CollApprox) { + + case smultin_CollNormal: + gofw_ActiveTests1 (Q->V, Q->NObs, wdist_Normal, (double *) NULL, + res->sVal2[s], res->pVal2[s]); + /* This line is necessary for the array pd from module tmultin */ + res->pColl = res->pVal2[s][gofw_Mean]; + if (N > 1) { + racN = sqrt ((double) N); + /* Calculate the mean, the correlation and their p-values */ + res->sVal2[s][gofw_Mean] = SumX / racN; + res->pVal2[s][gofw_Mean] = fbar_Normal1 (res->sVal2[s][gofw_Mean]); + res->sVal2[s][gofw_Cor] = racN * SumX2 / (N - 1); + res->pVal2[s][gofw_Cor] = fbar_Normal1 (res->sVal2[s][gofw_Cor]); + /* This line is necessary for the array pd from module tmultin */ + res->pColl = res->pVal2[s][gofw_KSP]; + } + break; + + case smultin_CollPoissonSparse: + /* The sum of N Poisson obeys also a Poisson law */ + W = fmass_CreatePoisson (N * Esperance); + pCollLeft = fdist_Poisson2 (W, (long) res->NbCollisions); + pCollRight = fbar_Poisson2 (W, (long) res->NbCollisions); + res->pColl = gofw_pDisc (pCollLeft, pCollRight); + fmass_DeletePoisson (W); + break; + + case smultin_CollPoissonDense: + /* The sum of N Poisson obeys also a Poisson law */ +#if 0 + W = fmass_CreatePoisson (N * Esperance); + pCollLeft = fdist_Poisson2 (W, res->NbCells[0]); + pCollRight = fbar_Poisson2 (W, res->NbCells[0]); + res->pColl = res->pEmpty = gofw_pDisc (pCollLeft, pCollRight); + fmass_DeletePoisson (W); +#endif + /* Since we can have very large values of res->NbCells[0]) (2^52), we + compute the Poisson pCollLeft, pCollRight by calling the Gamma + distribution, since our Poisson takes a long (31 bits) argument. */ + + if (res->NbCells[0] <= EMPTYLIM && N * Esperance <= EMPTYLIM) { + pCollLeft = fbar_Gamma (res->NbCells[0] + 1.0, 15, N * Esperance); + if ((res->NbCells[0] <= 0) || (res->NbCells[0] > res->NbCellsTotal)) + pCollRight = 1.0; + else + pCollRight = fdist_Gamma ((double) (res->NbCells[0]), 15, + N * Esperance); + res->pEmpty = res->pColl = gofw_pDisc (pCollLeft, pCollRight); + } + break; + + default: + util_Error ("res->CollApprox: Impossible case"); + } +} + + +/*=======================================================================*/ + +static void WriteResCollOver ( + smultin_Param *par, + smultin_Res *res, + DeltaIndex s, + long N, /* Number of replications */ + double EColl, + double Esperance + ) +/* + * Write results for CollisionOver test + */ +{ + int j; + printf ("\n-----------------------------------------------\n" + "Results of CollisionOver test:\n\n"); + if (Esperance < 0.0) { + util_Warning (TRUE, "TEST NON IMPLEMENTED FOR THESE PARAMETERS"); + return; + } + + switch (res->CollApprox) { + + case smultin_CollNormal: + printf ("NORMAL approximation:\n"); + if (N == 1) { + printf ("Value of the standardized statistic :"); + gofw_Writep2 (res->sVal2[s][gofw_Mean], res->pVal2[s][gofw_Mean]); + } else { + gofw_WriteActiveTests0 (N, res->sVal2[s], res->pVal2[s]); + printf ("Standardized empirical mean :"); + gofw_Writep2 (res->sVal2[s][gofw_Mean], res->pVal2[s][gofw_Mean]); + printf ("Standardized empirical correlation :"); + gofw_Writep2 (res->sVal2[s][gofw_Cor], res->pVal2[s][gofw_Cor]); + } + break; + + case smultin_CollPoissonSparse: + /* The sum of N Poisson random variables is also a Poisson r. v. */ + printf ("POISSON approximation :\n"); + /* "Value of N * EColl : "); num_WriteD (N * EColl, 11, 2, 2); */ + printf ("Expected number of collisions = N*Mu : "); + num_WriteD (N * Esperance, 11, 2, 2); + printf ("\nObserved number of collisions : %8ld\n", + (long) res->NbCollisions); + gofw_Writep1 (res->pColl); + break; + + case smultin_CollPoissonDense: + /* The sum of N Poisson random variables is also a Poisson r. v. */ + printf ("POISSON approximation :\n" + "Expected number of empty cells = N*Mu : "); + num_WriteD (N * Esperance, 18, 2, 2); +#ifdef USE_LONGLONG + printf ("\nObserved number of empty cells : %15" PRIuLEAST64 "\n", + res->NbCells[0]); +#else + printf ("\nObserved number of empty cells : %15.0f\n", + res->NbCells[0]); +#endif + gofw_Writep1 (res->pColl); + break; + + default:; + util_Error ("smultin_WriteResCollOver: IMPOSSIBLE CASE"); + break; + } + + + if (swrite_Collectors) + statcoll_Write (res->Collector[s], 5, 14, 2, 1); + + printf ("-----------------------------\n" + "Total number of cells containing j balls\n\n"); + for (j = 0; j <= smultin_MAXB / 2; j++) { + printf (" j = %2d", j); +#ifdef USE_LONGLONG + printf (" : %16" PRIuLEAST64 "\n", + res->NbCells[j]); +#else + printf (" : %16.0f\n", res->NbCells[j]); +#endif + } + printf ("\n"); +} + + +/*=======================================================================*/ + +static void OverDenseGenere ( + unif01_Gen *gen, + smultin_Res *res, + long n, /* Number of balls */ + int r, + long d, /* Division of 1-dim interval */ + int t, /* Dimension */ + long k, /* Number of urns in t dimensions */ + long k1 /* Number of urns in t - 1 dimensions */ + ) +/* + * Generate the n balls for smultin_MultinomialOver in the dense + * case, and fill the counters Count and Count1 + */ +{ + long element; + long Indice; + long j; + long Premier[MAX_DIM]; + long *Count = res->Count; /* Counters in t dimensions */ + long *Count1 = res->Count1; /* Counters in t - 1 dimensions */ + smultin_CellType *Nb = res->Nb; + + util_Assert (t < MAX_DIM, "OverDenseGenere: t > 64"); + for (j = 1; j <= res->NbSize; j++) + Nb[j] = 0; + Nb[0] = k; + for (j = 0; j <= k; j++) + Count[j] = 0; + for (j = 0; j <= k1; j++) + Count1[j] = 0; + + /* Generation of the first (t - 1) random numbers for the first tuple. */ + /* We shall keep them in the array Premier[] since the sequence of */ + /* generated numbers must be circular. They will be used to build the */ + /* last t - 1 tuples. Here, tuples are balls or points. */ + Indice = 0; + for (j = 1; j < t; j++) { + element = unif01_StripL (gen, r, d); + Premier[j] = element; + /* Shift tuple by s bits and insert new element */ + Indice = Indice * d + element; + } + + /* Generation of the first n - (t - 1) tuples */ + for (j = 1; j <= n - (t - 1); j++) { + Indice %= k1; + ++Count1[Indice]; + Indice = Indice * d + unif01_StripL (gen, r, d); + ++Count[Indice]; + } + + /* Generation of the last (t - 1) tuples. Use the elements of Premier */ + for (j = 1; j < t; j++) { + Indice %= k1; + ++Count1[Indice]; + Indice = Indice * d + Premier[j]; + ++Count[Indice]; + } +} + + +/*=======================================================================*/ + +static void OverHashGenere ( + unif01_Gen *gen, + smultin_Res *res, + long n, /* Number of balls */ + int r, + smultin_CellType dLR, /* Parameter d */ + int t, /* Dimension */ + long Hache1, /* Size of hashing table in t dimensions */ + long Hache11, /* Size of hashing table in t - 1 dimensions */ + smultin_CellType k, /* Number of urns in t dimensions */ + smultin_CellType k1, /* Number of urns in t - 1 dimensions */ + long *CoMax, /* Max number of balls in any cell in t dim. */ + long *CoMax1 /* Max number of balls in any cell in t-1 dim. */ + ) +/* + * Generate the n balls for smultin_MultinomialOver in the sparse + * case, and fill the counters. We use hashing. + */ +{ + long j, tem; + long d = dLR; + smultin_CellType Indice; + smultin_CellType element; + double UnSurHache1; + double UnSurHache11; + double UnSurk1; + smultin_CellType Premier[MAX_DIM]; + long *Count = res->Count; /* Counters in t dimensions */ + long *Count1 = res->Count1; /* Counters in t - 1 dimensions */ + smultin_CellType *Cell = res->Cell; /* Cell numbers in t dimensions */ + smultin_CellType *Cell1 = res->Cell1; /* Cell numbers in t - 1 dimensions */ + smultin_CellType *Nb = res->Nb; + smultin_CellType *Nb1 = res->Nb1; + + util_Assert (t < MAX_DIM, "OverHashGenere: t > 64"); + UnSurk1 = 1.0 / k1; + UnSurHache1 = 1.0 / Hache1; + UnSurHache11 = 1.0 / Hache11; + + for (j = 0; j <= Hache1; j++) { + Count[j] = 0; +#ifdef USE_LONGLONG + Cell[j] = MASK64; /* Empty cells */ +#else + Cell[j] = -1.0; /* Empty cells */ +#endif + } + for (j = 0; j <= Hache11; j++) { + Count1[j] = 0; +#ifdef USE_LONGLONG + Cell1[j] = MASK64; /* Empty cells */ +#else + Cell1[j] = -1.0; /* Empty cells */ +#endif + } + for (j = 1; j <= res->NbSize; j++) + Nb[j] = 0; + for (j = 1; j <= res->Nb1Size; j++) + Nb1[j] = 0; + Nb[0] = k; + Nb1[0] = k1; + *CoMax = 0; + *CoMax1 = 0; + + /* Generation of the first (t - 1) elements of the first tuple. We shall + keep them in array Premier[] since the sequence of generated numbers + must be circular. They will be used to obtain the last t - 1 tuples. + When we generate a random number, we keep s bits and they become the + least significant element of the tuple. We then shift the elements so + that the most significant element is dropped. The tuples are balls. */ + + /* Generate the first (t - 1) components of the first tuple (ball) */ + Indice = 0; + for (j = 1; j < t; j++) { + element = unif01_StripL (gen, r, d); + Premier[j] = element; + /* Shift tuple by s bits and insert new element */ + Indice = Indice * dLR + element; + } + + /* Generation of the first n - (t - 1) tuples */ + for (j = 1; j <= n - (t - 1); j++) { + /* Operation % k1 */ +#ifdef USE_LONGLONG + Indice %= k1; +#else + tem = Indice * UnSurk1; + Indice -= k1 * tem; +#endif + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Indice * dLR + unif01_StripL (gen, r, d); + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + } + + /* Generate the last (t - 1) tuples. We use the elements of Premier[] */ + for (j = 1; j < t; j++) { +#ifdef USE_LONGLONG + Indice %= k1; +#else + tem = Indice * UnSurk1; + Indice -= k1 * tem; +#endif + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Indice * dLR + Premier[j]; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + } +} + + +/*=======================================================================*/ + +static void OverDenseGenereBits ( + unif01_Gen *gen, + smultin_Res *res, + long n, /* Number of balls */ + int r, /* Drop first r bits of each random number */ + int L, /* Cells numbered with L bits */ + int s, /* Take s bits of each random number */ + long k, /* Number of urns in L dimensions */ + long k1 /* Number of urns in L - 1 dimensions */ + ) +/* + * Generate the n balls for smultin_MultinomialBitsOver in the dense + * case, and fill the counters Count and Count1 + */ +{ + int j; + long i; + unsigned long Premier[MAX_DIM]; + long *Count = res->Count; /* Counters in L dimensions */ + long *Count1 = res->Count1; /* Counters in L - 1 dimensions */ + smultin_CellType *Nb = res->Nb; + + util_Assert (L < MAX_DIM, "OverDenseGenereBits: L > 64"); + for (i = 1; i <= res->NbSize; i++) + Nb[i] = 0; + Nb[0] = k; + for (i = 0; i <= k; i++) + Count[i] = 0; + for (i = 0; i <= k1; i++) + Count1[i] = 0; + + if (L + s <= 32) { + const unsigned long MASK = num_TwoExp[L] - 1.0; + const unsigned long MASK1 = num_TwoExp[L - 1] - 1.0; + const int t = (L - 1) / s + 1; + unsigned long Z, Z0; + int b; + + /* Generation of the first t*s random bits for the first tuple. */ + /* We shall keep them in Premier since the sequence of generated */ + /* bits will be circular. */ + Z0 = 0; + for (j = 0; j < t; j++) { + Z0 <<= s; + Premier[j] = unif01_StripB (gen, r, s); + Z0 |= Premier[j]; + } + + /* Generation of other bits: main loop */ + for (i = 0; i < (n - t * s - 1) / s; i++) { + Z = Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + for (j = 0; j < s; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + + /* Generation of the last b random bits */ + Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + b = n % s; + if (b) + Z0 >>= (s - b); + else + b = s; + + Z = Z0; + for (j = 0; j < b; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + + /* Must do last few bits using circular overlap with Premier */ + for (i = 0; i < t; i++) { + Z = Z0 = (Z0 << s) | Premier[i]; + for (j = 0; j < s; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + return; + } + +#ifndef USE_LONGLONG + util_Error ("OverDenseGenereBits: L + s > 32"); +#else + + /* ---------------------------------------------------------- */ + if (L + s <= 64) { + const ulonglong MASK = num_TwoExp[L] - 1.0; + const ulonglong MASK1 = num_TwoExp[L - 1] - 1.0; + const int t = (L - 1) / s + 1; + ulonglong Z, Z0; + int b; + + /* Generation of the first t*s random bits */ + Z0 = 0; + for (j = 0; j < t; j++) { + Z0 <<= s; + Premier[j] = unif01_StripB (gen, r, s); + Z0 |= Premier[j]; + } + + /* Generation of the other random bits: main loop */ + for (i = 0; i < (n - t * s - 1) / s; i++) { + Z = Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + for (j = 0; j < s; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + + /* Generation of the last b random bits */ + Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + b = n % s; + if (b) + Z0 >>= s - b; + else + b = s; + + Z = Z0; + for (j = 0; j < b; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + + /* Must do last few bits using circular overlap with Premier */ + for (i = 0; i < t; i++) { + Z = Z0 = (Z0 << s) | Premier[i]; + for (j = 0; j < s; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + return; + + /* ---------------------------------------------------------- */ + } else { /* L + s > 64 */ + + const ulonglong MASK = num_TwoExp[L] - 1.0; + const ulonglong MASK1 = num_TwoExp[L - 1] - 1.0; + const int t = (L - 1) / s + 1; + const int q1 = 64 - L; + const int q2 = s % q1; + const int t2 = s / q1; + ulonglong Z, Z0; + unsigned long Bloc; + int k, b; + + /* Generation of the first t*s random bits */ + Z0 = 0; + for (j = 0; j < t; j++) { + Z0 <<= s; + Premier[j] = unif01_StripB (gen, r, s); + Z0 |= Premier[j]; + } + + /* Generation of bits: main loop */ + for (i = 0; i < (n - t * s - 1) / s; i++) { + Bloc = unif01_StripB (gen, r, s); + + /* Since L + s overflows a ulonglong, process a s-bit block in */ + /* t2 subblocks of q1 bits and one last subblock of q2 bits. */ + for (k = 1; k <= t2; k++) { + Z = Z0 = (Z0 << q1) | (Bloc >> (q2 + (t2 - k) * q1)); + for (j = 0; j < q1; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + Z = Z0 = (Z0 << q2) | Bloc; + for (j = 0; j < q2; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + + /* Generation of the last b random bits */ + Bloc = unif01_StripB (gen, r, s); + b = n % s; + if (0 == b) + b = s; + Bloc >>= s - b; + { + const int q3 = b % q1; + const int t3 = b / q1; + for (k = 1; k <= t3; k++) { + Z = Z0 = (Z0 << q1) | (Bloc >> (q3 + (t3 - k) * q1)); + for (j = 0; j < q1; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + Z = Z0 = (Z0 << q3) | Bloc; + for (j = 0; j < q3; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + + /* Must do last few bits using circular overlap with Premier */ + for (i = 0; i < t; i++) { + Bloc = Premier[i]; + for (k = 1; k <= t2; k++) { + Z = Z0 = (Z0 << q1) | (Bloc >> (q2 + (t2 - k) * q1)); + for (j = 0; j < q1; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + Z = Z0 = (Z0 << q2) | Bloc; + for (j = 0; j < q2; j++) { + ++Count1[Z & MASK1]; + ++Count[Z & MASK]; + Z >>= 1; + } + } + return; + } +#endif +} + + +/*=======================================================================*/ + +static void OverHashGenereBits ( + unif01_Gen *gen, + smultin_Res *res, + long n, /* Number of balls */ + int r, + int L, /* Dimension */ + int s, + long Hache1, /* Size of hashing table in t dimensions */ + long Hache11, /* Size of hashing table in t - 1 dimensions */ + smultin_CellType k, /* Number of urns in t dimensions */ + smultin_CellType k1, /* Number of urns in t - 1 dimensions */ + long *CoMax, /* Max number of balls in any cell in t dim. */ + long *CoMax1 /* Max number of balls in any cell in t-1 dim. */ + ) +/* + * Generate the n balls for smultin_MultinomialOver in the sparse + * case, and fill the counters. We use hashing. + */ +{ + int j; + long i; + unsigned long Premier[MAX_DIM]; + smultin_CellType Indice; + double UnSurHache1; + double UnSurHache11; + + util_Assert (L < MAX_DIM, "OverHashGenereBits: L > 64"); + UnSurHache1 = 1.0 / Hache1; + UnSurHache11 = 1.0 / Hache11; + + for (j = 0; j <= Hache1; j++) { + res->Count[j] = 0; +#ifdef USE_LONGLONG + res->Cell[j] = MASK64; /* Empty cells */ +#else + res->Cell[j] = -1.0; /* Empty cells */ +#endif + } + for (j = 0; j <= Hache11; j++) { + res->Count1[j] = 0; +#ifdef USE_LONGLONG + res->Cell1[j] = MASK64; /* Empty cells */ +#else + res->Cell1[j] = -1.0; /* Empty cells */ +#endif + } + for (j = 1; j <= res->NbSize; j++) + res->Nb[j] = 0; + for (j = 1; j <= res->Nb1Size; j++) + res->Nb1[j] = 0; + res->Nb[0] = k; + res->Nb1[0] = k1; + *CoMax = 0; + *CoMax1 = 0; + + if (L + s <= 32) { + const unsigned long MASK = num_TwoExp[L] - 1.0; + const unsigned long MASK1 = num_TwoExp[L - 1] - 1.0; + const int t = (L - 1) / s + 1; + unsigned long Z, Z0, b; + + /* Generation of the first t*s random bits for the first tuple. */ + /* We shall keep them in Premier since the sequence of */ + /* generated bits will be circular. */ + Z0 = 0; + for (j = 0; j < t; j++) { + Z0 <<= s; + Premier[j] = unif01_StripB (gen, r, s); + Z0 |= Premier[j]; + } + + /* Generation of all other bits: main loop */ + for (i = 0; i < (n - t * s - 1) / s; i++) { + Z = Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + for (j = 0; j < s; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + } + + /* Generation of the last b random bits */ + Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + b = n % s; + if (b) + Z0 >>= (s - b); + else + b = s; + + Z = Z0; + for (j = 0; j < (int) b; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + + /* Must do last few bits using circular overlap with Premier */ + for (i = 0; i < t; i++) { + Z = Z0 = (Z0 << s) | Premier[i]; + for (j = 0; j < s; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + } + return; + } + + /* ---------------------------------------------------------- */ +#ifndef USE_LONGLONG + util_Error ("OverHashGenereBits: L + s > 32"); +#else + + if (L + s <= 64) { + const ulonglong MASK = num_TwoExp[L] - 1.0; + const ulonglong MASK1 = num_TwoExp[L - 1] - 1.0; + const int t = (L - 1) / s + 1; + ulonglong Z, Z0, b; + + /* Generation of the first t*s random bits */ + Z0 = 0; + for (j = 0; j < t; j++) { + Z0 <<= s; + Premier[j] = unif01_StripB (gen, r, s); + Z0 |= Premier[j]; + } + + /* Generation of the other random bits: main loop */ + for (i = 0; i < (n - t * s - 1) / s; i++) { + Z = Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + for (j = 0; j < s; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + } + + /* Generation of the last b random bits */ + Z0 = (Z0 << s) | unif01_StripB (gen, r, s); + b = n % s; + if (b) + Z0 >>= (s - b); + else + b = s; + + Z = Z0; + for (j = 0; j < (int) b; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + + /* Must do last few bits using circular overlap with Premier */ + for (i = 0; i < t; i++) { + Z = Z0 = (Z0 << s) | Premier[i]; + for (j = 0; j < s; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + } + return; + + /* ---------------------------------------------------------- */ + } else { /* L + s > 64 */ + + const ulonglong MASK = num_TwoExp[L] - 1.0; + const ulonglong MASK1 = num_TwoExp[L - 1] - 1.0; + const int t = (L - 1) / s + 1; + const int q1 = 64 - L; + const int t2 = s / q1; + const int q2 = s % q1; + ulonglong Z, Z0; + unsigned long Bloc; + int k, b; + + /* Generation of the first t*s random bits */ + Z0 = 0; + for (j = 0; j < t; j++) { + Z0 <<= s; + Premier[j] = unif01_StripB (gen, r, s); + Z0 |= Premier[j]; + } + + /* Generation of the other random bits: main loop */ + for (i = 0; i < (n - t * s - 1) / s; i++) { + Bloc = unif01_StripB (gen, r, s); + + /* Since L + s overflows a ulonglong, process a s-bit block in */ + /* t2 subblocks of q1 bits and one last subblock of q2 bits. */ + for (k = 1; k <= t2; k++) { + Z = Z0 = (Z0 << q1) | (Bloc >> (q2 + (t2 - k) * q1)); + for (j = 0; j < q1; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, + CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, + FALSE); + Z >>= 1; + } + } + Z = Z0 = (Z0 << q2) | Bloc; + for (j = 0; j < q2; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + } + + /* Generation of the last b random bits */ + b = n % s; + Bloc = unif01_StripB (gen, r, s); + if (0 == b) + b = s; + Bloc >>= s - b; + + { + const int q3 = b % q1; + const int t3 = b / q1; + for (k = 1; k <= t3; k++) { + Z = Z0 = (Z0 << q1) | (Bloc >> (q3 + (t3 - k) * q1)); + for (j = 0; j < q1; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, + CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, + CoMax, FALSE); + Z >>= 1; + } + } + Z = Z0 = (Z0 << q3) | Bloc; + for (j = 0; j < q3; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + } + + /* Must do last few bits using circular overlap with Premier */ + for (i = 0; i < t; i++) { + Bloc = Premier[i]; + for (k = 1; k <= t2; k++) { + Z = Z0 = (Z0 << q1) | (Bloc >> (q2 + (t2 - k) * q1)); + for (j = 0; j < q1; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, + CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, + CoMax, FALSE); + Z >>= 1; + } + } + Z = Z0 = (Z0 << q2) | Bloc; + for (j = 0; j < q2; j++) { + Indice = Z & MASK1; + UpdateCountHash (res, Indice, Hache11, UnSurHache11, CoMax1, TRUE); + Indice = Z & MASK; + UpdateCountHash (res, Indice, Hache1, UnSurHache1, CoMax, FALSE); + Z >>= 1; + } + } + return; + } +#endif +} + + +/*=======================================================================*/ + +static void MultinomOver (unif01_Gen * gen, smultin_Param * par, + smultin_Res * res, long N, long n, int r, long d, int t, lebool Sparse, + smultin_CellType k, smultin_CellType k1, char *TestName, + chrono_Chrono *Timer, lebool BitFlag) +{ + long Seq; + smultin_CellType dLR = d; + double nLR = n; + double NbExp; /* Expected number per cell in t dimensions */ + double NbExp1; /* Expected number per cell in t - 1 dim. */ + double EColl; /* Approx. expected number of collisions */ + DeltaIndex s; + long Hache1, Hache11; /* Hashing modules */ + long CoMax1; /* Max number of balls in any cell: t-1 dim. */ + long CoMax; /* Max number of balls in any cell: t dim. */ + double X, X0, X1; /* Statistics */ + double Esperance; /* Expected value of number of collisions */ + double StandDev; /* Standard deviation of number of collisions */ + double V[1]; /* Number of degrees of freedom for ChiSquare */ + double SumX2[smultin_MAX_DELTA]; + double SumX[smultin_MAX_DELTA]; + double X0Pre[smultin_MAX_DELTA]; + lebool localRes = FALSE; + + NbExp = (double) n / k; + NbExp1 = (double) n / k1; + EColl = nLR * nLR / (2.0 * k); + if (par == NULL) + par = &smultin_ParamDefault; + if (res == NULL) { + localRes = TRUE; + res = smultin_CreateRes (par); + } else + /* Clean memory from a previous call */ + CleanPD (res); + + res->NbCellsTotal = k; + res->Over = TRUE; + InitRes (par, res, N); + InitPowDiv (par, res, N, Sparse, n, k - k1); + if (swrite_Basic) { + if (BitFlag) + /* Here t stand for s, d for L */ + WriteDataMNBits (gen, par, res, TestName, N, n, r, d, t, Sparse, k, + TRUE); + else + WriteDataPowDiv (gen, par, res, TestName, N, n, r, d, t, Sparse, k); + } + for (s = 0; s < par->NbDelta; s++) { + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) { + /* CollisionOver test */ + InitCollOver (res, n, k, d, t, &Esperance, &StandDev); + if (swrite_Basic) + WriteDataCollOver (res, n, k, Esperance, StandDev); + } + } + for (s = 0; s < par->NbDelta; s++) { + SumX[s] = 0.0; + SumX2[s] = 0.0; + X0Pre[s] = 0.0; + } + CalcTabFj (par, res, Sparse, (double) k, NbExp); + if (res->Hashing) { + Hache1 = tables_HashPrime (n, smultin_env.HashLoad); + if ((unsigned) Hache1 > k1) + Hache11 = k1; + else + Hache11 = Hache1; + res->Cell = util_Calloc ((size_t) Hache1 + 2, sizeof (smultin_CellType)); + res->Cell1 = util_Calloc ((size_t) Hache11 + 2, + sizeof (smultin_CellType)); + } else { + Hache1 = k; + Hache11 = k1; + } + res->CountSize = Hache1; + res->Count1Size = Hache11; + res->Count = util_Calloc ((size_t) Hache1 + 2, sizeof (long)); + res->Count1 = util_Calloc ((size_t) Hache11 + 2, sizeof (long)); + res->NbSize = res->Nb1Size = 8000; + res->Nb = util_Calloc ((size_t) res->NbSize + 2, sizeof (smultin_CellType)); + res->Nb1 = util_Calloc ((size_t) res->Nb1Size + 2, + sizeof (smultin_CellType)); + + /* Generate the points or balls */ + for (Seq = 1; Seq <= N; Seq++) { + if (BitFlag) { + /* Here, d stands for L, and t for s */ + if (res->Hashing) { + OverHashGenereBits (gen, res, n, r, d, t, Hache1, Hache11, k, k1, + &CoMax, &CoMax1); + } else { + OverDenseGenereBits (gen, res, n, r, d, t, Hache1, Hache11); + } + } else { + if (res->Hashing) { + OverHashGenere (gen, res, n, r, dLR, t, Hache1, Hache11, k, k1, + &CoMax, &CoMax1); + } else { + OverDenseGenere (gen, res, n, r, d, t, Hache1, Hache11); + } + } + + if (swrite_Counters) { + if (res->Hashing) { +#ifdef USE_LONGLONG + tables_WriteTabULL (res->Nb, 0, CoMax, 5, 12, + "Observed numbers in res->Nb"); + tables_WriteTabULL (res->Nb1, 0, CoMax1, 5, 12, + "Observed numbers in res->Nb1"); +#else + tables_WriteTabD (res->Nb, 0, CoMax, 5, 12, 0, 0, + "Observed numbers in res->Nb"); + tables_WriteTabD (res->Nb1, 0, CoMax1, 5, 12, 0, 0, + "Observed numbers in res->Nb1"); +#endif + } else if (!Sparse) { + tables_WriteTabL (res->Count, 0, res->CountSize - 1, 5, + 10, "Observed numbers in res->Count"); + tables_WriteTabL (res->Count1, 0, res->Count1Size - 1, 5, + 10, "Observed numbers in res->Count1"); + } + } + + /* The balls have been generated; now compute the statistics */ + for (s = 0; s < par->NbDelta; s++) { + /* Compute the stat. X */ + if (res->Hashing) { + CalcPoDiEqHache (par, res, s, NbExp, res->Nb, CoMax, TRUE, &X); + + } else if (res->flagTab) { + CalcPowDivEqual (par, res, s, NbExp, + res->Count, 0, Hache1 - 1, TRUE, &X); + + } else { + CalcPowDivEqual (par, res, s, NbExp, + res->Count, 0, Hache1 - 1, FALSE, &X); + } + + if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM && Esperance >= 0.0) { + /* CollisionOver test */ + switch ((unsigned) res->CollApprox) { + case smultin_CollPoissonDense: /* Number of empty cells */ + X0 = k + X - nLR; + break; + case smultin_CollPoissonSparse: /* Number of collisions */ + X0 = X; + break; + case smultin_CollNormal: /* Standardized number of collisions */ + X0 = (X - Esperance) / StandDev; + break; + default: + util_Error + ("smultin_MultinomialOver: Computing X0 with CollNotInit"); + break; + } + res->NbCollisions += X; + res->Nb[0] = k + X - nLR; + statcoll_AddObs (res->Collector[s], X0); + CalcNbCells (par, res, 0, Hache1 - 1, CoMax); + + } else { + /* In the case delta = 1, X-X1 is approx. a chi-square with + k - k1 degrees of freedom, or a normal in the sparse case */ + /* Compute X1 */ + if (res->Hashing) { + CalcPoDiEqHache (par, res, s, NbExp1, res->Nb1, + CoMax1, FALSE, &X1); + } else { + CalcPowDivEqual (par, res, s, NbExp1, + res->Count1, 0, Hache11 - 1, FALSE, &X1); + } + X0 = (X - X1 - res->Mu[s]) / res->Sigma[s]; + statcoll_AddObs (res->Collector[s], X0); + if (!Sparse) + X0 = (X0 - k + k1) / sqrt (2.0 * (k - k1)); + /* Now, X0 is standardized, with mean 0 and variance 1. */ + } + + /* The following is to compute the mean and correlation */ + SumX[s] += X0; + SumX2[s] += X0 * X0Pre[s]; + X0Pre[s] = X0; + } + } + + /* For now, we understand only the cases delta = 1 and Collision */ + for (s = 0; s < par->NbDelta; s++) { + statcoll_Collector *Q = res->Collector[s]; + double racN = sqrt ((double) N); + + if (par->ValDelta[s] > -1.0 + EPS_LAM) { + /* Not Collisions test */ + if (Sparse) { + util_Warning (fabs (par->ValDelta[s] - 1.0) > EPS_LAM, + "The theoretical distribution for the overlapping case\nis known only for Delta = 1"); + gofw_ActiveTests1 (Q->V, Q->NObs, wdist_Normal, + (double *) NULL, res->sVal2[s], res->pVal2[s]); + } else { + V[0] = k - k1; + gofw_ActiveTests1 (Q->V, Q->NObs, wdist_ChiSquare, V, + res->sVal2[s], res->pVal2[s]); + } + /* Compute the mean, the correlation, and their p-values */ + if (Q->NObs > 1) { + res->sVal2[s][gofw_Mean] = SumX[s] / racN; + res->pVal2[s][gofw_Mean] = fbar_Normal1 (res->sVal2[s][gofw_Mean]); + res->sVal2[s][gofw_Cor] = racN * SumX2[s] / (N - 1); + res->pVal2[s][gofw_Cor] = fbar_Normal1 (res->sVal2[s][gofw_Cor]); + } + if (swrite_Basic) { + WriteResultsPowDiv (par, res, s, N, EColl, k - k1, Sparse, + res->Mu[s]); + } + + } else if (fabs (par->ValDelta[s] + 1.0) < EPS_LAM) { + /* Collisions test */ + CalcResCollOver (res, s, N, Esperance, SumX[s], SumX2[s]); + if (swrite_Basic) { + WriteResCollOver (par, res, s, N, EColl, Esperance); + } + } + } + if (swrite_Basic) + swrite_Final (gen, Timer); + + if (localRes) + smultin_DeleteRes (res); +} + + +/*=======================================================================*/ + +void smultin_MultinomialOver (unif01_Gen * gen, smultin_Param * par, + smultin_Res * res, long N, long n, int r, long d, int t, lebool Sparse) +{ + int i; + smultin_CellType k1; /* Number of urns in t - 1 dimensions */ + smultin_CellType k; /* Number of urns in t dimensions */ + double NbExp; /* Expected number per cell in t dimensions */ + chrono_Chrono *Timer; + char *TestName = "smultin_MultinomialOver test"; + + Timer = chrono_Create (); + if (NULL == par) + par = &smultin_ParamDefault; + k1 = 1; + for (i = 1; i < t; i++) + k1 *= d; + k = k1 * d; + NbExp = (double) n / k; + util_Assert (n > 4, "smultin_MultinomialOver: n <= 4"); + util_Assert (t > 1, "smultin_MultinomialOver: t < 2"); + if (par->GenerCell != smultin_GenerCellPermut) + util_Assert (d > 1, "smultin_MultinomialOver: d <= 1"); + util_Assert (k <= smultin_env.Maxk, + "smultin_MultinomialOver: d^t > Maxk"); +#ifndef USE_LONGLONG + util_Assert (NbExp > 1.0 / num_TwoExp[31], + "smultin_MultinomialOver: NbExp <= 1/2^31"); +#endif + MultinomOver (gen, par, res, N, n, r, d, t, Sparse, k, k1, + TestName, Timer, FALSE); + chrono_Delete (Timer); +} + + +/*=======================================================================*/ + +void smultin_MultinomialBits (unif01_Gen *gen, smultin_Param *par, + smultin_Res *res, long N, long n, int r, int s, int L, lebool Sparse) +{ +/* + * Sparse: normal approximation for Delta != -1. + * Non sparse: chi-square approximation. + * Collisions test meaningfull only in Sparse case. + */ + smultin_CellType k; /* Number of cells */ + chrono_Chrono *Timer; + char *TestName = "smultin_MultinomialBits test"; + + Timer = chrono_Create (); + k = num_TwoExp[L]; + if (NULL == par) + par = &smultin_ParamDefault; + if (L >= s) { + long d = num_TwoExp[s]; + int t = L / s; + if (swrite_Basic) { + printf + ("***********************************************************\n" + "Test smultin_MultinomialBits calling smultin_Multinomial\n\n"); + printf (" N = %2ld, n = %2ld, r = %1d", N, n, r); + printf (", s = %2d, L = %2d, Sparse = ", s, L); + util_WriteBool (Sparse, 5); + printf ("\n\n Number of bits = n*L = %.0f\n\n\n", (double) n * L); + } + if ((t == 1) && (s > 30)) { + util_Warning (TRUE, "smultin_MultinomialBits: L = s and s > 30"); + return; + } + util_Assert (L % s == 0, "smultin_MultinomialBits: L Mod s > 0"); + par->GenerCell = smultin_GenerCellSerial; + smultin_Multinomial (gen, par, res, N, n, r, d, t, Sparse); + return; + } + + util_Assert (s % L == 0, "smultin_MultinomialBits: s Mod L > 0"); + util_Assert (k <= smultin_env.Maxk, + "smultin_MultinomialBits: k > Maxk"); + util_Assert (n > 4, "smultin_MultinomialBits: n <= 4"); +#ifndef USE_LONGLONG + util_Assert ((double) n / k > 1.0 / num_TwoExp[31], + "smultin_MultinomialBits: NbExp <= 1/2^31"); +#endif + Multinom (gen, par, res, N, n, r, L, s, Sparse, k, TestName, Timer, TRUE); + chrono_Delete (Timer); +} + + +/*=======================================================================*/ + +void smultin_MultinomialBitsOver (unif01_Gen * gen, smultin_Param * par, + smultin_Res * res, long N, long n, int r, int s, int L, lebool Sparse) +{ + smultin_CellType k1; /* Number of urns in L - 1 dimensions */ + smultin_CellType k; /* Number of urns in L dimensions */ + double NbExp; /* Expected number per cell in L dimensions */ + chrono_Chrono *Timer; + char *TestName = "smultin_MultinomialBitsOver test"; + + Timer = chrono_Create (); + if (NULL == par) + par = &smultin_ParamDefault; + util_Assert (L <= 64, "smultin_MultinomialBitsOver: L > 64"); + k1 = num_TwoExp[L - 1]; + k = num_TwoExp[L]; + NbExp = (double) n / k; + util_Assert (n > 4, "smultin_MultinomialBitsOver: n <= 4"); + util_Assert (L > 1, "smultin_MultinomialBitsOver: L < 2"); + util_Assert (s > 0, "smultin_MultinomialBitsOver: s < 1"); + util_Assert (k <= smultin_env.Maxk, + "smultin_MultinomialBitsOver: L too large"); +#ifndef USE_LONGLONG + util_Assert (NbExp > 1.0 / num_TwoExp[31], + "smultin_MultinomialBitsOver: NbExp <= 1/2^31"); +#endif + MultinomOver (gen, par, res, N, n, r, L, s, Sparse, k, k1, + TestName, Timer, TRUE); + + chrono_Delete (Timer); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/smultin.tex b/TESTU01/TestU01-1.2.3/testu01/smultin.tex new file mode 100644 index 0000000..23dc6fe --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/smultin.tex @@ -0,0 +1,1282 @@ +\defmodule {smultin} + +Testing the uniformity and independence of a RNG amounts to testing +that $t$-dimensional vectors $(u_i,\dots,u_{i+t-1})$ of successive +output values of the RNG behave like random points uniformly distributed +over the unit hypercube $[0,1]^t$, for all $t$. +A natural approach for testing this is to generate such vectors and measure +(in some way) the uniformity of their distribution in the unit hypercube. + +%%%%%%%%%%%%% +\paragraph*{A class of tests based on the multinomial distribution.} \ + +One simple way of measuring this uniformity is as follows.\index{multinomial} +For some integer $d$, partition the interval $[0,1)$ into $d$ equal +segments. This determines a partition of $[0,1)^t$ into $k = d^t$ +small hypercubes (or cubic {\em cells\/}) of equal sizes. +Then, generate $n$ random points in the unit hypercube, using $nt$ +output values from the generator, and let $X_j$ be the number of +points falling into cell $j$, for $0\le j\le k-1$. +Under $\cH_0$, the vector $(X_0,\dots,X_{k-1})$ has the +{\em multinomial distribution\/} with parameters $(n,1/k,\dots,1/k)$. +The next step is to measure how well the observed vector +$(X_0,\dots,X_{k-1})$ ``agrees'' with this multinomial distribution. +For example, if $n \gg k$, the $X_j$'s should not be too far from +their expected values $E[X_j] = \lambda = n/k$. +The most popular test statistic in this context is Pearson's +chi-square \cite{rKNU98a,sLAW91a,tREA88a}: +\eq + X^2 = \sum_{j=0}^{k-1} {(X_j - \lambda)^2 \over \lambda} + = -n + {1\over\lambda} \sum_{j=0}^{k-1} X_j^2, + \label {eq:X2} +\endeq +Its distribution under $\cH_0$ is approximately +chi-square with $k-1$ degrees of freedom, if $\lambda$ is large enough. +Other test statistics can be used as well, and some of +them turn out to be better than the chi-square for detecting +deficiencies in typical RNGs. + +The present module implements several such tests for the +multinomial distribution, and for a variant of it where the points +are formed by overlapping vectors. +These tests are described and studied by +L'Ecuyer, Simard, and Wegenkittl \cite{rLEC02c}. +The test statistic has the general form +\eq + Y = \sum_{j=0}^{k-1} f_{n,k} (X_j) \label{eq:Y} +\endeq +where $f_{n,k}$ is a real-valued function which may depend on $n$ and $k$. +A subclass is the {\em power divergence\/} statistic\index{power divergence} +\eq + D_\delta = \sum_{j=0}^{k-1} {\frac2{\delta(1+\delta)}} X_j + \left[\left(\frac{X_j}{\lambda}\right)^\delta -1\right], \label{eq:Ddelta} +\endeq +studied in \cite{tREA88a}, +where $\delta > -1$ is a real-valued parameter and +$\delta=0$ means the limit as $\delta\to 0$. +One has $D_1 = X^2$ as a special case. + +Other choices of $f_{n,k}$ are given in Table~\ref{tab:choosef}. +In each case, $Y$ is a measure of clustering: It decreases +when the points are more evenly distributed between the cells. +The loglikelihood\index{loglikelihood} statistic $G^2$ is also a + special case of $D_\delta$ +for $\delta\to 0$ \cite{tREA88a}, and it is related to $H$ via the relation +$H = \log_2(k) - {G^2 / (2n \ln 2)}$. +The statistic $N_b$ counts the number of cells that +contain exactly $b$ points (for $b\ge 0$), $W_b$ is the number of cells that +contain at least $b$ points (for $b\ge 1$), %% We need W_1 2 lines below. +and $C$ is the number of collisions\index{collisions} +(i.e., the number of times a point falls in +a cell that already has one or more points in it). +These statistics are related by $N_0 = k - W_1 = k - n + C$, +$W_b = N_b + \cdots + N_n$, and $C = W_2 + \cdots + W_n$. + + +\begin{table}[htb] +\caption {Some choices of $f_{n,k}$ and the corresponding statistics $Y$.} +\label {tab:choosef} +\smallskip +\centering +\renewcommand {\arraystretch}{1.2} +\begin{tabular}{|rcc|} +\hline + $Y$ & $f_{n,k}(x)$ & name \\ +\hline + $D_\delta$ & $2x[(x/\lambda)^\delta-1]/(\delta(1+\delta)) $ + & power divergence \rule{0pt}{16pt}\\ + $X^2$ & $(x-\lambda)^2/\lambda$ & Pearson \\ + $G^2$ & $2x\ln(x/\lambda)$ & loglikelihood \\ + $-H$ & $(x/n)\log_2(x/n)$ & negative entropy \\ + $N_b$ & $I[x = b]$ & number of cells with exactly $b$ points \\ + $W_b$ & $I[x \ge b]$ & number of cells with at least $b$ points \\ + $N_0$ & $I[x = 0]$ & number of empty cells \\ + $C$ & $(x-1)\,I[x>1]$ & number of collisions \\ +\hline +\end{tabular} +\end{table} + + +%%%%%%%%%%%%% +\paragraph*{How to generate the cell numbers.} \ + +The\index{entropy}\index{Pearson} + standard way of generating the cell numbers is as described earlier, +by generating one fresh uniform for each coordinate of each point. +That is, $nt$ random numbers $u_0,\dots,u_{nt-1}$ are generated and +the $n$ points are $(u_{ti},\dots,u_{ti+t-1})$, for $i=0,\dots,n-1$. +This is the {\em non-overlapping serial\/} approach used in the +classical {\em serial test\/} \cite{rKNU98a}. +It is the method used by default by the function\index{serial} +{\tt smultin\_Multinomial}. +Here, the points are independent and $(X_0,\dots,X_{k-1})$ has the +{\em multinomial distribution\/} as mentioned earlier. + +Another way of producing the cell numbers is as follows: +Generate $nt$ random numbers $u_0,\dots,u_{nt-1}$. +For $i=0,\dots,n-1$, let $v_{ti} = (u_{ti},\dots,u_{ti+t-1})$, +and find which of the $t!$ {\em permutations\/} of $t$ objects would +reorder the coordinates of $v_{ti}$ in increasing order.\index{permutations} +Let $k = t!$ number the $t!$ possible permutations from 0 to $k-1$, +and let $X_j$ be the number of vectors $v_{ti}$ that are reordered +by permutation $j$, for $j = 0,\dots,k-1$. +Here, since the permutations are independent, $(X_0,\dots,X_{k-1})$ +has the multinomial distribution with parameters $(n,1/k,\dots,1/k)$. + +Yet another method is to examine which coordinate in each $v_{ti}$ has +the {\em largest value\/}, and let $X_j$ be the number of vectors $v_{ti}$ +whose largest coordinate is the $j$th. +In this case, $k=t$ and $(X_0,\dots,X_{k-1})$ is again +multinomially distributed with parameters $(n,1/k,\dots,1/k)$. +\hpierre {This is what is implemented in {\tt smultin\_GenerCellMax}, + with $t$ replaced by $td$. } + +To change the method for generating the cells numbers +in {\tt smultin\_Multinomial},\index{cells generation} +it suffices to set the environment variable {\tt smultin\_GenerCell} +to the appropriate function ({\tt smultin\_GenerCellSerial}, +{\tt smultin\_GenerCellPermut}, etc.) or to +a user-defined function having the same types of parameters and +that generates cell numbers uniformly and independently. + +It is also possible and often advantageous to generate cell numbers +that are {\em dependent}. This is what happens in the +{\em overlapping serial\/} approach, where only $n$ uniforms +$u_0,\dots,u_{n-1}$ are generated; they are placed in a circle +and each one starts a new vector. The $n$ points are thus +defined as $v_0 = (u_0,\dots,u_{t-1})$, $v_1=(u_1,\dots,u_t)$, \dots, + $v_{n-t+1} = (u_{n-t+1},\dots,u_n)$, + $v_{n-t+2} = (u_{n-t+2},\dots,u_n,u_0)$, \dots, + $v_{n-1} = (u_{n-1},u_n,u_0,\dots,u_{t-3})$, + $v_n = (u_n,u_0,\dots,u_{t-2})$. +These points are dependent, because their coordinates overlap, +so $(X_0,\dots,X_{k-1})$ is no longer multinomially distributed in +this case. The function {\tt smultin\_MultinomialOver} uses this approach. + +Another set of methods generate the cell numbers from a long string +of ``random'' bits, which are produced $s$ bits at a time by the RNG. +Let $k = 2^L$ be the number of cells, for some integer $L$. +Each cell number is generated by taking $L$ successive bits from +the string, either with or without overlap. +The {\em non-overlapping\/} version requires $nL$ bits +($\lceil nL/s\rceil$ calls to the generator) whereas the +{\em overlapping\/} one requires $n$ bits ($\lceil n/s\rceil$ calls). +The overlapping version operates similarly as the overlapping serial +approach described earlier, except that the uniforms $u_j$ are replaced +by bits. +The functions {\tt smultin\_MultinomialBits} and +{\tt smultin\_MultinomialBitsOver} implement these tests. +% They use {\tt smultin\_GenerCellSerialBits}. +(See also the tests +{\tt sentrop\_EntropyDisc} and {\tt sentrop\_EntropyDiscOver}.) + +%%%%%%%%%%%%%%%%%% +\paragraph*{Distribution of $Y$ for the non-overlapping case.} \ + +We now examine the distribution of the different statistics $Y$ in +Table~\ref{tab:choosef}, under $\cH_0$, assuming that $(X_0,\dots,X_{k-1})$ +has the multinomial distribution. +Exact expressions for $E[Y]$ and Var$[Y]$ for this situation are given +in Eqs.\ (2.1) and (2.2) of \cite{rLEC02c}. +In fact, one has $E[Y] = k\mu$ where $\mu = E[f_{n,k}(X_j)]$. +These expressions for the mean and variance are cheap to compute +when $\lambda = n/k$ is small +but become very expensive to compute when $n$ and $\lambda$ are large. +For the case where $\lambda \gg 1$, approximations with $o(1/n)$ +error are provided in \cite{tREA88a}, page 65. + +The following propositions, taken from \cite{rLEC02c}, provide +approximations for the distribution of $Y$ under various conditions. +Define $\sigma^2_N = \Var[Y]$, $\sigma^2_C = \Var[Y]/(2(k-1))$, +\[ + Y^{(N)} = {Y - k\mu \over \sigma_N}, +\] +and +\[ + Y^{(C)} = {Y - k\mu + (k-1)\sigma_C\over\sigma_C}. +\] +Observe that $Y^{(N)}$ has mean 0 and variance 1 (the same as a +standard normal) and that $Y^{(C)}$ has mean $k-1$ and variance $2(k-1)$ +(the same as the chi-square random variable with $k-1$ degrees of freedom). +Let $\To$ denote convergence in distribution, +$N(0,1)$ the standard normal distribution, and $\chi^2(k-1)$ +the chi-square distribution with $k-1$ degrees of freedom. + +\begin {proposition} +\label {prop1} +% \vspace {-8pt} +For $\delta > -1$, under $\cH_0$. +\begin {itemize} +\item[{\rm (i)}] +{\rm [Dense case]} \ +If $k$ is fixed and $n\to\infty$, $D_{\delta}^{(C)} \To \chi^2(k-1)$. +% +\item[{\rm (ii)}] +{\rm [Sparse case]} \ +If $k\to\infty$, $n\to\infty$, and $n/k \to\lambda_0$ where +$0<\lambda_0<\infty$, then $D_{\delta}^{(N)} \To N(0,1)$. +\end {itemize} +\end {proposition} + +The counting variables $N_b$, $W_b$, and $C$ do not obey the +preceding proposition. +For example if $k$ is fixed and $n\to\infty$, eventually $N_b$ becomes +0 and $W_b$ becomes equal to $k$. +If both $k$ and $n$ are large, then each $X_j$ is approximately +Poisson with mean $\lambda$, +so $P[X_j = b] \approx e^{-\lambda} \lambda^b/b!$ for $b\ge 0$. +If $k$ is large and $P[X_j=b]$ is small, $N_b$ is thus approximately +Poisson with mean +\eq + E[N_b] = {n^b e^{-\lambda} \over k^{b-1} b!}. + \label{eq:ENb} +\endeq +for $b\ge 0$. The following proposition is also taken from \cite{rLEC02c}. + +\begin {proposition} +\label {prop2} +Under $\cH_0$, suppose $k\to\infty$ and $n\to\infty$, +and let $\lambda_\infty$, +$\gamma_0$, and $\lambda_0$ denote positive constants. +\begin {itemize} +\item[{\rm (i)}] +{\rm [Very sparse case]} \ +If $b \ge 2$ and $n^b / (k^{b-1} b!) \to \lambda_\infty$, then +$W_b \To N_b \To$ {\rm Poisson}$(\lambda_\infty)$. +For $b=2$, one also has $C \To N_2$. +% +\item[{\rm (ii)}] +For $b=0$, if $n/k - \ln(k) \to \gamma_0$, then +$N_0 \To$ {\rm Poisson}$(e^{-\gamma_0})$. +% +\item[{\rm (iii)}] +{\rm [Sparse case]} \ +If $k\to\infty$ and $n/k \to\lambda_0 > 0$, +for $Y = N_b$, $W_b$, or $C$, one has $Y^{(N)} \To N(0,1)$. +\end {itemize} +\end {proposition} + + The exact distributions of $C$ and $N_0$ under $\cH_0$ + (one has $P(C = c) = P(N_0 = k-n+c)$), for the multinomial setup, + can be found in Knuth's book + (see \cite {rKNU98a}, page 71), where an algorithm is also given to + compute all the non-negligible exact probabilities in time $O(n\log n)$. + Computing the exact distribution is very slow + when $n$ is large. + The probability of having exactly $c$ collisions is given by + \eq + P[C = c] = \frac{k (k-1) \ldots (k-n+c+1)}{k^n} + \left\{{n \atop n-c }\right\} \eqlabel{fmass-collis} + \endeq + where the $\left\{{n \atop k}\right\}$ are the Stirling numbers of + the second kind \cite{iKNU97a}. + The expected number of collisions is + $$ + \mu_c \eqdef E[C] + = k \left[{\textstyle \frac n k - 1 + \left(1 - \frac1k\right)^n}\right] + \approx \frac{n^2}{2k}. + $$ + + The current implementation of the test based on $C$ uses the following: + If $n \le 10^5$, the exact distribution is used, + else if $n/k \le 1$, $C$ is approximated by the Poisson + distribution with mean $\mu_c$, + else it is approximated by a normal distribution + with the exact mean and standard deviation. +% These approximations should give 3 decimal digits of precision for +% the distribution function, except (possibly) far in the lower tail +% of the distribution, i.e., when $C\ll \lambda$. + For two-level tests, the +Poisson approximation for the total number of collisions is used. +\hpierre {In this case, how are the two-level tests performed?} + + +%%%%%%%%%%%%%%%%%% +\paragraph*{Distribution of $Y$ for the overlapping serial approach.} \ + +Let $X_{t,j}^\o$ be the number of overlapping vectors $v_i$, +$i=0,\dots,n-1$, falling into cell $j$. +The distributions of the statistics $Y$ are more difficult to analyze +in this case, because of the more complicated dependence relationship +between the $X_{t,j}^\o$. + +For $\delta > -1$, let +\eq + D_{\delta,(t)} = \sum_{j=0}^{k-1} {2\over \delta(1+\delta)} X_{t,j}^\o + \left[(X_{t,j}^\o/\lambda)^\delta -1\right], \label{eq:Ddeltat} +\endeq +the power divergence statistic for the $t$-dimensional overlapping +vectors, and define +\eq + \tilde D_{\delta,(t)} = D_{\delta,(t)}-D_{\delta,(t-1)}. +\endeq +The following is taken from \cite{rLEC02c} +(The case $\delta=1$ was proved long ago by Good \cite{rGOO53a}): + +\begin {proposition} \null +{\rm [Dense case]} \ Under $\cH_0$, if $k$ is fixed and $n\to\infty$, +$\tilde D_{\delta,(t)} \To \chi^2(d^t-d^{t-1})$. +\end {proposition} + +For the sparse case, where $k,n\to\infty$ +and $n/k \to\lambda_0$ where $0<\lambda_0<\infty$, +simulation experiments support the conjecture that +\eq + \frac{\tilde D_{1,(t)}^2 - (k-k')}{\sqrt{2(k-k')}} \To N(0,1) +\endeq +but this has not been proved. + +Marsaglia and Zaman \cite{rMAR93b} speculate that $N_0$ is +approximately normal with mean $k e^{-\lambda}$ and variance +$k e^{-\lambda}(1-3e^{-\lambda})$. +This approximation is reasonably accurate for $2 \le \lambda\le 5$ +(roughly), but no longer makes sense when $\lambda$ is too large or +close to zero. +Marsaglia \cite{rMAR85a} calls the test based on $N_0$ with $t=2$ the +{\em overlapping pairs sparse occupancy\/} (OPSO) test +(see {\tt smarsa\_CollisionOver} and {\tt smarsa\_Opso}). + +Proposition \ref{prop2} (i) and (ii) probably holds in the overlapping +case as well, but we do not have a formal proof. +Simulation experiments indicate that the Poisson approximation +for $C$ is very accurate for (say) $\lambda < 1/32$, and already +quite good for $\lambda\le 1$, when $n$ is large. + +%%%%%%%%%%%%%%%% +\paragraph*{Calling the tests.} \ + +Four functions are available here to launch a test: +{\tt smultin\_Multinomial} for the case where the cell numbers are +independent of each other (so we have the multinomial distribution) +and {\tt smultin\_MultinomialOver} for the case where the cell numbers +are generated by overlapping $t$-tuples. +In each of these two procedures, the type of approximation that is used +for the distributions of the power divergence statistics is determined +by the boolean parameter {\tt Sparse}: The normal approximation is used +when it is true, and the chi-square approximation otherwise. The +two analog functions for bit tests are {\tt smultin\_MultinomialBits} and +{\tt smultin\_MultinomialBitsOver}. + + +\iffalse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +Furthermore, we may consider the sparse case, when the density + $n/k$ $\le 1$, or the dense case when the density $n/k > 1$. + We may also generate the cells number by different methods. + If we generate the cells number following the method of the serial test, + then the {\sl Multinomial} test will be equivalent to + {\tt sknuth\_Serial}, {\tt sknuth\_SerialSparse}, or {\tt smarsa\_SerialOver} + (see also {\tt sknuth\_Collision} and {\tt smarsa\_CollisionOver}). + If we generate a cell by generating a permutation number, we get the + test {\tt sknuth\_Permutation} (see also {\tt sknuth\_CollisionPermut}). + It is possible to use yet other methods to generate the cells number. + +The Cressie-Read statistic \cite{tREA88a} is defined by +\eq + 2nI^\delta = {2\over \delta(1+\delta)} \sum_{i=1}^k + X_i \left[\left(X_i \over n p_i\right)^\delta -1\right], + \eqlabel {powdiv} +\endeq + where $(X_1,\dots,X_k) \ge 0$ is a vector of observations. + +For $p_i = 1/k$ and $\delta = 1$, the exact mean and variance +of ${\cal X}^2 = I^1$ are $\mu = k-1$ and $\sigma^2 = (k-1)(2 - (k-1)/n)$ +(e.g., \cite{tHAL37a,tKOE80a}). %%% Haldane (1937) and Koehler 1980. +For $\delta \not= 0$, we do not have simple formulae for +these exact values, but they may be expressed in terms of expectations +of functions of Poisson random variables \cite{tKOE80a,tREA88a}. +For the case $\delta = 0$, \cite{rLEC96e} give expressions + computable in $O(n^2)$ for the mean and the variance of +the entropy $\hat H$. + +If $k$ is relatively small with respect to $n$, +Read and Cressie \cite[p.67]{tREA88a} suggest using a +version of $2nI^\delta$ corrected for the first two moments, +obtaining thus a statistic $2nI^\delta_C$ for which the mean +and the variance are $k-1 + O(kn^{-3/2})$ and $2(k-1) + O(k^2 n^{-3/2})$, +respectively, and for which the distribution should be closer to a + Chi-square law with $k-1$ degrees of freedom. +The corrected statistic is +$$ + 2nI^\delta_C = {2nI^\delta - \mu_C \over \sigma_C}, +$$ +where +\begin {eqnarray*} + \mu_C &=& (k-1)(1-\sigma) + {\delta-1\over n}\left[ + {2-3k+t\over 3} + {(\delta-2)(1-2k+t)\over 4}\right], \\ + \sigma_C^2 &=& 1 + {1\over 2n(k-1)}\left[ 2 - 2k - k^2 + t \right.\\[4pt] + && \hspace{-20pt} + \left. (\delta-1)\left[8 -12k -2k^2 +6t + + (\delta-1)(4 -6k -3k^2 + 5t)/3 \\ + && \hspace{30pt} + 2(\delta-2)(1-2k+t)\right]\right],\\ + t &=& \sum_{i=1}^k {1\over p_i}. +\end {eqnarray*} + + +For the case with overlap, let us define this time + $\nu = (n-t+1)/d^t$ ($\approx$ the density). + If $n$ (the number of balls) and $d^t$ (the number of cells) + are very large and of the same order of magnitude, + the number of collisions is a random variable obeying approximately + a normal law with mean $\mu \approx d^t (\nu - 1 + e^{-\nu})$ + (this follows from Theorem 2 in \cite{rPER95a}), + and variance $\sigma^2 \approx d^t e^{-\nu}(1-3e^{-\nu})$, + as conjectured in \cite{rMAR93a}. + If $n \ll d^t$, then the number of collisions should be + approximately Poisson with mean $\mu$, while if + $\nu$ is somewhat large (e.g., $> 6$), then the + number of empty cells ($d^t - n + {}$ the number of collisions) + should be approximately Poisson with mean $d^t e^{-\nu}$. + +\fi %%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%% \newpage +\bigskip\hrule +\code\hide +/* smultin.h for ANSI C */ +#ifndef SMULTIN_H +#define SMULTIN_H +\endhide +#include "gdef.h" +#include "fmass.h" +#include "statcoll.h" +#include "gofw.h" +#include "unif01.h" + + +#define smultin_MAX_DELTA 8 +\endcode +\tab + Maximal number of distinct values of $\delta$ for which the + statistic $D_\delta$ can be computed in a single test + (with $\delta=-1$ representing the family of collision-type tests). +\endtab +\code + + +#define smultin_MAXB 10 +\endcode +\tab + Maximal value of $b$ for which the statistic $W_b$ + can be computed (see Table \ref{tab:choosef}). +%, together with their $p$-values. +% for which we may calculate the +% statistics {\tt smultin\_WbUrn} and their $p$-values. +\endtab + + +% \newpage +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Environment variables} + +The parameters in {\tt smultin\_Envir} are environment variables that +should be fixed once for all and will not normally be changed. + +\code + +typedef struct { + + double Maxk; +\endcode +\tabb + Maximal value of $k = d^t$, the number of cells. The default value is + either $2^{63}$ if 64-bit integers are available, or else $2^{53}$, + the largest number of cells that can be enumerated by {\tt double's} + without loss of precision. +\endtabb +\ifdetailed +\code + + double SeuilHash; +\endcode +\tabb + When the number of cells $k$ is larger than this threshold and + the average number of balls per cell is less than 1, + the variable {\tt Hashing} is set to {\tt TRUE} and + hashing is used to compute the numbers $X_j$ and the power divergence + statistics. + In this case, {\tt Count[i]} counts how many $X_j$ are + equal to $i$, for $i \ge 0$. + The default value is {\tt SeuilHash} $= 2^{20}$. +\endtabb +\code + + double HashLoad; +\endcode +\tabb + Maximal load factor when hashing is used. The number + of cells times {\tt HashLoad} is always larger than the number + of balls. The default value is 0.75. The actual load factor will + most often be smaller than this value. +\endtabb +\code + + double SeuilEColl; +\endcode +\tabb + For the two-level collision tests, if the expected number of + collisions for a replication is larger than this value, the statistic + {\tt gofw\_Mean} will + correspond to a test based on the average number of collisions + using the normal approximation. Otherwise, it will + correspond to a test based on the total number of collisions + using the Poisson approximation. + In both cases, {\tt gofw\_KS} and {\tt gofw\_AD} will + correspond to two-level tests as usual, assuming that the number + of collisions + $C$ is a random variable approximatively continuous, which is reasonnable + when the normal approximation is valid. +\endtabb +\code + + double SeuilCOverDense; + double SeuilCOverNorSup; + double SeuilCOverNorInf; + double SeuilCOverSparse; +\endcode +\tabb + Thresholds determining the different approximations used for + the distribution function in the {\tt CollisionOver} test. + Let the density $\nu = n/k$, where $n$ is + the number of balls thrown into $k$ cells. + When {\tt SeuilCOverNorSup} $< \nu < $ + {\tt SeuilCOverDense}, + we use the Poisson approximation for the number of empty cells. + When {\tt SeuilCOverNorInf} $< \nu \le $ + {\tt SeuilCOverNorSup}, we use the + normal approximation for the number of collisions. + For $ \nu < $ {\tt SeuilCOverSparse}, we use the + Poisson approximation for the number of collisions. + The default values are {\tt SeuilCOverDense} = 12, + {\tt SeuilCOverNorSup} = 5, {\tt SeuilCOverNorInf} = 2, + {\tt SeuilCOverSparse} = 1. +\endtabb +\fi +\code + +} smultin_Envir; + + +extern smultin_Envir smultin_env; +\endcode +\tab + This is the environment variable used to keep the values of the fields + described above in {\tt smultin\_Envir}. +\endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Functions to generate the cell numbers} + +\code + +#ifdef USE_LONGLONG + typedef ulonglong smultin_CellType; +#else + typedef double smultin_CellType; +#endif +\endcode + \tab Type used to enumerate cell numbers, either 64-bit integers + if they are available, or else {\tt double's} with a 53-bit mantissa. + \endtab +\code + + +typedef smultin_CellType (*smultin_GenerCellType) (unif01_Gen *, int, int, + long); +\endcode + \tab + Type of function used to generate a cell number. It returns the cell + number.\index{cells generation} + \endtab +\code + + +smultin_CellType smultin_GenerCellSerial (unif01_Gen *gen, int r, int t, + long d); +\endcode + \tab Generates and returns a cell number in $\{0,\dots,k-1\}$ for the + multinomial test, with $k = d^t$. The function generates $t$ integers + $y_0,\dots,y_{t-1}$ in $\{0,\dots,d-1\}$, using the most significant + bits of $t$ successive uniforms + (after throwing away their leading $r$ bits). + The cell number $c = y_0 d^{t-1} + \cdots + y_{t-2} d + y_{t-1}$ + is returned. + \endtab +\code + + +smultin_CellType smultin_GenerCellSerial2 (unif01_Gen *gen, int r, int t, + long d); +\endcode + \tab Similar to {\tt smultin\_GenerCellSerial}, except that the + cell number is $c = y_{t-1} d^{t-1} + \cdots + y_{1} d + y_0$. + This is equivalent to using {\tt smultin\_GenerCellSerial}, + because it only changes the numbering of the cells and the power + divergence test statistics do not depend on the numbering. + \endtab +\code + + +smultin_CellType smultin_GenerCellPermut (unif01_Gen *gen, int r, int t, + long junk); +\endcode + \tab Similar to {\tt smultin\_GenerCellSerial}, except that there are + $t!$ cells, corresponding to the $t!$ permutations of $t$ real numbers, + The function generates $t$ uniforms and returns the number of the + permutation that corresponds to their ordering. + \endtab +\code + + +smultin_CellType smultin_GenerCellMax (unif01_Gen *gen, int r, int t, + long junk); +\endcode + \tab Similar to {\tt smultin\_GenerCellSerial}, except that $k=t$ + and the cell number is the number of the largest coordinate in $v_{ti}$. + \endtab +\hide +\code + + +smultin_CellType smultin_GenerCellSerialBits (unif01_Gen *gen, int r, int s, + long L); +\endcode + \tab Generates a cell number in $\{0,\dots,k-1\}$ for the + multinomial test, from a bit string, where $k = 2^L$. + The function extracts $s$ bits from each call to the RNG + (after throwing away their leading $r$ bits) + and concatenates these bits into a long string. + Each cell number is generated by taking $L$ successive bits from + the string, say $b_0,\dots,b_{L-1}$. +% , either with or without overlap. + The cell number $c = b_0 2^{L-1} + \cdots + b_{L-2} 2 + b_{L-1}$ + is returned. + \endtab +\endhide + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Test parameters having default values} +\nopagebreak + +The parameters in the following global structure {\tt smultin\_Param} +often remain the same in a given experiment. +They can practically be viewed as environment variables. +To change their default values, one should create a {\tt smultin\_Param} +structure and pass it as a pointer to the tests. +When a {\tt NULL} pointer is passed as argument to a test, the +default values are used instead. + +\code + + +typedef struct { + + int NbDelta; + double ValDelta [smultin_MAX_DELTA]; +\endcode + \tabb + The number of values of $\delta$, and the list of values of $\delta$, + for which the multinomial tests are applied (simultaneously) + when calling a test. If {\tt NbDelta} = $m$, then the + tests are applied for the $m$ values $\delta_0,\dots,\delta_{m-1}$ + which must be given in array {\tt ValDelta[0..m-1]}. + The value $\delta = -1$ corresponds to the collision test + and the other values of $\delta$ correspond to power divergence tests. + The default values are $m=2$, $\delta_0 = -1$, $\delta_1 = 1$. + \endtabb +\code + + smultin_GenerCellType GenerCell; +\endcode +\tabb + This function is used to generate the cell numbers in the tests. + It is one of the function {\tt smultin\_GenerCell} described above. + The default value is {\tt smultin\_GenerCellSerial}. +\endtabb +\code + + int bmax; +\endcode + \tabb In the non-overlapping case for $\delta = -1$, in addition to + applying the collision test, the statistic $W_b$ and its $p$-value + are computed for $b=0,\dots,${\tt bmax}. + For $b=0$, the test is actually based on $N_0$, the number of + empty cells. + If the value is negative, none of these statistics is computed. + The default value is {\tt bmax = -1}. +% Setting {\tt bmax} to a larger value permits one to see how many cells +% are empty, how many contain exactly one point, how many contain +% two points, etc. + \endtabb +\code + +} smultin_Param; + + +smultin_Param * smultin_CreateParam (int NbDelta, double ValDelta[], + smultin_GenerCellType GenerCell, + int bmax); +\endcode + \tab + Function creating and returning a structure that will hold the + parameters described above. The parameters have + the same meaning as in the structure {\tt smultin\_Param}. + \endtab +\code + + +void smultin_DeleteParam (smultin_Param *par); +\endcode + \tab + Procedure freeing the memory allocated by {\tt smultin\_CreateParam}. + \endtab + +\hide +\code + +extern smultin_Param smultin_ParamDefault; +\endcode +\endhide + + + +\ifdetailed %%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Test results} + + The following large structure type {\tt smultin\_Res} is used to + keep the intermediate and final results of a test. + It contains the counters, the test statistics, their $p$-values, + and some quantities related to the theoretical distributions. + If one needs these results for post-processing or for any + other reason after a test has ended, it suffices to create a + {\tt smultin\_Res} structure by calling the function + {\tt smultin\_CreateRes} and pass it as a pointer to the tests. + Otherwise, a {\tt NULL} pointer can be passed in place of the {\tt res} + argument to the tests. + +\code + +typedef enum { + smultin_CollNotInit, /* Not initialized */ + smultin_CollExact, /* Exact distribution */ + smultin_CollNormal, /* Normal approximation */ + smultin_CollPoissonSparse, /* Poisson approximation: sparse case */ + smultin_CollPoissonDense /* Poisson approximation: dense case */ +} smultin_CollApproxType; +\endcode + \tab + Approximation used for the distribution function in the + {\tt Collision} and {\tt CollisionOver} tests. + \endtab +\code + + +typedef struct { + + lebool Hashing; +\endcode +\tabb + {\tt TRUE} if hashing is used. + The value of this variable is chosen for each test depending on + {\tt smultin\_env.SeuilHash}. +\endtabb +\code + + smultin_CellType NbCellsTotal; +\endcode +\tabb + Total number of cells for a test (value of $k$). + \endtabb +\code + + lebool Over; +\endcode +\tabb {\tt TRUE} if we are doing the overlapping version of the tests, + {\tt FALSE} otherwise. +\endtabb +\code + + smultin_CollApproxType CollApprox; +\endcode +\tabb Approximation used for the distribution function in the + {\tt Collision} or {\tt CollisionOver} tests. + \endtabb +\code + + double Mu [smultin_MAX_DELTA]; + double Sigma [smultin_MAX_DELTA]; +\endcode +\tabb + Theoretical mean and standard deviation (\ref{eq:smultin-mu}) and + (\ref{eq:smultin-sigma2}), for each value of {\tt ValDelta[s]}. +\endtabb +\code + + double EsEmpty; +\endcode +\tabb + The expected number of empty cells. +\endtabb +\code + + long CountSize; + long Count1Size; + long *Count; + long *Count1; + smultin_CellType *Cell; + smultin_CellType *Cell1; +\endcode +\tabb + {\tt CountSize} is the size of array {\tt Count} and + {\tt Count1Size} is the size of array {\tt Count1}. These arrays contain + counters keeping track of the number of balls in a cell, numbered + by the array index in the case where {\tt Hashing = FALSE}. + If {\tt Hashing = TRUE}, the counter with index $i$ + indicates the number of balls in cell numbered by {\tt Cell[i]}. + {\tt Count1} and {\tt Cell1} are used in + the {\tt Over} version of the tests in dimension $t-1$. +\endtabb +\code + + long NbSize; + long Nb1Size; + smultin_CellType *Nb; + smultin_CellType *Nb1; +\endcode +\tabb + {\tt NbSize} is the size of array {\tt Nb} and + {\tt Nb1Size} is the size of array {\tt Nb1}. + {\tt Nb[i]} is the observed number of cells containing $i$ points. + {\tt Nb1[i]} is the observed number of cells containing $i$ points + in dimension $t-1$ (for the {\tt Over} versions of the tests). +\endtabb +\code + + smultin_CellType NbCells [smultin_MAXB + 1]; + double EsCells [smultin_MAXB + 1]; + smultin_CellType WbCells [smultin_MAXB + 1]; +\endcode +\tabb + The array element {\tt NbCells[i]} is the observed numbers of + cells containing exactly $i$ points, where the counters are added over + {\em all $N$ replications\/} (in contrast with {\tt Nb} and {\tt Nb1}, + which are reinitialized to zero after each replication). + The test statistics are the sums of the $N$ Poisson variables + over the $N$ replications. + {\tt EsCells[i]} and {\tt WbCells[i]} contain the expected number + (asymptotically when the density $n/k \rightarrow 0$) and the + observed number of cells containing at least $i$ points, for $i\ge 0$, + respectively. +\endtabb +\code + + double NbCollisions; +\endcode +\tabb + Total observed number of collisions, over all $N$ replications. + \endtabb +\code + + statcoll_Collector *Collector [smultin_MAX_DELTA]; +\endcode +\tabb + {\tt Collector[s]} is used to keep the $N$ observations of $Y$ + for the test based on {\tt ValDelta[s]}. +\endtabb +\code + + gofw_TestArray sVal2 [smultin_MAX_DELTA]; + gofw_TestArray pVal2 [smultin_MAX_DELTA]; +\endcode + \tabb + After a call to a test ({\tt smultin\_Multinomial}, + {\tt smultin\_MultinomialOver}, etc.) with $N > 1$, + the values and the $p$-values of the different statistics (but not + {\em Collisions\/}) for {\tt ValDelta [s]} will be found in arrays + {\tt sVal2 [s, $\cdot$]} and {\tt pVal2 [s, $\cdot$]}. + For $N > 1$, the indices {\tt [s, gofw\_Mean]} and {\tt [s, gofw\_Cor]} + stand for tests based on the empirical mean and correlation + of the $N$ observations and their $p$-values are computed by assuming + that they are normally distributed. + In the cases where $N=1$, {\tt sVal2 [s, gofw\_KSP]} and + {\tt pVal2 [s, gofw\_KSP]} will contain + the $p$-value of the test at the first level and the + other array elements are unused. + For the collision tests using the Poisson approximation, + or using the exact law with $N = 1$, + {\tt gofw\_Mean} corresponds to a test based on the total number of + collisions (or empty cells, in the dense case) + for the $N$ replications. + \endtabb +\code + + double pCollLeft, pCollRight; +\endcode + \tabb The left and the right $p$-values for the collision test. + \endtabb +\code + + double pColl; +\endcode + \tabb The $p$-value for the collision test. + \endtabb +\code + + double pEmpty; +\endcode +\tabb + The $p$-value for the number of empty cells. +\endtabb +\code + + double pWb [smultin_MAXB + 1]; +\endcode + \tabb + The $p$-values for $W_b$, the number of cells containing at + least $b$ points (see the description of {\tt EsCells} and + {\tt WbCells}). + \endtabb +\fi %%%%%%%%%%%%%%%%% +\hide %%%%%%%%%% +\code + + int NbDeltaOld; +\endcode +\tabb + The number of values of $\delta$ of the previous test (see the + documentation in {\tt smultin\_Param}). This is necessary to prevent + memory leaks and bugs, in case {\tt NbDelta} changes from the previous + test with the same variable {\tt res}. +\endtabb +\code + + double *TabFj[smultin_MAX_DELTA]; +\endcode +\tabb If we replicate a test many times, we may keep some complicated + terms in these tables instead of recomputing them every time + (depending on the value of {\tt flagTab}). +\endtabb +\code + + int nLimit; +\endcode +\tabb The tables {\tt TabFj} are precomputed for elements {\tt + [0..nLimit]}. +\endtabb +\code + + lebool flagTab; +\endcode +\tabb This flag is set to TRUE if we precompute tables of values and keep + them in arrays {\tt TabFj}. +\endtabb +\endhide %%%%%%%%%%%% +\ifdetailed %%%%%%%%%%%%%% +\code + +} smultin_Res; + + +smultin_Res * smultin_CreateRes (smultin_Param *par); +\endcode + \tab + Creates and returns a structure to hold the results of a test, + based on the parameter values given in the structure {\tt par}. + If {\tt par = NULL}, the default parameter values are used + (see the description of {\tt smultin\_Param}). The user may change + the parameter values before a test or between tests using the same + {\tt smultin\_Res} structure. + \endtab +\code + + +void smultin_DeleteRes (smultin_Res *res); +\endcode + \tab + Recovers the memory allocated to {\tt res} by {\tt smultin\_CreateRes}. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Specialized functions used inside the tests} + +These functions are used to compute the theoretical mean, variance, +and correction factors used in some tests, and to compute individual terms +of the test statistics. + +\code + +typedef double (*smultin_MNTermeType) (double, double, long); +\endcode + \tab Represents one term for the different + statistics computed by {\tt smultin\_MultinomMuSigma}. + The first two arguments are parameters; + the third is the variable of the function, equal for example to the + number of points in a cell. See {\tt smultin\_MNTermeColl, + smultin\_MNTermeKhi2, smultin\_MNTermeLogLikhood}, and + {\tt smultin\_MNTermePowDiv} below. + \endtab +\code + + +double smultin_MNTermeColl (double, double, long j); +\endcode + \tab Returns $\max(0, j-1)$, the number of collisions in a cell + containing $j$ points. + \endtab +\code + + +double smultin_MNTermePowDiv (double Delta, double E, long j); +\endcode + \tab Returns one term of the {\sl power divergence} statistic: +% (with $\delta =$ {\tt Delta}): + $${2j\over \delta(1+\delta)} + \left[\left(j \over E\right)^\delta -1\right].$$ + \endtab +\code + +double smultin_MNTermeKhi2 (double, double E, long j); +\endcode + \tab Returns one term of the {\em Pearson's chi-square\/} statistic: +% (with $E =$ {\tt NbEsp}) + $ (j - E)^2 / E$. + \endtab +\code + + +double smultin_MNTermeLogLikhood (double, double E, long j); +\endcode + \tab Returns one term of the {\em loglikelihood ratio\/} statistic: +% (with $E =$ {\tt NbEsp}) + $ 2 j\; \ln \left(j / E\right)$. + \endtab +\code + + +void smultin_MultinomMuSigma (long n, double k, double theta1, + double theta2, smultin_MNTermeType F, + double *Mu, double *Sigma); +\endcode + \tab + Computes the exact values of the mean $\mu$ and the standard deviation + $\sigma$ of a statistic of the form +% (with $T1 = \theta_1$ and $T2 =\theta_2$) + $$ + Y = \sum_{j=0}^{k-1} F(\theta_1, \theta_2, X_j), + $$ + assuming that $(X_0,\ldots, X_{k-1})$ + obeys a multinomial law with parameters $(n, 1/k, \ldots,$ $1/k)$. + + If we write $F(X)$ for $F(\theta_1,\theta_2, X)$ (to simplify the notation), + the values of $\mu$ and $\sigma$ are given by: + \begin{eqnarray} + k\mu_0 & \eqdef & \mu\ = \ \sum_{x=0}^n {n \choose x} + \frac{(k-1)^{n-x}}{k^{n-1}} F(x) \label{eq:smultin-mu} \\ + \sigma^2 &=& E\left[\left(\sum_{j=0}^{k-1}\left(F(X_j) - \mu_0 \right) + \right)^2 \right]\\[6pt] + &=& k E\left[\Big(F(X_0) - \mu_0 \Big)^2 \right] + k(k-1) + E\left[\left(F(X_0) - \mu_0 \right) \left(F(X_1) - \mu_0 \right) \right]. + \label{eq:smultin-sigma2} + \end{eqnarray} +\iffalse %%%% + We meet such multinomial vectors in the following context: + We throw $n$ balls into $k$ cells, independently and with a + uniform probability $1/k$ for each cell, and we define + $X_j$ as the number of balls falling into cell $j$. +\fi %%%% + \endtab +\code + +void smultin_PowDivMomCorChi (double Delta, long n, double k, + double *MuC, double *SigmaC); +\endcode + \tab + Computes and returns the values of $\mu_C = $ {\tt MuC} and + $\sigma_C = $ {\tt SigmaC} for the two-moment corrected statistic + $D_\delta^{(C)} = (D_\delta - \mu_C) / \sigma_C$, + in the cases where we use the approximation by the {\em chi-square\/} + distribution. + If $\delta \le -1$ (the collision test), this function computes nothing. + Here, $n$ is the number of points and $k$ is the number of cells. + \endtab +\code + + +void smultin_PowDivMom (double Delta, long n, double k, + double NbExp, double *Mu, double *Sigma); +\endcode + \tab + Compute the mean $\mu = $ {\tt Mu} and the standard deviation $\sigma = $ + {\tt Sigma} for the theoretical distribution of the test statistic for + this $\delta = $ {\tt Delta}. This function is called when we use the + normal approximation and for the collision test with the normal + approximation. + The returned values are close to the exact values in most cases. + \endtab + +\fi %%%%%%%%%%%%%%%% + +\ifdetailed %%% + +% \newpage +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Distribution for collision test} + +This section provides tools to compute the theoretical distribution +of the number of collisions for the collisions test (the non-overlapping +case only). +To use these tools, one must first call {\tt smultin\_CreateCollisions} +to create the appropriate structure. When it is no longer needed, +this structure can be deleted by +calling {\tt smultin\_DeleteCollisions}. + +\code + + +fmass_INFO smultin_CreateCollisions (long n, smultin_CellType k); +\endcode + \tab Creates and returns a structure that contains the mass and + distribution functions of the random variable $C$, + the number of collisions when $n$ balls (or points) + are thrown at random and independently into $k$ boxes (or cells), each + ball having probability $1/k$ of falling into any given box. + A collision occurs when a ball falls into a box already occupied + with one or more balls. + Such a structure is needed for calling + {\tt smultin\_FDistCollisions}, {\tt smultin\_FBarCollisions} or + {\tt smultin\_CollisionsTerm}. It can be deleted by calling + {\tt smultin\_DeleteCollisions}. + (The module {\tt fmass} is in library ProbDist.) + + \endtab +\code + + +void smultin_DeleteCollisions (fmass_INFO W); +\endcode + \tab Deletes the structure {\tt W} created previously + by {\tt smultin\_CreateCollisions}. + \endtab +\code + + +double smultin_FDistCollisions (fmass_INFO W, long c); +\endcode + \tab Returns $P[C\le c]$ for the random variable $C$ + described in {\tt smultin\_CreateCollisions}, from the structure + {\tt W}, which must have been created previously by calling + {\tt smultin\_CreateCollisions} with the desired $n$ and $k$. + \endtab +\code + + +double smultin_FBarCollisions (fmass_INFO W, long c); +\endcode + \tab Similar to {\tt smultin\_FDistCollisions}, but returns $P[C\ge c]$. +\endtab +\code + + +double smultin_CollisionsTerm (fmass_INFO W, long c); +\endcode + \tab Similar to {\tt smultin\_FDistCollisions}. Returns an + approximation of $P[C = c]$ given in (\ref{fmass-collis}). + \endtab + +\fi + + + +% \newpage +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +% \resdef + +\code + +void smultin_Multinomial (unif01_Gen *gen, smultin_Param *par, + smultin_Res *res, long N, long n, int r, long d, int t, lebool Sparse); +\endcode + \tab + This function applies the power divergence + test,\index{Test!Multinomial} based on +% (corrected for the first two moments) + statistic $D_\delta$, for each value of $\delta$ specified in the array + {\tt par->ValDelta[0..NbDelta-1]} (where $\delta = -1$ + corresponds to the collision test, based on $C$). + The theoretical distribution of $D_\delta$ (with a two-moment correction) + is approximated by a normal if {\tt Sparse = TRUE}, and by a chi-square + with $k-1$ degrees of freedom if {\tt Sparse = FALSE}. + This function also applies tests based on $W_b$ for + $b=0, 2,\dots, ${\tt par->bmax}. + All these tests are applied simultaneously, using the same cell + countings. The cell numbers are generated by the function in variable + {\tt par->GenerCell}. + By default, it is {\tt smultin\_GenerCellSerial}. + Both {\tt par} or {\tt res} can be set to the {\tt NULL} pointer, in + which case these structures are created and deleted internally. + It is recommended to have $n/k > 8$ if {\tt Sparse = FALSE}, + except for $\delta=1$. + If {\tt Sparse = TRUE}, $n$ and $k$ should both be very large. + Restriction: $k = d^t \le ${ \tt smultin\_Maxk}. + \endtab +\code + + +void smultin_MultinomialOver (unif01_Gen *gen, smultin_Param *par, + smultin_Res *res, long N, long n, int r, long d, int t, lebool Sparse); +\endcode + \tab + Similar to {\tt smultin\_Multinomial}, but where the $n$ cell + numbers are generated using the {\em overlapping serial\/} approach, + as described earlier in the paragraph ``How to generate the cell numbers'' + and used in {\tt smarsa\_SerialOver}.\index{Test!MultinomialOver} +% The $n$ generated values are placed in a circle, and the $n$ $t$-tuples +% of successive values are the points. + \endtab +\code + + +void smultin_MultinomialBits (unif01_Gen *gen, smultin_Param *par, + smultin_Res *res, long N, long n, int r, int s, int L, lebool Sparse); +\endcode + \tab + Similar to {\tt smultin\_Multinomial}, except that the cells are generated + from a string of bits obtained by taking {\tt s} bits from each + output value.\index{Test!MultinomialBits} There are $k = 2^L$ cells + and each cell number is determined by taking $L$ successive bits from + the string. +% The cell numbers are generated via {\tt smultin\_GenerCellSerialBits}. +% \richard {Non. Quand $L\ge s$, le test appelle {\tt smultin\_Multinomial}, +% et quand $L < s$, on ne peut pas l'utiliser, car on g\'en\`ere plus d'un +% point avec chaque U01. Cette fonction n'est pas utilis\'ee.} + In the case where $L = ts$ for some integer $t$, this test is + equivalent to {\tt smultin\_Multinomial} with $d = 2^s$ and $t = L/s$. + The present function is to cover the other cases (e.g., if $L < s$). + Restrictions: $L \bmod s = 0$ when $L > s$, and + $s \bmod L = 0$ when $s > L$. + \endtab +\code + + +void smultin_MultinomialBitsOver (unif01_Gen *gen, smultin_Param *par, + smultin_Res *res, long N, long n, int r, int s, int L, lebool Sparse); +\endcode + \tab + Similar to {\tt smultin\_MultinomialBits}, except that the $n$ cell + numbers are generated using the {\em overlapping\/} approach at the + bit level. The $n$ bits are placed in a circle and each block of $L$ + successive bits determines a cell number.\index{Test!MultinomialBitsOver} + $L$ and $s$ do not have to divide each other. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/snpair.c b/TESTU01/TestU01-1.2.3/testu01/snpair.c new file mode 100644 index 0000000..39d3a26 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/snpair.c @@ -0,0 +1,2635 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: snpair.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "util.h" +#include "tables.h" +#include "chrono.h" +#include "num.h" +#include "num2.h" + +#include "snpair.h" +#include "swrite.h" +#include "unif01.h" + +#include "statcoll.h" +#include "fdist.h" +#include "fbar.h" +#include "fmass.h" +#include "gofs.h" +#include "gofw.h" + +#include +#include +#include +#include +#include + +#undef DEBUG +#ifdef DEBUG + +#include +/* Prints all the points */ +#define TRACEP(n, name) { \ + FILE *f; \ + long i, j; \ + f = util_Fopen (name, "w"); \ + fprintf (f, "------------------------\n"); \ + for (i = 1; i <= n; i++) { \ + for (j = 1; j <= kk; j++) \ + fprintf (f, "%f ", res->Points[1][i][j]); \ + fprintf (f, "\n"); \ + } \ +} +#endif + + + + +/*---------------------------- extern variables ---------------------------*/ + +snpair_Envir snpair_env = { + 20, 30, 30, 1000 +}; + +/* For now, we do not use it. Is used in the t modules */ +long snpair_MaxNumPoints = LONG_MAX; + +lebool snpair_TimeBB = FALSE; +lebool snpair_mNP2S_Flag = TRUE; + + + + +/*---------------------------- static variables ---------------------------*/ + +typedef struct { + + int L1; /* Change coordinate at each L1 recur- */ + /* sion level in FindClosePairs */ + int L2; /* Same thing for CheckBoundary */ + int kk; /* = k = Dimension */ + int pp; /* = p (L_p norm); p = 0 is sup norm */ + int mm; /* = m = (number of kept distances) */ + int mcd; /* Dimension of CloseDist[] */ + double dlim1; /* (m \mu2)^{1/k} */ + double dlim1p; /* dlim1^p (when p > 0) */ + double dlim; /* = max (dlim1, CloseDist[m]); search */ + /* for points at distance < dlim */ + double dlimp; /* = dlim^p (when p > 0) */ + double pLR; /* = p */ + double Invp; /* 1/p; ( = 1 if p = 0) */ + int Maxnp; /* Max level of recursion */ + lebool Torus; /* TRUE if in Torus; FALSE if in cube */ + lebool BBFlag; /* TRUE if BickelBreimann test */ + wdist_CFUNC FDistBB; /* BickelBreimann CDF */ + +/* The largest distance for snpair_DistanceCPBitM: the largest number of + equal bits for all components of a pair of points (all components of + the pair have at least YLim identical bits) amongst all pairs. */ + int YLim; + +} WorkType; + + +/*------------------ Module variables for G+, G-, H+, H- -----------------*/ +/* + * To compute the jumps in FDistGPlus, FDistGMinus, FDistHPlus, FDistHMinus + */ + + +#if 0 +static double t0; + +#define xinf 1.0e50 + +static lebool GPlusFlag = FALSE; +static lebool GMinusFlag = FALSE; +static lebool HPlusFlag = FALSE; +static lebool HMinusFlag = FALSE; + +static double GPlust0 = -xinf; /* = t0 for GPlus */ +static double GMinust0 = -xinf; /* = t0 for GMinus */ +static double HPlust0 = -xinf; /* = t0 for HPlus */ +static double HMinust0 = -xinf; /* = t0 for HMinus */ +static double GPlust1 = -xinf; /* = t1 for GPlus */ +static double GMinust1 = -xinf; /* = t1 for GMinus */ +static double HPlust1 = -xinf; /* = t1 for HPlus */ +static double HMinust1 = -xinf; /* = t1 for HMinus */ + +static double *GPlusJumpX; /* Position x of the jumps of G+ */ +static double *GPlusJumpYBottom; /* Value y left of the jumps of G+ */ +static double *GPlusJumpYTop; /* Value y right of the jumps of G+ */ + +static double *GMinusJumpX; /* Similarly for G- */ +static double *GMinusJumpYBottom; +static double *GMinusJumpYTop; + +static double *HPlusJumpX; /* Similarly for H+ */ +static double *HPlusJumpYBottom; +static double *HPlusJumpYTop; + +static double *HMinusJumpX; /* Similarly for H- */ +static double *HMinusJumpYBottom; +static double *HMinusJumpYTop; + +static int GPlusNJump; /* The number of jumps of G+ */ +static int GMinusNJump; /* The number of jumps of G- */ +static int HPlusNJump; /* The number of jumps of H+ */ +static int HMinusNJump; /* The number of jumps of H- */ + +#endif + +/*------------------ Module variables for Bickel-Breiman test ------------*/ + +static double BB2[132]; +static double BB3[132]; +static double BB4[43]; +static double BB5[22]; + + + + + + +/*-------------------------------- functions ------------------------------*/ + +static void CopyPoints (snpair_PointType A[], snpair_PointType B[], long r, + long s) +/* + * Copies A[r..s] into B[r..s] + */ +{ + long i; + for (i = r; i <= s; i++) + B[i] = A[i]; +} + + +/*=========================================================================*/ + +void snpair_QuickSort (snpair_PointType A[], long l, long r, int c) +/* + * Sort points of indices l to r using coordinate c as key. Exchange + * pointers instead of points. + */ +{ + long j; + long i; + double pivot; + snpair_PointType vec; + i = l; + j = r; + pivot = A[(l + r) / 2][c]; + do { + while (A[i][c] < pivot) + ++i; + while (pivot < A[j][c]) + --j; + if (i <= j) { + vec = A[i]; + A[i] = A[j]; + A[j] = vec; + ++i; + --j; + } + } while (i <= j); + if (l < j) + snpair_QuickSort (A, l, j, c); + if (i < r) + snpair_QuickSort (A, i, r, c); +} + + +/*=========================================================================*/ + +void snpair_DistanceCP (snpair_Res * res, snpair_PointType P1, + snpair_PointType P2) +/* + * For ClosePairs, checks if the distance between P1 and P2 is < dlim. + * If so, updates dlim, dlimp, and adds the new distance in the list + * of shortest distances. + */ +{ + int i; + double temp; + double dist; + double distp = 0.0; + WorkType *work = res->work; + + for (i = 1; i <= work->kk; i++) { + temp = P1[i] - P2[i]; + if (temp < 0.0) + temp = -temp; + if (work->Torus && temp > 0.5) + temp = 1.0 - temp; + if (work->pp == 0) { + if (temp > distp) + distp = temp; + } else if (work->pp == 1) + distp += temp; + else if (work->pp == 2) + distp += temp * temp; + else + distp += pow (temp, work->pLR); + if (distp >= work->dlimp) + return; + } + +#define NUM_JUMPS_LIM 50000 +/* I put this arbitrary limit on the size of res->CloseDist because for bad + generators, there will be many pairs of points with 0 distances between + them, and res->CloseDist will otherwise eat up the whole memory. + If the parameters N and m in ClosePairs should be such that + N*m > NUM_JUMPS_LIM, then this limit will have to be increased. (RS) */ + + if (distp < work->dlimp) { + if (work->pp <= 1) + dist = distp; + else if (work->pp == 2) + dist = sqrt (distp); + else + dist = pow (distp, work->Invp); + if ((res->NumClose < work->mm || + res->CloseDist[res->NumClose] < work->dlim1) && + (res->NumClose < NUM_JUMPS_LIM)) { + ++res->NumClose; /* Complete the list of close pairs */ + if (res->NumClose >= work->mcd) { + double *A; + work->mcd *= 2; + A = util_Realloc (res->CloseDist, (work->mcd + 1)*sizeof (double)); + if (A == NULL) { + util_Warning (1, "Cannot realloc res->CloseDist"); + } else + res->CloseDist = A; + } + util_Warning ((res->NumClose >= NUM_JUMPS_LIM) && swrite_Basic, + "res->NumClose > 50000"); + } + + /* Insert the new distance in the sorted list */ + i = res->NumClose; + while (i > 1 && dist < res->CloseDist[i - 1]) { + --i; + res->CloseDist[i + 1] = res->CloseDist[i]; + } + res->CloseDist[i] = dist; + + if (res->NumClose == work->mm && res->CloseDist[work->mm] < work->dlim + && work->dlim1 < work->dlim) { + work->dlim = res->CloseDist[work->mm]; + if (work->dlim < work->dlim1) { + work->dlim = work->dlim1; + work->dlimp = work->dlim1p; + } else if (work->pp <= 1) + work->dlimp = work->dlim; + else if (work->pp == 2) + work->dlimp = work->dlim * work->dlim; + else + work->dlimp = pow (work->dlim, work->pLR); + } + } +} + + +/*=========================================================================*/ + +void snpair_DistanceBB (snpair_Res * res, snpair_PointType P1, + snpair_PointType P2) +/* + * For Bickel-Breiman, checks whether the distance between P1 and P2, to the + * power p, is less than P1[0] or P2[0]. If so, updates these values. + */ +{ + int i; + double bound; + double temp; + double distp; + WorkType *work = res->work; + + if (P2[0] > P1[0]) + bound = P2[0]; + else + bound = P1[0]; + + distp = 0.0; + for (i = 1; i <= work->kk; i++) { + temp = P1[i] - P2[i]; + if (temp < 0.0) + temp = -temp; + if (work->Torus && temp > 0.5) + temp = 1.0 - temp; + if (work->pp == 1) + distp += temp; + else if (work->pp == 2) + distp += temp * temp; + else if (work->pp == 0) { + if (temp > distp) + distp = temp; + } else + distp += pow (temp, work->pLR); + if (distp >= bound) + return; + } + + if (distp < P1[0]) + P1[0] = distp; + if (distp < P2[0]) + P2[0] = distp; +} + + +/*=========================================================================*/ + +void snpair_VerifPairs0 (snpair_Res * res, snpair_PointType A[], long r, + long s, int junk1, int junk2) +/* + * Compute the distance between all pairs of points with indices in the + * interval [r..s] for the array A; updates the distances for BB. We assume + * the points are sorted with respect to coordinate c. + */ +{ + long i, j; + for (i = r; i < s; i++) { + for (j = i + 1; j <= s; j++) { + res->Distance (res, A[i], A[j]); + } + } +} + + +/*=========================================================================*/ + +void snpair_VerifPairs1 (snpair_Res * res, snpair_PointType A[], long r, + long s, int np, int c) +/* + * Compute the distance between all pairs of points with indices in the + * interval [r..s] for the array A; updates dlim and dlimp if necessary. + * We assume the points are sorted with respect to coordinate c. + */ +{ + long i, j; + double high; + WorkType *work = res->work; + + util_Assert (np <= work->Maxnp, + "Calling snpair_VerifPairs1 with np > Maxnp"); + for (i = r; i <= s; i++) { + /* util_Assert (r <= s, "Calling snpair_VerifPairs1 with r > s"); */ + + /* Consider only points at distance <= dlim from A[i] with respect to + coordinate c */ + high = A[i][c] + work->dlim; + j = i + 1; + while (j <= s && A[j][c] < high) { + res->Distance (res, A[i], A[j]); + ++j; + } + if (j > s && work->Torus && np <= work->kk) { + high -= 1.0; + j = r; + while (j < i && A[j][c] < high) { + /* util_Assert (i != j, "Calling distance with i=j in + snpair_VerifPairs1"); */ + res->Distance (res, A[i], A[j]); + ++j; + } + } + } +} + + +/*=========================================================================*/ + +static void dlimSlice ( + snpair_Res *res, + snpair_PointType A[], + long *r, + long *imed, + long *jmed, + long *s, + int c, + lebool Tor + ) +/* + * Let E1 = A [*r..*imed] and E2 = A [*jmed..*s] be two sets of points sorted + * with respect to the c-th coordinate. + * If Torus = FALSE, will reduce E1 to a slice of width dlim (in the direction + * c) of the leftmost point of E2; and similarly for E2 with respect to the + * rightmost point of E1 (always with respect to the c-th coordinate). + * There will be thus a slice on each side of the boundary line. + * If Torus = TRUE, we consider rather the points to the left of + * (E1 + 1.0) as being close to those to the right of E2. This procedure + * tries to decrease imed and to increase jmed. + */ +{ + long i; + double temp; + WorkType *work = res->work; + + if (*r > *imed || *jmed > *s) + return; + +#ifdef DEBUG + printf ("ENTER dlimslice "); + num_WriteD (work->dlim, 10, 5, 1); + printf (" %5ld %5ld %5ld %5ld %3d ", *r, *imed, *jmed, *s, c); + util_WriteBool (Tor, 5); + printf ("\n"); +#endif + + if (Tor) { + temp = A[*s][c] - 1.0; + i = *r; + while (i <= *imed && A[i][c] - temp < work->dlim) + ++i; + *imed = i - 1; + temp = A[*r][c] + 1.0; + i = *s; + while (i >= *jmed && temp - A[i][c] < work->dlim) + --i; + *jmed = i + 1; + + } else { + temp = A[*jmed][c]; + i = *imed; + while (i >= *r && temp - A[i][c] < work->dlim) + --i; + *r = i + 1; + temp = A[*imed][c]; + i = *jmed; + while (i <= *s && A[i][c] - temp < work->dlim) + ++i; + *s = i - 1; + } + +#ifdef DEBUG + printf ("EXIT dlimslice "); + printf (" %5ld %5ld %5ld %5ld\n", *r, *imed, *jmed, *s); +#endif +} + + +/*=========================================================================*/ + +void snpair_MiniProc0 (snpair_Res * res, snpair_PointType T[], long r, + long s, long u, long v, int junk1, int junk2) +/* + * Call "res->Distance" for each point of T[r..s] with each point + * of T[u..v]. + */ +{ + long i, j; + + for (i = r; i <= s; i++) + for (j = u; j <= v; j++) + res->Distance (res, T[i], T[j]); +} + + +/*=========================================================================*/ + +void snpair_MiniProc1 (snpair_Res * res, snpair_PointType T[], long r, + long s, long u, long v, int np, int c) +/* + * Compute the distance between each point of the set E1 = T[r..s] and + * those of E2 = T[u..v]. We consider only the pairs for which the + * differences between the c-th coordinate is <= dlim. + * Assume that the points of E1 and those of E2 are sorted with respect to + * coordinate c. If we have the case of snpair_DistanceCP, updates dlim and + * dlimp whenever a shorter value is found. + */ +{ + long inf; + long l, k, j, i; + double high, low; + WorkType *work = res->work; + +#ifdef DEBUG + printf ("ENTER MiniProc1 "); + num_WriteD (work->dlim, 10, 5, 1); + printf (" %5ld %5ld %5ld %5ld %3d\n", r, s, u, v, np); + if (v < r) + printf ("MiniProc1 with v < r !!!\n"); + util_Assert (np <= work->Maxnp, "MiniProc1: np > Maxnp"); + util_Assert ((s < u) || (v < r), + "MiniProc1: Overlap of E1 and E2 dans MiniProc"); +#endif + + if (s < r || v < u) + return; + inf = u; + /* sup = v; */ + +#ifdef DEBUG + for (i = r; i < s; i++) + util_Assert (T[i][c] <= T[i + 1][c], "Wrong order in MiniProc1"); + for (i = u; i < v; i++) + util_Assert (T[i][c] <= T[i + 1][c], "Wrong order in MiniProc1"); +#endif + + + for (i = r; i <= s; i++) { + low = T[i][c] - work->dlim; + high = low + 2.0 * work->dlim; + /* consider only points at distance <= dlim of T[i] w.r. to coord. c */ + while (inf <= v && T[inf][c] <= low) + ++inf; + j = inf; + while (j <= v && T[j][c] < high) { + res->Distance (res, T[i], T[j]); + ++j; + } + if (work->Torus) { /* AND (np <= kk): does not work with this + cond. */ + + /* Search for close points in the torus */ + low += 1.0; + high -= 1.0; + k = u; + l = v; + while (k <= v && T[k][c] < high) { + res->Distance (res, T[i], T[k]); + ++k; + } + while (l >= u && T[l][c] > low) { + res->Distance (res, T[i], T[l]); + --l; + } + } + } +} + + +/*=========================================================================*/ + +void snpair_CheckBoundary (snpair_Res * res, long r, long s, long u, long v, + int nr, int nrb, int np, int c) +/* + * Compute the minimal distance between the points of the sets E1 = A[r..s] + * and E2 = A[u..v]. + * nrb is the recursion level of the calls of snpair_CheckBoundary. + * A always stands for Points[np], sorted with respect to coordinate c. + */ +{ + long jmed2, imed2; + long jmed, imed; + long nextc; + lebool newc; + snpair_PointTableType B, A; + WorkType *work = res->work; + +#ifdef DEBUG + printf ("CheckBoundary: "); + printf (" %8ld %8ld %8ld %8ld %3d %3d %3d %3d\n", + r, s, u, v, nr, nrb, np, c); +#endif + + if (r > s || u > v) + return; + + util_Assert (np <= work->Maxnp, "np > Maxnp in snpair_CheckBoundary"); + A = res->Points[np]; + newc = ((nrb - 1) % work->L2) == 0; + if (newc && np < work->Maxnp) { + B = res->Points[np + 1]; + ++np; + if (c < work->kk) + nextc = c + 1; + else + nextc = 1; + + /* Copy the remaining points in the table of level np+1, then */ + /* sort with respect to coordinate nextc. */ + CopyPoints (A, B, r, s); + CopyPoints (A, B, u, v); + snpair_QuickSort (B, r, s, nextc); + snpair_QuickSort (B, u, v, nextc); + + } else { + nextc = c; + B = A; + } + + if ((nrb >= work->kk || s - r < snpair_env.Seuil2) + || v - u < snpair_env.Seuil2) { + /* Max recursion or small sets of points */ + res->MiniProc (res, B, r, s, u, v, np, nextc); + return; + } + + /* We halve each set of points, and we check each half on one side */ + /* with each half of the other side. */ + imed = (r + s) / 2; + jmed = (u + v) / 2; + + /* Check the halves which are face to face */ + snpair_CheckBoundary (res, r, imed, u, jmed, nr + 1, nrb + 1, np, nextc); + snpair_CheckBoundary (res, imed + 1, s, jmed + 1, v, nr + 1, nrb + 1, np, + nextc); + + /* Check the other (crossed) halves */ + if ((work->Torus && np <= work->kk) && newc) { + imed2 = imed; + jmed2 = jmed + 1; + dlimSlice (res, B, &r, &imed2, &jmed2, &v, nextc, TRUE); + snpair_CheckBoundary (res, r, imed2, jmed2, v, nr + 1, nrb + 1, np, + nextc); + + imed2 = imed + 1; + jmed2 = jmed; + dlimSlice (res, B, &u, &jmed2, &imed2, &s, nextc, TRUE); + snpair_CheckBoundary (res, u, jmed2, imed2, s, nr + 1, nrb + 1, np, + nextc); + } + + jmed2 = jmed + 1; + imed2 = imed + 1; + if (newc) + dlimSlice (res, B, &r, &imed, &jmed2, &v, nextc, FALSE); + snpair_CheckBoundary (res, r, imed, jmed + 1, v, nr + 1, nrb + 1, np, + nextc); + if (newc) + dlimSlice (res, B, &u, &jmed, &imed2, &s, nextc, FALSE); + snpair_CheckBoundary (res, u, jmed, imed + 1, s, nr + 1, nrb + 1, np, + nextc); +} + + +/*=========================================================================*/ + +static void Setdlim (snpair_Res *res, snpair_PointType A[], long r, long s) +/* + * Used in snpair_BickelBreiman to update dlim + */ +{ + long i; + WorkType *work = res->work; + + work->dlimp = 0.0; + for (i = r; i <= s; i++) { + if (A[i][0] > work->dlimp) + work->dlimp = A[i][0]; + } + if (work->pp == 0 || work->pp == 1) + work->dlim = work->dlimp; + else if (work->pp == 2) + work->dlim = sqrt (work->dlimp); + else + work->dlim = pow (work->dlimp, work->Invp); + +#ifdef DEBUG + printf ("Setdlim: "); + num_WriteD (work->dlim, 10, 5, 1); + printf ("\n"); +#endif +} + + +/*=========================================================================*/ + +void snpair_FindClosePairs (snpair_Res * res, long r, long s, + int nr, int np, int c) +/* + * Checks whether the minimal distance between the 2 nearest points, + * amongst those with indices [r..s] in the table of level np, is < dlim. + * If so, updates dlim and dlimp. A and B are always Points [np] and + * Points [np+1]. + * Assume that A = Point [np] is sorted with respect to coordinate c. + */ +{ + long jmed2; + long imed2; + long imed; + long nextc; /* Next coordinate to be used */ + snpair_PointTableType B; + snpair_PointTableType A; + WorkType *work = res->work; + + /* IF (((nr-1) MOD L) = 0) THEN newc := TRUE ELSE newc := FALSE END; */ +#ifdef DEBUG + printf ("FindClosePairs: "); + printf (" %8ld %8ld %3d %3d %3d\n", r, s, nr, np, c); +#endif + + util_Assert (np <= work->Maxnp, "np > Maxnp in snpair_FindClosePairs"); + A = res->Points[np]; + if (s - r < snpair_env.Seuil1) { + res->VerifPairs (res, A, r, s, np, c); + /* Here we are finished */ + return; + } + + /* We divide the points in 2 approximately equal sets E1 and E2; */ + /* then recursions upon the sets E1 and E2. */ + imed = (r + s) / 2; + if (nr % work->L1 == 0 && np < work->Maxnp && np < work->kk) { + /****** Condition np < kk is temporary... ********/ + util_Assert (np == 1 + (nr - 1) / work->L1, + "Bad np in snpair_FindClosePairs"); + /* IF np >= Maxnp THEN VerifPairs (A^, r, s, nr, c); RETURN END; */ + + /* We shall now increase np and switch coordinate. */ + /* Copy the points in a new table for the next level. */ + B = res->Points[np + 1]; + CopyPoints (A, B, r, s); + if (c < work->kk) + nextc = c + 1; + else + nextc = 1; + util_Assert (nextc == 1 + (np % work->kk), + "Bad nextc dans snpair_FindClosePairs"); + snpair_QuickSort (B, r, imed, nextc); + snpair_QuickSort (B, imed + 1, s, nextc); + snpair_FindClosePairs (res, r, imed, nr + 1, np + 1, nextc); + snpair_FindClosePairs (res, imed + 1, s, nr + 1, np + 1, nextc); + + } else { + snpair_FindClosePairs (res, r, imed, nr + 1, np, c); + snpair_FindClosePairs (res, imed + 1, s, nr + 1, np, c); + } + + /* It remains to check the boundary between E1 and E2. */ + if (work->kk == 1) { + res->Distance (res, A[imed], A[imed + 1]); + if (work->Torus) + res->Distance (res, A[r], A[s]); + return; + } + + /* Bring m and n closer in order to sqeeze only the points which could */ + /* be at a distance less than dlim from the median. */ + if (work->BBFlag) + Setdlim (res, A, r, s); + if (work->Torus && np <= work->kk && (nr - 1) % work->L1 == 0) { + imed2 = imed; + jmed2 = imed + 1; + dlimSlice (res, A, &r, &imed2, &jmed2, &s, c, TRUE); + snpair_CheckBoundary (res, r, imed2, jmed2, s, nr, 1, np, c); + } + + jmed2 = imed + 1; + dlimSlice (res, A, &r, &imed, &jmed2, &s, c, FALSE); + snpair_CheckBoundary (res, r, imed, jmed2, s, nr, 1, np, c); +} + + +/*=========================================================================*/ + +#if 0 +#define Epsilon 1.0e-10 + +static double Probsup (double b, double c, double x) +{ + int jsup; + int msup; + int m; + int j; + double comb; + double mLR; + double jLR; + double mFact; + double Sum2; + double Sum; + double Previous; + + if (x < 0.0) + return 0.0; + + Sum = 0.0; + mFact = 1.0; + if (x <= 0.0) { + msup = c * b; + if (msup > 100) { + msup = 100; + util_Warning (TRUE, "Probsup: msup > 100. Reset to 100"); + } + for (m = 1; m <= msup; m++) { + mLR = m; + mFact *= mLR; + Sum += (pow (b, mLR) / mFact) * (1.0 - mLR / (c * b)); + } + if (msup >= 0) + Sum += 1.0; + return Sum * exp (-b); + } + + Previous = -1.0; + m = 1; + msup = c * b + x; + if (msup > 100) { + msup = 100; + util_Warning (TRUE, "Probsup: msup > 100. Reset to 100"); + } + while (m <= msup && Sum - Previous > Epsilon) { + Previous = Sum; + Sum2 = 0.0; + mLR = m; + mFact *= mLR; + jsup = x; + if (jsup > m) { + jsup = m; + util_Warning (TRUE, "Probsup: jsup > m. Reset to m"); + } + comb = 1.0; + for (j = 0; j <= jsup; j++) { + jLR = j; + Sum2 += comb * pow (jLR - x, jLR) * + pow (c * b + x - jLR, mLR - jLR - 1.0); + comb *= (mLR - jLR) / (jLR + 1.0); + } + Sum += (c * b + x - mLR) / (mFact * pow (c, mLR)) * Sum2; + ++m; + } + if (msup >= 0) + Sum += 1.0; + return Sum * exp (-b); +} + + +/*=========================================================================*/ + +static double Probinf (double b, double c, double x) +{ + int msup; + int m; + double mLR; + double mFact; + double Sum; + + if (x >= 0.0) + return 1.0; + + msup = c * b + x; + if (msup > 100) { + msup = 100; + util_Warning (TRUE, "Probinf: msup > 100. Reset to 100"); + } + Sum = 0.0; + mFact = 1.0; + for (m = 1; m <= msup; m++) { + mLR = m; + mFact *= mLR; + Sum += exp (-(mLR - x) / c) * + (pow (mLR - x, mLR - 1.0) / (pow (c, mLR) * mFact)); + } + if (msup >= 0) + Sum = -(x * Sum) + exp (x / c); + return Sum; +} + + +/*=========================================================================*/ + +static double FDistGPlus (double Bidon, double c) +/* + * Obsolete. This discontinuous distribution uses a complicated statistic + * and did not seem sensitive. We don't use it anymore. + + * See the reference + * P. L'Ecuyer, J.-F. Cordeau, and R. Simard, "Close-Point Spatial Tests + * and their Application to Random Number Generators", + * Operations Research, 48, 2 (2000), 308--317 + * + */ +{ + int lSup; + int l; + double lLR; + double lFact; + double Previous; + double Sum; + + if ((!GPlusFlag || GPlust0 != t0) || GPlust1 != t1) { + GPlust0 = t0; + GPlust1 = t1; + GPlusFlag = TRUE; + /* + fdist_FindJumps (W, Detail); + + FindJumpsKnown (Bidon, FDistGPlus, GPlust0, 20.0, 0.00001, &GPlusNJump, + &GPlusJumpX, &GPlusJumpYBottom, &GPlusJumpYTop);*/ + } + + if (c < 0.0) + return 0.0; + l = 1; + Sum = 0.0; + Previous = -1.0; + lFact = 1.0; + lSup = GPlust0 * c; + while (l <= lSup && Sum - Previous > Epsilon) { + Previous = Sum; + lLR = l; + lFact *= lLR; + Sum += pow (GPlust0, lLR) / lFact * + Probsup (GPlust1 - GPlust0, c, GPlust0 * c - lLR); + ++l; + } + Sum += Probsup (GPlust1 - GPlust0, c, GPlust0 * c); + return Sum * exp (-GPlust0); +} + + +/*=========================================================================*/ + +static double FDistGMinus (double Bidon, double c) +/* + * Obsolete. This discontinuous distribution uses a complicated statistic + * and did not seem sensitive. We don't use it anymore. + + * See the reference + * P. L'Ecuyer, J.-F. Cordeau, and R. Simard, "Close-Point Spatial Tests + * and their Application to Random Number Generators", + * Operations Research, 48, 2 (2000), 308--317 + * + */ +{ + int l; + double lLR; + double lFact; + double Previous; + double Sum; + + if ((!GMinusFlag || GMinust0 != t0) || GMinust1 != t1) { + GMinust0 = t0; + GMinust1 = t1; + GMinusFlag = TRUE; + /* + FindJumpsKnown (Bidon, FDistGMinus, GMinust1, 20.0, 0.00001, + &GMinusNJump, &GMinusJumpX, &GMinusJumpYBottom, &GMinusJumpYTop); + */ + } + + if (c < 0.0) + return 0.0; + l = 1; + Sum = 0.0; + Previous = -1.0; + lFact = 1.0; + while (Sum - Previous > Epsilon) { + Previous = Sum; + lLR = l; + lFact *= lLR; + Sum += pow (GMinust0, lLR) / lFact * + Probinf (GMinust1 - GMinust0, c, GMinust0 * c - lLR); + ++l; + } + Sum += Probinf (GMinust1 - GMinust0, c, GMinust0 * c); + return Sum * exp (-GMinust0); +} + + +/*=========================================================================*/ + +static double FDistHPlus (double b, double x) +/* + * Obsolete. This discontinuous distribution uses a complicated statistic + * and did not seem sensitive. We don't use it anymore. + + * See the reference + * P. L'Ecuyer, J.-F. Cordeau, and R. Simard, "Close-Point Spatial Tests + * and their Application to Random Number Generators", + * Operations Research, 48, 2 (2000), 308--317 + * + */ +{ + int msup; + int jsup; + int m; + int j; + double comb; + double mLR; + double jLR; + double mFact; + double Sum2; + double Sum; + double Previous; + + if ((!HPlusFlag || HPlust0 != t0) || HPlust1 != t1) { + /* this function has a single jump at x = 0 */ + HPlust0 = t0; + HPlust1 = t1; + HPlusFlag = TRUE;/* + FindJumpsKnown (b, FDistHPlus, 1.0, 0.00001, 1.E-6, &HPlusNJump, + &HPlusJumpX, &HPlusJumpYBottom, &HPlusJumpYTop);*/ + } + + if (x < 0.0) + return 0.0; + + Sum = 0.0; + mFact = 1.0; + if (x <= 0.0) { + msup = b; + if (msup > 100) + msup = 100; + for (m = 1; m <= msup; m++) { + mLR = m; + mFact *= mLR; + Sum += pow (b, mLR) / mFact * (1.0 - mLR / b); + } + if (msup >= 0) + Sum += 1.0; + return Sum * exp (-b); + } + + Previous = -1.0; + m = 1; + msup = b + x; + if (msup > 100) + msup = 100; + while (m <= msup && Sum - Previous > Epsilon) { + Previous = Sum; + Sum2 = 0.0; + mLR = m; + mFact *= mLR; + jsup = x; + if (jsup > m) + jsup = m; + comb = 1.0; + for (j = 0; j <= jsup; j++) { + jLR = j; + Sum2 += comb*pow (jLR - x, jLR)*pow (b + x - jLR, mLR - jLR - 1.0); + comb *= (mLR - jLR) / (jLR + 1.0); + } + Sum += (b + x - mLR) / mFact * Sum2; + ++m; + } + if (msup >= 0) + Sum += 1.0; + return Sum * exp (-b); +} + + +/*=========================================================================*/ + +static double FDistHMinus (double b, double x) +/* + * Obsolete. This discontinuous distribution uses a complicated statistic + * and did not seem sensitive. We don't use it anymore. + + * See the reference + * P. L'Ecuyer, J.-F. Cordeau, and R. Simard, "Close-Point Spatial Tests + * and their Application to Random Number Generators", + * Operations Research, 48, 2 (2000), 308--317 + * + */ +{ + int msup; + int m; + double mLR; + double mFact; + double Sum; + + if ((!HMinusFlag || HMinust0 != t0) || HMinust1 != t1) { + HMinust0 = t0; + HMinust1 = t1; + HMinusFlag = TRUE; + /* + FindJumpsKnown (b, FDistHMinus, -b, 0.0001, 0.00001, &HMinusNJump, + &HMinusJumpX, &HMinusJumpYBottom, &HMinusJumpYTop); */ + } + + if (x >= 0.0) + return 1.0; + + msup = b + x; + if (msup > 100) + msup = 100; + Sum = 0.0; + mFact = 1.0; + for (m = 1; m <= msup; m++) { + mLR = m; + mFact *= mLR; + Sum += exp (-(mLR - x)) * (pow (mLR - x, mLR - 1.0) / mFact); + } + + if (msup >= 0) + Sum = -(x * Sum) + exp (x); + return Sum; +} + +#endif + +/*=========================================================================*/ + +static void snpair_AllocPoints (snpair_Res *res, long n) +{ + long i; + WorkType *work = res->work; + + if (n <= 0) + return; + /* Allocates Maxnp tables of pointers to the points; one for each level + of recursion */ + for (i = 1; i <= work->Maxnp; i++) + res->Points[i] = + util_Calloc ((size_t) (n + 1), sizeof (snpair_PointType)); + + /* Allocates memory for the points; initially, only the first table + of pointers, i = 1, points to the points. */ + for (i = 0; i <= n; i++) + res->Points[1][i] = util_Calloc ((size_t) (work->kk + 1), + sizeof (double)); + + res->CloseDist = util_Calloc ((size_t) work->mcd + 1, sizeof (double)); +} + + +/*=========================================================================*/ + +static void snpair_DeletePoints (snpair_Res * res) +/* + * To clean up after the test. + */ +{ + long i; + long n = res->n; + WorkType *work = res->work; + + if (n <= 0) + return; + res->CloseDist = util_Free (res->CloseDist); + + for (i = 0; i <= n; i++) + util_Free (res->Points[1][i]); + + for (i = 1; i <= work->Maxnp; i++) + res->Points[i] = util_Free (res->Points[i]); +} + + +/*=========================================================================*/ + +static void AllocClosePairs ( + snpair_Res *res, /* Results holder */ + long N, + long n, + int m + ) +{ + snpair_AllocPoints (res, n); + res->Yn = statcoll_Create (m, "Yn: The m jumps of Y"); + res->Y = statcoll_Create (N * m + 100, + "Y: All the jumps of Y, superposed"); + res->U = statcoll_Create (N * m, + "U: The jumps of Y transformed into uniforms"); + res->V = statcoll_Create (N * m + 100, "V: A copy of the uniforms"); + res->S = statcoll_Create (N * m + 100, "S: Spacings"); + res->TheWn = statcoll_Create (N, "The N values of the W_n"); + res->TheWni = statcoll_Create (N * m, "The Nm values of the W_{n,i}"); + res->ThepValAD = statcoll_Create (N, "The p-values of A2"); + res->BitMax = statcoll_Create (N, "Largest bit distances"); +} + + +/*=========================================================================*/ + +static void CleanClosePairs (snpair_Res * res) +{ + int i; + res->Yn = statcoll_Delete (res->Yn); + res->Y = statcoll_Delete (res->Y); + res->U = statcoll_Delete (res->U); + res->V = statcoll_Delete (res->V); + res->S = statcoll_Delete (res->S); + res->TheWn = statcoll_Delete (res->TheWn); + res->TheWni = statcoll_Delete (res->TheWni); + res->ThepValAD = statcoll_Delete (res->ThepValAD); + res->BitMax = statcoll_Delete (res->BitMax); + snpair_DeletePoints (res); + for (i = 0; i < snpair_StatType_N; i++) { + res->sVal[i] = -1.0; + res->pVal[i] = -1.0; + } +} + + +/*=========================================================================*/ + +static void InitRes ( + snpair_Res *res, /* Results holder */ + long N, /* Number of replications */ + long n, /* Number of points */ + int m /* Number of closest distances kept */ + ) +/* + * Initializes the res structure + */ +{ + if (res->CleanFlag) + CleanClosePairs (res); + AllocClosePairs (res, N, n, m); + res->n = n; + res->CleanFlag = TRUE; +} + + +/*-------------------------------------------------------------------------*/ + +snpair_Res *snpair_CreateRes (void) +{ + snpair_Res *res; + res = util_Malloc (sizeof (snpair_Res)); + memset (res, 0, sizeof (snpair_Res)); + res->work = util_Malloc (sizeof (WorkType)); + res->CleanFlag = FALSE; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void snpair_DeleteRes (snpair_Res * res) +{ + if (res == NULL) + return; + if (res->CleanFlag) + CleanClosePairs (res); + res->work = util_Free (res->work); + util_Free (res); +} + + +/*=========================================================================*/ + +static void WriteSeuils (WorkType * work, lebool flag, double mu2, + double nLR, double kLR) +{ + printf ("\n Seuil1 = %2d\n Seuil2 = %2d\n " + "Seuil3 = %2d\n Seuil4 = %2d\n" + " L1 = %2d\n L2 = %2d\n s1 = ", snpair_env.Seuil1, + snpair_env.Seuil2, snpair_env.Seuil3, snpair_env.Seuil4, work->L1, + work->L2); + + /* s1 = n / 2^{kL1} */ + num_WriteD (nLR * pow (2.0, -kLR * work->L1), 9, 2, 2); + printf ("\n s2 = "); + /* s2 = n / 2^{kL2} */ + num_WriteD (nLR * pow (2.0, -kLR * work->L2), 9, 2, 2); + printf ("\n\n"); + + if (flag) { + printf (" The minimal distance, to the power k, should be" + " approximately\n exponential with mean mu2 = "); + num_WriteD (mu2, 12, 4, 2); + printf ("\n\n dlim1 = "); + num_WriteD (work->dlim1, 15, 5, 3); + printf ("\n dlim1p = "); + num_WriteD (work->dlim1p, 15, 5, 3); + printf ("\n\n"); + } +} + + +/*=========================================================================*/ + +static void CalcSeuils (WorkType * work, long k, long m, lebool flag, + double mu2, double nLR, double kLR) +{ + work->L1 = 1 + num_Log2 (nLR / snpair_env.Seuil3) / k; + work->L2 = 1 + num_Log2 (nLR / snpair_env.Seuil4) / k; + if (work->L1 < 1) + work->L1 = 1; + if (work->L2 < 1) + work->L2 = 1; + if (k < 6 && work->L1 < 2) + work->L1 = 2; + if (k < 6 && work->L2 < 2) + work->L2 = 2; + work->dlim1 = pow (m * mu2, 1.0 / k); + work->dlim1p = pow (work->dlim1, work->pLR); + if (swrite_Parameters) + WriteSeuils (work, flag, mu2, nLR, kLR); +} + + +/*=========================================================================*/ + +void snpair_WriteDataCP (unif01_Gen * gen, char *TestName, + long N, long n, int r, int t, int p, int m, lebool Torus) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", t = %1d,", t); + if (p >= 0) + printf (" p = %1d,", p); + printf (" m = %1d, Torus = ", m); + util_WriteBool (Torus, 5); + printf ("\n\n"); +} + + +/*=========================================================================*/ +#define SPACINGS_9 +/* + * La constante SPACINGS permet l'inclusion des 4 tests de ClosePairs suivants + * qui sont mis en commentaire sinon: NP-S, NP-PR, mNP1-S, mNP2-S. + */ + +void snpair_WriteResultsCP (unif01_Gen * gen, chrono_Chrono * Timer, + snpair_Res * res, long N, long m) +{ + printf ("\n---------------------------------------\n"); + printf ("Test based on the 2 nearest points (NP):\n\n"); + + if (N == 1) { + printf ("The closest distance : "); + num_WriteD (res->CloseDist[1], 7, 2, 2); + printf ("\n"); + gofw_Writep1 (res->pVal[snpair_NP]); + } else { + printf ("Stat. AD on the N values (NP) :"); + gofw_Writep2 (res->sVal[snpair_NP], res->pVal[snpair_NP]); +#ifdef SPACINGS + printf ("Stat. AD after spacings (NP-S) :"); + gofw_Writep2 (res->sVal[snpair_NPS], res->pVal[snpair_NPS]); + printf ("Stat. AD after power ratio (NP-PR) :"); + gofw_Writep2 (res->sVal[snpair_NPPR], res->pVal[snpair_NPPR]); +#endif + } + + if (m > 1) { + printf ("\nA2 test based on the spacings between the\n" + " successive jump times of process Y_n(t):\n\n"); + printf ("A2 test on the values of A2 (m-NP) :"); + gofw_Writep2 (res->sVal[snpair_mNP], res->pVal[snpair_mNP]); + + if (N > 1) { + printf ("Test on the Nm values of W_{n,i}(mNP1):"); + gofw_Writep2 (res->sVal[snpair_mNP1], res->pVal[snpair_mNP1]); +#ifdef SPACINGS + printf ("Stat. AD after spacings (mNP1-S) :"); + gofw_Writep2 (res->sVal[snpair_mNP1S], res->pVal[snpair_mNP1S]); +#endif + printf ("Test on the jump times of Y\n (superposition of Yn):\n\n"); + printf ("Expected number of jumps of Y = mN : %7ld\n", m*N); + printf ("Number of jumps of Y "); + if (res->sVal[snpair_NJumps] >= N*NUM_JUMPS_LIM) + printf ("> %6.0f *****\n", res->sVal[snpair_NJumps]); + else + printf (": %7.0f\n", res->sVal[snpair_NJumps]); + gofw_Writep1 (res->pVal[snpair_NJumps]); + + if (res->Y->NObs > 0) { + printf ("Stat. AD (mNP2) :"); + gofw_Writep2 (res->sVal[snpair_mNP2], res->pVal[snpair_mNP2]); +#if 1 + if (snpair_mNP2S_Flag) { + printf ("Stat. AD after spacings (mNP2-S) :"); + gofw_Writep2 (res->sVal[snpair_mNP2S], res->pVal[snpair_mNP2S]); + } +#endif + } + } + } + swrite_Final (gen, Timer); +} + + +/*=========================================================================*/ + +void snpair_ClosePairs (unif01_Gen * gen, snpair_Res * res, + long N, long n, int r, int k, int p, int m) +/* + * Looks at the m closest pairs in the torus and the first m jumps of the + * process Y_n(t). A simplified version of snpair_ClosePairs. + */ +{ + long j; + long i; + long Seq; + double Wn; + double t1; + snpair_PointType T; + double x; + double NextJump; + double Jump; + double mu2; /* Expected minimum distance */ + double A2; + double Vol; /* Volume of unit sphere in k dimension */ + double mLR, nLR, kLR; + fmass_INFO Mass; + double pLeft, pRight; + statcoll_Collector *Q; + WorkType *work; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "snpair_ClosePairs test"; + + Timer = chrono_Create (); + if (swrite_Basic) + snpair_WriteDataCP (gen, TestName, N, n, r, k, p, m, TRUE); + + /* util_Assert (k <= snpair_MaxDim, "snpair_ClosePairs: k > + snpair_MaxDim"); + util_Assert (n <= snpair_MaxNumPoints, + "snpair_ClosePairs: n > snpair_MaxNumPoints"); */ + util_Assert (m > 0, "snpair_ClosePairs: m <= 0"); + util_Assert (m <= snpair_MAXM, "snpair_ClosePairs: m > snpair_MAXM"); + if (res == NULL) { + localRes = TRUE; + res = snpair_CreateRes (); + } + work = res->work; + work->Torus = TRUE; + work->kk = k; + work->pp = p; + work->mm = m; + kLR = k; + nLR = n; + mLR = m; + work->mcd = 2 * m; + if (p == 0) + work->pLR = 1.0; + else + work->pLR = p; + work->Invp = 1.0 / work->pLR; + if (k < snpair_MAXREC) + work->Maxnp = k; + else + work->Maxnp = snpair_MAXREC; + work->BBFlag = FALSE; /* Bickel-Breiman Flag */ + + Vol = num2_VolumeSphere ((double) p, k); + mu2 = 2.0 / (nLR * (nLR - 1.0) * Vol); + t1 = mLR; + + CalcSeuils (work, k, m, TRUE, mu2, nLR, kLR); + InitRes (res, N, n, m); + res->Distance = snpair_DistanceCP; + res->VerifPairs = snpair_VerifPairs1; + res->MiniProc = snpair_MiniProc1; + + /* Beginning of test */ + for (Seq = 1; Seq <= N; Seq++) { + + for (i = 1; i <= n; i++) { + /* Generate n points in dimension k */ + T = res->Points[1][i]; + for (j = 1; j <= k; j++) + T[j] = unif01_StripD (gen, r); + } + res->NumClose = 0; + work->dlimp = work->dlim = kLR; /* Initial upper bounds */ + snpair_QuickSort (res->Points[1], 1, n, 1); + snpair_FindClosePairs (res, 1, n, 1, 1, 1); + Wn = 1.0 - exp (-pow (res->CloseDist[1], kLR) / mu2); + statcoll_AddObs (res->TheWn, Wn); + statcoll_Init (res->Yn, m); + statcoll_Init (res->U, m); + if (m > 1) { + /* Calculate the spacings Delta_{n,i} between the jumps of Y_n, */ + /* then the W^*_{n(i)}, which are in principle i.i.d. U(0,1). */ + Jump = 0.0; + for (i = 1; i <= m; i++) { + NextJump = pow (res->CloseDist[i], kLR) / mu2; + statcoll_AddObs (res->Yn, NextJump); + x = 1.0 - exp (-(NextJump - Jump)); + statcoll_AddObs (res->U, x); + statcoll_AddObs (res->TheWni, x); + Jump = NextJump; + } + + tables_QuickSortD (res->U->V, 1, m); + /* res->U should now contain m random var. i.i.d U(0,1), sorted */ + if (swrite_Collectors) { + statcoll_Write (res->Yn, 5, 14, 4, 3); + statcoll_Write (res->U, 5, 14, 4, 3); + } + A2 = gofs_AndersonDarling (res->U->V, m); + x = fbar_AndersonDarling (m, A2); + statcoll_AddObs (res->ThepValAD, x); + + if (N > 1) { + /* Put in res->Y all the jumps between 0 and t1 */ + for (i = 1; i <= res->NumClose; i++) { + NextJump = pow (res->CloseDist[i], kLR) / mu2; + if (NextJump <= t1) + statcoll_AddObs (res->Y, NextJump); + } + } + } + } + + if (N == 1) + res->pVal[snpair_NP] = 1.0 - Wn; + else { + Q = res->TheWn; + tables_QuickSortD (Q->V, 1, N); + /* Test NP at level 1 */ + res->sVal[snpair_NP] = gofs_AndersonDarling (Q->V, N); + res->pVal[snpair_NP] = fbar_AndersonDarling (N, res->sVal[snpair_NP]); + +#ifdef SPACINGS + /* Test NP with the spacings */ + tables_CopyTabD (Q->V, res->V->V, 1, N); + gofs_DiffD (res->V->V, res->S->V, 1, N, 0.0, 1.0); + gofs_IterateSpacings (res->V->V, res->S->V, N); + tables_QuickSortD (res->V->V, 1, N); + res->sVal[snpair_NPS] = gofs_AndersonDarling (res->V->V, N); + res->pVal[snpair_NPS] = + fbar_AndersonDarling (N, res->sVal[snpair_NPS]); + /* Test NP with power ratio */ + tables_CopyTabD (Q->V, res->V->V, 1, N); + gofs_PowerRatios (res->V->V, N); + tables_QuickSortD (res->V->V, 1, N); + res->sVal[snpair_NPPR] = gofs_AndersonDarling (res->V->V, N); + res->pVal[snpair_NPPR] = + fbar_AndersonDarling (N, res->sVal[snpair_NPPR]); +#endif + } + + if (m > 1) { + if (N == 1) { + res->sVal[snpair_mNP] = A2; + res->pVal[snpair_mNP] = res->ThepValAD->V[1]; + } else { + tables_CopyTabD (res->ThepValAD->V, res->V->V, 1, N); + tables_QuickSortD (res->V->V, 1, N); + res->sVal[snpair_mNP] = gofs_AndersonDarling (res->V->V, N); + res->pVal[snpair_mNP] = + fbar_AndersonDarling (N, res->sVal[snpair_mNP]); + Q = res->TheWni; + tables_QuickSortD (Q->V, 1, Q->NObs); + /* Here, Q->NObs = N*m */ + res->sVal[snpair_mNP1] = gofs_AndersonDarling (Q->V, Q->NObs); + res->pVal[snpair_mNP1] = + fbar_AndersonDarling (Q->NObs, res->sVal[snpair_mNP1]); +#ifdef SPACINGS + /* Test NP with the spacings */ + tables_CopyTabD (Q->V, res->V->V, 1, Q->NObs); + gofs_DiffD (res->V->V, res->S->V, 1, Q->NObs, 0.0, 1.0); + gofs_IterateSpacings (res->V->V, res->S->V, Q->NObs); + tables_QuickSortD (res->V->V, 1, Q->NObs); + res->sVal[snpair_mNP1S] = gofs_AndersonDarling (res->V->V, Q->NObs); + res->pVal[snpair_mNP1S] = + fbar_AndersonDarling (Q->NObs, res->sVal[snpair_mNP1S]); +#endif + /* Superposition process of all the jumps of Y_n in [0, t1]. + Conditionnally on TotJumps = res->Y^.NObs, these jumps should be + uniformly distributed in [0, t1]. */ + + Q = res->Y; + for (i = 1; i <= Q->NObs; i++) + Q->V[i] /= t1; + if (Q->NObs > 0) { + tables_QuickSortD (Q->V, 1, Q->NObs); + /* res->Y must now contain random var. i.i.d U(0,1), sorted */ + res->sVal[snpair_mNP2] = gofs_AndersonDarling (Q->V, Q->NObs); + res->pVal[snpair_mNP2] = + fbar_AndersonDarling (Q->NObs, res->sVal[snpair_mNP2]); + } + + Mass = fmass_CreatePoisson (N * m); + pLeft = fdist_Poisson2 (Mass, res->Y->NObs); + pRight = fbar_Poisson2 (Mass, res->Y->NObs); + fmass_DeletePoisson (Mass); + res->sVal[snpair_NJumps] = res->Y->NObs; + res->pVal[snpair_NJumps] = gofw_pDisc (pLeft, pRight); + +#if 1 + /* Test on res->Y with the spacings */ + statcoll_Init (res->V, Q->Dim); + statcoll_Init (res->S, Q->Dim); + tables_CopyTabD (Q->V, res->V->V, 1, Q->NObs); + gofs_DiffD (res->V->V, res->S->V, 1, Q->NObs, 0.0, 1.0); + gofs_IterateSpacings (res->V->V, res->S->V, Q->NObs); + tables_QuickSortD (res->V->V, 1, Q->NObs); + res->sVal[snpair_mNP2S] = gofs_AndersonDarling (res->V->V, Q->NObs); + res->pVal[snpair_mNP2S] = + fbar_AndersonDarling (Q->NObs, res->sVal[snpair_mNP2S]); +#endif + } + } + + if (swrite_Collectors) { + if (N > 1) + statcoll_Write (res->Y, 5, 14, 4, 3); + statcoll_Write (res->TheWn, 5, 14, 4, 3); + statcoll_Write (res->TheWni, 5, 14, 4, 3); + statcoll_Write (res->ThepValAD, 5, 14, 4, 3); + } + + if (swrite_Basic) + snpair_WriteResultsCP (gen, Timer, res, N, m); + if (localRes) + snpair_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ +#if 0 + +void snpair_ReTestY (long N, long n, int m, double tt0, double tt1) +/* + * Make more (experimental) tests on Y after a call to ClosePairs1 + * (To do?? We should renormalize the Y[i] by multiplying them by nM) + + ***************************************** + This procedure is not used anymore. It makes use of discontinuous + distribution functions and the associated statistics are very + complicated and did not seem sensitive. + **************************************** + */ +{ + long i; + double Bidon; + double x; + double iLR; + double Fact; + double HM; + double HP; + double GM; + double GP; + statcoll_Collector *Q = res->Y; + fdist_FUNC_JUMPS *GPJumps; /* All info on the jumps of G+ */ + fdist_FUNC_JUMPS *GMJumps; /* All info on the jumps of G- */ + fdist_FUNC_JUMPS *HPJumps; /* All info on the jumps of H+ */ + fdist_FUNC_JUMPS *HMJumps; /* All info on the jumps of H- */ + + /* Calculate statistics G+, G-, H+, H- */ + util_Assert (!swrite_AutoClean, + "snpair_ReTestY: swrite_AutoClean must be FALSE"); + util_Assert (res->Y != NULL, + "snpair_ReTestY: res->Y is a NULL pointer"); + + Fact = N * m; + for (i = 1; i <= Q->NObs; i++) + Q->V[i] *= Fact; + HP = 0.0; + HM = 0.0; + i = 1; + while (Q->V[i] <= tt0 && i <= Q->NObs) + ++i; + GP = (i - 1) / tt0; + while (Q->V[i] <= tt1 && i <= Q->NObs) + ++i; + GM = (i - 1) / tt1; + if (i - 1 - tt1 < 0.0) + HM = i - 1 - tt1; + + for (i = 1; i <= Q->NObs; i++) { + if (Q->V[i] <= tt1) { + x = Q->V[i]; + iLR = i; + if (iLR - 1.0 - x < HM) + HM = iLR - 1.0 - x; + if (iLR - x > HP) + HP = iLR - x; + if (Q->V[i] >= tt0) { + if (iLR / x > GP) + GP = iLR / x; + if ((iLR - 1.0) / x < GM) + GM = (iLR - 1.0) / x; + } + } + } + + res->pVal[snpair_GPlus] = 1.0 - FDistGPlus (Bidon, GP); + res->sVal[snpair_GPlus] = GP; + res->pVal[snpair_GMinus] = 1.0 - FDistGMinus (Bidon, GM); + res->sVal[snpair_GMinus] = GM; + res->pVal[snpair_HPlus] = 1.0 - FDistHPlus (Bidon, HP); + res->sVal[snpair_HPlus] = HP; + res->pVal[snpair_HMinus] = 1.0 - FDistHMinus (Bidon, HM); + res->sVal[snpair_HMinus] = HM; + + if (swrite_Basic) { + printf ("Test on the statistic G+ :"); + gofw_Writep2 (GP, res->pVal[snpair_GPlus]); + printf ("\nTest on the statistic G- :"); + gofw_Writep2 (GM, res->pVal[snpair_GMinus]); + printf ("\nTest on the statistic H+ :"); + gofw_Writep2 (HP, res->pVal[snpair_HPlus]); + printf ("\nTest on the statistic H- :"); + gofw_Writep2 (HM, res->pVal[snpair_HMinus]); + printf ("\n"); + } +} + +#endif + +/*=========================================================================*/ + +static void InitBBp0k2 (void) +/* + * Initialize Bickel-Breiman distribution with p = 0, k = 2 + */ +{ + BB2[0] = 0.0; + BB2[1] = 6.6022859e-5; + BB2[2] = 2.111e-3; + BB2[3] = 1.10679e-2; + BB2[4] = 2.99898e-2; + BB2[5] = 5.80398e-2; + BB2[6] = 9.31672e-2; + BB2[7] = 1.326804e-1; + BB2[8] = 1.743017e-1; + BB2[9] = 2.168632e-1; + BB2[10] = 2.589057e-1; + BB2[11] = 2.996407e-1; + BB2[12] = 3.387514e-1; + BB2[13] = 3.758668e-1; + BB2[14] = 4.108985e-1; + BB2[15] = 4.442291e-1; + BB2[16] = 4.757295e-1; + BB2[17] = 5.053408e-1; + BB2[18] = 5.330166e-1; + BB2[19] = 5.589979e-1; + BB2[20] = 0.58358; + BB2[21] = 6.067753e-1; + BB2[22] = 6.281726e-1; + BB2[23] = 6.483016e-1; + BB2[24] = 6.670896e-1; + BB2[25] = 6.848204e-1; + BB2[26] = 7.016251e-1; + BB2[27] = 7.17358e-1; + BB2[28] = 7.319895e-1; + BB2[29] = 7.458925e-1; + BB2[30] = 7.589198e-1; + BB2[31] = 7.712947e-1; + BB2[32] = 7.82992e-1; + BB2[33] = 7.939033e-1; + BB2[34] = 8.044324e-1; + BB2[35] = 8.14079e-1; + BB2[36] = 8.233257e-1; + BB2[37] = 8.319796e-1; + BB2[38] = 8.402721e-1; + BB2[39] = 0.84794; + BB2[40] = 8.55173e-1; + BB2[41] = 8.621625e-1; + BB2[42] = 8.686291e-1; + BB2[43] = 8.748893e-1; + BB2[44] = 8.809175e-1; + BB2[45] = 8.864606e-1; + BB2[46] = 8.918151e-1; + BB2[47] = 8.968588e-1; + BB2[48] = 9.016258e-1; + BB2[49] = 9.061704e-1; + BB2[50] = 9.104084e-1; + BB2[51] = 9.143753e-1; + BB2[52] = 9.182571e-1; + BB2[53] = 9.219001e-1; + BB2[54] = 9.254505e-1; + BB2[55] = 9.28772e-1; + BB2[56] = 9.320133e-1; + BB2[57] = 9.351203e-1; + BB2[58] = 9.380936e-1; + BB2[59] = 9.408087e-1; + BB2[60] = 9.434704e-1; + BB2[61] = 9.459541e-1; + BB2[62] = 9.483018e-1; + BB2[63] = 0.95057; + BB2[64] = 9.526812e-1; + BB2[65] = 9.547303e-1; + BB2[66] = 9.566821e-1; + BB2[67] = 9.585939e-1; + BB2[68] = 9.603836e-1; + BB2[69] = 9.62073e-1; + BB2[70] = 9.637419e-1; + BB2[71] = 9.652689e-1; + BB2[72] = 9.666498e-1; + BB2[73] = 9.680299e-1; + BB2[74] = 9.693984e-1; + BB2[75] = 9.707229e-1; + BB2[76] = 9.720219e-1; + BB2[77] = 9.731801e-1; + BB2[78] = 9.742979e-1; + BB2[79] = 9.753166e-1; + BB2[80] = 9.763355e-1; + BB2[81] = 9.773626e-1; + BB2[82] = 9.782835e-1; + BB2[83] = 9.792146e-1; + BB2[84] = 9.800791e-1; + BB2[85] = 9.808841e-1; + BB2[86] = 9.816958e-1; + BB2[87] = 9.824477e-1; + BB2[88] = 9.831492e-1; + BB2[89] = 9.838786e-1; + BB2[90] = 9.845241e-1; + BB2[91] = 9.851295e-1; + BB2[92] = 9.857702e-1; + BB2[93] = 9.863849e-1; + BB2[94] = 9.869562e-1; + BB2[95] = 9.875006e-1; + BB2[96] = 9.879895e-1; + BB2[97] = 9.88473e-1; + BB2[98] = 9.889793e-1; + BB2[99] = 9.894184e-1; + BB2[100] = 9.898547e-1; + BB2[101] = 9.902526e-1; + BB2[102] = 9.906462e-1; + BB2[103] = 9.910496e-1; + BB2[104] = 9.914303e-1; + BB2[105] = 9.918174e-1; + BB2[106] = 9.921392e-1; + BB2[107] = 9.924491e-1; + BB2[108] = 9.92784e-1; + BB2[109] = 9.930638e-1; + BB2[110] = 9.933363e-1; + BB2[111] = 9.936298e-1; + BB2[112] = 9.93886e-1; + BB2[113] = 9.941112e-1; + BB2[114] = 9.943411e-1; + BB2[115] = 9.945669e-1; + BB2[116] = 9.947672e-1; + BB2[117] = 9.94994e-1; + BB2[118] = 9.951802e-1; + BB2[119] = 9.953648e-1; + BB2[120] = 9.955457e-1; + BB2[121] = 9.957099e-1; + BB2[122] = 9.959196e-1; + BB2[123] = 9.961046e-1; + BB2[124] = 9.962811e-1; + BB2[125] = 9.964261e-1; + BB2[126] = 9.965653e-1; + BB2[127] = 9.967088e-1; + BB2[128] = 0.99684; + BB2[129] = 9.969537e-1; + BB2[130] = 9.970835e-1; + BB2[131] = 9.972087e-1; +} + + +/*-------------------------------------------------------------------------*/ + +static void InitBBp2k2 (void) +/* + * Initialize Bickel-Breiman distribution with p = 2, k = 2 + */ +{ + BB4[0] = -8.2912955e-1; + BB4[1] = -9.4432194e-1; + BB4[2] = -1.0567132; + BB4[3] = -1.1679847; + BB4[4] = -1.2776563; + BB4[5] = -1.384483; + BB4[6] = -1.4916059; + BB4[7] = -1.5956447; + BB4[8] = -1.6994536; + BB4[9] = -1.8012517; + BB4[10] = -1.9014279; + BB4[11] = -2.0006153; + BB4[12] = -2.0997178; + BB4[13] = -2.1987994; + BB4[14] = -2.2959638; + BB4[15] = -2.391997; + BB4[16] = -2.4867876; + BB4[17] = -2.5815698; + BB4[18] = -2.6761017; + BB4[19] = -2.7658218; + BB4[20] = -2.8582757; + BB4[21] = -2.9522569; + BB4[22] = -3.0406141; + BB4[23] = -3.1311066; + BB4[24] = -3.2179075; + BB4[25] = -3.3057192; + BB4[26] = -3.3933087; + BB4[27] = -3.4815725; + BB4[28] = -3.5719191; + BB4[29] = -3.6592077; + BB4[30] = -3.7437809; + BB4[31] = -3.8274559; + BB4[32] = -3.9149689; + BB4[33] = -4.000307; + BB4[34] = -4.0874655; + BB4[35] = -4.1724253; + BB4[36] = -4.2619679; + BB4[37] = -4.3498336; + BB4[38] = -4.4349335; + BB4[39] = -4.5214761; + BB4[40] = -4.607099; + BB4[41] = -4.6921565; + BB4[42] = -4.7799781; + + BB5[0] = -4.5909e-3; + BB5[1] = -3.666e-4; + BB5[2] = 7.508e-5; + BB5[3] = 2.15483e-3; + BB5[4] = 1.115755e-2; + BB5[5] = 3.033271e-2; + BB5[6] = 5.881422e-2; + BB5[7] = 9.422896e-2; + BB5[8] = 1.3423286e-1; + BB5[9] = 1.7618124e-1; + BB5[10] = 2.1865118e-1; + BB5[11] = 2.6082507e-1; + BB5[12] = 3.0215075e-1; + BB5[13] = 3.4140313e-1; + BB5[14] = 3.7898955e-1; + BB5[15] = 4.1454877e-1; + BB5[16] = 4.4830003e-1; + BB5[17] = 4.7980029e-1; + BB5[18] = 5.093375e-1; + BB5[19] = 5.3717465e-1; + BB5[20] = 5.6357091e-1; + BB5[21] = 5.8817876e-1; +} + + +/*-------------------------------------------------------------------------*/ + +static void InitBBp0k15 (void) +/* + * Initialize Bickel-Breiman distribution with p = 0, k = 15 + */ +{ + BB3[0] = 0.0; + BB3[1] = 1.6778e-4; + BB3[2] = 2.6967455e-3; + BB3[3] = 1.28187e-2; + BB3[4] = 3.25519e-2; + BB3[5] = 0.06001; + BB3[6] = 9.28778e-2; + BB3[7] = 1.292254e-1; + BB3[8] = 1.674211e-1; + BB3[9] = 2.066797e-1; + BB3[10] = 2.439418e-1; + BB3[11] = 2.805974e-1; + BB3[12] = 3.156376e-1; + BB3[13] = 3.487236e-1; + BB3[14] = 3.804003e-1; + BB3[15] = 4.103833e-1; + BB3[16] = 4.394161e-1; + BB3[17] = 4.673735e-1; + BB3[18] = 4.935018e-1; + BB3[19] = 5.181638e-1; + BB3[20] = 5.403617e-1; + BB3[21] = 5.609553e-1; + BB3[22] = 5.813387e-1; + BB3[23] = 6.003938e-1; + BB3[24] = 6.188892e-1; + BB3[25] = 6.353537e-1; + BB3[26] = 6.509678e-1; + BB3[27] = 6.658608e-1; + BB3[28] = 6.797704e-1; + BB3[29] = 6.93198e-1; + BB3[30] = 7.059891e-1; + BB3[31] = 7.185495e-1; + BB3[32] = 7.306549e-1; + BB3[33] = 7.413516e-1; + BB3[34] = 7.517439e-1; + BB3[35] = 7.617069e-1; + BB3[36] = 7.709877e-1; + BB3[37] = 7.804121e-1; + BB3[38] = 7.898275e-1; + BB3[39] = 7.984594e-1; + BB3[40] = 8.058125e-1; + BB3[41] = 8.129582e-1; + BB3[42] = 8.199078e-1; + BB3[43] = 8.26626e-1; + BB3[44] = 8.332602e-1; + BB3[45] = 8.393936e-1; + BB3[46] = 8.452292e-1; + BB3[47] = 8.510694e-1; + BB3[48] = 8.569731e-1; + BB3[49] = 8.621826e-1; + BB3[50] = 8.671328e-1; + BB3[51] = 8.723293e-1; + BB3[52] = 8.770461e-1; + BB3[53] = 8.814338e-1; + BB3[54] = 8.853624e-1; + BB3[55] = 8.897322e-1; + BB3[56] = 8.937578e-1; + BB3[57] = 8.97254e-1; + BB3[58] = 9.008031e-1; + BB3[59] = 9.042233e-1; + BB3[60] = 9.076829e-1; + BB3[61] = 9.11218e-1; + BB3[62] = 9.139078e-1; + BB3[63] = 9.170002e-1; + BB3[64] = 9.199191e-1; + BB3[65] = 9.226127e-1; + BB3[66] = 9.250731e-1; + BB3[67] = 9.277341e-1; + BB3[68] = 9.301693e-1; + BB3[69] = 9.324761e-1; + BB3[70] = 9.347405e-1; + BB3[71] = 9.370394e-1; + BB3[72] = 9.390614e-1; + BB3[73] = 9.41111e-1; + BB3[74] = 9.429319e-1; + BB3[75] = 9.448513e-1; + BB3[76] = 9.466235e-1; + BB3[77] = 9.483763e-1; + BB3[78] = 9.500882e-1; + BB3[79] = 9.517579e-1; + BB3[80] = 9.531616e-1; + BB3[81] = 9.546471e-1; + BB3[82] = 9.561263e-1; + BB3[83] = 9.576014e-1; + BB3[84] = 9.592471e-1; + BB3[85] = 9.605977e-1; + BB3[86] = 9.618122e-1; + BB3[87] = 9.632723e-1; + BB3[88] = 9.644877e-1; + BB3[89] = 9.654043e-1; + BB3[90] = 9.666469e-1; + BB3[91] = 9.676583e-1; + BB3[92] = 9.687529e-1; + BB3[93] = 9.697718e-1; + BB3[94] = 9.708359e-1; + BB3[95] = 9.716986e-1; + BB3[96] = 9.726066e-1; + BB3[97] = 9.734057e-1; + BB3[98] = 9.743224e-1; + BB3[99] = 9.751716e-1; + BB3[100] = 9.759489e-1; + BB3[101] = 9.766958e-1; + BB3[102] = 9.774256e-1; + BB3[103] = 9.783317e-1; + BB3[104] = 9.789422e-1; + BB3[105] = 9.795293e-1; + BB3[106] = 9.801187e-1; + BB3[107] = 9.807522e-1; + BB3[108] = 9.812972e-1; + BB3[109] = 9.818664e-1; + BB3[110] = 9.825167e-1; + BB3[111] = 9.831091e-1; + BB3[112] = 9.835873e-1; + BB3[113] = 9.840919e-1; + BB3[114] = 9.845122e-1; + BB3[115] = 9.850374e-1; + BB3[116] = 9.854874e-1; + BB3[117] = 9.859857e-1; + BB3[118] = 9.865129e-1; + BB3[119] = 9.869294e-1; + BB3[120] = 9.873618e-1; + BB3[121] = 9.877482e-1; + BB3[122] = 9.880475e-1; +} + + +/*-------------------------------------------------------------------------*/ + +static double FDistBBp0k2 (double junk[], double x) +/* + * Bickel-Breiman distribution obtained by simulation with + * N = 1000000, n = 1000, r = 0, k = 2, p = 0, Torus = TRUE + * + * We first interpolated the empirical distribution on the points xs = j/100 + * (integer j) by building a parabola using a least-square fit with all + * the points in [xs - 0.005, xs + 0.005], and then by computing ys(xs) on + * the parabola, in order to reduce the noise. + * We use a Newton cubic interpolation with the 4 points closest to x to + * compute the distribution y(x). + */ +{ + static lebool BBp0k2Flag = FALSE; + int j; + double q; + double y; + if (x >= 6.0) + return 1.0; + if (x >= 1.3) + return 1.0 - exp (-5.94558e-1 - 3.99672 * x); + if (x <= 0.014) + return 0.0; + if (x <= 0.02) { + return -2.66337e-3 + x * (5.12234e-1 + x * (-32.8023 + 701.167 * x)); + } + + if (FALSE == BBp0k2Flag) { + InitBBp0k2 (); + BBp0k2Flag = TRUE; + } + + j = 100.0 * x + 2; /* x is in [P(j-2), P(j-1)] */ + q = 100.0 * x - j; + + /* Newton backward cubic interpolation */ + y = BB2[j - 1] + (BB2[j - 1] - BB2[j - 2]) * q + (((BB2[j - 3] + - 2.0 * BB2[j - 2]) + BB2[j - 1]) * q * (q + 1.0)) / 2.0 + + ((((-BB2[j - 4] + 3.0 * BB2[j - 3]) - + 3.0 * BB2[j - 2]) + BB2[j - 1]) * q * (q + 1.0) * (q + + 2.0)) / 6.0; + + return y; +} + + +/*-------------------------------------------------------------------------*/ + +static double FDistBBp0k15 (double junk[], double x) +/* + * Bickel-Breiman distribution obtained by simulation with + * N = 100000, n = 1000, r = 0, k = 15, p = 0, Torus = TRUE + * + * We first interpolated the empirical distribution on the points xs = j/100 + * (integer j) by building a parabola using a least-square fit with all + * the points in [xs - 0.005, xs + 0.005], and then by computing ys(xs) on + * the parabola, in order to reduce the noise. + * We use a Newton cubic interpolation with the 4 points closest to x to + * compute the distribution y(x). + */ +{ + static lebool BBp0k15Flag = FALSE; + int j; + double q; + double y; + if (x <= 0.015) + return 0.0; + if (x <= 0.02) + return (6.1123 * x - 0.18384) * x + 1.3984e-3; + if (x >= 6.0) + return 1.0; + if (x >= 1.2) + return 1.0 - exp (-3.15786 * x - 5.41639e-1); + + if (FALSE == BBp0k15Flag) { + InitBBp0k15 (); + BBp0k15Flag = TRUE; + } + + j = 100.0 * x + 2; /* x is in [P(j-2), P(j-1)] */ + q = 100.0 * x - j; + + /* Newton backward cubic interpolation */ + y = (BB3[j - 1] - BB3[j - 2]) * q + BB3[j - 1] + + (BB3[j - 3] - 2.0 * BB3[j - 2] + BB3[j - 1]) * q * (q + 1.0) / 2.0 + + (-BB3[j - 4] + 3.0 * BB3[j - 3] - 3.0 * BB3[j - 2] + + BB3[j - 1]) * q * (q + 1.0) * (q + 2.0) / 6.0; + + return y; +} + + +/*-------------------------------------------------------------------------*/ + +static double FDistBBp2k2 (double junk[], double x) +/* + * Bickel-Breiman distribution obtained by simulation with + * N = 1000000, n = 1000, r = 0, k = 2, p = 2, Torus = TRUE + */ +{ + static lebool BBp2k2Flag = FALSE; + int j; + double q; + double y; + if (x < 0.016) + return 0.0; + if (x >= 6.0) + return 1.0; + if (x >= 1.0) + return 1.0 - exp ((0.1408724 * x - 4.485674) * x - 0.264116); + + if (FALSE == BBp2k2Flag) { + InitBBp2k2 (); + BBp2k2Flag = TRUE; + } + + if (x >= 0.2) { + /* Newton quadratic interpolation based on the points 0.02*j */ + /* in the interval [0.2, 1.0] */ + j = x * 50.0; + q = x * 50.0 - j; + y = BB4[j - 10] + q * (BB4[j - 9] - BB4[j - 10]) + + (q * (q - 1.0) * ((BB4[j - 8] - 2.0 * BB4[j - 9]) + BB4[j - + 10])) / 2.0; + + return 1.0 - exp (y); + } + + /* Newton backward cubic interpolation based on the points */ + /* 0.01*j in the interval [0, 0.2] */ + j = 100.0 * x + 2; /* x is in [P(j-2), P(j-1)] */ + q = 100.0 * x - j; + + y = (BB5[j] - BB5[j - 1]) * q + BB5[j] + + (((BB5[j - 2] - 2.0 * BB5[j - 1]) + BB5[j]) + * q * (q + 1.0)) / 2.0 + + ((((-BB5[j - 3] + 3.0 * BB5[j - 2]) - 3.0 * BB5[j - 1]) + + BB5[j]) * q * (q + 1.0) * (q + 2.0)) / 6.0; + + return y; +} + + +/*-------------------------------------------------------------------------*/ + +void snpair_WriteDataBB (unif01_Gen * gen, char *TestName, + long N, long n, int r, int k, int p, lebool Torus, int L1, int L2) +{ + double z; + + swrite_Head (gen, TestName, N, n, r); + printf (", k = %1d, p = %1d, Torus = ", k, p); + util_WriteBool (Torus, 5); + printf ("\n"); + + if (swrite_Parameters) { + printf ("\n Seuil1 = %5d\n Seuil2 = %5d\n Seuil3 = %5d\n" + " Seuil4 = %5d\n L1 = %2d\n L2 = %2d\n", + snpair_env.Seuil1, snpair_env.Seuil2, snpair_env.Seuil3, + snpair_env.Seuil4, L1, L2); + + z = n * pow (2.0, -L1 * (double) k); + printf (" s1 = "); /* n / 2^{k L1} = "); */ + num_WriteD (z, 9, 2, 2); + printf ("\n s2 = "); /* n / 2^{k L2} = "); */ + z = n * pow (2.0, -L2 * (double) k); + num_WriteD (z, 9, 2, 2); + } + printf ("\n\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +void snpair_WriteResultsBB (unif01_Gen * gen, chrono_Chrono * Timer, + snpair_Res * res, long N) +{ + + printf ("-----------------------------------------------\n"); + if (N == 1) { + printf ("Value of the BB statistic :"); + gofw_Writep2 (res->sVal[snpair_BB], res->pVal[snpair_BB]); + } else { + printf ("AD Statistic on the N p-values of BB :"); + gofw_Writep2 (res->sVal[snpair_BB], res->pVal[snpair_BB]); + } + swrite_Final (gen, Timer); +} + + +/*=========================================================================*/ + +void snpair_BickelBreiman (unif01_Gen * gen, snpair_Res * res, + long N, long n, int r, int k, int p, lebool Torus) +{ + int j; + long i; + long Seq; + snpair_PointType T; + double mu1; /* -n * Vol */ + double ksurp; /* k / p */ + double Wni; + double SumBB; + double Vol; /* Volume of unit sphere in k dimension */ + double x, nLR, kLR; + WorkType *work; + lebool localRes = FALSE; + chrono_Chrono *Timer, *Time1; + char *TestName = "snpair_BickelBreiman test"; + + Timer = chrono_Create (); + + if (res == NULL) { + localRes = TRUE; + res = snpair_CreateRes (); + } + work = res->work; + work->Torus = Torus; + work->kk = k; + kLR = k; + nLR = n; + work->pp = p; + work->mm = 1; + work->mcd = 2; + if (p == 0) + work->pLR = 1.0; + else + work->pLR = p; + work->Invp = 1.0 / work->pLR; + ksurp = kLR / work->pLR; + + work->L1 = 1 + num_Log2 (nLR / snpair_env.Seuil3) / (sqrt (kLR)); + if (work->L1 < 2) + work->L1 = 2; + work->L2 = 1 + num_Log2 (nLR / snpair_env.Seuil4) / (sqrt (kLR)); + if (work->L2 < 2) + work->L2 = 2; + if (k < snpair_MAXREC) + work->Maxnp = k; + else + work->Maxnp = snpair_MAXREC; + Vol = num2_VolumeSphere ((double) p, k); + mu1 = -nLR * Vol; + work->BBFlag = TRUE; + if (swrite_Basic) + snpair_WriteDataBB (gen, TestName, N, n, r, k, p, Torus, + work->L1, work->L2); + + /* util_Assert (n <= snpair_MaxNumPoints, + "snpair_BickelBreiman: n is too large"); */ + util_Assert (p == 2 || p == 0, + "snpair_BickelBreiman implemented only for p = 2 and p = 0"); + util_Assert (k == 2 || k == 15, + "snpair_BickelBreiman implemented only for k = 2 and k = 15"); + util_Assert (p != 2 || k != 15, + "snpair_BickelBreiman: case p = 2, k = 15 not implemented"); + if (p == 0) { + if (k == 2) + work->FDistBB = FDistBBp0k2; + else + work->FDistBB = FDistBBp0k15; + } else + work->FDistBB = FDistBBp2k2; + + InitRes (res, N, n, 1); + res->Distance = snpair_DistanceBB; + res->VerifPairs = snpair_VerifPairs0; + res->MiniProc = snpair_MiniProc1; + statcoll_SetDesc (res->ThepValAD, "The N p-values of BickelBreiman"); + + /* Test begins */ + for (Seq = 1; Seq <= N; Seq++) { + + for (i = 1; i <= n; i++) { + /* Generate n points in dimension k */ + T = res->Points[1][i]; + /* Initialize nearest distance */ + T[0] = kLR; + for (j = 1; j <= k; j++) + T[j] = unif01_StripD (gen, r); + } + + /* Find the closest points */ + work->dlim = kLR; /* Initial upper bounds */ + work->dlimp = work->dlim; + if (snpair_TimeBB) + Time1 = chrono_Create (); + snpair_QuickSort (res->Points[1], 1, n, 1); + snpair_FindClosePairs (res, 1, n, 1, 1, 1); + + /* For each point, coordinate 0 now contains the distance to */ + /* the nearest point raised to power p (for p > 0) */ + snpair_QuickSort (res->Points[1], 1, n, 0); + + /* Compute the BB statistic, etc... */ + SumBB = 0.0; + for (i = 1; i <= n; i++) { + Wni = 1.0 - exp (mu1 * pow (res->Points[1][i][0], ksurp)); + x = Wni - i / nLR; + SumBB += x * x; + } + if (snpair_TimeBB) { + printf (" Time to compute the BB statistic: "); + chrono_Write (Time1, chrono_sec); + printf ("\n"); + chrono_Delete (Time1); + } + statcoll_AddObs (res->ThepValAD, + 1.0 - work->FDistBB ((double *) NULL, SumBB)); + } + + if (swrite_Collectors) + statcoll_Write (res->ThepValAD, 5, 14, 4, 3); + + if (N == 1) { + res->sVal[snpair_BB] = SumBB; + res->pVal[snpair_BB] = res->ThepValAD->V[1]; + } else { + tables_QuickSortD (res->ThepValAD->V, 1, N); + res->sVal[snpair_BB] = gofs_AndersonDarling (res->ThepValAD->V, N); + res->pVal[snpair_BB] = fbar_AndersonDarling (N, res->sVal[snpair_BB]); + } + + if (swrite_Basic) + snpair_WriteResultsBB (gen, Timer, res, N); + + if (localRes) + snpair_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void snpair_DistanceCPBitM (snpair_Res * res, snpair_PointType P1, + snpair_PointType P2) +/* + * Similar to snpair_DistanceCP, but for snpair_ClosePairsBitMatch. We take + * at most two groups of SizeUL bits for each coordinate of two points and + * find how many equal bits (= Y) they have before the first different bit, + * starting with the most significant. That is the distance in 1 dimension. + * We do that for each coordinate and the minimum of these is the distance + * between the two points (all components of the pair have at least Y + * identical bits). + */ +{ + const int NBitsUL = CHAR_BIT * sizeof (unsigned long); + const double Mul = num_TwoExp[NBitsUL]; + unsigned long x1, x2, z; + int i, j; + int Y = INT_MAX; /* Distance between the 2 points */ + WorkType *work = res->work; + + for (i = 1; i <= work->kk; i++) { + /* Take the first NBitsUL bits of each coordinates of the 2 points */ + x1 = Mul * P1[i]; + x2 = Mul * P2[i]; + /* Find the position - 1 of the first (left) bit where they differ */ + z = x1 ^ x2; + j = 0; + if (z) { + while (z < 2 * z) { + j++; + z <<= 1; + if (j >= Y) + continue; + } + } else { + /* The first NBitsUL bits are equal, consider the NBitsUL next bits + */ + x1 = Mul * (Mul * P1[i] - x1); + x2 = Mul * (Mul * P2[i] - x2); + z = x1 ^ x2; + if (z) { + j = NBitsUL; + while (z < 2 * z) { + j++; + z <<= 1; + if (j >= Y) + continue; + } + } else { + j = 2 * NBitsUL; + } + } + if (j < Y) + Y = j; + if (Y <= work->YLim) + /* We want the maximum (amongst all pairs of points) of the */ + /* minimum Y over all coordinates of a pair. This pair cannot */ + /* give a larger YLim. */ + return; + } + + /* A larger YLim has been found. From it, we define an inverse distance */ + /* so that the largest YLim gives the smallest new distance. This is */ + /* necessary if we want to use the fast but complicated algorithm for */ + /* finding the nearest pair. */ + if (Y > work->YLim) { + work->YLim = Y; + if (work->YLim <= num_MaxTwoExp) + work->dlim = 1.0 / num_TwoExp[work->YLim]; + else + work->dlim = pow (2.0, -(double) work->YLim); + res->CloseDist[1] = work->dlim; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteDataBM (unif01_Gen * gen, char *TestName, + long N, long n, int r, int k) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", t = %1d\n\n", k); +} + + +/*=========================================================================*/ + +void snpair_ClosePairsBitMatch (unif01_Gen * gen, snpair_Res * res, + long N, long n, int r, int k) +/* + * Similar to ClosePairs, but uses the BitMatch distance. + */ +{ + long Seq; + double z1, nLR; + snpair_PointType T; + int m; + int MaxY; /* Max of all bit distances */ + int j; + long i; + double pLeft, pRight; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "snpair_ClosePairsBitMatch test"; + WorkType *work; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataBM (gen, TestName, N, n, r, k); + + /* util_Assert (n <= snpair_MaxNumPoints, + "snpair_ClosePairsBitMatch: n > snpair_MaxNumPoints"); */ + util_Assert (n > 1, "snpair_ClosePairsBitMatch: n < 2"); + if (res == NULL) { + localRes = TRUE; + res = snpair_CreateRes (); + } + work = res->work; + work->Torus = FALSE; + work->kk = k; + work->mm = m = 1; + work->mcd = 2 * m; + nLR = n; + work->Invp = work->pLR = work->pp = 1; + + if (k < snpair_MAXREC) + work->Maxnp = k; + else + work->Maxnp = snpair_MAXREC; + work->BBFlag = FALSE; /* Bickel-Breiman Flag */ + + CalcSeuils (work, k, m, FALSE, 0.0, nLR, (double) k); + + InitRes (res, N, n, m); + res->Distance = snpair_DistanceCPBitM; + res->VerifPairs = snpair_VerifPairs1; + res->MiniProc = snpair_MiniProc1; + + MaxY = 0; + + /* Beginning of test */ + for (Seq = 1; Seq <= N; Seq++) { + + for (i = 1; i <= n; i++) { + /* Generate n points in dimension k */ + T = res->Points[1][i]; + for (j = 1; j <= k; j++) + T[j] = unif01_StripD (gen, r); + } + res->NumClose = 0; + work->YLim = 0; /* Initial lower bound */ + work->dlim = 1.0; /* Initial upper bound */ + snpair_QuickSort (res->Points[1], 1, n, 1); + snpair_FindClosePairs (res, 1, n, 1, 1, 1); + +#if 0 + /* Check by computing distances between all pairs; very slow. */ + printf ("%12d", work->YLim); + if (Seq % 5 == 0) + printf ("\n"); + swrite_Collectors = TRUE; + work->YLim = 0; + snpair_VerifPairs0 (res->Points[1], 1, n, 0, 0); +#endif + + statcoll_AddObs (res->BitMax, (double) work->YLim); + MaxY = util_Max (work->YLim, MaxY); + } + + if (swrite_Collectors) + statcoll_Write (res->BitMax, 5, 14, 4, 3); + + /* z1 = Probability [Min {k geometric (0.5)} >= MaxY] */ + if (k * (MaxY + 1) <= num_MaxTwoExp) + z1 = 1.0 / num_TwoExp[k * (MaxY + 1)]; + else + z1 = pow (2.0, -(double) k * (MaxY + 1)); + + /* There are n*(n - 1)/2 pairs of points and we replicate that basic test + N times, so we compute pLeft = the Probability [Max {N*n*(n - 1)/2 of + above random var.} <= MaxY] */ + if (z1 > DBL_EPSILON) { + pLeft = 1.0 - z1; + z1 = log (pLeft) * N * n * (n - 1) / 2; + pLeft = exp (z1); + pRight = 1.0 - pLeft; + } else { + /* Use approximation log (1 - z) = -z to avoid loss of precision */ + pRight = z1 * N * n * (n - 1) / 2; + pLeft = 1.0 - pRight; + } + res->pVal[snpair_BM] = gofw_pDisc (pLeft, pRight); + res->sVal[snpair_BM] = MaxY; + + if (swrite_Basic) { + printf ("\n-----------------------------------------------\n"); + printf ("Max of all bit distances :"); + gofw_Writep2 ((double) MaxY, res->pVal[snpair_BM]); + swrite_Final (gen, Timer); + } + + if (localRes) + snpair_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/snpair.tex b/TESTU01/TestU01-1.2.3/testu01/snpair.tex new file mode 100644 index 0000000..4ae34cd --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/snpair.tex @@ -0,0 +1,771 @@ +\defmodule {snpair} + +This module implements tests based on the distances between +the closest points in a sample of $n$ uniformly distributed points in +the unit torus in $t$ dimensions.\index{Test!nearest pairs} +These tests are studied by L'Ecuyer, Cordeau, and Simard \cite{rLEC00c}. + +Distances between points are measured using the $L_p$ norm +$\Vert\cdot\Vert_p^o$ in the unit torus $[0,1)^t$, +as defined in \cite{rLEC00c}. +The unit torus is obtained by identifying (pairwise) the opposite +sides of the unit hypercube, so that points that are face to face on +opposite sides are ``close'' to each other. +Each point is generated using $t$ calls to the generator, for a total +of $nt$ calls to get the $n$ points $X_1,\dots,X_n$. + +Let $D_{n,i,j} = \Vert X_j - X_i\Vert_p$ +be the distance between $X_i$ and $X_j$. +Put $\lambda(n) = n(n-1)V_t(1)/2$, where $V_t(r)$ +% $ V_t(r) = {\left[ 2r\,\Gamma(1+1/p)\right]^t / \Gamma(1+t/p)} $ +is the volume of the ball $\{x \in \mathbb{R}^t \mid \Vert x\Vert_p \le r\}$. +% and $\Gamma$ is the usual gamma function. %% (see, e.g., \cite{rDEV86a}). +For each $\tau\ge 0$, let $Y_n(\tau)$ be the number of distinct pairs +of points $(X_i, X_j)$, with $i 0$ and $n\to\infty$, +the truncated process $\{Y_n(\tau), 0\le \tau\le \tau_1\}$ +converges weakly to a Poisson process with unit rate. +% truncated to the interval $[0, \tau_1]$. +Moreover, for $\tau\le \lambda(n) /2^{t}$, one has +$E[Y_n(\tau)] = \tau$ and $\Var[Y_n(\tau)] = \tau - {2\tau^2 / (n(n-1))}$. +\end {proposition} + +Let $T_{n,i} = \inf\{\tau\ge 0 \mid Y_n(\tau) \ge i\}$, $i=1,2,3,\dots$, +be the jump times of $Y_n$, with $T_{n,0}=0$, and let +$W^*_{n,i} = 1-\exp[-(T_{n,i} - T_{n,i-1})]$ be the transformed +spacings between these jump times. +Proposition~\ref{prop:Poisson} implies that for any fixed integer $m > 0$, +for large enough $n$, the random variables $W^*_{n,1},\dots,W^*_{n,m}$ +are approximately i.i.d.\ $U(0,1)$. +The function {\tt snpair\_ClosePairs} applies the +{\em $m$-nearest-pairs\/} ({$m$-NP}) test, +which simply compares the empirical distribution of these random +variables with the uniform distribution, +using the Anderson-Darling test statistic (see module {\tt gofs}). +Why Anderson-Darling? Because typically, when a generator has too +much structure, the jump times of $Y_n$ tend to cluster, so there tends +to be several $W^*_{n,i}$'s near zero, and the Anderson-Darling test +is particularly sensitive to detect that type of behavior. + +For a two-level test, when $N>1$, the standard approach is to +apply a goodness-of-fit test to the $N$ values of the +Anderson-Darling statistic. A second approach is to pool the $N$ batches +of $m$ observations $W^*_{n,i}$ in a single sample of size $Nm$ and apply +the Anderson-Darling test to it. +These two possibilities are referred to by the acronyms +{$m$-NP} and {$m$-NP1} respectively. + +A third one is to superpose the $N$ copies of the process $Y_n$, +to obtain a process $Y$ defined as the sum of the $n$ copies of $Y_n$. +Fix a constant $\tau_1> 0$ and let $J$ be the number of jumps of $Y$ in the +interval $[0,\tau_1]$. Set $T_0 = 0$ +and let $T_1,\dots,T_{J}$ be the sorted times of these jumps. +Under $\cH_0$, $J$ is approximately Poisson with mean $N \tau_1$, +and conditionally on $J$, the jump times $T_j$ are distributed +as $J$ independent uniforms over $[0,\tau_1]$ sorted in increasing order. +We can test this uniformity with an AD test on the $J$ observations and +this is called the {$m$-NP2} test. +It is also worthwhile to compare the realization of $J$ with the Poisson +distribution and this is the {NJumps} test. + +In yet another variant of the uniformity test conditional on $J$, +we apply a ``spacings'' transformation to the uniforms before applying the +AD test (this is called the {$m$-NP2S} test). +This latter test is very powerful but it also turns out to be very sensitive +to the number of bits of ``precision'' in the output of the generator. +For example, in dimension $t=2$, for $N=20$, $n=10^6$ and $m=20$, +all generators returning less than 32 bits of precision will fail this test. + +We can finally apply a ``spacings'' transformation to the $N$ closest distances +$W^*_{n,1}$ and to the $mN$ nearest pairs $W^*_{n,i}$ before applying the +AD test, and these are called the {NPS} and the {$m$-NP1S} tests, respectively. + +\iffalse + A third approach is to pool all the +jump times of the $N$ copies $Y_n$ that occur in the interval $[0,m]$, +say $T_1,\dots,T_{n'}$, define $W^*_{i} = 1 -\exp[-N(T_i - T_{i-1})]$ +for $1\le i\le n'$, where $T_0=0$, and compare the distribution +of these $W^*_i$ to the uniform one by an Anderson-Darling test. +Here, $n'$ is a Poisson + random variable with mean $Nm$. +Conditionally on $n'$, the jump times should be distributed as +independent uniforms over $[0,m]$. +\hpierre {Must clarify details here.... This is not in the paper. + This way, with $n'$ random, the $W^*_i$ are no longer i.i.d. uniform.} +These three possibilities are referred to by the acronyms +$m$-NP, $m$-NP1, and $m$-NP2, respectively. +\fi + +The function {\tt snpair\_ClosePairs} implements the tests that we +just described. The function {\tt snpair\_ClosePairsBitMatch} +implements a similar type of test, but based on a different notion of +distance: The distance between two points is measured by counting +how many of the most significant bits of their coordinates are the same. +The function {\tt snpair\_BickelBreiman} implements a multivariate +goodness-of-fit test proposed by Bickel and Breiman \cite{tBIC83a}, +also based on distances between nearest points. + + +\bigskip\hrule + +\code\hide +/* snpair.h for ANSI C */ +#ifndef SNPAIR_H +#define SNPAIR_H +\endhide +#include "gdef.h" +#include "chrono.h" +#include "statcoll.h" +#include "unif01.h" +\endcode + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Constants} +%\code + +%#define snpair_MaxDim 30 +%\endcode +%\tab +% Maximal number of dimensions. +%\endtab +\code + + +#define snpair_MAXM 512 +\endcode +\tab + Maximal value of $m$ for {\tt snpair\_ClosePairs}. +\endtab +%%\hide %%%% +\code + + +#define snpair_MAXREC 12 +\endcode +\tab + Maximal number of dimensional recursions. +\endtab +%%\endhide %%% + +\ifdetailed %%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Environment variables} + +The structure {\tt snpair\_Envir} contains global parameters +that are usually fixed once and for all. +These parameters can be used to fine-tune the performance of +the algorithms that compute the close-pair distances. + +\code + +typedef struct { + + int Seuil1; /* Recursion threshold for snpair_FindClosePairs */ + int Seuil2; /* Recursion threshold for snpair_CheckBoundary */ + int Seuil3; /* L1 = 1 + (lg (n/Seuil3)) / sqrt(t) */ + int Seuil4; /* L2 = 1 + (lg (n/Seuil4)) / sqrt(t) */ +\endcode + \tabb + Different thresholds used in computing close pairs. + The default values of these parameters are respectively: + 20, 30, 30, 1000. These values have been chosen based on + empirical tests on the speed of execution. + See the code for more details. + \endtabb +\code + +} snpair_Envir; + + +extern snpair_Envir snpair_env; +\endcode +\tab + This global environment variable is used to keep the values of the fields + in {\tt snpair\_Envir}. +\endtab +\fi %%%%%%% +\hide +\code + + +extern long snpair_MaxNumPoints; +\endcode + \tab + Upper limit on $n$, the number of points. Depends on the size of + the memory available on the computer. When $n$ exceeds this limit, + the program prints an error message and halts. + The default value is $10^{9}$. + \endtab +\endhide + +\ifdetailed %%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Types and basic structures} + +\code + +typedef double * snpair_PointType; +\endcode + \tab + A point (a $t$-component vector) in the $t$-dimensional unit hypercube + or torus. + \endtab +\code + + +typedef snpair_PointType * snpair_PointTableType; +\endcode + \tab An array of points in the $t$-dimensional unit hypercube or torus. + \endtab +\fi +\hide %%%%% +\code + + +typedef struct snpair_Res snpair_Res; + +typedef void (*snpair_DistanceType) (snpair_Res *res, snpair_PointType, + snpair_PointType); +\endcode + \tab Type of function for computing the distance between two points + and updating the {\tt res} structure accordingly. + Specific instances are {\tt snpair\_DistanceCP}, + {\tt snpair\_DistanceBB}, etc., and other ones could be defined. + \endtab +\code + + +typedef void (*snpair_VerifPairsType) (snpair_Res *res, snpair_PointType [], + long, long, int, int); +\endcode + \tab Type of function for verifying the distance between all pairs + of points in a given set, and updating {\tt res} accordingly. + Specific instances are {\tt snpair\_VerifPairs0} and + {\tt snpair\_VerifPairs1}. + \endtab +\code + + +typedef void (*snpair_MiniProcType) (snpair_Res *res, snpair_PointType [], + long, long, long, long, int, int); +\endcode + \tab Type of function for verifying the distance between all the + points of a set with those of a second set, and updating {\tt res} + accordingly. See {\tt snpair\_MiniProc1} and {\tt snpair\_MiniProc0}) + for specific instances. + \endtab +\endhide %%%%% + +\ifdetailed %%%% +\code + + +enum snpair_StatType { + snpair_NP, + snpair_NPS, + snpair_NPPR, + snpair_mNP, + snpair_mNP1, + snpair_mNP1S, + snpair_mNP2, + snpair_mNP2S, + snpair_NJumps, + snpair_BB, + snpair_BM, + snpair_StatType_N +}; +\endcode + \tab Types of statistics that may be computed in the tests. + The names correspond to the test names in the description of + {\tt snpair\_ClosePairs}, {\tt snpair\_BickelBreiman} and + {\tt snpair\_ClosePairs\-Bit\-Match}. + The test {\tt snpair\_ClosePairs} computes {\tt snpair\_NP}, {\tt snpair\_mNP}, + {\tt snpair\_mNP1}, {\tt snpair\_mNP2} and {\tt snpair\_NJumps}; this last + corresponds to a test on the total number of jumps. + The test {\tt snpair\_BickelBreiman} computes {\tt snpair\_BB}, and + the test {\tt snpair\_Clo\-se\-Pairs\-Bit\-Match} computes {\tt snpair\_BM}. + The last one, {\tt snpair\_StatType\_N} is just a flag that counts how + many test types there are. The others are currently unused; they correspond + to tests with spacings and power ratio transformations applied on the + {\tt snpair\_ClosePairs} tests mentionned above, as described in \cite{rLEC00c}. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% \guisec{The test results} + +\code + + + +struct snpair_Res { + + long n; +\endcode + \tabb The number of points. + \endtabb +\fi +\hide %%%% +\code + lebool CleanFlag; /* If TRUE, free all memory */ + void *work; +\endcode + \tabb Working variables used internally. + \endtabb +\endhide +\ifdetailed +\code + + snpair_PointTableType Points[1 + snpair_MAXREC]; +\endcode + \tabb Tables of pointers to the points, one table for each + level of recursion on the dimensions. + For {\tt snpair\_BickelBreiman}, {\tt Points[1][i][0]} + will keep the distance from each + point $i$ to its nearest neighbour. + \endtabb +\code + + int NumClose; +\endcode + \tabb Number of close pairs of points kept for computing the different + statistics. + \endtabb +\code + + double * CloseDist; +\endcode + \tabb Distances between the closest pairs, sorted in increasing order. + {\tt CloseDist[i]} contains the $i$-th closest distance. + \endtabb +\fi\hide %%%% +\code + + snpair_DistanceType Distance; + snpair_VerifPairsType VerifPairs; + snpair_MiniProcType MiniProc; +\endcode + \tabb {\tt Distance} is a function computing the distance between + two points, for example {\tt snpair\_Dis\-tanceCP} or + {\tt snpair\_DistanceBB}, etc. + {\tt VerifPairs} is the current version of the procedure + verifying the distance between all pairs of points in a given set + (see {\tt snpair\_VerifPairs0} and {\tt snpair\_VerifPairs1}). + {\tt MiniProc} is the current version of the procedure + verifying the distances between all the points of a set with + those of a second set (see {\tt snpair\_MiniProc1} + and {\tt snpair\_MiniProc0}). + \endtabb +\endhide\ifdetailed %%%%% +\code + + statcoll_Collector * Yn; + statcoll_Collector * Y; + statcoll_Collector * U; + statcoll_Collector * V; + statcoll_Collector * S; + statcoll_Collector * TheWn; + statcoll_Collector * TheWni; + statcoll_Collector * ThepValAD; + statcoll_Collector * BitMax; +\endcode + \tabb For the test {\tt snpair\_ClosePairs}, + {\tt Yn} contains the jumps of $Y$ for the current replication, + {\tt Y} contains all the jumps of $Y$ for all $N$ replications, + {\tt U} contains jumps times at the first level transformed into + uniforms, {\tt V} and {\tt S} are both used for the + ``spacings'' and ``power ratio'' transformations described + in \cite{rLEC00c}, + {\tt TheWn} contains the $N$ values of $W_n$, + {\tt TheWni} the $Nm$ values of the $W_{n,i}$ and + {\tt ThepValAD} the $N$ $p$-values of the AD statistics. + + For the {\tt snpair\_BickelBreiman} test, {\tt ThepValAD} + contains the $N$ $p$-values of the AD statistics and the other + collectors are unused. + + For the {\tt snpair\_ClosePairsBitMatch} test, {\tt BitMax} + contains the $N$ values of the statistic and the other + collectors are unused. + \endtabb +\code + + double sVal [snpair_StatType_N]; + double pVal [snpair_StatType_N]; +\endcode + \tabb + Arrays used to hold the value of the + statistics and their significance level after a test. + The statistic values will be in + {\tt sVal} and their significance level + ($p$-values) in {\tt pVal}. + \endtabb +\code + +}; +\endcode + \tab + This structure is used to keep the results of + the tests of this module. + \endtab +\code + + +snpair_Res * snpair_CreateRes (void); +\endcode + \tab + Function creating and returning a structure to hold the test results. + \endtab +\code + + +void snpair_DeleteRes (snpair_Res *res); +\endcode + \tab + Frees the memory allocated by {\tt snpair\_CreateRes}. + \endtab +\fi +\hide %%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Functions for checking nearest pairs and sorting points} + +\code + +void snpair_QuickSort (snpair_PointType A[], long l, long r, int c); +\endcode + \tab Sorts the points $A[l]$ to $A[r]$, using coordinate $c$ + as key. Permutes the pointers instead of the points themselves. + \endtab +\code + + +void snpair_VerifPairs0 (snpair_Res *res, snpair_PointType A[], long r, long s, + int np, int c); +\endcode + \tab The simplest version of {\tt snpair\_VerifPairs}. + Computes the distance between all pairs of points with indices in the + interval {\tt [r..s]} for the array {\tt A}. + Assumes that the points are sorted with respect to coordinate {\tt c}. +\endtab +\code + + +void snpair_VerifPairs1 (snpair_Res *res, snpair_PointType A[], long r, long s, + int np, int c); +\endcode + \tab A more sophisticated version of {\tt snpair\_VerifPairs}. + Computes the distance between all pairs of points with indices in the + interval {\tt [r..s]} for the array {\tt A}. + We assume the points are sorted with respect to coordinate {\tt c}. +\endtab +\code + + +void snpair_MiniProc0 (snpair_Res *res, snpair_PointType A[], long r, long s, + long u, long v, int np, int c); +\endcode + \tab The simplest version of {\tt snpair\_MiniProc}. + Computes the distance between each point of {\tt A[r..s]} and each point + of {\tt A[u..v]}. +\endtab +\code + + +void snpair_MiniProc1 (snpair_Res *res, snpair_PointType A[], long r, long s, + long u, long v, int np, int c); +\endcode + \tab A more sophisticated version of {\tt snpair\_MiniProc}. + Computes the distance between each point of {\tt A[r..s]} and each point + of {\tt A[u..v]}. Assume the points are sorted with respect to + coordinate {\tt c}. +\endtab +\code + + +void snpair_CheckBoundary (snpair_Res *res, long r, long s, long u, long v, + int nr, int nrb, int np, int c); +\endcode + \tab Computes the minimum distance between the points of the sets + {\tt E1 = A[r..s]} and {\tt E2 = A[u..v]}. + The parameter {\tt nrb} gives the recursion level of the calls + to {\tt snpair\_CheckBoundary}. + The points are in {\tt A = snpair\_Points [np]}, sorted with respect to + coordinate {\tt c}. + \endtab +\code + + +void snpair_FindClosePairs (snpair_Res *res, long r, long s, int nr, + int np, int c); +\endcode + \tab Verifies if the minimal distance between the two nearest points, + amongst those with indices in {\tt [r..s]} in the table at level + {\tt np}, is less than the current bound {\tt dlim}. If so, + updates {\tt dlim} and {\tt dlimp}. + Assumes that {\tt snpair\_Points [np]} is sorted with respect to + coordinate {\tt c}. + \endtab +\endhide + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\ifdetailed +\guisec{The close-pairs tests} %%% separate only if detailed +\else %%% otherwise, put all the tests together. +\guisec{The tests} + +\resdef +\fi %%%%%%% + +\hide %%% +\code + +void snpair_DistanceCP (snpair_Res *res, snpair_PointType, snpair_PointType); +\endcode + \tab A version of {\tt snpair\_Distance} which uses the norm $L_p$. + \endtab +\endhide %%% +\ifdetailed %%% +\code + + +void snpair_WriteDataCP (unif01_Gen *gen, char *TestName, long N, long n, + int r, int t, int p, int m, lebool Torus); +\endcode + \tab Prints the data and parameters for the test {\tt snpair\_ClosePairs}. + \endtab +\code + + +void snpair_WriteResultsCP (unif01_Gen *gen, chrono_Chrono *Timer, + snpair_Res *res, long N, long m); +\endcode + \tab Prints the results of {\tt snpair\_ClosePairs}. + \endtab +\fi %%% +\code + + +extern lebool snpair_mNP2S_Flag; +\endcode + \tab If this flag is set {\tt TRUE}, the {\tt mNP2S} statistic in + {\tt snpair\_ClosePairs} will be printed as well as its $p$-value, otherwise not. + The default value is {\tt TRUE}. + This statistic requires many bits of resolution and for large enough values of + $N, n$ and $m$ in 2 dimensions, all generators with less than 32 bits of + resolution will fail the {\tt mNP2S} test. + For example, for $N=20$, $n=10^6$, $m=20$, $t=2$, all generators returning + less than 32 bits of resolution will fail the test. \endtab +\code + + +void snpair_ClosePairs (unif01_Gen *gen, snpair_Res *res, + long N, long n, int r, int t, int p, int m); +\endcode + \tab Applies the close-pairs tests NP, $m$-NP, $m$-NP1, and $m$-NP2, + and $m$-NP2S + by generating $n$ points in the $t$-dimensional unit torus + and computing the $m$ nearest distinct pairs of points, where + the distances between the points are measured using the + $L_p$ norm if $p \ge 1$, and the $L_\infty$ norm if $p=0$. + Recommendation: $n \ge 4m^2 \sqrt{N}$ for $t\le 8$. + Restrictions:\index{Test!ClosePairs} $m\le$ {\tt snpair\_MAXM}. +% $n\le$ {\tt snpair\_MaxNumPoints} +% \richard {Pour des valeurs tr\`es petites des statistiques ($m$-NP1, ...), +% quand des sauts sont pratiquement superpos\'es, +% les r\'esultats seront tr\`es diff\'erents sur diff\'erentes machines quand +% on compile avec optimisation. C'est d\^u \`a la perte de pr\'ecision dans la +% soustraction de deux quantit\'es presqu'\'egales.} + \endtab +\hide %%%%%%%%%%%%%%%%%% (For our private experiments only) +\code + + +void snpair_ClosePairs1 (unif01_Gen *gen, snpair_Res *res, + long N, long n, int r, int t, int p, int m); +\endcode + \tab + All the tests done are based on the Anderson-Darling (AD) statistic. + The statistics {\tt snpair\_NP, snpair\_NPS, snpair\_NPPR} + correspond to the ordinary nearest-pair + (NP) test, to the NP test with ``spacings'', and to the NP test with + ``power ratio'' (see the documentation of + {\tt gofs\_IterateSpacings} and {\tt gofs\_PowerRatios}. + The other tests will be done only if $m > 1$. + The statistic {\tt snpair\_mNP} corresponds to the $m$-NP test. + When $N > 1$, it is a two-levels test, which does an AD test + on the distribution of the AD values at the first level. + {\tt snpair\_mNP1} is the result of an AD test on the distribution + of the $Nm$ values of $W^*_{n,i}$ considered as a single sample. + If we apply a ``spacings'' transformation to these + $Nm$ values, we obtain {\tt snpair\_mNP1S}. + Another test superposes the $N$ copies of the process $Y_n$, + obtaining thus a process $Y$. All the jumps of $Y$ + in the interval $[0, \tau_1]$, where $\tau_1 = m$, are kept. + Conditionnally to the number of these jumps, they must be distributed + like independent uniforms in $[0,\tau_1]$. + The interval is normalized by dividing by $\tau_1$, and then + this hypothesis is tested by applying AD, before and after applying the + ``spacings'' transformation. + Restriction: The test with the {\tt snpair\_mNP2S} statistic requires + many bits of precision. As an example, for $N=20, n=10^6, m=20$, + generators returning less than 32 bits of precision will fail the + test. In this case, use {\tt unif01\_DoubleGenerator} to test these + generators. + \pierre {NON! Car alors on ne testera plus le m\^eme g\'en\'erateur!} + \endtab +\code + +void snpair_ReTestY (long N, long n, int m, double t0, double t1); +\endcode + \tab Useful when one wants to do more tests on $Y$ + \pierre {Which ones?} + after a call to {\tt snpair\_ClosePairs1}. Before the call to + {\tt snpair\_ClosePairs1}, the variable {\tt swrite\_AutoClean} must be + set to {\tt FALSE}. When the test is ended, one may free explicitly + the memory used by the test by calling {\tt snpair\_CleanClosePairs1}. + + This procedure is not used anymore. It makes use of discontinuous + distribution functions and the associated statistics are very + complicated and did not seem sensitive. + \endtab +\endhide %%%%%%%%%%%%%%%%%%%%%%%% +\ifdetailed %%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The Bit-match test} + +\code + +void snpair_DistanceCPBitM (snpair_Res *res, snpair_PointType, + snpair_PointType); + +\endcode + \tab Another version of {\tt snpair\_Distance} which uses bit-match + distance defined in {\tt snpair\_Clo\-se\-Pairs\-Bit\-Match}. +\endtab +\fi %%%% +\code + + +void snpair_ClosePairsBitMatch (unif01_Gen *gen, snpair_Res *res, + long N, long n, int r, int t); +\endcode + \tab Generates $n$ points in the unit hypercube in $t$ dimensions + as in {\tt snpair\_ClosePairs} and computes the closest pair, + but using a different definition of distance.\index{Test!ClosePairsBitMatch} + The distance between two points $X_i$ and $X_j$ is $2^{-b_{i,j}}$, + where $b_{i,j}$ is the maximal value of $b$ such that the first + $b$ bits in the binary expansion of each coordinate are the same + for both $X_i$ and $X_j$. This means that if the unit hypercube + is partitioned into $2^{tb}$ cubic boxes by dividing each axis into + $2^b$ equal parts, the two points are in the same box for + $b\le b_{i,j}$, but they are in different boxes for $b > b_{i,j}$. + Let $D = \min_{1\le i1$, the two-level test computes the minimum of the $N$ copies + of $D$ and uses it as a test statistic. The $p$-value is obtained from + $$ + P[\min\{D_1, D_2, \ldots, D_N\} \le 2^{-b}] + \approx 1 - \left(1 - 2^{-tb}\right)^{Nn(n-1)/2}. + $$ +% Restrictions: $n\le$ {\tt snpair\_MaxNumPoints}. + \endtab + +\ifdetailed %%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The Bickel-Breiman test} + +\fi %%% +\hide %%%% +\code + +extern lebool snpair_TimeBB; +\endcode + \tab Used in the Bickel-Breiman test. If this flag is set to {\tt TRUE}, + an internal chronometer will measure the time needed to + compute the Bickel-Breiman statistic. + \endtab +\code + + +void snpair_DistanceBB (snpair_Res *res, snpair_PointType, snpair_PointType); + +\endcode + \tab Another version of {\tt snpair\_Distance} for the + {\tt snpair\_BickelBreiman} test. +\endtab +\endhide %%%% +\ifdetailed %%%% +\code + + +void snpair_WriteDataBB (unif01_Gen *gen, char *TestName, long N, long n, + int r, int t, int p, lebool Tor, int L1, int L2); +\endcode + \tab Prints the data for the {\tt snpair\_BickelBreiman} test. The parameters + are as defined in the test {\tt snpair\_BickelBreiman}. + \endtab +\code + + +void snpair_WriteResultsBB (unif01_Gen *gen, chrono_Chrono *Timer, + snpair_Res *res, long N); +\endcode + \tab Prints the results of the {\tt snpair\_BickelBreiman} test. + The parameter {\tt N} must be the same as in {\tt snpair\_BickelBreiman}. + \endtab +\fi %%%%% +\code + + +void snpair_BickelBreiman (unif01_Gen *gen, snpair_Res *res, long N, + long n, int r, int t, int p, lebool Torus); +\endcode +\tab + Applies a test\index{Test!BickelBreiman} based on the statistic proposed by + Bickel and Breiman \cite {tBIC83a} to test the fit of a set of + points to a multidimensional density. + The test is described in \cite{rLEC00c}. + As for {\tt snpair\_ClosePairs}, $n$ points are generated in the + unit hypercube in $t$ dimensions. + If {\tt Torus = FALSE}, the distances are computed in the hypercube + as usual, whereas if {\tt Torus = TRUE}, the hypercube is treated as a + torus for computing distances, so that two points near + opposite faces of the cube can be close to each other \cite{rLEC00c}. + + For each point $i$, let $D_i$ be the distance to its nearest neighbour, + and let $W_i = \exp(-nV_i)$ where $V_i$ is the volume of a hypersphere of + radius $D_i$. The computed statistic is + $T = \sum_{i=1}^{n}(W_{(i)} - {i / n})^2$ + where the $W_{(i)}$ are the $W_i$ sorted in increasing order. + If $N>1$, the empirical distribution of the $N$ values of $T$ + is compared to the theoretical law which is approximated using + interpolation tables obtained by simulation as explained in \cite{rLEC00c}. + Restrictions: $\{p, t\} = \{0, 2\}$, $\{0, 15\}$ or $\{2, 2\}$. + \endtab +\hide %%%% +\code +#endif +\endcode +\endhide diff --git a/TESTU01/TestU01-1.2.3/testu01/sres.c b/TESTU01/TestU01-1.2.3/testu01/sres.c new file mode 100644 index 0000000..cdbb914 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sres.c @@ -0,0 +1,273 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: sres.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "sres.h" +#include "fbar.h" + +#include +#include + + + + +/*-------------------------------- Functions ------------------------------*/ + + + +void sres_InitChi2 (sres_Chi2 *res, long N, long jmax, char *nam) +{ + statcoll_Init (res->sVal1, N); + statcoll_Init (res->pVal1, N); + + if (jmax < 0) { + if (res->jmax > 0) { + res->NbExp = util_Free (res->NbExp); + res->Count = util_Free (res->Count); + res->Loc = util_Free (res->Loc); + } + } else { + if (res->jmax < 0) { + res->NbExp = util_Calloc ((size_t) (jmax + 1), sizeof (double)); + res->Count = util_Calloc ((size_t) (jmax + 1), sizeof (long)); + res->Loc = util_Calloc ((size_t) (jmax + 1), sizeof (long)); + } else { + int j; + res->NbExp = + util_Realloc (res->NbExp, (jmax + 1) * sizeof (double)); + res->Count = util_Realloc (res->Count, (jmax + 1) * sizeof (long)); + res->Loc = util_Realloc (res->Loc, (jmax + 1) * sizeof (long)); + for (j = 0; j <= jmax; j++) { + res->NbExp[j] = 0.0; + res->Count[j] = 0; + res->Loc[j] = 0; + } + } + } + res->degFree = 0; + res->jmin = 0; + res->jmax = jmax; + gofw_InitTestArray (res->sVal2, -1.0); + gofw_InitTestArray (res->pVal2, -1.0); + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); +} + + +/*-------------------------------------------------------------------------*/ + +sres_Chi2 *sres_CreateChi2 (void) +{ + sres_Chi2 *res; + res = util_Malloc (sizeof (sres_Chi2)); + memset (res, 0, sizeof (sres_Chi2)); + res->sVal1 = statcoll_Create (1, ""); + res->pVal1 = statcoll_Create (1, ""); + res->name = util_Calloc (1, sizeof (char)); + res->jmin = 0; + res->jmax = -1; + res->NbExp = NULL; + res->Count = NULL; + res->Loc = NULL; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sres_DeleteChi2 (sres_Chi2 * res) +{ + if (res == NULL) + return; + statcoll_Delete (res->sVal1); + statcoll_Delete (res->pVal1); + util_Free (res->NbExp); + util_Free (res->Count); + util_Free (res->Loc); + util_Free (res->name); + util_Free (res); +} + + +/*-------------------------------------------------------------------------*/ + +void sres_GetChi2SumStat (sres_Chi2 *res) +{ + const long N = res->sVal1->NObs; + double sum = N * statcoll_Average (res->sVal1); + res->sVal2[gofw_Sum] = sum; + if (N <= 1) { + res->pVal2[gofw_Sum] = res->sVal1->V[1]; + res->sVal2[gofw_Var] = 0; + return; + } + res->pVal2[gofw_Sum] = fbar_ChiSquare2 (N*res->degFree, 12, sum); +} + + +/*=========================================================================*/ + +void sres_InitBasic (sres_Basic *res, long N, char *nam) +{ + statcoll_Init (res->sVal1, N); + statcoll_Init (res->pVal1, N); + gofw_InitTestArray (res->sVal2, -1.0); + gofw_InitTestArray (res->pVal2, -1.0); + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); +} + + +/*-------------------------------------------------------------------------*/ + +sres_Basic *sres_CreateBasic (void) +{ + sres_Basic *res; + res = util_Malloc (sizeof (sres_Basic)); + memset (res, 0, sizeof (sres_Basic)); + res->sVal1 = statcoll_Create (1, ""); + res->pVal1 = statcoll_Create (1, ""); + res->name = util_Calloc (1, sizeof (char)); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sres_DeleteBasic (sres_Basic * res) +{ + if (res == NULL) + return; + statcoll_Delete (res->sVal1); + statcoll_Delete (res->pVal1); + util_Free (res->name); + util_Free (res); +} + + +/*-------------------------------------------------------------------------*/ + +void sres_GetNormalSumStat (sres_Basic *res) +{ + const long N = res->sVal1->NObs; + double sum = N * statcoll_Average (res->sVal1); + res->sVal2[gofw_Sum] = sum; + if (N <= 1) { + res->pVal2[gofw_Sum] = res->sVal1->V[1]; + res->sVal2[gofw_Var] = 0; + return; + } + res->pVal2[gofw_Sum] = fbar_Normal1 (sum/sqrt((double)N)); + sum = statcoll_Variance (res->sVal1); + res->sVal2[gofw_Var] = sum; + res->pVal2[gofw_Var] = fbar_ChiSquare2 (N - 1, 12, (N - 1)*sum); +} + + +/*=========================================================================*/ + +void sres_InitPoisson (sres_Poisson *res, long N, double Lambda, char *nam) +{ + statcoll_Init (res->sVal1, N); + res->Lambda = Lambda; + res->Mu = N * Lambda; + res->sVal2 = -1.0; + res->pLeft = -1.0; + res->pRight = -1.0; + res->pVal2 = -1.0; + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); + +} + + +/*-------------------------------------------------------------------------*/ + +sres_Poisson * sres_CreatePoisson (void) +{ + sres_Poisson *res; + res = util_Malloc (sizeof (sres_Poisson)); + memset (res, 0, sizeof (sres_Poisson)); + res->sVal1 = statcoll_Create (1, ""); + res->name = util_Calloc (1, sizeof (char)); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sres_DeletePoisson (sres_Poisson *res) +{ + if (res == NULL) + return; + statcoll_Delete (res->sVal1); + util_Free (res->name); + util_Free (res); +} + + +/*=========================================================================*/ + +void sres_InitDisc (sres_Disc *res, long N, char *nam) +{ + statcoll_Init (res->sVal1, N); + res->sVal2 = -1.0; + res->pLeft = -1.0; + res->pRight = -1.0; + res->pVal2 = -1.0; + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); + +} + + +/*-------------------------------------------------------------------------*/ + +sres_Disc * sres_CreateDisc (void) +{ + sres_Disc *res; + res = util_Malloc (sizeof (sres_Disc)); + memset (res, 0, sizeof (sres_Disc)); + res->sVal1 = statcoll_Create (1, ""); + res->name = util_Calloc (1, sizeof (char)); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sres_DeleteDisc (sres_Disc *res) +{ + if (res == NULL) + return; + statcoll_Delete (res->sVal1); + util_Free (res->name); + util_Free (res); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/sres.tex b/TESTU01/TestU01-1.2.3/testu01/sres.tex new file mode 100644 index 0000000..3d36a4b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sres.tex @@ -0,0 +1,428 @@ +\defmodule {sres} + +This module defines common structures used to keep the results of tests +in the {\tt s} modules. They are useful in tests where the statistics +obey either a chi-square, a normal or a Poisson distribution or some other +simple distribution. Some tests require more specialized structures for +the results and those are defined in the appropriate modules. + +The first argument of each testing function is the random number generator +to be tested. It must be created by calling the appropriate function +in one of the module {\tt u}, and deleted when no longer needed. +The second argument of each testing function is a structure +{\tt s\ldots\_Res} that can keep the test results (intermediate and final). +This is useful if one wishes to do something else with the +results or the information generated during a test. In that case, one +{\it must} call the appropriate {\tt Create} function to create the + {\tt s\ldots\_Res} structure. Simply declaring a variable {\tt +s\ldots\_Res} and passing its address as the argument will not work. +That structure must also be deleted when no longer needed. +The same structure can +be used to call a test many times with different parameters. +If one does not want to post-process or use the results after a test, +it suffices to set the {\tt \ldots\_Res} argument to the {\tt NULL} pointer. +Then, the structure is created and deleted automatically inside the +testing function. + + +\bigskip\hrule +\code\hide +/* sres.h for ANSI C */ +#ifndef SRES_H +#define SRES_H +\endhide +#include "gofw.h" +#include "statcoll.h" +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\guisec{Basic structure for test results (continuous distribution)} + +The detailed results for tests based on very simple continuous +distributions can be recovered in the structure defined below. In + particular, it is used for test statistics which obey a {\em normal\/} law. +\index{normal results} + +\code + +typedef struct { + + statcoll_Collector *sVal1, *pVal1; +\endcode + \tabb + These collectors contain the values of the test statistic and their + $p$-values (at the first level) for the $N$ replications of the current + test. The number $N$ of observations is in {\tt sVal1->NObs} and the + observations themselves are in \{{\tt sVal1->V[1], \ldots, + sVal1->V[N]}\}. They have been sorted. + The corresponding $p$-values are in {\tt pVal1}. + \endtabb +\code + + gofw_TestArray sVal2, pVal2; +\endcode + \tabb + These arrays contain the values of the statistics and their $p$-values + at the second level. In the case $N=1$, the value of the statistic at + the first level is returned in {\tt sVal2[gofw\_Mean]} and its $p$-value + in {\tt pVal2[gofw\_Mean]}. + \endtabb +\code + + char *name; +\endcode + \tabb + The name of the test which produced the above results. + \endtabb +\code + +} sres_Basic; +\endcode + \tab + This is the default basic structure used in the {\tt s} modules + to keep the results of tests when the statistic of the tests can take + continuous real values. Test results which require many parameters or + variables use more complicated structures. + \endtab +\code + + +sres_Basic * sres_CreateBasic (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a simple test. + \endtab +\code + + +void sres_DeleteBasic (sres_Basic *res); +\endcode + \tab + Frees the memory allocated to {\tt res} by {\tt sres\_CreateBasic}. + \endtab +\code + + +void sres_InitBasic (sres_Basic *res, long N, char *nam); +\endcode + \tab + Initializes the {\tt res} structure, ensures that its + collector {\tt sVal1} can contain up to {\tt N} values and sets + its {\tt name} field to {\tt nam}. This function must not be called + directly by the user. It has been made public because it is called + internally by the tests in different modules. + \endtab +\code + + +void sres_GetNormalSumStat (sres_Basic *res); +\endcode + \tab + Computes the sample sum and the sample variance $S^2$ of the $N$ observations in + the collector {\tt res->sVal1}. Then computes the $p$-value of the sum, assuming + that it obeys a {\em normal\/} law with mean 0 and variance $N$. Computes also + the $p$-value of $(N-1)S^2$, assuming it obeys a {\em chi-square\/} law with + $N-1$ degrees of freedom. The computed values are put in + {\tt res->sVal2[gofw\_Sum]}, {\tt res->pVal2[gofw\_Sum]}, + {\tt res->sVal2[gofw\_Var]} and {\tt res->pVal2[gofw\_Var]}. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Basic structure for test results (discrete distribution)} + +The detailed results for tests based on very simple discrete +distributions can be recovered in the structure defined below. + +\code + +typedef struct { + + statcoll_Collector *sVal1; +\endcode + \tabb + This collector contain the values of the test statistic + (at the first level) for the $N$ replications of the current + test. The number $N$ of observations is in {\tt sVal1->NObs} and the + observations themselves are in \{{\tt sVal1->V[1], \ldots, sVal1->V[N]}\}. + \endtabb +\code + + double sVal2; +\endcode + \tabb + The value of the statistic at the second level. It could be the sum, + the maximum or another combination of all $s$-values at the first + level (in {\tt sVal1}). + \endtabb +\code + + double pLeft, pRight, pVal2; +\endcode + \tabb + These are the left $p$-value, the right $p$-value, and the resulting + $p$-value (as computed in function {\tt gofw\_pDisc} of library + ProbDist) for the statistic at the second level ({\tt sVal12}). + \endtabb +\code + + char *name; +\endcode + \tabb + The name of the test which produced the above results. + \endtabb +\code + +} sres_Disc; +\endcode + \tab + This structure is used to keep the results of a simple + test involving a discrete distribution in the {\tt s} modules. + \endtab +\code + + +sres_Disc * sres_CreateDisc (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a simple test based on a discrete distribution. + \endtab +\code + + +void sres_DeleteDisc (sres_Disc *res); +\endcode + \tab + Frees the memory allocated to {\tt res} by {\tt sres\_CreateDisc}. + \endtab +\code + + +void sres_InitDisc (sres_Disc *res, long N, char *nam); +\endcode + \tab + Initializes the {\tt res} structure and ensures that its statistical + collector {\tt sVal1} can contain up to {\tt N} statistic values. + Also sets its {\tt name} field to {\tt nam}. + This function must not be called + directly by the user. It has been made public because it is called + internally by the tests in different modules. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for chi-square test results} + +The detailed results of a chi-square test can be recovered in the +following structure.\index{chi-square results} + +\code + +typedef struct { + + double *NbExp; + long *Count; + long *Loc; + long jmin; + long jmax; +\endcode + \tabb + {\tt NbExp} and {\tt Count} contain the expected and + observed numbers of observations in each class, respectively. + {\tt Loc} give the classes + redirections which ensure that the expected numbers in each class + are large enough to justify the application of the chi-square law. + The indices {\tt jmin} and {\tt jmax} are the lowest + and highest valid indices for these arrays. In the rare cases where + the above arrays are unused, we set {\tt jmax }$< 0$. + \endtabb +\code + + long degFree; +\endcode + \tabb + Gives the number of degrees of freedom of the chi-square. + \endtabb +\code + + statcoll_Collector *sVal1, *pVal1; +\endcode + \tabb + These collectors contain the values of the test statistic and their + $p$-values (at the first level) for the $N$ replications of the current + test. The number $N$ of observations is in {\tt sVal1->NObs} and the + observations themselves are in \{{\tt sVal1->V[1], \ldots, sVal1->V[N]}\}. + They have been sorted. The corresponding $p$-values are in {\tt pVal1}. + \endtabb +\code + + gofw_TestArray sVal2, pVal2; +\endcode + \tabb + These arrays contain the values of the statistics and their $p$-values + at the second level. In the case $N=1$, the value of the statistic at + the first level is returned in {\tt sVal2[gofw\_Mean]} and its $p$-value + in {\tt pVal2[gofw\_Mean]}. + \endtabb +\code + + char *name; +\endcode + \tabb + The name of the test which produced the above results. + \endtabb +\code + +} sres_Chi2; +\endcode + \tab + This structure is used to keep the results of a chi-square + test in the {\tt s} modules. + \endtab +\code + + +sres_Chi2 * sres_CreateChi2 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a chi-square test. + \endtab +\code + + +void sres_DeleteChi2 (sres_Chi2 *res); +\endcode + \tab + Frees the memory allocated to {\tt res} by {\tt sres\_CreateChi2}. + \endtab +\code + + +void sres_InitChi2 (sres_Chi2 *res, long N, long jmax, char *nam); +\endcode + \tab + Initializes the {\tt res} structure and ensures that its statistical + collector {\tt sVal1} can contain up to {\tt N} statistic values + while the counters can contain up to {\tt jmax + 1} classes. Also sets + its {\tt name} field to {\tt nam}. This function must not be called + directly by the user. It has been made public because it is called + internally by the tests in different modules. + \endtab +\code + + +void sres_GetChi2SumStat (sres_Chi2 *res); +\endcode + \tab + Computes the sum of the $N$ observations in the collector {\tt res->sVal1}. + Then computes the $p$-value of the sum, assuming that it obeys a + {\em chi-square\/} law with $N\ell$ degrees of freedom, where $\ell$ is the + number of degrees of freedom of the chi-square for each observation. + The computed values are put in {\tt res->sVal2[gofw\_Sum]} and + {\tt res->pVal2[gofw\_Sum]}. + \endtab + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for Poisson test results} + +The detailed results for a Poisson test can be recovered in the +following structure.\index{Poisson results} + +\code + +typedef struct { + + double Lambda, Mu; +\endcode + \tabb + The Poisson mean is {\tt Lambda}. When the number of replications + $N>1$, {\tt Mu = $N*\;$Lambda} gives the mean of the sum of all + Poisson means for the $N$ replications. + \endtabb +\code + + statcoll_Collector *sVal1; +\endcode + \tabb + This collector contain the values of the test statistic + (at the first level) for the $N$ replications of the current + test. The number $N$ of observations is in {\tt sVal1->NObs} and the + observations themselves are in \{{\tt sVal1->V[1], \ldots, sVal1->V[N]}\}. + \endtabb +\code + + double sVal2; +\endcode + \tabb + The value of the statistic at the second level + (the sum of all Poisson values in {\tt sVal1}). + \endtabb +\code + + double pLeft, pRight, pVal2; +\endcode + \tabb + These are the left $p$-value, the right $p$-value, and the resulting + $p$-value (as computed in function {\tt gofw\_pDisc} of library + ProbDist) for the Poisson statistic at the second level. + \endtabb +\code + + char *name; +\endcode + \tabb + The name of the test which produced the above results. + \endtabb +\code + +} sres_Poisson; +\endcode + \tab + This structure is used to keep the results of a Poisson + test in the {\tt s} modules. + \endtab +\code + + +sres_Poisson * sres_CreatePoisson (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a test based on the Poisson distribution. + \endtab +\code + + +void sres_DeletePoisson (sres_Poisson *res); +\endcode + \tab + Frees the memory allocated to {\tt res} by {\tt sres\_CreatePoisson}. + \endtab +\code + + +void sres_InitPoisson (sres_Poisson *res, long N, double Lambda, char *nam); +\endcode + \tab + Initializes the {\tt res} structure and ensures that its statistical + collector {\tt sVal1} can contain up to {\tt N} statistic values. + Also sets its {\tt Lambda} field to the Poisson mean {\tt Lambda} and + its {\tt name} field to {\tt nam}. This function must not be called + directly by the user. It has been made public because it is called + internally by the tests in different modules. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/sresshort.tex b/TESTU01/TestU01-1.2.3/testu01/sresshort.tex new file mode 100644 index 0000000..b3a8812 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sresshort.tex @@ -0,0 +1,18 @@ +\defmodule {sres} + +This module defines common structures used to keep the results of tests +in the {\tt s} modules. They are described in the detailed version of +this guide. + + +The first argument of each testing function is the random number generator +to be tested. It must be created by calling the appropriate function +in one of the module {\tt u}, and deleted when no longer needed. +The second argument of each testing function is a structure +{\tt s\ldots\_Res} that can keep the test results (intermediate and final). +This is useful if one wishes to do something else with the +results or the information generated during a test. +If one does not want to post-process or use the results after a test, +it suffices to set the {\tt \ldots\_Res} argument to the {\tt NULL} pointer. +Then, the structure is created and deleted automatically inside the +testing function. diff --git a/TESTU01/TestU01-1.2.3/testu01/sspacings.c b/TESTU01/TestU01-1.2.3/testu01/sspacings.c new file mode 100644 index 0000000..51a991f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sspacings.c @@ -0,0 +1,849 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: sspacings.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "chrono.h" +#include "num.h" +#include "tables.h" + +#include "sspacings.h" +#include "unif01.h" +#include "wdist.h" +#include "swrite.h" + +#include "statcoll.h" +#include "gofw.h" +#include "fbar.h" + +#include +#include +#include + + + + + + +/*------------------------------- Constants -------------------------------*/ + +/* String length */ +#define LEN 50 + +/* Euler's constant */ +static const double EULER = 0.577215664901533; + +/* Necessary so that the multiplication of a large number of U01 will not + underflow; the precise value is not so important: it could be bigger. */ +static const double Epsilon = 1.0E-200; + + +#define MAXM 201 + + +/*--------------------------------- Types -------------------------------*/ + +typedef enum +{ + LOG_EXACT_CIRC, /* Log of spacings, exact, circular */ + LOG_EXACT_LIN, /* Log of spacings, exact, linear */ + LOG_ASYMP_CIRC, /* Log of spacings, asymptotic, circular */ + LOG_ASYMP_LIN, /* Log of spacings, asymptotic, linear */ + SQUA_EXACT_CIRC, /* Square of spacings, exact, circular */ + SQUA_EXACT_LIN, /* Square of spacings, exact, linear */ + SQUA_ASYMP_CIRC, /* Square of spacings, asymptotic, circular */ + SQUA_ASYMP_LIN, /* Square of spacings, asymptotic, linear */ + Stats_N /* Number of statistics in this enum */ +} Stats; + + +typedef struct +{ + int NbColl; /* Number of collectors used for each m */ + int Nbm; /* Number of values of m to consider */ + int Loc[MAXM]; /* The statistic for m is in Loc [m] */ + double Mu[MAXM][Stats_N]; /* Mean */ + double Sig[MAXM][Stats_N]; /* Standard deviation */ + double HMu[MAXM][Stats_N]; /* Empirical mean */ + double HSig[MAXM][Stats_N]; /* Empirical standard deviation */ +} Param; + + + +/*------------------------------- Functions -------------------------------*/ + + +sspacings_Res * sspacings_CreateRes (void) +{ + sspacings_Res *res; + res = util_Malloc (sizeof (sspacings_Res)); + memset (res, 0, sizeof (sspacings_Res)); + res->name = util_Calloc (1, sizeof (char)); + res->smax = -1; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sspacings_DeleteRes (sspacings_Res *res) +{ + int j; + if (res == NULL) + return; + for (j = 0; j <= res->smax; j += 2) + res->Collectors[j] = statcoll_Delete (res->Collectors[j]); + util_Free (res->Collectors); + + for (j = 0; j <= res->imax; j++) { + sres_DeleteBasic (res->LogCAMu[j]); + sres_DeleteBasic (res->LogCEMu[j]); + sres_DeleteBasic (res->SquareCAMu[j]); + sres_DeleteBasic (res->SquareCEMu[j]); + } + + util_Free (res->LogCEMu); + util_Free (res->LogCAMu); + util_Free (res->SquareCEMu); + util_Free (res->SquareCAMu); + + util_Free (res->LogCESig_sVal); + util_Free (res->LogCESig_pVal); + util_Free (res->LogCASig_sVal); + util_Free (res->LogCASig_pVal); + util_Free (res->SquareCESig_sVal); + util_Free (res->SquareCESig_pVal); + util_Free (res->SquareCASig_sVal); + util_Free (res->SquareCASig_pVal); + + util_Free (res->name); + util_Free (res); +} + + +/*-------------------------------------------------------------------------*/ + +static void InitRes ( + sspacings_Res *res, /* Results holder */ + long N, /* Number of replications */ + int Nbm, /* Number of values of m to consider */ + char *nam /* Test name */ +) +/* + * Initializes res + */ +{ + char nom[LEN + 1]; + char spindex[LEN + 1]; + int j; + + if (res->smax < 0) { + res->Collectors = util_Calloc ((size_t) 8 * Nbm, + sizeof (statcoll_Collector *)); + for (j = 0; j < 8 * Nbm; j += 2) + res->Collectors[j] = statcoll_Create (N, ""); + + res->LogCAMu = util_Calloc ((size_t) Nbm, sizeof (sres_Basic *)); + res->LogCEMu = util_Calloc ((size_t) Nbm, sizeof (sres_Basic *)); + res->SquareCAMu = util_Calloc ((size_t) Nbm, sizeof (sres_Basic *)); + res->SquareCEMu = util_Calloc ((size_t) Nbm, sizeof (sres_Basic *)); + for (j = 0; j < Nbm; j++) { + res->LogCAMu[j] = sres_CreateBasic (); + res->LogCEMu[j] = sres_CreateBasic (); + res->SquareCAMu[j] = sres_CreateBasic (); + res->SquareCEMu[j] = sres_CreateBasic (); + } + + res->LogCESig_sVal = util_Calloc ((size_t) Nbm, sizeof (double)); + res->LogCESig_pVal = util_Calloc ((size_t) Nbm, sizeof (double)); + res->LogCASig_sVal = util_Calloc ((size_t) Nbm, sizeof (double)); + res->LogCASig_pVal = util_Calloc ((size_t) Nbm, sizeof (double)); + res->SquareCESig_sVal = util_Calloc ((size_t) Nbm, sizeof (double)); + res->SquareCESig_pVal = util_Calloc ((size_t) Nbm, sizeof (double)); + res->SquareCASig_sVal = util_Calloc ((size_t) Nbm, sizeof (double)); + res->SquareCASig_pVal = util_Calloc ((size_t) Nbm, sizeof (double)); + + } else { + for (j = 8 * Nbm; j <= res->smax; j += 2) + res->Collectors[j] = statcoll_Delete (res->Collectors[j]); + res->Collectors = util_Realloc (res->Collectors, + 8 * Nbm * sizeof (statcoll_Collector *)); + for (j = res->smax + 2; j < 8 * Nbm; j += 2) + res->Collectors[j] = statcoll_Create (N, ""); + + for (j = Nbm; j <= res->imax; j++) { + sres_DeleteBasic (res->LogCAMu[j]); + sres_DeleteBasic (res->LogCEMu[j]); + sres_DeleteBasic (res->SquareCAMu[j]); + sres_DeleteBasic (res->SquareCEMu[j]); + } + res->LogCAMu = util_Realloc (res->LogCAMu, + Nbm * sizeof (sres_Basic *)); + res->LogCEMu = util_Realloc (res->LogCEMu, + Nbm * sizeof (sres_Basic *)); + res->SquareCAMu = util_Realloc (res->SquareCAMu, + Nbm * sizeof (sres_Basic *)); + res->SquareCEMu = util_Realloc (res->SquareCEMu, + Nbm * sizeof (sres_Basic *)); + + for (j = res->imax + 1; j < Nbm; j++) { + res->LogCAMu[j] = sres_CreateBasic (); + res->LogCEMu[j] = sres_CreateBasic (); + res->SquareCAMu[j] = sres_CreateBasic (); + res->SquareCEMu[j] = sres_CreateBasic (); + } + + res->LogCESig_sVal = + util_Realloc (res->LogCESig_sVal, Nbm * sizeof (double)); + res->LogCESig_pVal = + util_Realloc (res->LogCESig_pVal, Nbm * sizeof (double)); + res->LogCASig_sVal = + util_Realloc (res->LogCASig_sVal, Nbm * sizeof (double)); + res->LogCASig_pVal = + util_Realloc (res->LogCASig_pVal, Nbm * sizeof (double)); + res->SquareCESig_sVal = + util_Realloc (res->SquareCESig_sVal, Nbm * sizeof (double)); + res->SquareCESig_pVal = + util_Realloc (res->SquareCESig_pVal, Nbm * sizeof (double)); + res->SquareCASig_sVal = + util_Realloc (res->SquareCASig_sVal, Nbm * sizeof (double)); + res->SquareCASig_pVal = + util_Realloc (res->SquareCASig_pVal, Nbm * sizeof (double)); + } + + for (j = 0; j < 8 * Nbm; j += 2) + statcoll_Init (res->Collectors[j], N); + res->smax = 8 * Nbm - 2; + + for (j = 0; j < Nbm; j++) { + strncpy (nom, "LogCEMu[", (size_t) LEN); + sprintf (spindex, "%1d", j); + strncat (nom, spindex, (size_t) 5); + strncat (nom, "]", (size_t) 2); + sres_InitBasic (res->LogCEMu[j], N, nom); + + strncpy (nom, "LogCAMu[", (size_t) LEN); + sprintf (spindex, "%1d", j); + strncat (nom, spindex, (size_t) 5); + strncat (nom, "]", (size_t) 2); + sres_InitBasic (res->LogCAMu[j], N, nom); + + strncpy (nom, "SquareCEMu[", (size_t) LEN); + sprintf (spindex, "%1d", j); + strncat (nom, spindex, (size_t) 5); + strncat (nom, "]", (size_t) 2); + sres_InitBasic (res->SquareCEMu[j], N, nom); + + strncpy (nom, "SquareCAMu[", (size_t) LEN); + sprintf (spindex, "%1d", j); + strncat (nom, spindex, (size_t) 5); + strncat (nom, "]", (size_t) 2); + sres_InitBasic (res->SquareCAMu[j], N, nom); + + res->imax = j; + } + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); + + memset (res->LogCESig_sVal, 0, sizeof (res->LogCESig_sVal)); + memset (res->LogCESig_pVal, 0, sizeof (res->LogCESig_pVal)); + memset (res->LogCASig_sVal, 0, sizeof (res->LogCASig_sVal)); + memset (res->LogCASig_pVal, 0, sizeof (res->LogCASig_pVal)); + memset (res->SquareCESig_sVal, 0, sizeof (res->SquareCESig_sVal)); + memset (res->SquareCESig_pVal, 0, sizeof (res->SquareCESig_pVal)); + memset (res->SquareCASig_sVal, 0, sizeof (res->SquareCASig_sVal)); + memset (res->SquareCASig_pVal, 0, sizeof (res->SquareCASig_pVal)); +} + + +/*=========================================================================*/ + + +void sspacings_SumLogsSpacings (unif01_Gen * gen, sspacings_Res * res, + long N, long n, int r, int m) +{ + util_Error ("sspacings_SumLogsSpacings is implemented inside " + "sspacings_AllSpacings2"); +} + + +/*=========================================================================*/ + +void sspacings_SumSquaresSpacings (unif01_Gen * gen, sspacings_Res * res, + long N, long n, int r, int m) +{ + util_Error ("sspacings_SumSquaresSpacings is implemented inside " + "sspacings_AllSpacings2"); +} + + +/*=========================================================================*/ + +void sspacings_ScanSpacings (unif01_Gen * gen, sspacings_Res * res, + long N, long n, int r, double d) +{ + util_Error ("sspacings_ScanSpacings not implemented"); +} + + +/*=========================================================================*/ + +static void WrRes (char S1[], long N, Param * par, int m, int i, + statcoll_Collector * Collectors[], gofw_TestArray sv, gofw_TestArray pv) +{ + printf ("%s", S1); + printf ("\n Mu = "); + num_WriteD (par->Mu[m][i], 12, 8, 7); + printf ("\n Sigma = "); + num_WriteD (par->Sig[m][i], 12, 8, 7); + printf ("\n\nEmpirical mean of standardized values :"); + num_WriteD (par->HMu[m][i] / N, 12, 8, 7); + printf ("\n"); + gofw_Writep1 (fbar_Normal1 (par->HMu[m][i] / N)); + printf ("Second empirical moment of standardized values:"); + num_WriteD (par->HSig[m][i] / N, 12, 8, 7); + printf ("\n"); + gofw_Writep1 (fbar_ChiSquare2 (N, 12, par->HSig[m][i])); + i += 8 * par->Loc[m]; + if (N > 1) + gofw_WriteActiveTests0 (N, sv, pv); + + if (swrite_Collectors) { + statcoll_Write (Collectors[i], 5, 14, 4, 3); + printf ("\n"); + } + printf ("\n"); +} + +/*-------------------------------------------------------------------------*/ + +static void UpdateStat (Param * par, int m, int i, double v, + statcoll_Collector * Collectors[]) +{ + double x; + + x = (v - par->Mu[m][i]) / par->Sig[m][i]; + par->HMu[m][i] += x; + par->HSig[m][i] += x * x; + i += 8 * par->Loc[m]; + statcoll_AddObs (Collectors[i], x); +} + +/*-------------------------------------------------------------------------*/ + +static void InitAllSpacings (unif01_Gen * gen, char *TestName, Param * par, + long N, long n0, int r, int M0, int M1, int D, int LgEps) +{ + double Rmn[MAXM]; /* R(m,n) and Q(m,n) from Cressie (1976) */ + double Qmn[MAXM]; + double Rmm1[MAXM]; + double Qmm1[MAXM]; + double Rm1; + double Qm1; /* R(1,m-1) and Q(1,m-1) from Cressie */ + double Fact; /* n^2 / (n+2) */ + double Mu0; + double x, y; + double I; + double R; + double Q; + double nLR; + double mLR; + int m; + int i; + + if (swrite_Basic) { + swrite_Head (gen, TestName, N, n0, r); + printf (", M0 = %1d, M1 = %1d, D = %1d\n", M0, M1, D); + printf (" LgEps = %1d\n\n\n", LgEps); + } + util_Assert (M1 < MAXM, "InitAllSpacings: M1 is too large"); + + par->Nbm = 1 + (M1 - M0) / D; + for (i = 0; i < par->Nbm; i++) + par->Loc[M0 + i * D] = i; + if (M0 == 0) + par->Loc[1] = 0; + + /* Initialize constants and arrays */ + nLR = n0; + Fact = nLR * nLR / (nLR + 2.0); + R = 0.0; + Q = 0.0; + + for (i = n0; i >= M1; i--) { + I = 1.0 / i; + R += I; + Q += I * I; + } + + Rmn[M1] = R; + Qmn[M1] = Q; + for (m = M1 - 1; m >= 1; m--) { + I = 1.0 / m; + Rmn[m] = Rmn[m + 1] + I; + Qmn[m] = Qmn[m + 1] + I * I; + } + + m = 1; + Rmm1[1] = 0.0; + Qmm1[1] = 0.0; + for (m = 2; m <= M1; m++) { + I = 1.0 / (m - 1); + Rmm1[m] = Rmm1[m - 1] + I; + Qmm1[m] = Qmm1[m - 1] + I * I; + } + + /* Compute theoretical means and variances */ + if (M0 == 0) + m = 1; + else + m = M0; + + while (m <= M1) { + mLR = m; + Rm1 = Rmm1[m]; + Qm1 = Qmm1[m]; + par->Mu[m][LOG_EXACT_CIRC] = -(nLR + 1.0) * Rmn[m]; + par->Mu[m][LOG_EXACT_LIN] = + par->Mu[m][LOG_EXACT_CIRC] * (nLR + 2.0 - mLR) / (nLR + 1.0); + par->Mu[m][LOG_ASYMP_CIRC] = + -(nLR + 1.0) * (log (nLR + 1.0) + EULER - Rm1); + par->Mu[m][LOG_ASYMP_LIN] = + par->Mu[m][LOG_ASYMP_CIRC] * (nLR + 2.0 - mLR) / (nLR + 1.0); + Mu0 = mLR * (mLR + 1.0); + par->Mu[m][SQUA_EXACT_CIRC] = Mu0 * Fact; + par->Mu[m][SQUA_EXACT_LIN] = + par->Mu[m][SQUA_EXACT_CIRC] * (nLR - mLR + 2.0) / (nLR + 1.0); + par->Mu[m][SQUA_ASYMP_CIRC] = Mu0 * (nLR + 1.0); + par->Mu[m][SQUA_ASYMP_LIN] = Mu0 * (nLR - mLR + 2.0); + + x = (2 * m * (m - 1) + 1) * ((num_Pi * num_Pi) / 6.0 - Qm1) + + (-2 * m + 1); + util_Assert (x > 0.0, "Negative Sig [m, 2]"); + par->Sig[m][LOG_ASYMP_CIRC] = sqrt (nLR * x); + par->Sig[m][LOG_ASYMP_LIN] = par->Sig[m][LOG_ASYMP_CIRC]; /* See Holst + 1979 */ + + x = Qmn[m] + nLR * Qmn[1] - 2.0 * (mLR - 1.0) * (mLR * Qm1 + 1.0) + + (2.0 * mLR * (mLR - 1.0) - nLR) * num_Pi * num_Pi / 6.0; + util_Assert (x > 0.0, "Negative Sig [m, 0] ..."); + par->Sig[m][LOG_EXACT_CIRC] = sqrt ((nLR + 1.0) * x); + + y = 2 * m * (m + 1) * (2 * m + 1) / 3.0; + par->Sig[m][SQUA_ASYMP_CIRC] = sqrt (nLR * y); + par->Sig[m][SQUA_ASYMP_LIN] = par->Sig[m][SQUA_ASYMP_CIRC]; + + x = 2.0 * mLR * (1.0 + mLR) * (2.0 + mLR * (1.0 - 3.0 * mLR) + + nLR * (1.0 + 2.0 * mLR)) / 3.0; + x = x / ((nLR + 3.0) * (nLR + 4.0)); + util_Assert (x > 0.0, "Negative Sig [m, 4]"); + par->Sig[m][SQUA_EXACT_CIRC] = sqrt (x) * Fact; + + x = 20.0 + mLR * (-54.0 + mLR * (6.0 + mLR * (58.0 - 30.0 * mLR))); + x += nLR * (34.0 + mLR * (-37.0 + mLR * (-27.0 + mLR * (48.0 - + 12.0 * mLR)))); + x += nLR * nLR * (16.0 + mLR * (3.0 + mLR * (-15.0 + 8.0 * mLR))); + x += nLR * nLR * nLR * 2.0 * (1.0 + 2.0 * mLR); + x = x * mLR * (1.0 + mLR) / 3.0; + x = x / ((nLR + 3.0) * (nLR + 4.0)); + util_Assert (x > 0.0, "Negative Sig [m, 5]"); + par->Sig[m][SQUA_EXACT_LIN] = sqrt (x) * Fact / (nLR + 1.0); + + /* Initalization of tables for the tests */ + for (i = 0; i < Stats_N; i++) { + par->HMu[m][i] = 0.0; + par->HSig[m][i] = 0.0; + } + if (M0 == 0 && m == 1) + m = D; + else + m += D; + } + /* + if (swrite_Basic) + printf (" Number of collectors initialized to N: %1d\n\n", + par->NbColl * par->Nbm); + */ +} + + +/*=========================================================================*/ + +static void CopyResults (sspacings_Res * res, Param * par, long N, + int M0, int M1, int D, int flag) +{ + int m, s, i, k; + + if (M0 == 0) + m = 1; + else + m = M0; + s = 0; + + while (m <= M1) { + i = LOG_EXACT_CIRC; + k = i + 8 * par->Loc[m]; + tables_CopyTabD (res->Collectors[k]->V, res->LogCEMu[s]->sVal1->V, 1, + N); + res->LogCEMu[s]->sVal1->NObs = N; + gofw_ActiveTests2 (res->Collectors[k]->V, res->LogCEMu[s]->pVal1->V, + N, wdist_Normal, (double *) NULL, res->LogCEMu[s]->sVal2, + res->LogCEMu[s]->pVal2); + + res->LogCEMu[s]->sVal2[gofw_Mean] = par->HMu[m][i] / N; + res->LogCEMu[s]->pVal2[gofw_Mean] = fbar_Normal1 (par->HMu[m][i] / N); + res->LogCESig_sVal[s] = par->HSig[m][i] / N; + res->LogCESig_pVal[s] = fbar_ChiSquare2 (N, 12, par->HSig[m][i]); + + i = LOG_ASYMP_CIRC; + k = i + 8 * par->Loc[m]; + tables_CopyTabD (res->Collectors[k]->V, res->LogCAMu[s]->sVal1->V, 1, + N); + res->LogCAMu[s]->sVal1->NObs = N; + if (flag) { + gofw_ActiveTests2 (res->Collectors[k]->V, res->LogCAMu[s]->pVal1->V, + N, wdist_Normal, (double *) NULL, res->LogCAMu[s]->sVal2, + res->LogCAMu[s]->pVal2); + + res->LogCAMu[s]->sVal2[gofw_Mean] = par->HMu[m][i] / N; + res->LogCAMu[s]->pVal2[gofw_Mean] = + fbar_Normal1 (par->HMu[m][i] / N); + res->LogCASig_sVal[s] = par->HSig[m][i] / N; + res->LogCASig_pVal[s] = fbar_ChiSquare2 (N, 12, par->HSig[m][i]); + } else { + res->LogCAMu[s]->sVal2[gofw_Mean] = 0.0; + res->LogCAMu[s]->pVal2[gofw_Mean] = 0.0; + res->LogCASig_sVal[s] = 0.0; + res->LogCASig_pVal[s] = 0.0; + memset (res->LogCAMu[s]->sVal2, 0, sizeof (res->LogCAMu[s]->sVal2)); + memset (res->LogCAMu[s]->pVal2, 0, sizeof (res->LogCAMu[s]->pVal2)); + } + + i = SQUA_EXACT_CIRC; + k = i + 8 * par->Loc[m]; + tables_CopyTabD (res->Collectors[k]->V, res->SquareCEMu[s]->sVal1->V, + 1, N); + res->SquareCEMu[s]->sVal1->NObs = N; + gofw_ActiveTests2 (res->Collectors[k]->V, res->SquareCEMu[s]->pVal1->V, + N, wdist_Normal, (double *) NULL, res->SquareCEMu[s]->sVal2, + res->SquareCEMu[s]->pVal2); + + res->SquareCEMu[s]->sVal2[gofw_Mean] = par->HMu[m][i] / N; + res->SquareCEMu[s]->pVal2[gofw_Mean] = + fbar_Normal1 (par->HMu[m][i] / N); + res->SquareCESig_sVal[s] = par->HSig[m][i] / N; + res->SquareCESig_pVal[s] = fbar_ChiSquare2 (N, 12, par->HSig[m][i]); + + i = SQUA_ASYMP_CIRC; + k = i + 8 * par->Loc[m]; + tables_CopyTabD (res->Collectors[k]->V, res->SquareCAMu[s]->sVal1->V, + 1, N); + res->SquareCAMu[s]->sVal1->NObs = N; + if (flag) { + gofw_ActiveTests2 (res->Collectors[k]->V, + res->SquareCAMu[s]->pVal1->V, N, wdist_Normal, (double *) NULL, + res->SquareCAMu[s]->sVal2, res->SquareCAMu[s]->pVal2); + res->SquareCAMu[s]->sVal2[gofw_Mean] = par->HMu[m][i] / N; + res->SquareCAMu[s]->pVal2[gofw_Mean] = + fbar_Normal1 (par->HMu[m][i] / N); + res->SquareCASig_sVal[s] = par->HSig[m][i] / N; + res->SquareCASig_pVal[s] = fbar_ChiSquare2 (N, 12, par->HSig[m][i]); + + } else { + res->SquareCAMu[s]->sVal2[gofw_Mean] = 0.0; + res->SquareCAMu[s]->pVal2[gofw_Mean] = 0.0; + res->SquareCASig_sVal[s] = 0.0; + res->SquareCASig_pVal[s] = 0.0; + memset (res->SquareCAMu[s]->sVal2, 0, + sizeof (res->SquareCAMu[s]->sVal2)); + memset (res->SquareCAMu[s]->pVal2, 0, + sizeof (res->SquareCAMu[s]->pVal2)); + } + + if (M0 == 0 && m == 1) + m = D; + else + m += D; + s++; + } +} + + +/*=========================================================================*/ + +void sspacings_AllSpacings (unif01_Gen * gen, sspacings_Res * res, + long N, long n0, int r, int M0, int M1, int D, int LgEps) +{ + long i; + int m, s; + long Seq; + double Eps; /* Minimal spacing for SumLogsSpacings */ + double *U; + double Prod, x; + double LnProd; + double SumSq; + int NbMinus[MAXM]; /* Number of spacings < Eps */ + Param par; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sspacings_AllSpacings test"; + + Timer = chrono_Create (); + memset (&par, 0, sizeof (Param)); + par.NbColl = 4; + InitAllSpacings (gen, TestName, &par, N, n0, r, M0, M1, D, LgEps); + Eps = 1.0 / num_TwoExp[LgEps]; + + if (res == NULL) { + localRes = TRUE; + res = sspacings_CreateRes (); + } + InitRes (res, N, par.Nbm, "sspacings_AllSpacings"); + res->step = 2; + + U = util_Calloc ((size_t) n0 + M1 + 2, sizeof (double)); + U[0] = 0.0; + + /* Beginning of tests */ + for (Seq = 1; Seq <= N; Seq++) { + for (i = 1; i <= n0; i++) + U[i] = unif01_StripD (gen, r); + tables_QuickSortD (U, 1, n0); + util_Assert (U[1] >= 0.0, "sspacings_AllSpacings: U[1] < 0.0"); + util_Assert (U[n0] <= 1.0, "sspacings_AllSpacings: U[n] > 1.0"); + + for (i = 1; i <= M1; i++) + U[n0 + i] = 1.0 + U[i - 1]; + if (M0 == 0) + m = 1; + else + m = M0; + + while (m <= M1) { + NbMinus[m] = 0; + Prod = 1.0; + LnProd = 0.0; + SumSq = 0.0; + + for (i = 0; i <= n0; i++) { + x = U[i + m] - U[i]; + SumSq += x * x; + /* In case a spacing is zero */ + if (x < Eps) { + x = Eps; + ++NbMinus[m]; + } + /* Compute log of product instead of sum of logs; it is faster */ + Prod *= x; + if (Prod < Epsilon) { + /* Take log once in a while to avoid underflow */ + LnProd += log (Prod); + Prod = 1.0; + } + } + LnProd += log (Prod); + + UpdateStat (&par, m, LOG_EXACT_CIRC, LnProd, res->Collectors); + UpdateStat (&par, m, LOG_ASYMP_CIRC, LnProd, res->Collectors); + UpdateStat (&par, m, SQUA_EXACT_CIRC, SumSq * n0 * n0, + res->Collectors); + UpdateStat (&par, m, SQUA_ASYMP_CIRC, SumSq * n0 * n0, + res->Collectors); + if (M0 == 0 && m == 1) + m = D; + else + m += D; + } + } + + CopyResults (res, &par, N, M0, M1, D, 1); + if (swrite_Basic) { + printf ("\nResults:"); + if (M0 == 0) + m = 1; + else + m = M0; + s = 0; + while (m <= M1) { + printf ("\n----------------------------------------------------\n"); + printf ("m = %1d\n\n", m); + if (NbMinus[m] > 0) + printf ("%1d spacings < 1 / 2^%1d\n\n", NbMinus[m], LgEps); + + printf ("Logs of spacings:\n-----------------\n\n"); + WrRes ("Exact mean and standard deviation, circular:", + N, &par, m, LOG_EXACT_CIRC, res->Collectors, + res->LogCEMu[s]->sVal2, res->LogCEMu[s]->pVal2); + WrRes ("Asymptotic mean and standard deviation, circular:", + N, &par, m, LOG_ASYMP_CIRC, res->Collectors, + res->LogCAMu[s]->sVal2, res->LogCAMu[s]->pVal2); + + printf ("\nSquares of spacings:\n--------------------\n\n"); + WrRes ("Exact mean and standard deviation, circular:", + N, &par, m, SQUA_EXACT_CIRC, res->Collectors, + res->SquareCEMu[s]->sVal2, res->SquareCEMu[s]->pVal2); + WrRes ("Asymptotic mean and standard deviation, circular:", + N, &par, m, SQUA_ASYMP_CIRC, res->Collectors, + res->SquareCAMu[s]->sVal2, res->SquareCAMu[s]->pVal2); + + if (M0 == 0 && m == 1) + m = D; + else + m += D; + s++; + } + printf ("\n"); + swrite_Final (gen, Timer); + } + + U = util_Free (U); + if (localRes) + sspacings_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sspacings_AllSpacings2 (unif01_Gen * gen, sspacings_Res * res, + long N, long n0, int r, int M0, int M1, int D, int LgEps) +{ + long i; + int m, j, s; + long Seq; + double Eps; /* Minimal spacing for SumLogsSpacings */ + double *U; + double Prod, x; + double LnProd; + double SumSq; + int NbMinus[MAXM]; /* Number of spacings < Eps */ + Param par; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sspacings_AllSpacings2 test"; + + Timer = chrono_Create (); + memset (&par, 0, sizeof (Param)); + par.NbColl = 2; + InitAllSpacings (gen, TestName, &par, N, n0, r, M0, M1, D, LgEps); + Eps = 1.0 / num_TwoExp[LgEps]; + + if (res == NULL) { + localRes = TRUE; + res = sspacings_CreateRes (); + } + InitRes (res, N, par.Nbm, "sspacings_AllSpacings2"); + res->step = 4; + + U = util_Calloc ((size_t) n0 + M1 + 2, sizeof (double)); + U[0] = 0.0; + + /* Beginning of tests */ + for (Seq = 1; Seq <= N; Seq++) { + for (i = 1; i <= n0; i++) + U[i] = unif01_StripD (gen, r); + tables_QuickSortD (U, 1, n0); + for (j = 1; j <= M1; j++) + U[n0 + j] = 1.0 + U[j - 1]; + if (M0 == 0) + m = 1; + else + m = M0; + + while (m <= M1) { + NbMinus[m] = 0; + Prod = 1.0; + LnProd = 0.0; + SumSq = 0.0; + + for (i = 0; i <= n0; i++) { + x = U[i + m] - U[i]; + SumSq += x * x; + /* In case a spacing is zero */ + if (x < Eps) { + x = Eps; + ++NbMinus[m]; + } + /* Compute log of product instead of sum of logs; it is faster */ + Prod *= x; + if (Prod < Epsilon) { + /* Take log once in a while to avoid underflow */ + LnProd += log (Prod); + Prod = 1.0; + } + } + LnProd += log (Prod); + + UpdateStat (&par, m, LOG_EXACT_CIRC, LnProd, res->Collectors); + UpdateStat (&par, m, SQUA_EXACT_CIRC, SumSq * n0 * n0, + res->Collectors); + if (M0 == 0 && m == 1) + m = D; + else + m += D; + } + } + + CopyResults (res, &par, N, M0, M1, D, 0); + if (swrite_Basic) { + printf ("\nResults:"); + if (M0 == 0) + m = 1; + else + m = M0; + s = 0; + + while (m <= M1) { + printf ("\n----------------------------------------------------\n"); + printf ("m = %1d\n\n", m); + if (NbMinus[m] > 0) + printf ("%1d spacings < 1 / 2^%1d\n\n", NbMinus[m], LgEps); + printf ("Logs of spacings:\n-----------------\n\n"); + WrRes ("Exact mean and standard deviation, circular:", + N, &par, m, LOG_EXACT_CIRC, res->Collectors, + res->LogCEMu[s]->sVal2, res->LogCEMu[s]->pVal2); + printf ("\nSquares of spacings:\n--------------------\n\n"); + WrRes ("Exact mean and standard deviation, circular:", + N, &par, m, SQUA_EXACT_CIRC, res->Collectors, + res->SquareCEMu[s]->sVal2, res->SquareCEMu[s]->pVal2); + if (M0 == 0 && m == 1) + m = D; + else + m += D; + s++; + } + printf ("\n"); + swrite_Final (gen, Timer); + } + + U = util_Free (U); + if (localRes) + sspacings_DeleteRes (res); + chrono_Delete (Timer); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/sspacings.tex b/TESTU01/TestU01-1.2.3/testu01/sspacings.tex new file mode 100644 index 0000000..01258ec --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sspacings.tex @@ -0,0 +1,245 @@ +\defmodule {sspacings} + +This module implements tests based on sum functions of the spacings +\index{spacings} +between the sorted observations of a sample of independent uniforms. +These tests are studied by L'Ecuyer \cite{rLEC97h}. + +Let $u_1,\dots,u_n$ be a sample of $n$ uniforms over $(0,1)$, and +$u_{(1)},\dots, u_{(n)}$ their values sorted by increasing order. +Define $u_{(0)} = 0$ and $u_{(n+i)} = 1 + u_{(i-1)}$ for $i > 1$. +For $m +#include +#include + + + + + + +/*-------------------------------- Functions ------------------------------*/ + + +static void InitRes ( + sspectral_Res *res, + long N, + long jmin, + long jmax, + char *nam +) +/* + * Initializes the sspectral_Res structure + */ +{ + long j; + sres_InitBasic (res->Bas, N, nam); + if (jmax > res->jmax) + res->Coef = util_Realloc (res->Coef, (jmax + 200) * sizeof (double)); + for (j = 0; j <= jmax; j++) + res->Coef[j] = 0.0; + res->jmin = jmin; + res->jmax = jmax; + res->Bas->name = util_Realloc (res->Bas->name, + 1 + strlen (nam) * sizeof (char)); + strcpy (res->Bas->name, nam); +} + + +/*-------------------------------------------------------------------------*/ + +sspectral_Res * sspectral_CreateRes (void) +{ + sspectral_Res *res; + res = util_Malloc (sizeof (sspectral_Res)); + res->Bas = sres_CreateBasic (); + res->Coef = util_Calloc (1, sizeof (double)); + res->jmax = 0; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sspectral_DeleteRes (sspectral_Res *res) +{ + if (res == NULL) + return; + sres_DeleteBasic (res->Bas); + util_Free (res->Coef); + util_Free (res); +} + + +/*=========================================================================*/ + +static void WriteDataFour ( + unif01_Gen *gen, /* generator */ + char *Test, /* Test name */ + long N, /* Number of replications */ + int k, /* Sample size n = 2^k */ + int r, /* r first bits of each random number dropped */ + int s /* s bits of each random number used */ +) +{ + long n; + n = num_TwoExp[k]; + swrite_Head (gen, Test, N, n, r); + printf (", s = %4d, k = %4d\n\n", s, k); +} + + +/*-------------------------------------------------------------------------*/ + +void sspectral_Fourier1 (unif01_Gen *gen, sspectral_Res *res, + long N, int t, int r, int s) +{ + const unsigned long SBIT = 1UL << (s - 1); + unsigned long jBit; + unsigned long Z; + long k, KALL, Seq, n, i; + double x, NbExp, h, per; + long co; + double *A; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sspectral_Fourier1 test"; + + Timer = chrono_Create (); + util_Assert (t <= 20, "sspectral_Fourier1: k > 20"); + util_Assert (t > 1, "sspectral_Fourier1: k < 2"); + if (swrite_Basic) + WriteDataFour (gen, TestName, N, t, r, s); + if (res == NULL) { + localRes = TRUE; + res = sspectral_CreateRes (); + } + n = num_TwoExp[t]; + KALL = n / s; + if (n % s > 0) + KALL++; + per = 0.95; + NbExp = per * (n / 2 + 1); +/* h = 3.0 * n; */ + h = 2.995732274 * n; + InitRes (res, N, 0, n, "sspectral_Fourier1"); + statcoll_SetDesc (res->Bas->sVal1, "sVal1: a standard normal"); + A = res->Coef; + + for (Seq = 1; Seq <= N; Seq++) { + /* Fill array A: 1 for bit 1, -1 for bit 0 */ + i = 0; + for (k = 0; k < KALL; k++) { + Z = unif01_StripB (gen, r, s); + jBit = SBIT; + while (jBit) { + if (jBit & Z) + A[i] = 1.0; + else + A[i] = -1.0; + jBit >>= 1; + i++; + } + } + /* + * Compute the Fourier transform of A and return the result in A. The + * first half of the array, (from 0 to n/2) is filled with the real + * components of the FFT. The second half of the array (from n/2+1 to + * n-1) is filled with the imaginary components of the FFT. + * The n new elements of A are thus: + * [Re(0), Re(1), ...., Re(n/2), Im(n/2-1), ..., Im(1)] + * The procedure is due to H.V. Sorensen, University of Pennsylvania + * and is found in file fftc.c. + */ + rsrfft (A, t); + + /* Count the number of Fourier coefficients smaller than h */ + co = 0; + for (i = 1; i < n / 2; i++) { + x = A[i] * A[i] + A[n - i] * A[n - i]; + if (x < h) + co++; + } + if (A[0] * A[0] < h) + co++; + + /* Compute the NIST statistic */ + x = (co - NbExp) / sqrt (NbExp * (1.0 - per)); + statcoll_AddObs (res->Bas->sVal1, x); + + if (swrite_Counters) { + tables_WriteTabD (res->Coef, 0, n - 1, 5, 14, 5, 5, + "Fourier coefficients"); + } + } + + gofw_ActiveTests2 (res->Bas->sVal1->V, res->Bas->pVal1->V, N, wdist_Normal, + (double *) NULL, res->Bas->sVal2, res->Bas->pVal2); + res->Bas->pVal1->NObs = N; + sres_GetNormalSumStat (res->Bas); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->Bas->sVal2, res->Bas->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res->Bas); + if (swrite_Collectors) + statcoll_Write (res->Bas->sVal1, 5, 14, 4, 3); + swrite_Final (gen, Timer); + } + if (localRes) + sspectral_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sspectral_Fourier3 (unif01_Gen *gen, sspectral_Res *res, + long N, int t, int r, int s) +{ + const unsigned long SBIT = 1UL << (s - 1); + unsigned long jBit; + unsigned long Z; + long k, KALL, Seq, n, i; + double *A, *B; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sspectral_Fourier3 test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataFour (gen, TestName, N, t, r, s); + util_Assert (r + s <= 32, "sspectral_Fourier3: r + s > 32"); + util_Assert (t <= 26, "sspectral_Fourier3: k > 26"); + util_Assert (t >= 2, "sspectral_Fourier3: k < 2"); + if (res == NULL) { + localRes = TRUE; + res = sspectral_CreateRes (); + } + n = num_TwoExp[t]; + KALL = n / s + 1; + InitRes (res, n/4 + 1, 0, n, "sspectral_Fourier3"); + statcoll_SetDesc (res->Bas->sVal1, "sVal1: a standard normal"); + B = res->Bas->sVal1->V; + A = res->Coef; + for (i = 0; i <= n / 4; i++) + B[i] = 0.0; + + for (Seq = 1; Seq <= N; Seq++) { + /* Fill array A: 1 for bit 1, -1 for bit 0 */ + i = 0; + for (k = 0; k < KALL; k++) { + Z = unif01_StripB (gen, r, s); + jBit = SBIT; + while (jBit) { + if (jBit & Z) + A[i] = 1.0; + else + A[i] = -1.0; + jBit >>= 1; + i++; + } + } + /* + * Compute the Fourier transform of A and return the result in A. The + * first half of the array, (from 0 to n/2) is filled with the real + * components of the FFT. The second half of the array (from n/2+1 to + * n-1) is filled with the imaginary components of the FFT. + * The n new elements of A are thus: + * [Re(0), Re(1), ...., Re(n/2), Im(n/2-1), ..., Im(1)] + * The procedure is due to H.V. Sorensen, University of Pennsylvania + * and is found in file fftc.c. + */ + rsrfft (A, t); + + /* Add the squares of the Fourier coefficients over the N replications + for each i = [1, ..., n/4], and keep them in B[i] */ + for (i = 1; i <= n / 4; i++) + B[i] += A[i] * A[i] + A[n - i] * A[n - i]; + + if (0 && swrite_Counters) + tables_WriteTabD (B, 1, n / 4, 5, 14, 5, 5, + "Sums of square of Fourier coefficients"); + } + + /* There is an extra sqrt (n) factor between the Fourier coefficients + of Sorensen and those of Erdmann */ + for (i = 1; i <= n / 4; i++) + B[i] /= n; + + /* The N random variables have been added for each i and kept in B[i]. + Their mean (1) and variance (~1) is known from Diane Erdmann. Now + consider the B[i] as n/4 normal random variables. */ + for (i = 1; i <= n / 4; i++) { + B[i] = (B[i] - N) / sqrt (N * (1.0 - 2.0 / n)); + statcoll_AddObs (res->Bas->sVal1, B[i]); + } + + gofw_ActiveTests2 (res->Bas->sVal1->V, res->Bas->pVal1->V, n/4, wdist_Normal, + (double *) NULL, res->Bas->sVal2, res->Bas->pVal2); + res->Bas->pVal1->NObs = n/4; + + if (swrite_Basic) { + gofw_WriteActiveTests2 (n/4, res->Bas->sVal2, res->Bas->pVal2, + "Normal statistic :"); + if (swrite_Collectors) + statcoll_Write (res->Bas->sVal1, 5, 14, 4, 3); + swrite_Final (gen, Timer); + } + if (localRes) + sspectral_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void sspectral_Fourier2 (unif01_Gen *gen, sspectral_Res *res, + long N, int t, int r, int s) +{ + const unsigned long SBIT = 1UL << (s - 1); + unsigned long jBit; + unsigned long Z; + long k, KALL, Seq, n, i; + double *A; + double x, sum; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sspectral_Fourier2 test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataFour (gen, TestName, N, t, r, s); + util_Assert (r + s <= 32, "sspectral_Fourier2: r + s > 32"); + util_Assert (t <= 26, "sspectral_Fourier2: k > 26"); + util_Assert (t >= 2, "sspectral_Fourier2: k < 2"); + if (res == NULL) { + localRes = TRUE; + res = sspectral_CreateRes (); + } + n = num_TwoExp[t]; + KALL = n / s + 1; + InitRes (res, N, 0, n, "sspectral_Fourier2"); + statcoll_SetDesc (res->Bas->sVal1, "sVal1: a standard normal"); + A = res->Coef; + + for (Seq = 1; Seq <= N; Seq++) { + /* Fill array A: 1 for bit 1, -1 for bit 0 */ + i = 0; + for (k = 0; k < KALL; k++) { + Z = unif01_StripB (gen, r, s); + jBit = SBIT; + while (jBit) { + if (jBit & Z) + A[i] = 1.0; + else + A[i] = -1.0; + jBit >>= 1; + i++; + } + } + /* + * Compute the Fourier transform of A and return the result in A. The + * first half of the array, (from 0 to n/2) is filled with the real + * components of the FFT. The second half of the array (from n/2+1 to + * n-1) is filled with the imaginary components of the FFT. + * The n new elements of A are thus: + * [Re(0), Re(1), ...., Re(n/2), Im(n/2-1), ..., Im(1)] + * The procedure is due to H.V. Sorensen, University of Pennsylvania + * and is found in file fftc.c. + */ + rsrfft (A, t); + + /* Sum the square of the Fourier coefficients (only half of them) */ + sum = 0.0; + for (i = 1; i <= n / 4; i++) + sum += A[i] * A[i] + A[n - i] * A[n - i]; + + /* There is an extra sqrt (n) factor between the Fourier coefficients + of Sorensen and those of Erdmann */ + sum /= n; + + /* Standardize the statistic */ + x = 2.0*(sum - n / 4.0) / sqrt (n - 2.0); + statcoll_AddObs (res->Bas->sVal1, x); + + if (swrite_Counters) { + tables_WriteTabD (res->Coef, 0, n - 1, 5, 14, 5, 5, + "Fourier coefficients"); + } + } + + gofw_ActiveTests2 (res->Bas->sVal1->V, res->Bas->pVal1->V, N, wdist_Normal, + (double *) NULL, res->Bas->sVal2, res->Bas->pVal2); + res->Bas->pVal1->NObs = N; + sres_GetNormalSumStat (res->Bas); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->Bas->sVal2, res->Bas->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res->Bas); + if (swrite_Collectors) + statcoll_Write (res->Bas->sVal1, 5, 14, 4, 3); + swrite_Final (gen, Timer); + } + if (localRes) + sspectral_DeleteRes (res); + chrono_Delete (Timer); +} + diff --git a/TESTU01/TestU01-1.2.3/testu01/sspectral.tex b/TESTU01/TestU01-1.2.3/testu01/sspectral.tex new file mode 100644 index 0000000..b5b6c40 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sspectral.tex @@ -0,0 +1,168 @@ +\defmodule {sspectral} + +This module contains tests based on spectral methods. +\index{spectral}% +\index{Fourier transform}% +The tests currently available compute the {\em discrete Fourier transform\/} +for a string of $n$ bits and look for deviations in the spectrum +\index{spectrum}% +that are inconsistent with $\cH_0$. +% They are taken from \cite{rRUK01a} and \cite{rERD92a}. +\resdef + +\bigskip +\hrule +\code\hide +/* sspectral.h for ANSI C */ +#ifndef SSPEC_H +#define SSPEC_H +\endhide +#include "statcoll.h" +#include "gofw.h" +#include "unif01.h" +#include "sres.h" +\endcode + +\ifdetailed %%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structure for test results} +\code +typedef struct { + + sres_Basic *Bas; +\endcode + \tabb + For the $s$-values and the $p$-values of the tests. + \endtabb +\code + + double *Coef; +\endcode + \tabb The array {\tt Coef} contains the + Fourier coefficients or their complex absolute values squared + depending on the test. + \endtabb +\code + + long jmin, jmax; +\endcode + \tabb + These indices are the lowest and highest valid indices + of array {\tt Coef}. + \endtabb +\code + +} sspectral_Res; +\endcode + \tab + Structure used to keep the results of the tests in this module. + \endtab +\code + + +sspectral_Res * sspectral_CreateRes (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a test. + \endtab +\code + + +void sspectral_DeleteRes (sspectral_Res *res); +\endcode + \tab + Frees the memory allocated by {\tt sspectral\_CreateRes}. + \endtab + +\fi %%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code + +void sspectral_Fourier1 (unif01_Gen *gen, sspectral_Res *res, + long N, int k, int r, int s); +\endcode +\tab + This test is taken from \cite{rRUK01a}. \index{Test!Fourier1}% + Given a string of $n= 2^k$ bits, let $A_j = -1$ if the $j${th} bit + is 0 and $A_j = 1$ if the $j$th bit is 1. + Define the discrete Fourier coefficients +\begin{equation} + f_\ell = \sum_{j=0}^{n-1} A_j e^{2\pi i j\ell/n},\qquad + \ell = 0, 1, \ldots,n-1, \label{eq:Fourier1} +\end{equation} + where $i = \sqrt{-1}$, and let $|f_\ell|$ be the modulus of the + complex number $f_\ell$. + Note that since the $A_j$ are real, + the $f_\ell$ for $\ell > n/2$ can be obtained + simply from the $f_\ell$ with $\ell \le n/2$. + Let $O_h$ denote the observed number of $|f_\ell|$'s, for $\ell \le n/2$, + that are smaller than $h$. + According to \cite{rRUK01a}, under $\cH_0$, for large enough + $n$ and $h = \sqrt{2.995732274n}$, $O_h$ has approximately the + normal distribution with mean $\mu = 0.95 n/2$ and variance + $\sigma^2 = 0.05 \mu$. + The test computes the $N$ values of the standardized statistic + $(O_h - \mu)/\sigma$ and compares their distribution to the standard + normal. + Restrictions: $8 \le k \le 20$ and $N$ very small. +\endtab +\code + + +void sspectral_Fourier2 (unif01_Gen *gen, sspectral_Res *res, + long N, int k, int r, int s); +\endcode +\tab + This test, proposed and studied by Erdmann~\cite{rERD92a}, + computes $S_\ell = |f_\ell|^2/n$, \index{Test!Fourier2}% + for $\ell = 0, 1, \ldots,n-1$, where the Fourier coefficients + $f_\ell$ are defined in (\ref{eq:Fourier1}). + It is shown in \cite{rERD92a} that under $\cH_0$, + each $S_\ell$ has mean 1 and variance $1 - 2 /n$ for $ \ell \not= 0$. +% \begin{eqnarray*} +% V_\ell &=& \left\{\begin{array}{ll} +% 2 - 2 /n & \qquad \mbox{ for } \ell = 0, \\[6pt] +% 1 - 2 /n & \qquad \mbox{ for } \ell \not= 0. +% \end{array} \right. +% \end{eqnarray*} + The test computes the sum \index{Test!Fourier3} + $$ + X = \sum_{\ell= 1}^{n/4} S_\ell, +$$ + which should be approximately normal +with mean $n/4$ and variance equal to $(n-2)/4$. + \hpierre{Again, assuming independence...} + It compares the distribution of the $N$ values of $X$ + with the normal distribution. + Restrictions: $4 \le k \le 26$ and $N$ very small. + Recommendations: $N=1$. +\endtab +\code + + +void sspectral_Fourier3 (unif01_Gen *gen, sspectral_Res *res, + long N, int k, int r, int s); +\endcode +\tab + For each $\ell$, let $X_\ell$ denote the sum of the $N$ copies of $S_\ell$, + where $S_\ell$ is computed and defined as in {\tt sspectral\_Fourier2}. + The central limit theorem ensures that for $N$ large enough, + $X_\ell$ should be approximately normal with mean \index{Test!Fourier3}% + $N$ and variance $NV_\ell$. This test compares the empirical + distribution of the $n/4$ normal variables $X_\ell, \ \ell = 1, 2, \ldots, + n/4$, to the standard normal distribution. + \hpierre{Why do we expect these $X_\ell$'s to be independent?} + Restriction: $4 \le k \le 26$. Recommendation: $N \ge 2^k$. +\endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/sstring.c b/TESTU01/TestU01-1.2.3/testu01/sstring.c new file mode 100644 index 0000000..966ec23 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sstring.c @@ -0,0 +1,2268 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: sstring.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "chrono.h" +#include "num.h" +#include "tables.h" +#include "bitset.h" + +#include "sstring.h" +#include "unif01.h" +#include "wdist.h" +#include "swrite.h" +#include "sres.h" + +#include "gofs.h" +#include "gofw.h" +#include "fbar.h" +#include "statcoll.h" + +#include +#include +#include +#include +#include + + + + + +/*------------------------------ Constants --------------------------------*/ + +/* Minimal length (number of bits) of a sequence for LongestHeadRun */ +#define LMIN 1000 + +/* Max string length for the correlations in PeriodsInStrings */ +#define MAX_CORR 31 + +/* Max dimension of arrays */ +#define DIM 1000 + +/* Max string lengths */ +#define LEN1 200 +#define LEN2 200 + + + + + +/*-------------------------------- Types ----------------------------------*/ + +typedef struct InfoListC *ListC; /* A correlation list */ + +struct InfoListC { + long Nb; /* Number of bits of a correlation in + the initial computations; then + number of occurences */ + bitset_BitSet C; /* A correlation */ + long Pop; /* Population related to C (and c) */ + ListC Ext; /* The smallest extension of C */ + ListC Ext0; /* The smallest extension of D longer + than C, if C is an extension of D. + Initially NULL */ + ListC Next; /* Next correlation of same length */ +}; + +/* Corr contains the lists of correlations of each length for s in [0..smax] + */ +typedef struct { + ListC Corr[MAX_CORR + 1]; + int smax; +} sstring_Corr; + + +/*----------------------------- Variables --------------------------------*/ + +lebool sstring_CorrFlag = FALSE; +lebool sstring_Counters = FALSE; + + + + +/*----------------------------- Functions --------------------------------*/ + +static void InitRes3 ( + sstring_Res3 *res, /* Results holder */ + long N, /* Number of replications */ + int jmax /* Max class index for chi2 */ +) +/* + * Initializes the sstring_Res3 structure + */ +{ + sres_InitBasic (res->NBits, N, "sstring_Run: Number of Bits"); + sres_InitChi2 (res->NRuns, N, jmax, "sstring_Run: Number of Runs"); + res->Count0 = util_Realloc (res->Count0, (jmax + 1) * sizeof (long)); + res->Count1 = util_Realloc (res->Count1, (jmax + 1) * sizeof (long)); + res->NRuns->jmin = 1; + res->NRuns->degFree = jmax - 1; +} + + +/*-------------------------------------------------------------------------*/ + +sstring_Res3 * sstring_CreateRes3 (void) +{ + sstring_Res3 *res; + res = util_Malloc (sizeof (sstring_Res3)); + res->NBits = sres_CreateBasic (); + res->NRuns = sres_CreateChi2 (); + res->Count0 = util_Calloc (1, sizeof (long)); + res->Count1 = util_Calloc (1, sizeof (long)); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_DeleteRes3 (sstring_Res3 *res) +{ + if (res == NULL) + return; + res->Count0 = util_Free (res->Count0); + res->Count1 = util_Free (res->Count1); + sres_DeleteBasic (res->NBits); + sres_DeleteChi2 (res->NRuns); + util_Free (res); +} + + +/*=========================================================================*/ + +static void InitRes2 ( + sstring_Res2 *res, /* Results holder */ + long N, /* Number of replications */ + int jhigh /* Max class index for chi2 */ +) +/* + * Initializes the sstring_Res2 structure + */ +{ + sres_InitDisc (res->Disc, N, + "sstring_LongestHeadRun: Global longest run of 1's"); + sres_InitChi2 (res->Chi, N, jhigh, + "sstring_LongestHeadRun: Block longest runs of 1's"); +} + + +/*-------------------------------------------------------------------------*/ + +sstring_Res2 * sstring_CreateRes2 (void) +{ + sstring_Res2 *res; + res = util_Malloc (sizeof (sstring_Res2)); + res->Chi = sres_CreateChi2 (); + res->Disc = sres_CreateDisc (); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_DeleteRes2 (sstring_Res2 *res) +{ + if (res == NULL) + return; + sres_DeleteChi2 (res->Chi); + sres_DeleteDisc (res->Disc); + util_Free (res); +} + + +/*=========================================================================*/ + +static void InitRes ( + sstring_Res *res, /* Results holder */ + long N, /* Number of replications */ + int L, /* Size of blocks (number of bits) */ + int d, /* Parameter for sub-matrices */ + char *nam +) +/* + * Initializes res + */ +{ + int i; + sres_InitBasic (res->Bas, N, nam); + + if (res->L > 0) { + tables_DeleteMatrixL (&res->Counters); + tables_DeleteMatrixD (&res->ZCounters); + } + res->Counters = tables_CreateMatrixL (L + 2, L + 1); + res->ZCounters = tables_CreateMatrixD (L + 2, L + 1); + + if (d < 0) + d = 0; + for (i = d + 1; i <= res->d; i++) + sres_DeleteBasic (res->Block[i]); + + for (i = res->d + 1; i <= d; i++) + res->Block[i] = sres_CreateBasic (); + + for (i = 1; i <= d; i++) + sres_InitBasic (res->Block[i], N, nam); + + res->L = L; + res->d = d; +} + + +/*-------------------------------------------------------------------------*/ + +sstring_Res * sstring_CreateRes (void) +{ + sstring_Res *res; + res = util_Malloc (sizeof (sstring_Res)); + memset (res, 0, sizeof (sstring_Res)); + res->Bas = sres_CreateBasic (); + res->Style = tables_Plain; + res->L = -1; + res->d = 0; + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_DeleteRes (sstring_Res *res) +{ + if (res == NULL) + return; + + if (res->d > 0) { + int i; + for (i = 1; i <= res->d; i++) { + sres_DeleteBasic (res->Block[i]); + } + } + if (res->L > 0) { + tables_DeleteMatrixD (&res->ZCounters); + tables_DeleteMatrixL (&res->Counters); + } + sres_DeleteBasic (res->Bas); + util_Free (res); +} + + +/*=========================================================================*/ + +static long Psi ( + bitset_BitSet C, /* Correlation making up tail of correlation k */ + long j, /* Length of correlation C */ + long k /* Correlation made up of 1 followed by 0's + until C, i.e. k = 100...000C */ +) +{ + /* j <=> c & k <=> k in the article */ + if (k > j) + return 0; + if (k <= 0) + return (long) num_TwoExp[-k]; + if (bitset_TestBit (C, j - k)) + return 1; + else + return 0; +} + + +/*-------------------------------------------------------------------------*/ + +static void DeleteCorr (sstring_Corr *corr) +/* + * Delete all correlations. + */ +{ + ListC Ci, OldCi; + int i; + + if (corr == NULL) + return; + for (i = 0; i <= corr->smax; i++) { + Ci = corr->Corr[i]; + while (Ci) { + OldCi = Ci; + Ci = Ci->Next; + util_Free (OldCi); + } + } + util_Free (corr); +} + + +/*-------------------------------------------------------------------------*/ + +static sstring_Corr * CreateCorr (int s) +/* + * Compute all possible correlations for strings of length s + */ +{ + ListC CjE, Cj, Ci, OldCi, XS; + sstring_Corr *corr; + int j, i, k, Tmax; + long p; + + corr = util_Malloc (sizeof (sstring_Corr)); + memset (corr, 0, sizeof (sstring_Corr)); + + corr->smax = s; + + XS = corr->Corr[0] = util_Malloc (sizeof (struct InfoListC)); + XS->Nb = 0; + XS->Pop = 1; + XS->Ext = NULL; + XS->Ext0 = NULL; + XS->Next = NULL; + + XS = corr->Corr[1] = util_Malloc (sizeof (struct InfoListC)); + XS->Nb = 1; + bitset_SetBit (XS->C, 0); + XS->Pop = 2; + XS->Ext = NULL; + XS->Ext0 = NULL; + XS->Next = NULL; + + for (i = 2; i <= s; i++) { /* i is the string length */ + /* Count and build the list of correlations of length i. */ + Ci = corr->Corr[i] = util_Malloc (sizeof (struct InfoListC)); + + for (j = 0; j <= i - 2; j++) { + /* j is the length of correlation C in 100...00C */ + Cj = corr->Corr[j]; + + while (Cj) { + /* Compute the number of strings of length i and with corre- */ + /* lation "10...0C", and if > 0, add this corr. to Corr[i] */ + p = Cj->Pop * Psi (Cj->C, j, 2*j - i); + /* Check if 1C may be a correlation. Possible only if + C = 111....1, i.e. the last of the list */ + if (Cj->Next == NULL) + p -= 2 * Psi (Cj->C, j, 2*j + 2 - i); + CjE = Cj->Ext; + /* Note: j <= j-2, i.e. j+1 <= (i+j) / 2 */ + Tmax = (i + j) / 2; + while (CjE && CjE->Nb <= Tmax) { + p -= CjE->Pop * Psi (Cj->C, j, 2*CjE->Nb - i); + CjE = CjE->Ext0; + } + /* p = number of strings looked for */ + if (p > 0) { + /* Put this correlation in Ci */ + Ci->Nb = i; + Ci->Pop = p; + Ci->Ext = NULL; + Ci->Ext0 = NULL; + /* Ci->C becomes Cj->C shifted right by i-j */ + /* positions, with a 1 in first position. */ + Ci->C = 0; + bitset_SetBit (Ci->C, 0); + if (j > 0) { + for (k = 0; k < j; k++) { + if (bitset_TestBit (Cj->C, k)) { + bitset_SetBit (Ci->C, k + i - j); + } + } + } + if (Cj->Ext == NULL) + Cj->Ext = Ci; + else { + CjE = Cj->Ext; + while (CjE->Ext0) + CjE = CjE->Ext0; + CjE->Ext0 = Ci; + } + OldCi = Ci; + Ci = util_Malloc (sizeof (struct InfoListC)); + OldCi->Next = Ci; + } + Cj = Cj->Next; + } + } + /* For j = i-1, we have the correlation "11...1" */ + Ci->C = 0; + for (k = 0; k < i; k++) { + bitset_SetBit (Ci->C, k); + } + Ci->Nb = i; + Ci->Pop = 2; + Ci->Ext = NULL; + Ci->Ext0 = NULL; + Ci->Next = NULL; + } + return corr; +} + + +/*=========================================================================*/ + +static void sstring_WriteCorr (sstring_Corr *corr, int s) +{ + ListC Cs; + int k; + char str [LEN1 + 1]; + + if (corr == NULL) { + util_Warning (TRUE, + "sstring_WriteCorr: corr is a NULL pointer"); + return; + } + + if (corr->smax < s) { + sprintf (str, "sstring_WriteCorr: invalid s = %d", s); + util_Error (str); + } + + Cs = corr->Corr[s]; + if (Cs == NULL) + return; + printf ("\n-----------------------------------------------------\n" + "List of correlations of length %d and their population\n\n", s); + while (Cs) { + for (k = 0; k < s; k++) { + if (bitset_TestBit (Cs->C, k)) + printf ("1"); + else + printf ("0"); + } + printf ("%12ld\n", Cs->Pop); + Cs = Cs->Next; + } + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static bitset_BitSet GenerateC ( + unif01_Gen *gen, /* Generator */ + int r, /* Drop first r bits of each random number */ + int s /* Keep next s bits of each random number */ +) +/* + * Generate a string of s bits and return its correlation. To determine the + * correlation of a bit string, compare strings g and d (initially equal). + * For each iteration: + * 1) drop leftmost bit of string g + * 2) drop rightmost bit of string d + * 3) if g = d, bit k of the correlation c is 1, otherwise 0. + */ +{ + int k; + unsigned long g, d, lbit = s - 1; + bitset_BitSet c = 0; + + /* Generate a random number; drop r most significant bits; keep s next + bits */ + g = d = unif01_StripB (gen, r, s); + + /* Initialization of correlation, trivial case */ + bitset_SetBit (c, 0); + for (k = 1; k < s; k++) { + /* drop leftmost bit of string g */ + bitset_ClearBit (g, lbit); + /* drop rightmost bit of string d */ + d >>= 1; + /* if g = d, bit k of the correlation c is 1, otherwise 0 */ + if (g == d) + bitset_SetBit (c, k); + lbit--; + } + return c; +} + + +/*=========================================================================*/ + +static void WriteDataPeriod ( + unif01_Gen *gen, /* generator */ + char *Test, /* Test name */ + long N, /* Number of replications */ + long n, /* Sample size */ + int r, /* r first bits of each random number dropped */ + int s /* s bits of each random number used */ +) +{ + swrite_Head (gen, Test, N, n, r); + printf (", s = %4d\n\n", s); +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_PeriodsInStrings (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int s) +{ + ListC XS, Ci; + sstring_Corr *corr; + long jhigh, /* Highest class for ChiSquare */ + jlow, /* Lowest class for ChiSquare */ + NbGroups; /* Number of classes for ChiSquare */ + long j, i; + long Seq; /* One replication of the test */ + double Fraction, X2; + bitset_BitSet D; /* A correlation */ + double V[1]; /* Number of ChiSquare degrees of freedom */ + char str [LEN1 + 1]; + double NbExp [DIM + 1]; + long Loca [DIM + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_PeriodsInStrings test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataPeriod (gen, TestName, N, n, r, s); + + util_Assert (r >= 0, "sstring_PeriodsInStrings: r < 0"); + util_Assert (r <= 31, "sstring_PeriodsInStrings: r > 31"); + util_Assert (r + s <= 31, "sstring_PeriodsInStrings: r + s > 31"); + util_Assert (s <= 31, "sstring_PeriodsInStrings: s > 31"); + util_Assert (s >= 2, "sstring_PeriodsInStrings: s < 2"); + /* util_Assert (n > 2.0 * gofs_MinExpected, + "sstring_PeriodsInStrings: n <= 2*gofs_MinExpected"); */ + + Fraction = n / num_TwoExp[s]; + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + corr = CreateCorr (s); + if (sstring_CorrFlag) + sstring_WriteCorr (corr, s); + + /* Get the expected numbers of the population count */ + XS = Ci = corr->Corr[s]; + j = 1; + while (Ci) { + NbExp[j] = Fraction * Ci->Pop; + Ci = Ci->Next; + ++j; + util_Assert (j <= DIM, "sstring_PeriodsInStrings: DIM too small"); + } + jlow = 1; + jhigh = j - 1; + + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, 0); + + /* Merge classes for the chi-square test */ + gofs_MergeClasses (NbExp, Loca, &jlow, &jhigh, &NbGroups); + + if (swrite_Classes) + gofs_WriteClasses (NbExp, Loca, jlow, jhigh, NbGroups); + + res->degFree = NbGroups - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + sres_InitChi2 (res, N, jhigh, "sstring_PeriodsInStrings"); + res->jmin = jlow; + tables_CopyTabD (NbExp, res->NbExp, jlow, jhigh); + tables_CopyTabL (Loca, res->Loc, jlow, jhigh); + + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbGroups - 1); + statcoll_SetDesc (res->sVal1, str); + + /* Test begins */ + for (Seq = 1; Seq <= N; Seq++) { + /* Zero the population counters */ + Ci = XS; + while (Ci) { + Ci->Nb = 0; + Ci = Ci->Next; + } + for (i = 1; i <= n; i++) { + D = GenerateC (gen, r, s); + /* Find the correlation */ + Ci = XS; + while (Ci->C != D) + Ci = Ci->Next; + ++Ci->Nb; + } + + /* Keep the observed numbers in sstring_Count */ + for (j = jlow; j <= jhigh; j++) + res->Count[j] = 0; + Ci = XS; + j = 1; + while (Ci) { + if (j >= res->jmax) + res->Count[res->jmax] += Ci->Nb; + else + res->Count[Loca[j]] += Ci->Nb; + Ci = Ci->Next; + ++j; + } + + X2 = gofs_Chi2 (res->NbExp, res->Count, jlow, jhigh); + statcoll_AddObs (res->sVal1, X2); + if (swrite_Counters) + tables_WriteTabL (res->Count, jlow, jhigh, 5, 10, + "Observed population counts"); + } + + res->degFree = V[0] = NbGroups - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + if (swrite_Basic) { + swrite_AddStrChi (str, LEN1, NbGroups - 1); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + DeleteCorr (corr); + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static double ProbabiliteLHR (long j, double Lnl) +/* + * Returns the probability that the longest series of successive 1 has + * length = j. + */ +{ + double x, temp; + temp = (j + 1) * num_Ln2 - Lnl; + x = exp (-exp (-temp)); + temp += num_Ln2; + x = exp (-exp (-temp)) - x; + return x; +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteDataLongHead (unif01_Gen *gen, char *Test, + long N, long n, int r, int s, long L) +{ + swrite_Head (gen, Test, N, n, r); + printf (", s = %1d, L = %1ld\n\n", s, L); +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_LongestHeadRun (unif01_Gen *gen, sstring_Res2 *res, + long N, long n, int r, int s, long L) +{ + const double eps = DBL_EPSILON; + const long K = L/s; /* Number of iterations */ + long Rep; /* Current replication number */ + long Seq; /* Current sequence number */ + long i; + double LnLen; /* log (L) or log (NnL) */ + double X2, temp; + int j; + long longest; /* Longest serie of 1 in a block */ + long longest2; /* Longest serie of 1 over all blocks */ + long longest3; /* Longest serie of 1 over all Replic. */ + long longueur; /* Run length in a block */ + long longueur2; /* Run length in a sequence */ + long longueur3; /* Run length in a replication */ + long jhigh; /* Highest class for Chi2 */ + long jhigh2; /* Highest index for CDF[j] */ + long NbGroups; /* Number of classes for Chi2 */ + bitset_BitSet ensemble; /* Chosen bits in each generated number */ + double V[1]; /* Number degrees of freedom for Chi2 */ + char str [LEN1 + 1]; + double NbExp [DIM + 1]; /* Expected numbers */ + double CDF [DIM + 1]; /* Cumulative probabilities */ + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_LongestHeadRun test"; + sres_Chi2 *Chi; + sres_Disc *Disc; + + Timer = chrono_Create (); + L = K * s; + if (swrite_Basic) + WriteDataLongHead (gen, TestName, N, n, r, s, L); + util_Assert (L >= LMIN, "sstring_LongestHeadRun: L < 1000"); + if (res == NULL) { + localRes = TRUE; + res = sstring_CreateRes2 (); + } + jhigh = DIM; + + /* Get the expected numbers for the chi-square for blocks of L bits */ + LnLen = log ((double) L); + CDF[0] = ProbabiliteLHR (0, LnLen); + NbExp[0] = n * CDF[0]; + for (j = 1; j < DIM; j++) { + temp = ProbabiliteLHR (j, LnLen); + NbExp[j] = n * temp; + CDF[j] = temp + CDF[j-1]; + if ((temp <= eps) && (CDF[j] > 0.5)) { + jhigh = j; + break; + } + } + util_Assert (jhigh > 0, "sstring_LongestHeadRun: jhigh = 0"); + NbExp[jhigh] = n * (1.0 - CDF[jhigh - 1]); + + /* Get the probabilities for the global run over the N*n*L bits */ + LnLen = log (N * (double) n * (double) L); /* Avoid overflow of long */ + CDF[0] = ProbabiliteLHR (0, LnLen); + for (j = 1; j < DIM; j++) { + temp = ProbabiliteLHR (j, LnLen); + CDF[j] = temp + CDF[j-1]; + if ((temp <= eps) && (CDF[j] > 0.5)) { + jhigh2 = j; + break; + } + } + + InitRes2 (res, N, jhigh); + Disc = res->Disc; + Chi = res->Chi; + tables_CopyTabD (NbExp, Chi->NbExp, 0, jhigh); + + if (swrite_Classes) + gofs_WriteClasses (Chi->NbExp, Chi->Loc, 0, jhigh, 0); + gofs_MergeClasses (Chi->NbExp, Chi->Loc, &Chi->jmin, &Chi->jmax, &NbGroups); + if (swrite_Classes) + gofs_WriteClasses (Chi->NbExp, Chi->Loc, Chi->jmin, Chi->jmax, NbGroups); + Chi->degFree = NbGroups - 1; + if (Chi->degFree <= 0) { + util_Assert (1, "sstring_LongestHeadRun: Chi->degFree = 0"); + if (localRes) + sstring_DeleteRes2 (res); + return; + } + + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", Chi->degFree); + statcoll_SetDesc (Chi->sVal1, str); + statcoll_SetDesc (Disc->sVal1, + "The longest run of 1 for each replication "); + + /* Beginning of test */ + longest3 = longueur3 = 0; + for (Rep = 1; Rep <= N; Rep++) { + for (i = Chi->jmin; i <= Chi->jmax; i++) + Chi->Count[i] = 0; + + longest2 = -1; /* -1 at the beginning of a new replication */ + longueur2 = 0; + for (Seq = 1; Seq <= n; Seq++) { + longest = -1; /* -1 at the beginning of a new sequence */ + longueur = 0; + for (i = 1; i <= K; i++) { + /* Now build a block of L bits */ + ensemble = unif01_StripB (gen, r, s); + /* Examine each bit of a number */ + for (j = s - 1; j >= 0; j--) { + if (bitset_TestBit (ensemble, j)) + ++longueur; + else { + /* Beginning of a sequence: merge last block of 1's of */ + /* last sequence with first block of 1's of new sequence */ + if (longest < 0) { + /* Beginning of a replication: merge last sequence of */ + /* 1's of last replication with first sequence of 1's */ + /* of new replication */ + if (longest2 < 0) { + longueur3 += longueur; + if (longueur3 > longest3) + longest3 = longueur3; + } + longueur2 += longueur; + if (longueur2 > longest2) + longest2 = longueur2; + } + if (longueur > longest) + longest = longueur; + longueur = 0; + } + } + } + if (longueur > longest) + longest = longueur; + if (longest >= Chi->jmax) + ++Chi->Count[Chi->jmax]; + else if (longest <= Chi->jmin) + ++Chi->Count[Chi->jmin]; + else + ++Chi->Count[Chi->Loc[longest]]; + if (longest > longest2) + longest2 = longest; + longueur3 = longueur2 = longueur; + } + + X2 = gofs_Chi2 (Chi->NbExp, Chi->Count, Chi->jmin, Chi->jmax); + statcoll_AddObs (Chi->sVal1, X2); + statcoll_AddObs (Disc->sVal1, (double) longest2); + if (longest2 > longest3) + longest3 = longest2; + if (swrite_Counters) + tables_WriteTabL (Chi->Count, Chi->jmin, Chi->jmax, 5, 10, + "Observed numbers"); + longueur = 0; + for (j = Chi->jmin; j <= Chi->jmax; j++) + longueur += Chi->Count[j]; + util_Warning (longueur != n, "Total Count != n"); + } + Disc->sVal2 = longest3; + if (longest3 > jhigh2) { + Disc->pLeft = 1.0; + Disc->pRight = 0.0; + } else { + Disc->pLeft = CDF[longest3]; + if (longest3 > 0) + Disc->pRight = 1.0 - CDF[longest3 - 1]; + else + Disc->pRight = 1.0; + } + Disc->pVal2 = gofw_pDisc (Disc->pLeft, Disc->pRight); + + V[0] = Chi->degFree; + gofw_ActiveTests2 (Chi->sVal1->V, Chi->pVal1->V, N, wdist_ChiSquare, V, + Chi->sVal2, Chi->pVal2); + Chi->pVal1->NObs = N; + sres_GetChi2SumStat (Chi); + + if (swrite_Collectors) { + statcoll_Write (Chi->sVal1, 5, 14, 4, 3); + statcoll_Write (Disc->sVal1, 5, 14, 0, 0); + } + if (swrite_Basic) { + swrite_AddStrChi (str, LEN1, Chi->degFree); + gofw_WriteActiveTests2 (N, Chi->sVal2, Chi->pVal2, str); + swrite_Chi2SumTest (N, Chi); + printf ("-----------------------------------------------\n"); + printf ("Global longest run of 1 :"); + gofw_Writep2 (Disc->sVal2, Disc->pVal2); + printf ("\n\n"); + swrite_Final (gen, Timer); + } + if (localRes) + sstring_DeleteRes2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void HammingWeight2_L (unif01_Gen * gen, sres_Basic * res, + long N, int r, int s, long L, long K) +/* + * Generate all the n bits for the HammingWeight2 test in the case L > s. + * For the last number generated in a block of L bits, we keep its first + * LMods bits and discard the other bits. + */ +{ + const int LDivs = L / s; /* A block uses LDivs numbers ... */ + const int LMods = L % s; /* + 1 if LMods > 0 */ + const double L2 = L / 2.0; + int co, j; + long i, Seq; + unsigned long Z; + double X2; + + for (Seq = 1; Seq <= N; Seq++) { + X2 = 0.0; + for (i = 0; i < K; i++) { + /* Generate a block of L bits */ + co = 0; + for (j = 0; j < LDivs; j++) { + Z = unif01_StripB (gen, r, s); + while (Z > 0) { /* Count the number of 1 bits */ + Z &= Z - 1; /* Clear lowest 1 bit */ + ++co; + } + } + /* The last bits of the block */ + if (LMods > 0) { + Z = unif01_StripB (gen, r, LMods); + while (Z > 0) { + Z &= Z - 1; + ++co; + } + } + X2 += (co - L2)*(co - L2); + } + X2 *= 4.0 / L; + statcoll_AddObs (res->sVal1, X2); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void HammingWeight2_S (unif01_Gen * gen, sres_Basic * res, + long N, int r, int s, long L, long K) +/* + * Generate all the n bits for the HammingWeight2 test in the case L <= s. + * A number generates sDivL blocks. If s % L == 0, we use all s bits of the + * number. + */ +{ + const int sDivL = s / L; /* A number generates sDivL blocks */ + const long Q = K / sDivL + (K % sDivL > 0); + const unsigned long MASK = num_TwoExp[L] - 1.0; + const double L2 = L / 2.0; + int co, j; + long i, Seq; + unsigned long Z, Y; + double X2; + + for (Seq = 1; Seq <= N; Seq++) { + X2 = 0.0; + for (i = 0; i < Q; i++) { + Z = unif01_StripB (gen, r, s); + + /* Generate sDivL blocks of L bits */ + for (j = 0; j < sDivL; j++) { + co = 0; + Y = Z & MASK; + while (Y > 0) { /* Count the number of 1 bits */ + Y &= Y - 1; /* Clear lowest 1 bit */ + ++co; + } + X2 += (co - L2)*(co - L2); + Z >>= L; + } + } + X2 *= 4.0 / L; + statcoll_AddObs (res->sVal1, X2); + } +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_HammingWeight2 (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r, int s, long L) +{ + const long K = n / L; + double sum; + double V[1]; /* Number of Chi2 degrees of freedom */ + char chaine[LEN1 + 1] = ""; + char str[LEN2 + 1] = ""; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_HammingWeight2 test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataLongHead (gen, TestName, N, n, r, s, L); + util_Assert (r + s <= 32, "sstring_HammingWeight2: r + s > 32"); + util_Assert (L <= n, "sstring_HammingWeight2: L > n"); + util_Assert (L >= 2, "sstring_HammingWeight2: L < 2"); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "sstring_HammingWeight2"); + strncpy (chaine, "sVal1: a chi-square with ", (size_t) LEN1); + sprintf (str, "%ld", K); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, " degrees of freedom", (size_t) LEN1); + statcoll_SetDesc (res->sVal1, chaine); + + if (L >= s) + HammingWeight2_L (gen, res, N, r, s, L, K); + else + HammingWeight2_S (gen, res, N, r, s, L, K); + + V[0] = K; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sum = N * statcoll_Average (res->sVal1); + res->sVal2[gofw_Sum] = sum; + res->pVal2[gofw_Sum] = fbar_ChiSquare2 (N*K, 12, sum); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 2, 1); + if (swrite_Basic) { + swrite_AddStrChi (str, LEN2, K); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTestb (N, res->sVal2[gofw_Sum], res->pVal2[gofw_Sum], K); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void HammingWeight_L (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, int s, long L) +/* + * Generate all the n*L bits for the HammingWeight test in the case L > s. + * For the last number generated in a block of L bits, we keep its first + * LMods bits and discard the other bits. + */ +{ + const int LDivs = L / s; /* A block uses LDivs numbers ... */ + const int LMods = L % s; /* + 1 if LMods > 0 */ + int co, j; + long i, Seq; + unsigned long Z; + double X2; + + for (Seq = 1; Seq <= N; Seq++) { + for (i = res->jmin; i <= res->jmax; i++) + res->Count[i] = 0; + + for (i = 0; i < n; i++) { + /* Generate a block of L bits */ + co = 0; + for (j = 0; j < LDivs; j++) { + Z = unif01_StripB (gen, r, s); + while (Z > 0) { /* Count the number of 1 bits */ + Z &= Z - 1; /* Clear lowest 1 bit */ + ++co; + } + } + /* The last bits of the block */ + if (LMods > 0) { + Z = unif01_StripB (gen, r, LMods); + while (Z > 0) { + Z &= Z - 1; + ++co; + } + } + ++res->Count[res->Loc[co]]; + } + + X2 = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax); + statcoll_AddObs (res->sVal1, X2); + if (swrite_Counters) + tables_WriteTabL (res->Count, res->jmin, res->jmax, 5, 10, + "Observed numbers of blocks"); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void HammingWeight_S (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, int s, long L) +/* + * Generate all the n*L bits for the HammingWeight test in the case L <= s. + * A number generates sDivL blocks. If s % L == 0, we use all s bits of the + * number. + */ +{ + const int sDivL = s / L; /* A number generates sDivL blocks */ + const int s1 = s - s % L; + const long Q = n / sDivL; + const int Q2 = n % sDivL; + const unsigned long MASK = num_TwoExp[L] - 1.0; + int co, j; + long i, Seq; + unsigned long Z, Y; + double X2; + + for (Seq = 1; Seq <= N; Seq++) { + for (i = res->jmin; i <= res->jmax; i++) + res->Count[i] = 0; + + for (i = 0; i < Q; i++) { + Z = unif01_StripB (gen, r, s1); + + /* Generate sDivL blocks of L bits */ + for (j = 0; j < sDivL; j++) { + co = 0; + Y = Z & MASK; + while (Y > 0) { /* Count the number of 1 bits */ + Y &= Y - 1; /* Clear lowest 1 bit */ + ++co; + } + ++res->Count[res->Loc[co]]; + Z >>= L; + } + } + + /* The last bits */ + if (Q2 > 0) { + Z = unif01_StripB (gen, r, Q2 * L); + for (j = 0; j < Q2; j++) { + co = 0; + Y = Z & MASK; + while (Y > 0) { /* Count the number of 1 bits */ + Y &= Y - 1; /* Clear lowest 1 bit */ + ++co; + } + ++res->Count[res->Loc[co]]; + Z >>= L; + } + } + + X2 = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax); + statcoll_AddObs (res->sVal1, X2); + if (swrite_Counters) + tables_WriteTabL (res->Count, res->jmin, res->jmax, 5, 10, + "Observed numbers of blocks"); + } +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_HammingWeight (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, int s, long L) +{ + long i; + double V[1]; /* Number of Chi2 degrees of freedom */ + char str[LEN1 + 1] = ""; + fmass_INFO Q; + lebool localRes = FALSE; + chrono_Chrono *Timer; + long jlow, jhigh; + long NbGroups; /* Number of classes */ + char *TestName = "sstring_HammingWeight test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataLongHead (gen, TestName, N, n, r, s, L); + util_Assert (r + s <= 32, "sstring_HammingWeight: r + s > 32"); + util_Assert (L >= 2, "sstring_HammingWeight: L < 2"); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, L, "sstring_HammingWeight"); + + Q = fmass_CreateBinomial (L, 0.5, 0.5); + for (i = 0; i <= L; i++) + res->NbExp[i] = n * fmass_BinomialTerm2 (Q, i); + fmass_DeleteBinomial (Q); + + jlow = 0; + jhigh = L; + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, res->Loc, jlow, jhigh, 0); + gofs_MergeClasses (res->NbExp, res->Loc, &jlow, &jhigh, &NbGroups); + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, res->Loc, jlow, jhigh, NbGroups); + res->jmin = jlow; + res->jmax = jhigh; + res->degFree = NbGroups - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbGroups - 1); + statcoll_SetDesc (res->sVal1, str); + + if (L >= s) + HammingWeight_L (gen, res, N, n, r, s, L); + else + HammingWeight_S (gen, res, N, n, r, s, L); + + V[0] = res->degFree; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 2, 1); + if (swrite_Basic) { + swrite_AddStrChi (str, LEN1, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +#if 0 +void sstring_Run0 (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r, int s) +{ + const long K = n / s; /* If n % s != 0, a string will contain + K * s bits instead of n */ + const unsigned long SBIT = 1UL << (s - 1); + unsigned long jBit; /* Position of current bit in Z */ + int pBit; /* Previous bit */ + long i, Seq; + long co1; /* Counter for number of 1 */ + long cor; /* Counter for number of runs */ + unsigned long Z; + double X, f1; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_Run test"; + + Timer = chrono_Create (); + n = K * s; + if (swrite_Basic) + WriteDataPeriod (gen, TestName, N, n, r, s); + + util_Assert (r + s <= 32, "sstring_Run: r + s > 32"); + /* util_Assert (100 <= n, "sstring_Run: n < 100"); */ + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "sstring_Run"); + statcoll_SetDesc (res->sVal1, "sVal1: a standard normal"); + + for (Seq = 1; Seq <= N; Seq++) { + co1 = cor = 0; + /* Be sure to count the first run with pBit != {0, 1} */ + pBit = 2; + for (i = 0; i < K; i++) { + Z = unif01_StripB (gen, r, s); + jBit = SBIT; + + /* Add the number of 1 bit and number of runs in Z */ + while (jBit > 0) { + if (Z & jBit) { /* bit 1 */ + co1++; + if (pBit != 1) + cor++; + pBit = 1; + } else { /* bit 0 */ + if (pBit != 0) + cor++; + pBit = 0; + } + jBit >>= 1; + } + } + f1 = (double) co1 / (K * s); + X = (cor - n * 2.0 * f1 * (1.0 - f1)) / + (2.0 * sqrt ((double) n) * f1 * (1.0 - f1)); + statcoll_AddObs (res->sVal1, X); + } + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Normal statistic :"); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteBasic(res); + chrono_Delete (Timer); +} +#endif + + +/*=========================================================================*/ + +void sstring_Run (unif01_Gen * gen, sstring_Res3 *res, + long N, long n, int r, int s) +{ + const unsigned long SBIT = 1UL << (s - 1); + const double sr = s; + unsigned long jBit; /* Position of current bit in Z */ + int pBit; /* Previous bit */ + int k, j; + long Seq; + double cob; /* Counter for number of bits */ + long cor; /* Counter for number of 1 runs */ + int len; /* Length of current run */ + unsigned long Z; + double X2, X, temp; + char str[LEN1 + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_Run test"; + sres_Basic *NBits; + sres_Chi2 *NRuns; + long *Count0, *Count1; + double *Prob, *NbExp; + double Param[1]; + + Timer = chrono_Create (); + k = 1 + num_Log2 (n / gofs_MinExpected); + if (swrite_Basic) + WriteDataPeriod (gen, TestName, N, n, r, s); + util_Assert (r + s <= 32, "sstring_Run: r + s > 32"); + /* util_Assert (100 <= n, "sstring_Run: n < 100"); */ + + if (res == NULL) { + localRes = TRUE; + res = sstring_CreateRes3 (); + } + InitRes3 (res, N, k); + NBits = res->NBits; + NRuns = res->NRuns; + Count0 = res->Count0; + Count1 = res->Count1; + + statcoll_SetDesc (NBits->sVal1, + "The N statistic values (a standard normal):"); + sprintf (str, "The N statistic values (a ChiSquare with %1d degrees" + " of freedom):", 2*(k - 1)); + statcoll_SetDesc (NRuns->sVal1, str); + + Prob = util_Calloc (1 + (size_t) k, sizeof (double)); + Prob[0] = 1.0; + for (j = 1; j < k; j++) { + Prob[j] = Prob[j - 1] / 2.0; + NRuns->NbExp[j] = n * Prob[j]; + } + Prob[k] = Prob[k - 1]; + NRuns->NbExp[k] = n * Prob[k]; + util_Assert (NRuns->NbExp[k] >= gofs_MinExpected, + "sstring_Run: NRuns->NbExp[k] < gofs_MinExpected"); + + if (swrite_Classes) + gofs_WriteClasses (NRuns->NbExp, NRuns->Loc, 1, k, 0); + NRuns->jmax = k; + NRuns->jmin = 1; + NRuns->degFree = 2*(k - 1); + if (NRuns->degFree < 1) { + util_Warning (TRUE, "Chi-square with 0 degree of freedom."); + if (localRes) + sstring_DeleteRes3 (res); + return; + } + + for (Seq = 1; Seq <= N; Seq++) { + cob = cor = len = 0; + for (j = 1; j <= k; j++) { + Count0[j] = 0; + Count1[j] = 0; + } + + /* Make sure to count the first run; set pBit != {0, 1} */ + pBit = 2; + while (cor < n) { + Z = unif01_StripB (gen, r, s); + jBit = SBIT; + cob += sr; + if (len >= n) { + util_Warning (TRUE, "sstring_Run: all bits are 0 !"); + util_Free (Prob); + if (localRes) + sstring_DeleteRes3 (res); + return; + } + + /* Add the number of runs in Z */ + while (jBit > 0) { + if (Z & jBit) { /* bit 1 */ + if (pBit != 1) { + cor++; + if (len < k) + (Count0[len])++; + else + (Count0[k])++; + len = 1; + } else { + len++; + } + pBit = 1; + } else { /* bit 0 */ + if (pBit != 0) { + if (len < k) + (Count1[len])++; + else + (Count1[k])++; + len = 1; + } else { + len++; + } + pBit = 0; + } + jBit >>= 1; + } + } + + X2 = 0.0; + NbExp = NRuns->NbExp; + for (j = NRuns->jmin; j <= NRuns->jmax; j++) { + temp = Count0[j] - NbExp[j]; + X2 += temp * temp / (NbExp[j] * (1.0 - Prob[j])); + } + X = X2; + X2 = 0.0; + for (j = NRuns->jmin; j <= NRuns->jmax; j++) { + temp = Count1[j] - NbExp[j]; + X2 += temp * temp / (NbExp[j] * (1.0 - Prob[j])); + } + statcoll_AddObs (NRuns->sVal1, X2 + X); + + if (swrite_Counters) { + tables_WriteTabL (Count0, 1, k, 5, 10, + "Observed number of runs of 0"); + tables_WriteTabL (Count1, 1, k, 5, 10, + "Observed number of runs of 1"); + } + + X = (cob - 4.0 * n) / sqrt (8.0 * n); + statcoll_AddObs (NBits->sVal1, X); + } + + Param[0] = 2*(k - 1); + gofw_ActiveTests2 (NRuns->sVal1->V, NRuns->pVal1->V, N, wdist_ChiSquare, + Param, NRuns->sVal2, NRuns->pVal2); + NRuns->pVal1->NObs = N; + sres_GetChi2SumStat (NRuns); + + gofw_ActiveTests2 (NBits->sVal1->V, NBits->pVal1->V, N, wdist_Normal, + (double *) NULL, NBits->sVal2, NBits->pVal2); + NBits->pVal1->NObs = N; + sres_GetNormalSumStat (NBits); + + + if (swrite_Basic) { + printf ("\n-----------------------------------------------\n"); + if (N == 1) { + printf ("Total number of 1 runs: %1ld\n\n", cor); + printf ("Number of degrees of freedom : %4ld\n", + NRuns->degFree); + printf ("Chi2 statistic for number of runs :"); + gofw_Writep2 (NRuns->sVal2[gofw_Mean], NRuns->pVal2[gofw_Mean]); + } else { + printf ("Test results for the number of runs:\n"); + gofw_WriteActiveTests0 (N, NRuns->sVal2, NRuns->pVal2); + swrite_Chi2SumTest (N, NRuns); + } + if (swrite_Collectors) + statcoll_Write (NRuns->sVal1, 5, 14, 4, 3); + + printf ("\n-----------------------------------------------\n"); + if (N == 1) { + printf ("Total number of bits: %.0f\n\n", cob); + printf ("Normal statistic for number of bits :"); + gofw_Writep2 (NBits->sVal2[gofw_Mean], NBits->pVal2[gofw_Mean]); + } else { + printf ("Test results for the number of bits:\n"); + gofw_WriteActiveTests0 (N, NBits->sVal2, NBits->pVal2); + swrite_NormalSumTest (N, NBits); + } + if (swrite_Collectors) + statcoll_Write (NBits->sVal1, 5, 14, 4, 3); + + printf ("\n\n"); + swrite_Final (gen, Timer); + } + util_Free (Prob); + if (localRes) + sstring_DeleteRes3 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataAutoCor (unif01_Gen *gen, char *Test, + long N, long n, int r, int s, int d) +{ + swrite_Head (gen, Test, N, n, r); + printf (", s = %1d, d = %1d\n\n", s, d); +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_AutoCor (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r, int s, int d) +{ + const long K = (n - d) / s; + const long M = d / s + 2; + unsigned long *Y; /* Circular buffer for random numbers */ + unsigned long A; /* Correlation */ + unsigned long Z, s1, s2; + unsigned long mask1, mask2; /* Masks of s1, s2 least sig. bits */ + double X; + long i, Seq; + int j1, j2; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_AutoCor test"; + + Timer = chrono_Create (); + /* There are a few bits less than n */ + n -= (n - d) % s; + if (swrite_Basic) + WriteDataAutoCor (gen, TestName, N, n, r, s, d); + + util_Assert (r + s <= 32, "sstring_AutoCor: r + s > 32"); + util_Assert (d <= n / 2, "sstring_AutoCor: d > n/2"); + util_Assert (d > 0, "sstring_AutoCor: d < 1"); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "sstring_AutoCor"); + Y = util_Calloc ((size_t) M, sizeof (unsigned long)); + statcoll_SetDesc (res->sVal1, "sVal1: a standard normal"); + s1 = d % s; + s2 = s - s1; + mask1 = num_TwoExp[s1] - 1.0; + mask2 = num_TwoExp[s2] - 1.0; + + for (Seq = 1; Seq <= N; Seq++) { + /* Fill circular buffer with first random numbers */ + for (i = 0; i < M-1; i++) + Y[i] = unif01_StripB (gen, r, s); + + A = 0; + j1 = M - 1; + j2 = M - 2; + for (i = 0; i < K; i++) { + Y[j1] = unif01_StripB (gen, r, s); + j1 = (j1 + 1) % M; + Z = ((Y[j1] >> s1) ^ Y[j2]) & mask2; + while (Z > 0) { /* Count the number of 1 bits in Z */ + Z &= Z - 1; /* Clear lowest 1 bit */ + ++A; + } + j2 = (j2 + 1) % M; + + Z = ((Y[j2] >> s2) ^ Y[j1]) & mask1; + while (Z > 0) { + Z &= Z - 1; + ++A; + } + } + + X = 2.0 * (A - (n - d) / 2.0) / sqrt ((double) (n - d)); + statcoll_AddObs (res->sVal1, X); + } + + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetNormalSumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res); + swrite_Final (gen, Timer); + } + util_Free (Y); + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataHammingCorr (unif01_Gen *gen, char *TestName, + long N, long n, int r, int s, int L) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d, L = %1d\n\n\n", s, L); +} + + +/*-------------------------------------------------------------------------*/ + +static void HammingCorr_L (unif01_Gen *gen, sstring_Res * res, + long n, int r, int s, int L) +/* + * Generate all the n bits for the HammingCorr test in the case L > s. + * For the last number generated in a block of L bits, we keep its first + * LMods bits and discard the other bits. + */ +{ + const int LMods = L % s; + const int LDivs = L / s; + int Pre, X; + int j; + long k; + unsigned long Z; + + /* Junk value to avoid a test "if (k == 1)" for every generated + number; it will not be counted. */ + Pre = L + 1; + for (k = 1; k <= n; k++) { + /* Generate a sequence of L bits */ + X = 0; + for (j = 1; j <= LDivs; j++) { + Z = unif01_StripB (gen, r, s); + /* Count the number of 1 bits */ + while (Z > 0) { + Z &= Z - 1; /* Clear lowest 1 bit */ + ++X; + } + } + /* The last bits of the sequence */ + if (LMods > 0) { + Z = unif01_StripB (gen, r, LMods); + while (Z > 0) { + Z &= Z - 1; + ++X; + } + } + ++res->Counters[Pre][X]; + Pre = X; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void HammingCorr_S (unif01_Gen *gen, sstring_Res * res, + long n, int r, int s, int L) +/* + * Generate all the n bits for the HammingCorr test in the case L <= s. + * A number generates sDivL blocks. If s % L == 0, we use all s bits of the + * number. + */ +{ + const int sDivL = s / L; /* A number generates sDivL blocks */ + const long Q = n / sDivL; + const long Q1 = n % sDivL; + const unsigned long MASK = num_TwoExp[L] - 1.0; + int Pre, X; + int j; + long k; + unsigned long Z, Y; + + /* Junk value to avoid a test "if (k == 1)" for every generated + number; it will not be counted. */ + Pre = L + 1; + for (k = 0; k < Q; k++) { + Z = unif01_StripB (gen, r, s); + + for (j = 0; j < sDivL; j++) { + X = 0; + Y = Z & MASK; + while (Y > 0) { /* Count the number of 1 bits */ + Y &= Y - 1; /* Clear lowest 1 bit */ + ++X; + } + ++res->Counters[Pre][X]; + Pre = X; + Z >>= L; + } + } + + /* The last Q1 blocks */ + if (Q1 > 0) { + Z = unif01_StripB (gen, r, s); + for (j = 0; j < Q1; j++) { + X = 0; + Y = Z & MASK; + while (Y > 0) { /* Count the number of 1 bits */ + Y &= Y - 1; /* Clear lowest 1 bit */ + ++X; + } + ++res->Counters[Pre][X]; + Pre = X; + Z >>= L; + } + } +} + + +/*-------------------------------------------------------------------------*/ + +void sstring_HammingCorr (unif01_Gen * gen, sstring_Res * res, + long N, long n, int r, int s, int L) +{ + int i, j; + long Seq; + double Sum; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_HammingCorr test"; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataHammingCorr (gen, TestName, N, n, r, s, L); + + util_Assert (s <= num_MaxTwoExp, "sstring_HammingCorr: s too large"); + util_Assert ((unsigned) s <= CHAR_BIT * sizeof (unsigned long), + "sstring_HammingCorr: s too large"); + + if (res == NULL) { + localRes = TRUE; + res = sstring_CreateRes (); + } + InitRes (res, N, L, -1, "sstring_HammingCorr"); + statcoll_SetDesc (res->Bas->sVal1, "HammingCorr sVal1: standard normal"); + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i <= L; i++) { + for (j = 0; j <= L; j++) + res->Counters[i][j] = 0; + } + if (L >= s) + HammingCorr_L (gen, res, n, r, s, L); + else + HammingCorr_S (gen, res, n, r, s, L); + + if (swrite_Counters) + /* Print the matrix of counters */ + tables_WriteMatrixL (res->Counters, 0, L, 0, L, 8, + res->Style, "Number of pairs [0..L, 0..L]"); + + /* Calculate statistic */ + Sum = 0.0; + for (i = 0; i <= L; i++) { + for (j = 0; j <= L; j++) + Sum += res->Counters[i][j] * (i - L / 2.0) * (j - L / 2.0); + } + Sum = Sum * 4.0 / (L * sqrt (n - 1.0)); + statcoll_AddObs (res->Bas->sVal1, Sum); + } + + gofw_ActiveTests2 (res->Bas->sVal1->V, res->Bas->pVal1->V, N, + wdist_Normal, (double *) NULL, res->Bas->sVal2, res->Bas->pVal2); + res->Bas->pVal1->NObs = N; + sres_GetNormalSumStat (res->Bas); + + if (swrite_Collectors) + statcoll_Write (res->Bas->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->Bas->sVal2, res->Bas->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res->Bas); + swrite_Final (gen, Timer); + } + if (localRes) + sstring_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataHammingIndep (unif01_Gen * gen, char *TestName, + long N, long n, int r, int s, int L, int d) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d, L = %1d, d = %1d\n\n\n", s, L, d); +} + + +/*-------------------------------------------------------------------------*/ + +static void HammingIndep_L (unif01_Gen *gen, sstring_Res * res, + long n, int r, int s, int L) +/* + * Generate all the n bits for the HammingIndep test in the case L > s. + * For the last number generated in a block of L bits, we keep its first + * LMods bits and discard the other bits. + */ +{ + int Pre; /* Previous value of X */ + int X; + const int LMods = L % s; + const int LDivs = L / s; + int j; + unsigned long U; + unsigned long TwonUL; + unsigned long ic; + + /* For the test with n >= 2^30 */ + TwonUL = 2 * (unsigned long) n; + + Pre = 0; /* Eliminate a warning from compiler */ + for (ic = 1; ic <= TwonUL; ic++) { + /* Generate 1 block of L bits */ + X = 0; + for (j = 1; j <= LDivs; j++) { + U = unif01_StripB (gen, r, s); + /* Count the number of 1 bits */ + while (U > 0) { + U &= U - 1; /* Clear lowest 1 bit */ + ++X; + } + } + /* The last bits of the block */ + if (LMods > 0) { + U = unif01_StripB (gen, r, LMods); + while (U > 0) { + U &= U - 1; + ++X; + } + } + /* Non-overlapping pairs; count only when ic % 2 == 0 */ + if (!(ic & 1)) + ++res->Counters[Pre][X]; + Pre = X; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void HammingIndep_S (unif01_Gen *gen, sstring_Res * res, + long n, int r, int s, int L) +/* + * Generate all the n bits for the HammingIndep test in the case L <= s. + * A number generates sDivL blocks. If s % L == 0, we use all s bits of the + * number. + */ +{ + const int sDivL = s / L; /* A number generates sDivL blocks */ + const unsigned long MASK = num_TwoExp[L] - 1.0; + int Pre; /* Previous value of X */ + int X; + int j; + unsigned long Q, Q1, i; + unsigned long Z, Y; + unsigned long TwonUL; + unsigned long bloc = 0; + + /* For the test with n >= 2^30 */ + TwonUL = 2 * (unsigned long) n; + Q = TwonUL / sDivL; + Q1 = TwonUL % sDivL; + + Pre = 0; /* Eliminate a warning from compiler */ + for (i = 0; i < Q; i++) { + Z = unif01_StripB (gen, r, s); + + for (j = 0; j < sDivL; j++) { + X = 0; + Y = Z & MASK; + while (Y > 0) { /* Count the number of 1 bits */ + Y &= Y - 1; /* Clear lowest 1 bit */ + ++X; + } + /* Non-overlapping pairs; count only when bloc % 2 == 0 */ + if (!(++bloc & 1)) + ++res->Counters[Pre][X]; + Pre = X; + Z >>= L; + } + } + + /* The last Q1 blocks */ + if (Q1 > 0) + Z = unif01_StripB (gen, r, s); + for (i = 0; i < Q1; i++) { + X = 0; + Y = Z & MASK; + while (Y > 0) { /* Count the number of 1 bits */ + Y &= Y - 1; /* Clear lowest 1 bit */ + ++X; + } + if (!(++bloc & 1)) + ++res->Counters[Pre][X]; + Pre = X; + Z >>= L; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void CountBlocks ( + sstring_Res *res, + int L, /* Length of blocks (num bits) */ + int d /* Rank of rows-columns counted */ + +) +/* + * Add the diagonal blocks for the matrix res->Counters, i.e. count the + * number of values in the 4 corners of the matrix with the center removed. + * We count only rows-columns of rank >= d starting from the center of + * the matrix. We eliminate 2d - 1 rows and columns at the center of the + * matrix when L is even. When L is odd, we eliminate 2d - 2 rows and + * columns at the center (except when d = 1, where we keep all the rows + * and columns). + */ +{ + int L2, L1, k, j, i; + + L2 = L1 = L / 2; + if ((L & 1)) + ++L1; + + for (k = 1; k <= d; k++) { + res->XD[k][0] = 0; + res->XD[k][1] = 0; + + /* Block ++ */ + for (i = 0; i <= L1 - k; i++) { + for (j = 0; j <= L1 - k; j++) { + res->XD[k][0] += res->Counters[i][j]; + } + } + /* Block -- */ + for (i = L2 + k; i <= L; i++) { + for (j = L2 + k; j <= L; j++) { + res->XD[k][0] += res->Counters[i][j]; + } + } + /* Block +- */ + for (i = 0; i <= L1 - k; i++) { + for (j = L2 + k; j <= L; j++) { + res->XD[k][1] += res->Counters[i][j]; + } + } + /* Block -+ */ + for (i = L2 + k; i <= L; i++) { + for (j = 0; j <= L1 - k; j++) { + res->XD[k][1] += res->Counters[i][j]; + } + } + } +} + +/*-------------------------------------------------------------------------*/ + +static void WriteBlocs ( + sstring_Res *res, + int d /* Rank of rows-columns */ + ) +/* + * Print the sum of counters in the diagonal blocks for different d + */ +{ + int i; + printf ("--------------------------------------------------\n"); + + for (i = 1; i <= d; i++) { + printf ("The number of blocks ++, -- with d >= %1d is %10ld\n", + i, res->XD[i][0]); + printf ("The number of blocks +-, -+ with d >= %1d is %10ld\n\n", + i, res->XD[i][1]); + } + printf ("\n"); +} + +/*-------------------------------------------------------------------------*/ + +void sstring_HammingIndep (unif01_Gen * gen, sstring_Res * res, + long N, long n, int r, int s, int L, int d) +{ + int Liber = 0; /* Num of degrees of freedom for main test */ + int Liberte; /* Num of degrees of freedom for block tests */ + int X; + int i, j; + long Seq; + double NbEsp; + double Var; + double NbMoyen; + double X2; + double Sum; + const double nLR = n; + double Z; + double *Prob; + double *NbEsp5; + long *Count5; + double V[1]; + fmass_INFO Q; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "sstring_HammingIndep test"; + char chaine[LEN1 + 1] = ""; + char str[LEN2 + 1]; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataHammingIndep (gen, TestName, N, n, r, s, L, d); + + if (n < 2.0 * gofs_MinExpected) { + util_Warning (TRUE, "sstring_HammingIndep: n < 20"); + return; + } + /* util_Assert (n >= 30, "sstring_HammingIndep: n < 30"); */ + util_Assert (d <= sstring_MAXD, "sstring_HammingIndep: d > sstring_MAXD"); + util_Assert (((L + 1) / 2) >= d, "sstring_HammingIndep: d > (L + 1) / 2"); + util_Assert (s <= num_MaxTwoExp, "sstring_HammingIndep: s too large"); + util_Assert ((unsigned) s <= CHAR_BIT * sizeof (unsigned long), + "sstring_HammingIndep: s too large"); + + if (res == NULL) { + localRes = TRUE; + res = sstring_CreateRes (); + } + InitRes (res, N, L, d, "sstring_HammingIndep"); + + for (i = 1; i <= d; i++) { + strncpy (chaine, "HammingIndep Block[", (size_t) LEN1); + sprintf (str, "%1d", i); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, "]", (size_t) 2); + statcoll_SetDesc (res->Block[i]->sVal1, chaine); + } + strncpy (chaine, "\nCounters with expected numbers >= ", (size_t) LEN1); + sprintf (str, "%g", gofs_MinExpected); + strncat (chaine, str, (size_t) LEN2); + statcoll_SetDesc (res->Bas->sVal1, chaine); + + Prob = util_Calloc ((size_t) L + 1, sizeof (double)); + NbEsp5 = util_Calloc ((size_t) (L + 1)*(L + 1) + 1, sizeof (double)); + Count5 = util_Calloc ((size_t) (L + 1)*(L + 1) + 1, sizeof (long)); + + Q = fmass_CreateBinomial (L, 0.5, 0.5); + for (i = 0; i <= L; i++) + Prob[i] = fmass_BinomialTerm2 (Q, i); + fmass_DeleteBinomial (Q); + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i <= L; i++) { + for (j = 0; j <= L; j++) { + res->Counters[i][j] = 0; + } + } + if (L >= s) + HammingIndep_L (gen, res, n, r, s, L); + else + HammingIndep_S (gen, res, n, r, s, L); + + /* The cells for which the expected number >= gofs_MinExpected will */ + /* correspond to one class each. Merge all other cells such that */ + /* their expected number is < gofs_MinExpected into 1 big class: Z */ + /* will contain the sum of all their expected numbers, and the */ + /* counter X will contain the sum of all their observed numbers. We */ + /* shall apply a chi-square test with Liber degrees of freedom. We */ + /* have (Liber + 1) classes. */ + Liber = 0; + Z = 0.0; + X = 0; + for (i = 0; i <= L; i++) { + for (j = 0; j <= L; j++) { + res->ZCounters[i][j] = nLR * Prob[i] * Prob[j]; + if (res->ZCounters[i][j] >= gofs_MinExpected) { + NbEsp5[Liber] = res->ZCounters[i][j]; + Count5[Liber] = res->Counters[i][j]; + ++Liber; + } else { + Z += res->ZCounters[i][j]; + X += res->Counters[i][j]; + } + } + } + if (Z >= gofs_MinExpected) { + /* We have one more class */ + /* if (swrite_Classes && Seq == 1) { + printf ("All cells with NbExp < "); + printf ("%s", str); + printf (" are merged into one big class with NbExp = %f\n\n", Z); + } */ + NbEsp5[Liber] = Z; + Count5[Liber] = X; + } else if (Liber > 0) { + /* We add them to the last class instead */ + --Liber; + NbEsp5[Liber] += Z; + Count5[Liber] += X; + } + + /* Everything has been put in a single class; separate all in two + classes */ + if (Liber == 0) { + Z = 0.0; + X = 0; + for (i = 0; i <= L; i++) { + for (j = 0; j <= L / 2; j++) { + res->ZCounters[i][j] = nLR * Prob[i] * Prob[j]; + Z += res->ZCounters[i][j]; + X += res->Counters[i][j]; + } + } + NbEsp5[0] = Z; + Count5[0] = X; + Z = 0.0; + X = 0; + for (i = 0; i <= L; i++) { + for (j = 1 + L / 2; j <= L; j++) { + res->ZCounters[i][j] = nLR * Prob[i] * Prob[j]; + Z += res->ZCounters[i][j]; + X += res->Counters[i][j]; + } + } + NbEsp5[1] = Z; + Count5[1] = X; + Liber = 1; + } + if (Liber > 0) { + X2 = gofs_Chi2 (NbEsp5, Count5, 0, Liber); + statcoll_AddObs (res->Bas->sVal1, X2); + } + + /* Compute the normalized observed number for each pair */ + for (i = 0; i <= L; i++) { + for (j = 0; j <= L; j++) { + NbEsp = nLR * Prob[i] * Prob[j]; + Var = NbEsp * (1.0 - Prob[i] * Prob[j]); + if (Var <= 0.0) { + /* This case will occur when NbEsp = 0; if so, fail the test */ + /* when res->Counters[i][j] != 0 */ + res->ZCounters[i][j] = (res->Counters[i][j] - NbEsp) * 1.E100; + } else { + res->ZCounters[i][j] = (res->Counters[i][j] - NbEsp) / + sqrt (Var); + } + } + } + if (sstring_Counters) + /* Print the matrix of counters */ + tables_WriteMatrixL (res->Counters, 0, L, 0, L, 8, res->Style, + "res->Counters, the number of pairs [0..L, 0..L]"); + if (swrite_Counters) + /* Print the matrix of normalized counters */ + tables_WriteMatrixD (res->ZCounters, 0, L, 0, L, 12, 4, + res->Style, "res->ZCounters, the normalized counters"); + + /* These blocks are sub-matrices symmetrically placed with respect to */ + /* the diagonals in the matrix of the number of pairs [Xi, X(i+1)]. */ + /* For those, we shall apply a chi-square test for the total number */ + /* in the diagonal sub-matrices. */ + CountBlocks (res, L, d); + + if (swrite_Counters) + WriteBlocs (res, d); + + for (i = 1; i <= d; i++) { + double NumExp[3]; + long Count[3]; + Sum = 0.0; + for (j = 0; j <= (L + 1) / 2 - i; j++) + Sum += Prob[j]; + /* Probability of a sub-matrix block */ + Sum *= Sum; + /* Average number for each of the 2 blocks */ + NbMoyen = Sum * nLR * 2.0; + NumExp[0] = NumExp[1] = NbMoyen; + if (2.0*NbMoyen < gofs_MinExpected) + printf ("******* sample too small for chi-square for d = %d\n", i); + NumExp[2] = nLR - 2.0*NbMoyen; + Count[0] = res->XD[i][0]; + Count[1] = res->XD[i][1]; + Count[2] = n - Count[0] - Count[1]; + X2 = gofs_Chi2 (NumExp, Count, 0, 2); + statcoll_AddObs (res->Block[i]->sVal1, X2); + } + } + + for (i = 1; i <= d; i++) { + /* Degrees of freedom */ + if ((L & 1) && i == 1) + Liberte = 1; + else + Liberte = 2; + + V[0] = Liberte; + gofw_ActiveTests2 (res->Block[i]->sVal1->V, res->Block[i]->pVal1->V, N, + wdist_ChiSquare, V, res->Block[i]->sVal2, res->Block[i]->pVal2); + res->Block[i]->pVal1->NObs = N; + Sum = N * statcoll_Average (res->Block[i]->sVal1); + res->Block[i]->sVal2[gofw_Sum] = Sum; + res->Block[i]->pVal2[gofw_Sum] = fbar_ChiSquare2 (N*Liberte, 12, Sum); + + if (swrite_Basic) { + printf ("\nDiagonal blocks with d = %2d", i); + swrite_AddStrChi (str, LEN2, Liberte); + gofw_WriteActiveTests2 (N, res->Block[i]->sVal2, + res->Block[i]->pVal2, str); + swrite_Chi2SumTestb (N, res->Block[i]->sVal2[gofw_Sum], + res->Block[i]->pVal2[gofw_Sum], Liberte); + if (swrite_Collectors) { + strncpy (chaine, res->Block[i]->sVal1->Desc, (size_t) LEN1); + strncat (chaine, ": a chi2 with ", (size_t) LEN1); + sprintf (str, "%1d", Liberte); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, " degrees of freedom", (size_t) LEN1); + statcoll_SetDesc (res->Block[i]->sVal1, chaine); + statcoll_Write (res->Block[i]->sVal1, 5, 14, 4, 3); + } + } + } + + if (Liber > 0) { + V[0] = Liber; + gofw_ActiveTests2 (res->Bas->sVal1->V, res->Bas->pVal1->V, N, + wdist_ChiSquare, V, res->Bas->sVal2, res->Bas->pVal2); + res->Bas->pVal1->NObs = N; + Sum = N * statcoll_Average (res->Bas->sVal1); + res->Bas->sVal2[gofw_Sum] = Sum; + res->Bas->pVal2[gofw_Sum] = fbar_ChiSquare2 (N*Liber, 12, Sum); + + if (swrite_Basic) { + printf ("%s", res->Bas->sVal1->Desc); + swrite_AddStrChi (str, LEN2, Liber); + gofw_WriteActiveTests2 (N, res->Bas->sVal2, res->Bas->pVal2, str); + swrite_Chi2SumTestb (N, res->Bas->sVal2[gofw_Sum], + res->Bas->pVal2[gofw_Sum], Liber); + if (swrite_Collectors) { + strncpy (chaine, res->Bas->sVal1->Desc, (size_t) LEN1); + strncat (chaine, ": a ChiSquare with ", (size_t) LEN1); + sprintf (str, "%1d", Liber); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, " degrees of freedom", (size_t) LEN1); + statcoll_SetDesc (res->Bas->sVal1, chaine); + statcoll_Write (res->Bas->sVal1, 5, 14, 4, 3); + } + } + } else { + /* for the module tvaria */ + res->Bas->pVal2[gofw_Mean] = -1.0; + if (d < 1) + util_Warning (1, + "n is too small: ChiSquare with 0 degree of freedom"); + } + + if (swrite_Basic) + swrite_Final (gen, Timer); + + util_Free (Prob); + util_Free (NbEsp5); + util_Free (Count5); + if (localRes) + sstring_DeleteRes (res); + chrono_Delete (Timer); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/sstring.tex b/TESTU01/TestU01-1.2.3/testu01/sstring.tex new file mode 100644 index 0000000..c21a107 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/sstring.tex @@ -0,0 +1,550 @@ +\defmodule {sstring} + +This module implements different tests that are applied to +strings of random bits. Each test takes a block of $s$ bits +from each uniform and concatenate them to construct bit strings. +\resdef + + +\bigskip +\hrule +\code\hide +/* sstring.h for ANSI C */ +#ifndef SSTRING_H +#define SSTRING_H +\endhide +#include "tables.h" +#include "unif01.h" +#include "sres.h" +\endcode +\ifdetailed %%%%%%%%%%%%%%%%%%%% + +\code + + +#define sstring_MAXD 8 +\endcode + \tab + Maximal value of $d$ in {\tt sstring\_HammingIndep}. + \endtab +\code + + +extern lebool sstring_Counters; +\endcode + \tab + This flag is used only in test {\tt sstring\_HammingIndep}. +% and {\tt svaria\_MarkovEigenvalue}. + Its default value is {\tt FALSE}. + If it is set to {\tt TRUE}, the {\it unnormalized} {\tt Counters} in + the test will be printed. The {\it normalized} {\tt Counters} + will be printed if {\tt swrite\_Counters} is set to {\tt TRUE}. + \endtab +\code + + +extern lebool sstring_CorrFlag; +\endcode + \tab + This switch controls the printing of strings correlations + in test {\tt sstring\_PeriodsInStrings}. By default, it is set to + {\tt FALSE}. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Structures for test results} + +The detailed test results can be recovered in a structure of type +{\tt sres\_Basic}, {\tt sres\_Chi2} or in one of the structures +defined in this module, depending on the test. + +\code + +typedef struct { + + sres_Chi2 *Chi; + sres_Disc *Disc; +\endcode + \tabb + The results of the chi-square test for the longest run of 1's in each + block are kept in {\tt Chi}. The results for the longest run of 1's + over all blocks and all $N$ replications of the base test are kept in + {\tt Disc}. + \endtabb +\code + +} sstring_Res2; +\endcode + \tab + Structure used to keep the results of the tests of + {\tt sstring\_LongestHeadRun}. + \endtab +\code + + +sstring_Res2 * sstring_CreateRes2 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt sstring\_LongestHeadRun} test. + \endtab +\code + + +void sstring_DeleteRes2 (sstring_Res2 *res); +\endcode + \tab + Frees the memory allocated by {\tt sstring\_CreateRes2}. + \endtab + + +\bigskip\hrule +\code + + +typedef struct { + + sres_Basic *NBits; + sres_Chi2 *NRuns; + long *Count0; + long *Count1; +\endcode + \tabb + The results for the total number of bits are in {\tt NBits}, + and those for the total number of runs in {\tt NRuns}. + The arrays {\tt Count0} and {\tt Count1} are the counters for the + runs of 0's and runs of 1's. + The indices {\tt 1} and {\tt NRuns->jmax} are the lowest + and highest valid indices for these arrays. + \endtabb +\code + +} sstring_Res3; +\endcode + \tab + Structure used to keep the results of the {\tt sstring\_Run} tests. + \endtab +\code + + +sstring_Res3 * sstring_CreateRes3 (void); +\endcode + \tab + Creates and returns a structure that will hold the results + of a {\tt sstring\_Run} test. + \endtab +\code + + +void sstring_DeleteRes3 (sstring_Res3 *res); +\endcode + \tab + Frees the memory allocated by {\tt sstring\_CreateRes3}. + \endtab + + +\bigskip\hrule +\code + + +typedef struct { + + int L; +\endcode + \tabb + Indicates the sizes ($(L+1)\times (L+1)$) of the square matrices + {\tt Counters[i][j]} and + {\tt ZCounters[i][j]} used in tests {\tt sstring\_HammingCorr} and + {\tt sstring\_HammingIndep}. Valid indices are in {\tt [0..L]}. +%% , and {\tt [0..L-1]} for {\tt svaria\_MarkovEigenvalue}. + \endtabb +\code + + tables_StyleType Style; +\endcode + \tabb + Printing style for {\tt ZCounters} and {\tt Counters}. + The default value is {\tt tables\_Plain}. + \endtabb +\code + + long **Counters; +\endcode + \tabb + Counters for the couples $[X_i, X_{i+1}]$ in {\tt sstring\_HammingCorr} + and {\tt sstring\_HammingIndep}. +%%% and {\tt svaria\_MarkovEigenvalue}. + \endtabb +\code + + double **ZCounters; +\endcode + \tabb + Normalized counters in {\tt sstring\_HammingIndep}. +%%% and {\tt svaria\_MarkovEigenvalue}. + \endtabb +\code + + int d; +\endcode + \tabb + Actual dimension of the matrix {\tt XD[][2]} (the first dimension) + and of {\tt Block[]}. Valid indices for these arrays are in {\tt [1..d]}. + \endtabb +\code + + long XD [sstring_MAXD + 1][2]; +\endcode + \tabb + Counters for the number of values in the diagonal blocks + (sub-matrices) in the test {\tt sstring\_HammingIndep}: + {\tt XD[][0]} for the blocks $++$ and $--$, + {\tt XD[][1]} for the blocks $+-$ and $-+$. + \endtabb +\code + + sres_Basic *Block [sstring_MAXD + 1]; +\endcode + \tabb + Used only for the diagonal blocks in {\tt sstring\_HammingIndep} + for each index $i \le d$, where $d$ is the parameter of the test. +\endtabb +\code + + sres_Basic *Bas; +\endcode + \tabb + Results of the main test. + \endtabb +\code + +} sstring_Res; +\endcode + \tab + This structure is used to keep the results of the tests + {\tt sstring\_HammingCorr} and {\tt sstring\_Ham\-mingIndep}. +%% and {\tt svaria\_MarkovEigenvalue} tests. + \endtab +\code + + +sstring_Res * sstring_CreateRes (void); +\endcode + \tab + Creates and returns a structure that will hold the results of a test. + \endtab +\code + + +void sstring_DeleteRes (sstring_Res *res); +\endcode + \tab + Frees the memory allocated by {\tt sstring\_CreateRes}. + \endtab + +\fi %%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code + + +void sstring_PeriodsInStrings (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int s); +\endcode + \tab This function applies a test +\index{Test!PeriodsInStrings}% + based on the distribution of the correlations +\index{correlation of bits}% + in bit strings of length $s$. + The {\em correlation\/} of a bit string $b = b_0 b_1 \cdots b_{s-1}$ + is defined as the bit vector $c = c_0 c_1 \cdots c_{s-1}$ such that + $c_p=1$ if and only if $p$ is a period of $b$, i.e. if and only if + $b_i = b_{i+p}$ for $i=0,\dots,s-p-1$ + (see Guibas and Odlyzko \cite{pGUI81a}). + One always has $c_0=1$. + + The function first enumerates all possible correlations $c$ for bit + strings of length $s$, and computes the expected number of strings + of correlation $c$, $E_s(c) = n L_s(c)/2^s$, + where $L_s(c)$ is the number of strings, among all $2^s$ strings + of length $s$, having correlation $c$. + These numbers are computed as explained in \cite{pGUI81a}. + Then, $n$ strings of length $s$ are generated, by generating $n$ + uniforms and keeping the $s$ most significant bits of each + (after discarding the first $r$), the corresponding correlations are + computed, and the number of occurrences of each correlation is + computed. These countings are compared with the corresponding + expected values via a chi-square test, after regrouping classes + if needed to make sure that the expected number of values in each class + is at least {\tt gofs\_MinExpected}. + Restrictions: $2 \le s \le 31$, $r + s \le 31$, + $n/2 > $ {\tt gofs\_MinExpected}. + \endtab +\code + + +void sstring_LongestHeadRun (unif01_Gen *gen, sstring_Res2 *res, + long N, long n, int r, int s, long L); +\endcode + \tab This test +\index{Test!LongestHeadRun}% + \index{Test!Longest Run of ones|see{LongestHeadRun}}% + generates $n$ blocks of $L$ bits by taking $s$ bits + from each of $n \lfloor L/s\rfloor$ successive uniforms. + In each block, it finds the length $\ell$ of the longest run + of successive 1's, and counts how many times each value of $\ell$ + has occurred. It then compares these countings to the corresponding + expected values via a chi-square test, after regrouping classes + if needed. The expected values (i.e., the theoretical distribution) + are computed as described in \cite{tFOL79a}, \cite{tGOR86a} and + \cite[p. 21]{rRUK01a}. It also finds the length $\ell$ of the longest run + of 1's over all blocks of all $N$ replications + and compares it with the theoretical distribution. +% Recommendation: $n \ge 100$. + Restrictions: $L \ge 1000$, $r + s \le 32$. + \endtab +\hrichard{NIST semble utiliser la distribution exacte. Il faudra la rajouter +\'eventuellement. Nous utilisons la distribution extr\^eme qui est +probablement asymptotique.} +\hpierre {On devrait peut-\^etre regrouper ces deux tests en un seul?} +\hrichard {R\'ep.: Non, car le second exige des chaines d'au moins 1000 bits + alors que le premier utilise des cha\^\i nes d'au plus 30 bits. } +\code + + +void sstring_HammingWeight (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, int s, long L); +\endcode + \tab + This test is a one-dimensional version of {\tt sstring\_HammingIndep}. + It generates $n$ blocks of $L$ bits and examines the proportion of 1's + \index{Test!HammingWeight}% + \index{Test!Frequency|see{HammingWeight}}% + within each (non-overlapping) $L$-bit block. + \index{Hamming weight}% + Under $\cH_0$, the number of 1's in each block are + i.i.d.\ binomial random variables + with parameters $L$ and $1/2$ (with mean $L/2$ and variance $L/4$). + Let $X_j$ be the number of blocks amongst $n$, having $j$ 1's + (i.e., with Hamming weight $j$). + The observed numbers of blocks having $j$ 1's are compared + with the expected numbers via a chi-square test. + Restrictions: $r + s \le 32$ and $n \ge 2*$ {\tt gofs\_MinExpected}. + \endtab +\code + + +void sstring_HammingWeight2 (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, int s, long L); +\endcode + \tab +\hrichard {Pour une valeur fixe de $n*N$, il ne semble pas y avoir de + diff\'erence de sensibilit\'e entre grand ou petit $n$. Il semble + pr\'ef\'erable de choisir un bloc de longueur moyenne $s << L << n$.} + This test is taken from \cite{rRUK01a}. + Given a string of $n$ bits, the test examines the proportion of 1's + \index{Test!HammingWeight2}% + \index{Test!Monobit|see{HammingWeight2}}% + within (non-overlapping) $L$-bit blocks. It partitions the bit string into + $K = \lfloor n/L \rfloor$ blocks. + Let $X_j$ be the number of 1's in block $j$ (i.e., its Hamming weight). + \index{Hamming weight}% + Under $\cH_0$, the $X_j$'s are i.i.d.\ binomial random variables + with parameters $L$ and $1/2$ (with mean $L/2$ and variance $L/4$). + The test computes the chi-square statistic +$$ + X^2 = \sum_{j=1}^K \frac{(X_j - L/2)^2}{L/4} + = \frac{4}{L} \sum_{j=1}^K (X_j - L/2)^2, +$$ + which should have approximately the chi-square distribution with $K$ + degrees of freedom if $L$ is large enough. + For $L=n$, this test degenerates to the {\em monobit\/} test + used in \cite{rRUK01a}, which simply counts the proportion of 1's + in a string of $n$ bits. + Restrictions: $r + s \le 32$, \ $ L \le n$ and $L$ large. + \endtab +\code + + +void sstring_HammingCorr (unif01_Gen *gen, sstring_Res *res, + long N, long n, int r, int s, int L); +\endcode + \tab + Applies a correlation test on the Hamming weights + of successive blocks of $L$ bits (see \cite{rLEC99e}). +\index{Test!HammingCorr}% +\index{Hamming weight}% +\index{correlation of bits}% + It is strongly related to the test {\tt sstring\_HammingIndep} below. + The test uses the $s$ most significant bits from each generated random + number (after dropping the first $r$ bits) to build $n$ blocks of $L$ bits. + Let $X_j$ be the Hamming weight (the numbers of bits equal to 1) + of the $j$th block, for $j=1,\dots,n$. + The test computes the empirical correlation between the + successive $X_j$'s, + $$ + \hat\rho = {4 \over (n-1) L } \sum_{j=1}^{n-1} + \left(X_j - L/2\right) \left(X_{j+1} - L/2\right). + $$ + Under $\cH_0$, as $n\to\infty$, $\hat\rho \sqrt{n-1}$ has asymptotically + the standard normal distribution. + This is what is used in the test. + The test is valid only for large $n$. + \endtab +\code + + +void sstring_HammingIndep (unif01_Gen *gen, sstring_Res *res, + long N, long n, int r, int s, int L, int d); +\endcode + \tab + Applies two tests of independence between the Hamming weights + of successive blocks of $L$ bits. +\index{Test!HammingIndep}% +\index{Hamming weight}% +\index{Test!Independence of bits}% + These tests were introduced by L'Ecuyer and Simard \cite{rLEC99e}. + They use the $s$ most significant bits from each generated random number + (after dropping the first $r$ bits) to build $2n$ blocks of $L$ bits. + Let $X_j$ be the Hamming weight (the numbers of bits equal to 1) + of the $j$th block, for $j=1,\dots,2n$. + Each vector $(X_i, X_{i+1})$ can take $(L+1)\times(L+1)$ possible + values. The test counts the number of occurrences of each possibility + among the non-overlapping pairs $\{(X_{2j-1}, X_{2j}),\, 1\le j\le n\}$, + and compares these observations with the expected numbers under $\cH_0$, + via a chi-square test, after lumping together in a single class + all classes for which the expected number is less than + {\tt gofs\_MinExpected}. Restriction: $n \ge 2*${\tt gofs\_MinExpected}. + + The function also applies the following (second) test on these countings, + which are placed in a $(L+1)\times(L+1)$ matrix in the natural way. + First, the $2d-1$ rows and $2d-1$ columns at the center of the matrix + are discarded if $L$ is even, and the $2d-2$ central rows and columns + are discarded if $L$ is odd. + There remain four submatrices, at the four corners. + Now, let $Y_1$ be the sum of the counters in the lower left and + upper right submatrices, $Y_2$ the sum of the counters in the + lower right and upper left submatrices, and $Y_3 = n - Y_1 - Y_2$. + The observed values of $Y_1$, $Y_2$ and $Y_3$ are compared with their + expected values with a chi-square test. + The chi-square statistic has 1 degree of freedom if $d=1$ and $m$ is odd + (because $Y_3=0$ in that case), and 2 degrees of freedom otherwise. +\ifdetailed + Restrictions: $d \le $ {\tt sstring\_MAXD}, $d \le (L + 1)/2$. +\else + Restrictions: $d \le 8$, $d \le (L + 1)/2$. +\fi + If $d$ is too large for a given $n$, the expected numbers in the + categories will be too small for the chi-square to be valid. + \endtab +\code + + +void sstring_Run (unif01_Gen *gen, sstring_Res3 *res, + long N, long n, int r, int s); +\endcode + \tab This is a version of the run test applicable to a bit string. + \index{Test!Run!bits}% + It is also related to the gap test. + In a bit string of length $n$, the runs of successive 1's can be seen + as {\em gaps\/} between the blocks of successive 0's. + These gap (or run) lengths are independent geometric random variables, + plus 1; i.e., each run has length $i$ with probability $2^{-i}$, + for $i=1,2,\dots$. Of course, this is also true if we swap 0 and 1 + and look at the runs of 0's. + + Suppose we construct a bit string until we have $n$ runs of 1's and + $n$ runs of 0's, i.e., a total of $2n$ runs. + Select some positive integer $k$. + For $j=0$ and 1, let $X_{j,i}$ be the number of runs of $j$'s of + length $i$ for $i = 1,\dots,k-1$, and let $X_{j,k}$ + be the number of runs of $j$'s of length $\ge k$. + Under $\cH_0$, for each $j$, $(X_{j,1},\dots,X_{j,k-1},X_{j,k})$ + is a multinomial random vector with parameters + $(n, p_1, p_2, \dots, p_{k-1}, p_k)$, where + $p_i = 2^{-i}$ for $1\le i < k$ and $p_k = p_{k-1} = 2^{-k+1}$. + Then, if $n p_k$ is large enough, the chi-square statistic +$$ + X_j^2 = \sum_{i=1}^k \frac{(X_{j,i} - n p_i)^2}{n p_i(1-p_i)} +$$ + has approximately the chi-square distribution with $k-1$ degrees + of freedom. + Moreover, $X_0^2$ and $X_1^2$ are independent, + so $X^2 = X_0^2 + X_1^2$ should be approximately chi-square with + $2(k-1)$ degrees of freedom. +% Moreover, $X_0^1$ and $X_{0,2}$ are independent, +% so $X^2 = X_0^1 + X_{0,2}$ should be approximately chi-square with +% $2(k-1)$ degrees of freedom. + The test is based on the statistic $X^2$ and uses + $k = 1 + \lfloor \log_2 (n / \mbox{\tt gofs\_MinExpected}) \rfloor$. + + Another test, applied simultaneously, looks at the total number + $Y$ of bits to get the $2n$ runs. Under $\cH_0$, $Y$ is the sum of + $2n$ independent geometric random variables with parameter $1/2$, + plus $2n$. For large $n$, it is approximately normal with mean + $4n$ and variance $8n$, so $Z = (Y - 4n)/\sqrt{8n}$ is approximately + standard normal. This second test, based on $Z$, is practically + equivalent to the run test proposed in \cite{rRUK01a}, which counts + the total number of runs for a fixed number of bits. + Restrictions: $r + s \le 32$. +% Recommendation: use $n$ large enough so that $k$ is not too small. +\endtab +\iffalse %%%%%%%%%%%%%%%%%%% + \tab This test, taken from \cite{rRUK01a}, considers whether the runs of + 0's and 1's in a sequence of bits is as expected for a random sequence. + \index{Test!Run!bits}% + A run of length $\ell$ is an uninterrupted sequence of + $\ell$ identical bits, preceded and followed by a bit of opposite value. + The test decomposes a sequence of $n$ bits into runs of identical bits + and counts the total number of runs $R$. +% (total number of 1 runs + total number of 0 runs). + + Under $\cH_0$, the standardized test statistic +$$ + Z = \frac{R - 2nf_1(1 - f_1)}{2\sqrt n f_1(1 - f_1)}, +$$ + where $f_1$ is the proportion of 1's amongst the $n$ bits, + has the standard normal distribution in the limit as $n\to\infty$ + (see \cite{rRUK01a} for a reference). + The test compares the value of $Z$ to the standard normal. + Restrictions: $r + s \le 32$. + Recommendation: $100 \le n$. +\endtab +\fi %%%%%%%%%%%%%%%%%%%%%%%% +\code + + +void sstring_AutoCor (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, int s, int d); +\endcode + \tab + This test measures the autocorrelation between bits with lag $d$ \cite{rERD92a}. + It generates a $n$-bit string and computes + \index{Test!AutoCor}% + \index{Test!Auto-correlation!bit}% +$$ + A_d = \sum_{i=1}^{n-d} b_i \oplus b_{i+d}, +$$ + where $b_i$ is the $i$th bit in the string and + $\oplus$ denotes the exclusive-or operation. + Under $\cH_0$, $A_d$ has the binomial distribution + with parameters $(n-d, 1/2)$, so that +$$ + \frac{2 A_d - (n-d)}{\sqrt{n-d}} +$$ + should be approximately standard normal for large $n-d$. + Restrictions: $r + s \le 32$, $1 \le d \le \lfloor n/2 \rfloor$, $n-d$ + large enough for the normal approximation to be valid. + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/svaria.c b/TESTU01/TestU01-1.2.3/testu01/svaria.c new file mode 100644 index 0000000..00d047b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/svaria.c @@ -0,0 +1,1230 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: svaria.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "tables.h" +#include "chrono.h" +#include "num.h" +#include "num2.h" + +#include "svaria.h" +#include "unif01.h" +#include "sres.h" +#include "wdist.h" +#include "swrite.h" +#include "smultin.h" + +#include "fmass.h" +#include "gofs.h" +#include "gofw.h" + +#include +#include +#include +#include +#include + + + + +lebool svaria_Timer = FALSE; + + + + +/*-------------------------------- Constants ------------------------------*/ + +/* Max string lengths */ +#define LEN1 100 +#define LEN2 200 + +/* Sample limit for normal approximation in svaria_SampleMean */ +#define SAM_LIM 60 + +/* Arrays dimension in svaria_AppearanceSpacings */ +#define AS_DIM 32 + +/* The Meschach package for matrix computations */ +#undef MESCHACH + + + + + +/*-------------------------------- Functions ------------------------------*/ + + +static void InitFDistMeans (int n, double Coef[]) +/* + * Initializes the distribution for svaria_SampleMean by computing the + * coefficients. We shall keep the value of n in element Coef[SAM_LIM], + * since we shall need it to get the value of the distribution at x. + */ +{ + int s; + double z; + fmass_INFO Q; + + z = num2_Factorial (n); + /* This uses the binomial formulae, but is not the binomial probability + distribution since p + q != 1 */ + Q = fmass_CreateBinomial (n, -1.0, 1.0); + for (s = 0; s <= n; s++) + Coef[s] = fmass_BinomialTerm2 (Q, s) / z; + fmass_DeleteBinomial (Q); + Coef[SAM_LIM] = n; + + if (swrite_Classes) { + printf ("---------------------------------------\n"); + for (s = 0; s <= n; s++) { + printf (" Coeff[%2d] = %14.6g\n", s, Coef[s]); + } + printf ("\n"); + } +} + +/*-------------------------------------------------------------------------*/ + +static double FDistMeans ( + double C[], /* Coefficients and sample size n */ + double x /* Argument */ + ) +/* + * Distribution function of sample mean as in Stephens (1966), p.235. + * This function is not very precise: the normal approximation is poor + * for small x, and the computation of the exact function is numerically + * unstable for large n. This will be used only for n < SAM_LIM. The + * value of n is in C[SAM_LIM]. + */ +{ + double Sum; + int M; + int i; + double nLR = C[SAM_LIM]; + int n = nLR; + + if (x <= 0.0) + return 0.0; + if (x >= n) + return 1.0; + + M = x; + Sum = 0.0; + if (x < n / 2.0) { + for (i = 0; i <= M; i++) { + Sum += C[i] * pow (x, nLR); + x -= 1.0; + } + } else { + x = -x + nLR; + for (i = n; i >= M + 1; i--) { + Sum += C[i] * pow (x, nLR); + x -= 1.0; + } + if (!(n & 1)) + Sum = -Sum; + Sum += 1.0; + } + return Sum; +} + +/*-------------------------------------------------------------------------*/ + +void svaria_SampleMean (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r) +{ + long i; + long Seq; + double Sum; + double Coef[SAM_LIM + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "svaria_SampleMean test"; + + Timer = chrono_Create (); + if (swrite_Basic) { + swrite_Head (gen, TestName, N, n, r); + printf ("\n\n"); + } + util_Assert (n > 1, "svaria_SampleMean: n < 2"); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "svaria_SampleMean"); + if (n < SAM_LIM) + InitFDistMeans (n, Coef); + + if (n < SAM_LIM) + statcoll_SetDesc (res->sVal1, "SampleMean sVal1: n*"); + else + statcoll_SetDesc (res->sVal1, "SampleMean sVal1: standard normal"); + + for (Seq = 1; Seq <= N; Seq++) { + Sum = 0.0; + for (i = 1; i <= n; i++) + Sum += unif01_StripD (gen, r); + + if (n < SAM_LIM) + statcoll_AddObs (res->sVal1, Sum); + else + statcoll_AddObs (res->sVal1, sqrt (12.0 / n) * (Sum - 0.5 * n)); + } + + if (n < SAM_LIM) { + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, FDistMeans, Coef, + res->sVal2, res->pVal2); + } else { + /* Normal approximation */ + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + } + res->pVal1->NObs = N; + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Statistic value :"); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void svaria_SampleCorr (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r, int k) +{ + long i; + long Seq; + double U; + double Sum; + double *Pre; /* Previous k generated numbers */ + int pos; /* Circular index to element at lag k */ + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "svaria_SampleCorr test"; + + Timer = chrono_Create (); + if (swrite_Basic) { + swrite_Head (gen, TestName, N, n, r); + printf (", k = %d\n\n", k); + } + util_Assert (n > 2, "svaria_SampleCorr: n <= 2"); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "svaria_SampleCorr"); + statcoll_SetDesc (res->sVal1, + "SampleCorr sVal1: asymptotic standard normal"); + + Pre = util_Calloc ((size_t) (k + 1), sizeof (double)); + + for (Seq = 1; Seq <= N; Seq++) { + /* Generate first k numbers U and keep them in Pre */ + for (i = 0; i < k; i++) + Pre[i] = unif01_StripD (gen, r); + + Sum = 0.0; + pos = 0; + /* Element Pre[pos] is at lag k from U */ + for (i = k; i < n; i++) { + U = unif01_StripD (gen, r); + Sum += Pre[pos] * U - 0.25; + Pre[pos] = U; + pos++; + pos %= k; + } + /* Save standardized correlation */ + statcoll_AddObs (res->sVal1, Sum * sqrt (12.0 / (n - k))); + } + + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetNormalSumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res); + swrite_Final (gen, Timer); + } + util_Free (Pre); + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static double FDistProd ( + double Par[], /* The parameter t = Par[0] */ + double x /* The argument */ + ) +/* + * Compute the distribution function F for the product of t random variables + * U[0, 1], where + * t - 1 + * __ j + * F[u1*u2*...ut <= x] = x \ (-ln(x)) + * /__ ----------- + * j = 0 j! + * + */ +{ + double vlog, jterm, vterm, Sum; + int j, t; + + if (x >= 1.0) + return 1.0; + if (x <= 0.0) + return 0.0; + + vlog = log (x); + t = Par[0]; + Sum = 1.0; + vterm = 1.0; + jterm = 1.0; + for (j = 1; j < t; j++) { + vterm *= vlog; + jterm *= -j; + Sum += vterm / jterm; + if (vterm / jterm < DBL_EPSILON) + break; + } + return x * Sum; +} + + +/*-------------------------------------------------------------------------*/ + +void svaria_SampleProd (unif01_Gen * gen, sres_Basic * res, + long N, long n, int r, int t) +{ + long i; + int j; + long Seq; + double *P; + double temp; + double Par[1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "svaria_SampleProd test"; + + Timer = chrono_Create (); + if (swrite_Basic) { + swrite_Head (gen, TestName, N, n, r); + printf (", t = %d\n\n", t); + } + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "svaria_SampleProd"); + + P = util_Calloc ((size_t) n + 1, sizeof (double)); + statcoll_SetDesc (res->sVal1, "SampleProd sVal1: Uniform [0, 1]"); + Par[0] = t; + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 1; i <= n; i++) { + temp = unif01_StripD (gen, r); + for (j = 2; j <= t; j++) + temp *= unif01_StripD (gen, r); + P[i] = temp; + } + gofw_ActiveTests1 (P, n, FDistProd, Par, res->sVal2, res->pVal2); + statcoll_AddObs (res->sVal1, res->pVal2[gofw_AD]); + } + + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Unif, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Anderson-Darling statistic :"); + swrite_Final (gen, Timer); + } + util_Free (P); + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +void svaria_SumLogs (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r) +{ + const double Eps = DBL_EPSILON / 2.0; /* To avoid log(0) */ + const double Epsilon = 1.E-100; /* To avoid underflow */ + long i; + long Seq; + double u; + double Prod; + double Sum; + double V[1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "svaria_SumLogs test"; + char chaine[LEN1 + 1] = ""; + char str[LEN2 + 1]; + + Timer = chrono_Create (); + if (swrite_Basic) { + swrite_Head (gen, TestName, N, n, r); + printf ("\n\n"); + } + util_Assert (n < LONG_MAX/2, "2n > LONG_MAX"); + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, -1, "svaria_SumLogs"); + + strncpy (chaine, "SumLogs sVal1: chi2 with ", (size_t) LEN1); + sprintf (str, "%ld", 2 * n); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, " degrees of freedom", (size_t) LEN1); + statcoll_SetDesc (res->sVal1, chaine); + res->degFree = 2 * n; + if (res->degFree < 1) { + util_Warning (TRUE, "Chi-square with 0 degree of freedom."); + if (localRes) + sres_DeleteChi2 (res); + return; + } + + for (Seq = 1; Seq <= N; Seq++) { + Prod = 1.0; + Sum = 0.0; + for (i = 1; i <= n; i++) { + u = unif01_StripD (gen, r); + if (u < Eps) + u = Eps; + Prod *= u; + if (Prod < Epsilon) { + Sum += log (Prod); + Prod = 1.0; + } + } + statcoll_AddObs (res->sVal1, -2.0 * (Sum + log (Prod))); + + } + V[0] = 2 * n; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LEN2, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataWeight (unif01_Gen * gen, char *TestName, + long N, long n, int r, long k, double Alpha, double Beta) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", k = %1ld, Alpha = %6.4g, Beta = %6.4g\n\n", + k, Alpha, Beta); +} + + +/*-------------------------------------------------------------------------*/ + +void svaria_WeightDistrib (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, long k, double Alpha, double Beta) +{ + long W; + long j; + long i; + long Seq; + double X; + double U; + double p; + double nLR = n; + double V[1]; + long NbClasses; + long *Loc; + fmass_INFO Q; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "svaria_WeightDistrib test"; + char chaine[LEN1 + 1] = ""; + char str[LEN2 + 1]; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataWeight (gen, TestName, N, n, r, k, Alpha, Beta); + + /* util_Assert (n >= 3.0 * gofs_MinExpected, + "svaria_WeightDistrib: n is too small"); */ + util_Assert (Alpha <= 1.0 && Alpha >= 0.0, + "svaria_WeightDistrib: Alpha must be in [0, 1]"); + util_Assert (Beta <= 1.0 && Beta >= 0.0, + "svaria_WeightDistrib: Beta must be in [0, 1]"); + p = Beta - Alpha; + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, k, "svaria_WeightDistrib"); + Loc = res->Loc; + + /* Compute binomial probabilities and multiply by n */ + Q = fmass_CreateBinomial (k, p, 1.0 - p); + for (i = 0; i <= k; i++) + res->NbExp[i] = nLR * fmass_BinomialTerm2 (Q, i); + fmass_DeleteBinomial (Q); + + res->jmin = 0; + res->jmax = k; + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, 0); + + /* Merge classes for the chi-square */ + gofs_MergeClasses (res->NbExp, Loc, &res->jmin, &res->jmax, &NbClasses); + + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, NbClasses); + + strncpy (chaine, "WeightDistrib sVal1: chi2 with ", (size_t) LEN1); + sprintf (str, "%ld", NbClasses - 1); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, " degrees of freedom", (size_t) LEN1); + statcoll_SetDesc (res->sVal1, chaine); + res->degFree = NbClasses - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i <= k; i++) + res->Count[i] = 0; + for (i = 1; i <= n; i++) { + W = 0; + for (j = 1; j <= k; j++) { + U = unif01_StripD (gen, r); + if (U >= Alpha && U < Beta) + ++W; + } + if (W > res->jmax) + ++res->Count[res->jmax]; + else + ++res->Count[Loc[W]]; + } + if (swrite_Counters) + tables_WriteTabL (res->Count, res->jmin, res->jmax, 5, 10, + "Observed numbers:"); + + X = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax); + statcoll_AddObs (res->sVal1, X); + } + + V[0] = NbClasses - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LEN2, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataArgMax (unif01_Gen * gen, char *TestName, + long N, long n, int r, long k, long m) +{ + double x; + + swrite_Head (gen, TestName, N, n, r); + printf (", k = %1ld, m = %1ld\n\n", k, m); + printf (" Number of balls = n = %1ld\n", n); + printf (" Number of urns = k = %1ld\n", k); + + x = n; + x = x * x / (2 * k); + printf (" Number (approx) of collisions = n^2 / 2k = %g\n\n\n", x); +} + +/*-------------------------------------------------------------------------*/ + +static int svaria_CollisionArgMax_00 (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long k, long m) +/* + * Return 0 if no error, otherwise return != 0. + */ +{ + double X; + double U; + double Max; + long NbColl; + long Indice = -1; + long j; + long i; + long Rep; + long Seq; + long NbClasses; + long *Loc; + int *Urne; + double V[1]; + fmass_INFO Q; + lebool localRes = FALSE; + chrono_Chrono *chro, *Timer; + char *TestName = "svaria_CollisionArgMax test"; + char chaine[LEN1 + 1] = ""; + char str[LEN2 + 1]; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataArgMax (gen, TestName, N, n, r, k, m); + + util_Assert (n <= 4 * k, "svaria_CollisionArgMax: n > 4k"); + /* util_Assert (m > 2.0 * gofs_MinExpected, + "svaria_CollisionArgMax: m <= 2*gofs_MinExpected"); */ + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, n, "svaria_CollisionArgMax"); + Loc = res->Loc; + Urne = util_Calloc ((size_t) k + 1, sizeof (int)); + + if (svaria_Timer) { + printf ("-----------------------------------------------"); + printf ("\nCPU time to initialize the collision distribution: "); + chro = chrono_Create (); + } + Q = smultin_CreateCollisions (n, (smultin_CellType) k); + if (svaria_Timer) { + chrono_Write (chro, chrono_hms); + printf ("\n\n"); + } + + /* Compute the expected numbers of collisions: m*P(j) */ + for (j = 0; j <= n; j++) + res->NbExp[j] = m * smultin_CollisionsTerm (Q, j); + smultin_DeleteCollisions (Q); + + res->jmin = 0; + res->jmax = n; + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, 0); + + gofs_MergeClasses (res->NbExp, Loc, &res->jmin, &res->jmax, &NbClasses); + + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, NbClasses); + + strncpy (chaine, "CollisionArgMax sVal1: chi2 with ", (size_t) LEN1); + sprintf (str, "%ld", NbClasses - 1); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, " degrees of freedom", (size_t) LEN1); + statcoll_SetDesc (res->sVal1, chaine); + res->degFree = NbClasses - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return 1; + } + + if (svaria_Timer) + chrono_Init (chro); + + for (Seq = 1; Seq <= N; Seq++) { + for (j = 0; j <= n; j++) + res->Count[j] = 0; + + for (Rep = 1; Rep <= m; Rep++) { + for (j = 0; j <= k; j++) + Urne[j] = -1; + + NbColl = 0; + for (j = 1; j <= n; j++) { + Max = -1.0; + for (i = 1; i <= k; i++) { + U = unif01_StripD (gen, r); + if (U > Max) { + Max = U; + Indice = i; + } + } + if (Urne[Indice] < 0) + Urne[Indice] = 1; + else + ++NbColl; + } + if (NbColl > res->jmax) + ++res->Count[res->jmax]; + else + ++res->Count[Loc[NbColl]]; + } + if (swrite_Counters) + tables_WriteTabL (res->Count, res->jmin, res->jmax, 5, 10, + "Observed numbers:"); + X = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax); + statcoll_AddObs (res->sVal1, X); + } + + if (svaria_Timer) { + printf ("\n----------------------------------------------\n" + "CPU time for the test : "); + chrono_Write (chro, chrono_hms); + printf ("\n\n"); + chrono_Delete (chro); + } + + V[0] = NbClasses - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LEN2, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + util_Free (Urne); + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); + return 0; +} + + +/*-------------------------------------------------------------------------*/ + +void svaria_CollisionArgMax (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, long k, long m) +{ + if (m > 1) { + svaria_CollisionArgMax_00 (gen, res, N, n, r, k, m); + + } else if (m == 1) { + double ValDelta[] = { -1.0 }; + smultin_Param *par; + + if (swrite_Basic) { + printf ( + "***********************************************************\n" + "Test svaria_CollisionArgMax calling smultin_Multinomial\n\n"); + } + par = smultin_CreateParam (1, ValDelta, smultin_GenerCellMax, -3); + if (NULL == res) { + smultin_Multinomial (gen, par, NULL, N, n, r, 0, k, TRUE); + } else { + smultin_Res *resm; + resm = smultin_CreateRes (par); + smultin_Multinomial (gen, par, resm, N, n, r, 0, k, TRUE); + sres_InitChi2 (res, N, -1, "svaria_CollisionArgMax"); + statcoll_SetDesc (res->sVal1, "CollisionArgMax sVal1"); + res->sVal1->NObs = resm->Collector[0]->NObs; + tables_CopyTabD (resm->Collector[0]->V, res->sVal1->V, 1, N); + tables_CopyTabD (resm->sVal2[0], res->sVal2, 0, gofw_NTestTypes - 1); + tables_CopyTabD (resm->pVal2[0], res->pVal2, 0, gofw_NTestTypes - 1); + smultin_DeleteRes (resm); + } + smultin_DeleteParam (par); + } else { + util_Warning (m <= 0, "svaria_CollisionArgMax: m <= 0"); + } +} + + +/*=========================================================================*/ + +static void WriteDataSumColl (unif01_Gen * gen, char *TestName, + long N, long n, int r, double g) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", g = %g\n\n", g); +} + +/*-------------------------------------------------------------------------*/ + +static double ProbabiliteG (int jmin, int j, double g) +/* + * Returns the probability that the minimum number of random U(0,1) whose + * sum is larger than g is j+1. g cannot be too large because the + * calculation here becomes numerically unstable. + */ +{ + int s; + double temp; + const double jLR = j; + double signe; /* +1 or -1 */ + double somme; + + signe = 1.0; + somme = 0.0; + for (s = 0; s <= jmin; s++) { + temp = signe * num2_Combination (j + 1, s); + temp *= pow (g - s, jLR); + somme += temp; + signe = -signe; + } + somme = (jLR + 1.0 - g) * somme / num2_Factorial (j + 1); + return somme; +} + + +/*-------------------------------------------------------------------------*/ + +void svaria_SumCollector (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, double g) +{ + const double gmax = 10.0; /* Maximal value of g */ + const int jmax = 50; /* Maximal number of classes */ + int j; /* Class index */ + long Seq; + long i; + double X; + double Y; + double Sum; + long NbClasses; + long *Loc; + double V[1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "svaria_SumCollector test"; + char chaine[LEN1 + 1] = ""; + char str[LEN2 + 1]; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataSumColl (gen, TestName, N, n, r, g); + + if (g < 1.0 || g > gmax) { + util_Error ("svaria_SumCollector: g < 1.0 or g > 10.0"); + } + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, jmax, "svaria_SumCollector"); + Loc = res->Loc; + + res->jmin = g; + res->jmax = jmax; + Sum = 0.0; + for (j = res->jmin; j < jmax; j++) { + res->NbExp[j] = n * ProbabiliteG (res->jmin, j, g); + Sum += res->NbExp[j]; + } + res->NbExp[jmax] = util_Max (0.0, n - Sum); + + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, 0); + gofs_MergeClasses (res->NbExp, Loc, &res->jmin, &res->jmax, &NbClasses); + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, NbClasses); + + strncpy (chaine, "SumCollector sVal1: chi2 with ", (size_t) LEN1); + sprintf (str, "%ld", NbClasses - 1); + strncat (chaine, str, (size_t) LEN2); + strncat (chaine, " degrees of freedom", (size_t) LEN1); + statcoll_SetDesc (res->sVal1, chaine); + res->degFree = NbClasses - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + + for (Seq = 1; Seq <= N; Seq++) { + for (j = 1; j <= jmax; j++) + res->Count[j] = 0; + + for (i = 1; i <= n; i++) { + X = 0.0; + j = 0; + do { + X += unif01_StripD (gen, r); + ++j; + } + while (X <= g); + if (j > res->jmax) + ++res->Count[res->jmax]; + else + ++res->Count[Loc[j - 1]]; + } + if (swrite_Counters) + tables_WriteTabL (res->Count, res->jmin, res->jmax, 5, 10, + "Observed numbers:"); + Y = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax); + statcoll_AddObs (res->sVal1, Y); + } + + V[0] = NbClasses - 1; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LEN2, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void InitAppear (int r, int s, int L, long Q, double E[], double KV[]) +{ + util_Assert (r >= 0, "svaria_AppearanceSpacings: r < 0"); + util_Assert (s > 0, "svaria_AppearanceSpacings: s <= 0"); + /* if (L >= s && L % s) { + util_Error ("svaria_AppearanceSpacings: L mod s != 0"); + }*/ + if (L < s && s % L) { + util_Error ("svaria_AppearanceSpacings: s mod L != 0"); + } + util_Warning (Q < 10.0 * num_TwoExp[L], + "svaria_AppearanceSpacings: Q < 10 * 2^L"); + + /* Theoretical mean E and variance KV for different L given by Maurer */ + if (L > 16) { + /* For L > 16 and near 16, the 6-th decimal of E[L] could be + erroneous. For KV [L], the 4-th decimal. */ + E[L] = L - 8.32746E-1; + KV[L] = 3.423715; + } else { + E [1] = 0.73264948; KV[1] = 0.68977; + E [2] = 1.53743829; KV[2] = 1.33774; + E [3] = 2.40160681; KV[3] = 1.90133; + E [4] = 3.31122472; KV[4] = 2.35774; + E [5] = 4.25342659; KV[5] = 2.70455; + E [6] = 5.21770525; KV[6] = 2.95403; + E [7] = 6.19625065; KV[7] = 3.12539; + E [8] = 7.18366555; KV[8] = 3.23866; + E [9] = 8.17642476; KV[9] = 3.31120; + E [10] = 9.17232431; KV[10] = 3.35646; + E [11] = 10.1700323; KV[11] = 3.38409; + E [12] = 11.1687649; KV[12] = 3.40065; + E [13] = 12.1680703; KV[13] = 3.41043; + E [14] = 13.1676926; KV[14] = 3.41614; + E [15] = 14.1674884; KV[15] = 3.41943; + E [16] = 15.1673788; KV[16] = 3.42130; + } +} + +/*-------------------------------------------------------------------------*/ + +static double CalcSigma (int L, long K, double KV[]) +/* + * Compute the standard deviation for the svaria_AppearanceSpacings test. + */ +{ + double dCor[AS_DIM + 1]; /* Coron-Naccache factor d */ + double eCor[AS_DIM + 1]; /* Coron-Naccache factor e */ + double temp; + /* double c; */ + +#if 0 /* No correction */ + return sqrt (KV[L] / K); + +#elif 0 /* Maurer's correction c(L, K) */ + temp = 3.0 / L * num_Log2 ((double) K); + if (temp >= DBL_MAX_EXP - 1) + temp = 0.0; + else + temp = pow (2.0, -temp); + c = 0.7 - 0.8/L + (4.0 + 32.0/L) * temp / 15.0; + if (L < 3 || L > 16) + c = 1.0; + return c * sqrt (KV[L] / K); + +#else /* based on Coron and Naccache exact calculation */ + dCor [3] = 0.2732725; eCor [3] = 0.4890883; + dCor [4] = 0.3045101; eCor [4] = 0.4435381; + dCor [5] = 0.3296587; eCor [5] = 0.4137196; + dCor [6] = 0.3489769; eCor [6] = 0.3941338; + dCor [7] = 0.3631815; eCor [7] = 0.3813210; + dCor [8] = 0.3732189; eCor [8] = 0.3730195; + dCor [9] = 0.3800637; eCor [9] = 0.3677118; + dCor [10] = 0.3845867; eCor [10] = 0.3643695; + dCor [11] = 0.3874942; eCor [11] = 0.3622979; + dCor [12] = 0.3893189; eCor [12] = 0.3610336; + dCor [13] = 0.3904405; eCor [13] = 0.3602731; + dCor [14] = 0.3911178; eCor [14] = 0.3598216; + dCor [15] = 0.3915202; eCor [15] = 0.3595571; + dCor [16] = 0.3917561; eCor [16] = 0.3594040; + /* L = infinite */ + dCor [0] = 0.3920729; eCor [0] = 0.3592016; + + if (L < 3) + return sqrt (KV[L] / K); + if (L > 16) + temp = dCor[0] + eCor [0] * num_TwoExp[L] / K; + else + temp = dCor[L] + eCor [L] * num_TwoExp[L] / K; + return sqrt (temp * KV[L] / K); + +#endif +} + +/*-------------------------------------------------------------------------*/ + +static void WriteDataAppear (unif01_Gen * gen, + long N, int r, int s, int L, long Q, long K, double n) +{ + printf ("***********************************************************\n"); + printf ("HOST = "); + if (swrite_Host) { + gdef_WriteHostName (); + printf ("\n"); + } else + printf ("\n\n"); + unif01_WriteNameGen (gen); + printf ("\n"); + if (swrite_ExperimentName && strcmp (swrite_ExperimentName, "")) { + printf ("%s", swrite_ExperimentName); + printf (":\n\n"); + } + + printf ("svaria_AppearanceSpacings test:\n" + "-----------------------------------------------\n"); + + printf (" N = %2ld, Q = %1ld, K = %1ld, r = %1d, s = %1d," + " L = %1d\n\n", N, Q, K, r, s, L); + printf (" Sequences of n = (K + Q)L = %12.0f bits\n", n); + printf (" Q = %4ld initialization blocks\n", Q); + printf (" K = %4ld blocks for the test\n", K); + printf (" the blocks have L = %2d bits\n\n\n", L); +} + + +/*-------------------------------------------------------------------------*/ + +void svaria_AppearanceSpacings (unif01_Gen * gen, sres_Basic * res, + long N, long Q, long K, int r, int s, int L) +{ + double E[AS_DIM + 1]; /* Theoretical mean of the log (Base2) of + the most recent occurrence of a block */ + double KV[AS_DIM + 1]; /* K times the theoretical variance of the + same */ + long Seq; + long block; + long Nblocks; /* 2^L = total number of distinct blocks */ + long K2; + long Q2; + long i; + long sBits; /* Numerical value of the s given bits */ + long d; /* 2^s */ + const int SdivL = s / L; + const int LdivS = L / s; + const int LmodS = L % s; + long sd; /* 2^LmodS */ + long rang; + double n; /* Total number of bits in a sequence */ + double sigma; /* Standard deviation = sqrt (Variance) */ + double somme; + double ARang; /* Most recent occurrence of block */ + long *Count; /* Index of most recent occurrence of + block */ + double FactMoy; + lebool localRes = FALSE; + chrono_Chrono *Timer; + + Timer = chrono_Create (); + n = ((double) K + (double) Q) * L; + if (swrite_Basic) + WriteDataAppear (gen, N, r, s, L, Q, K, n); + util_Assert (s < 32, "svaria_AppearanceSpacings: s >= 32"); + InitAppear (r, s, L, Q, E, KV); + sigma = CalcSigma (L, K, KV); + d = num_TwoExp[s]; + Nblocks = num_TwoExp[L]; + FactMoy = 1.0 / (num_Ln2 * K); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateBasic (); + } + sres_InitBasic (res, N, "svaria_AppearanceSpacings"); + Count = util_Calloc ((size_t) Nblocks + 2, sizeof (long)); + + statcoll_SetDesc (res->sVal1, + "AppearanceSpacings sVal1: standard normal"); + + if (LdivS > 0) { + sd = num_TwoExp[LmodS]; + + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i < Nblocks; i++) + Count[i] = 0; + + /* Initialization with Q blocks */ + for (rang = 0; rang < Q; rang++) { + block = 0; + for (i = 1; i <= LdivS; i++) { + sBits = unif01_StripB (gen, r, s); + block = block * d + sBits; + } + if (LmodS > 0) { + sBits = unif01_StripB (gen, r, LmodS); + block = block * sd + sBits; + } + Count[block] = rang; + } + + /* Test proper with K blocks */ + somme = 0.0; + for (rang = Q; rang < Q + K; rang++) { + block = 0; + for (i = 1; i <= LdivS; i++) { + sBits = unif01_StripB (gen, r, s); + block = block * d + sBits; + } + if (LmodS > 0) { + sBits = unif01_StripB (gen, r, LmodS); + block = block * sd + sBits; + } + ARang = rang - Count[block]; + somme += log (ARang); + Count[block] = rang; + } + statcoll_AddObs (res->sVal1, (somme * FactMoy - E[L]) / sigma); + } + + } else { /* s > L */ + Q2 = Q / SdivL; + K2 = K / SdivL; + for (Seq = 1; Seq <= N; Seq++) { + for (i = 0; i < Nblocks; i++) + Count[i] = 0; + + /* Initialization: Q blocks */ + for (rang = 0; rang < Q2; rang++) { + sBits = unif01_StripB (gen, r, s); + for (i = 0; i < SdivL; i++) { + block = sBits % Nblocks; + Count[block] = SdivL * rang + i; + sBits /= Nblocks; + } + } + /* Test proper with K blocks */ + somme = 0.0; + for (rang = Q2; rang < Q2 + K2; rang++) { + sBits = unif01_StripB (gen, r, s); + for (i = 0; i < SdivL; i++) { + block = sBits % Nblocks; + ARang = SdivL * rang + i - Count[block]; + somme += log (ARang); + Count[block] = SdivL * rang + i; + sBits /= Nblocks; + } + } + statcoll_AddObs (res->sVal1, (somme * FactMoy - E[L]) / sigma); + } + } + + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, + (double *) NULL, res->sVal2, res->pVal2); + res->pVal1->NObs = N; + sres_GetNormalSumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 12, 4, 3); + + if (swrite_Basic) { + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, + "Normal statistic :"); + swrite_NormalSumTest (N, res); + swrite_Final (gen, Timer); + } + util_Free (Count); + if (localRes) + sres_DeleteBasic (res); + chrono_Delete (Timer); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/svaria.tex b/TESTU01/TestU01-1.2.3/testu01/svaria.tex new file mode 100644 index 0000000..2dde75f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/svaria.tex @@ -0,0 +1,231 @@ +\defmodule {svaria} + +This module implements various tests of uniformity based on +relatively simple statistics, as well as a few specific tests proposed +in the literature. \resdef + + +\bigskip +\hrule +\code\hide +#ifndef SVARIA_H +#define SVARIA_H +\endhide +#include "unif01.h" +#include "sres.h" +\endcode + +\ifdetailed %%%%%%%%%%%%%%%%%%%% +\code + + +extern lebool svaria_Timer; +\endcode + \tab + This flag is used only in test {\tt svaria\_CollisionArgMax}. + If it is set to {\tt TRUE}, a timer will measure separately the time to + initialize the collision distribution function, and the time for the + test proper. + \endtab + +\fi %%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} +\code + +void svaria_SampleMean (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r); +\endcode + \tab + This test generates $n$ uniforms $u_1,\dots,u_n$ and computes + their average\index{Test!SampleMean} + $$ \overline u_n = {1\over n} \sum_{j=1}^n u_j.$$ + The distribution of the $N$ values of $\overline u_n$ is compared + with the exact theoretical distribution +$$ + P[n \overline u_n \le z] = \frac 1 {n!} + \sum_{j = 0}^{\lfloor z \rfloor} (-1)^j {n \choose j} (z - j)^n, + \qquad 0 \le z \le n +$$ +\hrichard{The current method for computing the theoretical distribution + is numerically unstable for $n>60$. This should be changed if possible.} + given by Stephens \cite{tSTE66a} + for $n < 60$, and to the normal distribution with mean $1/2$ + and variance $1/(12n)$ for $n\ge 60$. + \endtab +\code + + +void svaria_SampleCorr (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, int k); +\endcode + \tab + This test generates $n$ uniforms $u_1,\dots,u_n$ and + computes\index{Test!SampleCorr} \index{Test!Auto-correlation!real} + the empirical autocorrelation \cite{sFIS78a} of lag $k$, + $$ + \hat\rho_k = {1 \over (n-k)} \sum_{j=1}^{n-k} + \left(u_j u_{j+k} - {\textstyle \frac14}\right). + $$ + The empirical distribution + \hrichard{Fishman \cite[p.382]{sFIS78a} uses $(u_j - 1/2) ( u_{j+k} - 1/2)$ + instead. The difference vanishes rapidly when $n \to\infty$.} + of the $N$ values of $\sqrt{12 (n-k)} \hat\rho_k$ + is compared with the standard normal distribution, + which is its asymptotic theoretical distribution when $n \to\infty$. + The approximation is valid only when $n$ is very large. + Restriction: $k \ll n$. + \endtab +\code + + +void svaria_SampleProd (unif01_Gen *gen, sres_Basic *res, + long N, long n, int r, int t); +\endcode + \tab + This test generates $t n$ uniforms $u_1,\dots,u_{tn}$ and + computes\index{Test!SampleProd} + the empirical distribution of the products of $n$ nonoverlapping + successive groups of $t$ values, $\{u_{(j-1)t + 1}, u_{(j-1)t + 2}, + \ldots, u_{jt}: j=1,\dots,n\}$. + For $N=1$, this test is equivalent to calling + {\tt svaria\_SumLogs (gen, res, n, t, r)}. + This distribution is compared with the theoretical distribution of + the product of $t$ independent $U(0,1)$ random variables, given by + $$ + P[U_1U_2\ldots U_t \le x] = F(x) = x \sum_{j=0}^{t-1} \frac {(-\ln x)^j} {j!} + $$ + for $0\le x\le 1$, via an Anderson-Darling (AD) test. + For $N > 1$, the empirical distribution of the $p$-values of the + AD test is compared with the AD distribution. + \endtab +\code + + +void svaria_SumLogs (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r); +\endcode + \tab + This test generates $n$ uniforms, $u_1,\dots,u_n$, and computes + \index{Test!SumLogs} + $$ + P = - 2 \sum_{j=1}^n \ln (u_j). + $$ + Under $\cH_0$, $P/2$ is a sum of $n$ i.i.d.\ exponentials of mean 1, + so $P$ has the chi-square distribution with $2n$ degrees of freedom + (see \cite{tSTE86a}). + \endtab +\code + + +void svaria_WeightDistrib (unif01_Gen *gen, sres_Chi2 *res, long N, long n, + int r, long k, double alpha, double beta); +\endcode + \tab + Applies the test proposed by Matsumoto and Kurita \cite{rMAT94a}, page 264. + This test\index{Test!WeightDistrib} + generates $k$ uniforms, $u_1,\dots,u_k$, and computes + $$ W = \sum_{j=1}^k I[\alpha\le u_j < \beta],$$ + the number of $u_j$'s falling in the interval $[\alpha,\beta)$. + Under $\cH_0$, $W$ is a binomial random variable with parameters $k$ and + $p = \beta-\alpha$. + This is repeated $n$ times, thus obtaining $W_1,\dots,W_n$, + whose empirical distribution is compared with the binomial + distribution via a chi-square test. + For the chi-square test, classes (possible values of $W$) are + regrouped as needed to ensure that the expected numbers in each + class is larger or equal to {\tt gofs\_MinExpected}. +% The function repeats all this $N$ times and compares the $N$ chi-square +% values obtained with the chi-square distribution. + \endtab +\code + + +void svaria_CollisionArgMax (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, long k, long m); +\endcode + \tab + Applies a generalization of the test proposed by Sullivan \cite{rSUL93a}. + This test generates $k$ uniforms, $u_1,\dots,u_k$, and computes + \index{Test!CollisionArgMax} + $$ + I = \min \Big\{ i \mid 1\le i\le k \mbox{ and } + u_i = \max (u_1,\dots,u_k) \Big\}, + $$ + the index of the largest value. + It repeats this $n$ times and counts the number $C$ of collisions + among the $n$ values of $I$, which is equal to + $n$ minus the number of distinct values of $I$. + If $m > 1$, this is repeated $m$ times and the empirical distribution + of the $m$ values of $C$ is compared with the theoretical distribution of + $C$, given in \cite{rKNU98a} (see also {\tt sknuth\_Collisions}) + by applying a chi-square test. +% At the next level, it will repeat all this $N$ times and will compare the +% empirical distribution of the $N$ chi-square values obtained +% with the theoretical distribution. + For $m=1$, this test is equivalent to the collision test applied by + {\tt smultin\_Multinomial} with + {\tt smultin\_GenerCell = smultin\_GenerCellMax}. + Recommendations: $n \le k$, and either $m=1$ or $m$ + large enough for the chi-square test to make sense. + \endtab +\code + + +void svaria_SumCollector (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, double g); +\endcode + \tab Applies a test\index{Test!SumCollector} proposed by + Ugrin-Sparac \cite{rUGR91a}. + It generates a sequence of uniforms $u_0,u_1,\dots$ adds them up + until their sum exceeds $g$. It then defines + $J = \min\{\ell\ge 0 : u_0 + \cdots + u_{\ell} > g \}$. + This is repeated $n$ times, to obtain $n$ copies of $J$, say + $J_1,\dots,J_n$, whose empirical distribution is compared to the + theoretical distribution given in \cite{rUGR91a}, by a chi-square test. +% It repeats all this $N$ times and compares the +% empirical distribution of the $N$ chi-square values with the theoretical +% distribution. + Restriction: $1 \le g \le 10$. + \endtab +\code + + +void svaria_AppearanceSpacings (unif01_Gen *gen, sres_Basic *res, + long N, long Q, long K, int r, int s, int L); +\endcode + \tab Applies the ``universal test'' proposed by Maurer \cite{rMAU92a}. + The goal of this test is to measure the entropy of a sequence + of\index{Test!AppearanceSpacings}\index{entropy} + \index{Test!Maurer|see{Appearance\-Spacings}} + \index{Test!Universal|see{Appearance\-Spacings}} + random bits (it is somewhat related to the test applied by + {\tt sentrop\_EntropyDisc}). + The test takes the $s$ most significant bits (after dropping the first + $r$) from each uniform, and concatenates these $s$-bit blocks to + construct $Q + K$ blocks of $L$ bits. + The first $Q$ blocks are used for the initialization, and + the $K$ following blocks serve for the test proper. + For each of these $K$ blocks, the function finds the number of blocks + generated since the most recent occurrence of the same block in the + sequence. If it is generating the $j$-th block and its most recent + occurrence was in block $(j-i)$-th, it sets $A_j = i$; + if it is its first occurrence, it sets $A_j = j$. + It then computes the average + $$ Y = {1\over K} \sum_{j=Q+1}^{Q+K} \log_2 A_j, $$ + whose distribution under $\cH_0$ is approximately normal with + mean and variance given in \cite{rMAU92a}. A better formula for the + variance was given in \cite{rCOR99a} and that is the one used. + The approximation is good only when $Q$ and $K$ are very large. + Recommendations: $Q\ge 10 \times 2^{L}$ and $K \gg 2^{L}$. + Restrictions: $s \bmod L = 0$ if $s > L$. +%% $K\ge 1000 \times 2^{L}$. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/swalk.c b/TESTU01/TestU01-1.2.3/testu01/swalk.c new file mode 100644 index 0000000..b2c8570 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/swalk.c @@ -0,0 +1,1250 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: swalk.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "chrono.h" +#include "num.h" +#include "num2.h" +#include "bitset.h" + +#include "swalk.h" +#include "wdist.h" +#include "swrite.h" +#include "unif01.h" + +#include "fmass.h" +#include "fbar.h" +#include "gofw.h" +#include "gofs.h" + +#include +#include +#include + + + + +/*------------------------------- Constants -------------------------------*/ + +#define PREC 52 /* Max number of bits in a number */ +#define LENGTH 200 /* Max length of strings */ + + +typedef enum { + swalk_rwH, /* H statistic */ + swalk_rwM, /* M statistic */ + swalk_rwJ, /* J statistic */ + swalk_rwR, /* R statistic */ + swalk_rwC, /* C statistic */ + swalk_rw_N /* Total number of statistics here */ +} swalk_rwType; + +/* The name of each type of statistic in swalk_rwType (predefined). */ +static const char *swalk_rwName[swalk_rw_N] = { + "Statistic H", + "Statistic M", + "Statistic J", + "Statistic R", + "Statistic C" +}; + + +/*--------------------------------- Types ---------------------------------*/ + +typedef struct { + long X; + long S; + long S_2; + long M; + long R; + long J; + long C; +} WorkType; + + +/* Type of algorithm used in swalk_VarGeo */ +typedef enum { + swalk_AlgoP, + swalk_AlgoN + } swalk_AlgoType; + + + + +/*-------------------------------- functions ------------------------------*/ + +static void CalcNbExp ( + long n, /* Sample size */ + long L0, + long k, + swalk_Res *res + ) +/* + ************ IMPORTANT: we assume that L is even ************ + * Compute the expected numbers for the different statistics in the + * swalk_RandomWalk1 and swalk_RandomWalk1a tests. We start from the + * maximum term and compute on each side all terms larger than epsilon. + * We set all others to 0. + */ +{ + const double epsilon = 1.0E-16; + double *NbExp; + long L1, L2; + const long L = L0 + k; + long i; + double nLR = n; + double epsn; + + util_Assert (!(L & 1), "CalcNbExp: L is odd"); + L2 = L / 2; + epsn = epsilon * nLR; + + /*----------- statistic H -----------*/ + NbExp = res->H[k]->NbExp; + for (i = 0; i <= L; i++) + NbExp[i] = 0.0; + + NbExp[L2] = nLR * fmass_BinomialTerm1 (L, 0.5, 0.5, L2); + i = L2; + while (i > 0 && NbExp[i] > epsn) { + NbExp[i - 1] = NbExp[i] * i / (L - i + 1); + --i; + } + i = L2; + while (i < L && NbExp[i] > epsn) { + NbExp[i + 1] = NbExp[i] * (L - i) / (i + 1); + ++i; + } + + /*----------- statistic M -----------*/ + NbExp = res->M[k]->NbExp; + for (i = 0; i <= L; i++) + NbExp[i] = 0.0; + + NbExp[0] = res->H[k]->NbExp[L2]; + i = 0; + while (i < L && NbExp[i] > epsn) { + NbExp[i + 1] = NbExp[i] * ((L - i) / 2) / ((L + i) / 2 + 1); + NbExp[i + 2] = NbExp[i + 1]; + i += 2; + } + + /*----------- statistic J -----------*/ + NbExp = res->J[k]->NbExp; + for (i = 0; i <= L; i++) + NbExp[i] = 0.0; + + NbExp[0] = res->M[k]->NbExp[0]; + NbExp[L] = NbExp[0]; + i = 0; + while (i < L2 && NbExp[i] > epsn) { + NbExp[i + 2] = NbExp[i] * ((L - i) / 2) * + (1 + i) / ((double)(i / 2 + 1) * (L - i - 1)); + NbExp[L - i - 2] = NbExp[i + 2]; + i += 2; + } + + /*----------- statistic R -----------*/ + NbExp = res->R[k]->NbExp; + for (i = 0; i <= L; i++) + NbExp[i] = 0.0; + + NbExp[0] = res->J[k]->NbExp[0]; + i = 0; + while (i < L2 && NbExp[i] > epsn) { + NbExp[i + 1] = NbExp[i] * (L - 2 * i) / (L - i); + ++i; + } + + /*----------- statistic C -----------*/ + NbExp = res->C[k]->NbExp; + for (i = 0; i <= L; i++) + NbExp[i] = 0.0; + + NbExp[0] = 2.0 * nLR * fmass_BinomialTerm1 (L - 1, 0.5, 0.5, L2); + i = 0; + L1 = L2 - 1; + while (i < L1 && NbExp[i] > epsn) { + NbExp[i + 1] = NbExp[i] * (L2 - i - 1) / (L2 + i + 1); + ++i; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteTabWalk ( + swalk_Res *res, + long N /* Number of replications */ + ) +/* + * Write the values of the statistics and their p-values in a table + * for all values of the walk length L from L0 to L1. These values have + * all been written before, but it is nice to have them all together. + * When L0 = L1, it is not useful. When the number of replications N > 1, it + * is not called either because there would be so many statistics to write. + */ +{ + swalk_rwType m; + long k; + double p; + long L0 = res->L0; /* Shortest walk length considered */ + long L1 = res->L1; /* Longest walk length considered */ + + if (L1 == L0) + return; + if (N > 1) + return; + printf ("\n\n***********************************************" + "\nTABLES FOR THE RESULTS ABOVE"); + for (m = 0; m < swalk_rw_N; m++) { + printf ("\n\n===============================================\n"); + printf ("Test on the values of the "); + printf ("%s", swalk_rwName[m]); + printf ("\n\n Walk length Chi-square p-value\n\n"); + + for (k = 0; k <= L1 - L0; k += 2) { + printf ("%8ld", L0 + k); + switch (m) { + case swalk_rwH: + num_WriteD (res->H[k]->sVal2[gofw_Mean], 18, 3, 2); + p = res->H[k]->pVal2[gofw_Mean]; + break; + case swalk_rwM: + num_WriteD (res->M[k]->sVal2[gofw_Mean], 18, 3, 2); + p = res->M[k]->pVal2[gofw_Mean]; + break; + case swalk_rwJ: + num_WriteD (res->J[k]->sVal2[gofw_Mean], 18, 3, 2); + p = res->J[k]->pVal2[gofw_Mean]; + break; + case swalk_rwR: + num_WriteD (res->R[k]->sVal2[gofw_Mean], 18, 3, 2); + p = res->R[k]->pVal2[gofw_Mean]; + break; + case swalk_rwC: + num_WriteD (res->C[k]->sVal2[gofw_Mean], 18, 3, 2); + p = res->C[k]->pVal2[gofw_Mean]; + break; + default: + util_Error ("swalk: WriteTabWalk: no such case"); + } + num_WriteD (p, 18, 3, 2); + if (p < gofw_Suspectp || p > 1.0 - gofw_Suspectp) { + printf (" *****"); + } + printf ("\n"); + } + } + printf ("\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteResultWalk ( + swalk_Res *res, + long N /* Number of replications */ + ) +/* + * Write the basic results of the swalk_RandomWalk1 and swalk_RandomWalk1a + * tests for all walks of length L between L0 and L1. May write the + * statistical collectors too. + */ +{ + swalk_rwType m; + long L0 = res->L0; /* Shortest walk length considered */ + long L1 = res->L1; /* Longest walk length considered */ + long k; + sres_Chi2 *Q; + + printf ("\n"); + for (k = 0; k <= L1 - L0; k += 2) { + if (L1 > L0) { + printf ("\n\n===============================================" + "\nWALK OF %3ld STEPS\n", L0 + k); + } + for (m = 0; m < swalk_rw_N; m++) { + printf ("-----------------------------------------------\n" + "Test on the values of the "); + printf ("%s", swalk_rwName[m]); + printf ("\n\n"); + switch (m) { + case swalk_rwH: + Q = res->H[k]; + break; + case swalk_rwM: + Q = res->M[k]; + break; + case swalk_rwJ: + Q = res->J[k]; + break; + case swalk_rwR: + Q = res->R[k]; + break; + case swalk_rwC: + Q = res->C[k]; + break; + default: + util_Error ("swalk: WriteResultWalk: no such case"); + } + if (N == 1) { + printf ("Number of degrees of freedom : %4ld\n", + Q->degFree); + printf ("ChiSquare statistic :"); + gofw_Writep2 (Q->sVal2[gofw_Mean], Q->pVal2[gofw_Mean]); + } else { + gofw_WriteActiveTests0 (N, Q->sVal2, Q->pVal2); + swrite_Chi2SumTest (N, Q); + } + printf ("\n"); + if (swrite_Collectors) + statcoll_Write (Q->sVal1, 5, 14, 4, 3); + } + } + WriteTabWalk (res, N); +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteDetailsWalk ( + swalk_Res *res, + long k, /* Walk length L = k + L0 */ + long n /* sample size */ + ) +/* + * Write detailed results for the different statistics of a walk of length + * L = k + L0: the expected numbers, the observed numbers (the counters), + * and the normalized values. If the normalized value is outside the interval + * [-3, 3], we indicate it explicitly. + + */ +{ + swalk_rwType m; + long i; + double iObs; /* Weighted sum of the observed numbers */ + double Obs; /* Observed numbers */ + double iEsp; /* Weighted sum of the expected numbers */ + double Esp; /* Expected numbers */ + double Z; /* Normalized value */ + double Var; /* Variance */ + long L0 = res->L0; /* Shortest length of walks considered */ + double nLR = n; + sres_Chi2 *Q; + + printf ("================================================\n"); + printf ("Walk of %3ld steps\n", L0 + k); + + for (m = 0; m < swalk_rw_N; m++) { + printf ("------------------------------------------------\n" + "Counters of the "); + printf ("%s", swalk_rwName[m]); + printf + ("\n\n i Expected num. Observed num. (Exp. - Obs.)/sigma\n\n"); + iEsp = 0.0; + iObs = 0.0; + switch (m) { + case swalk_rwH: + Q = res->H[k]; + break; + case swalk_rwM: + Q = res->M[k]; + break; + case swalk_rwJ: + Q = res->J[k]; + break; + case swalk_rwR: + Q = res->R[k]; + break; + case swalk_rwC: + Q = res->C[k]; + break; + default: + util_Error ("swalk: WriteDetailsWalk: no such case"); + } + i = Q->jmin - 1; + do { + i = Q->Loc[i + 1]; + Esp = Q->NbExp[i]; + Obs = Q->Count[i]; + iEsp = iEsp + Esp * i; /* Expected value of the statistic */ + iObs = iObs + Obs * i; /* Observed mean of the statistic */ + + /* If Esp = 0, this is a class that has been redirected to another + for the ChiSquare test; we shall not print it since the counters + have been redirected also: they are necessarily 0. */ + if (Esp > 0.0) { + printf ("%4ld", i); + num_WriteD (Esp, 14, 2, 0); + num_WriteD (Obs, 12, 0, 0); + Var = Esp * (1.0 - Esp / nLR); + if (Var <= 0.0) + Z = (Obs - Esp) * 1.E100; + else + Z = (Obs - Esp) / sqrt (Var); + num_WriteD (Z, 18, 4, 3); + if (Z > 3.0 || Z < -3.0) + printf (" *****"); + printf ("\n"); + } + } while (i != Q->jmax); + + printf ("\nExpected mean = "); + num_WriteD (iEsp / nLR, 10, 2, 0); + printf ("\nEmpirical mean = "); + num_WriteD (iObs / nLR, 10, 2, 0); + printf ("\n\n"); + } + printf ("\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteDataWalk1 (unif01_Gen *gen, char *TestName, + long N, long n, int r, int s, long L0, long L1) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d, L0 = %4ld, L1 = %4ld\n\n\n", s, L0, L1); +} + + +/*=========================================================================*/ + +swalk_Res * swalk_CreateRes (void) +{ + swalk_Res *res; + + res = util_Malloc (sizeof (swalk_Res)); + memset (res, 0, sizeof (swalk_Res)); + res->H = util_Calloc (1, sizeof (sres_Chi2 *)); + res->M = util_Calloc (1, sizeof (sres_Chi2 *)); + res->J = util_Calloc (1, sizeof (sres_Chi2 *)); + res->R = util_Calloc (1, sizeof (sres_Chi2 *)); + res->C = util_Calloc (1, sizeof (sres_Chi2 *)); + res->H[0] = sres_CreateChi2 (); + res->M[0] = sres_CreateChi2 (); + res->J[0] = sres_CreateChi2 (); + res->R[0] = sres_CreateChi2 (); + res->C[0] = sres_CreateChi2 (); + res->imax = 0; + res->name = util_Calloc (1, sizeof (char)); + return res; +} + + +/*-------------------------------------------------------------------------*/ + +void swalk_DeleteRes (swalk_Res *res) +{ + long i; + + if (res == NULL) + return; + util_Free (res->name); + for (i = 0; i <= res->imax; i += 2) { + sres_DeleteChi2 (res->H[i]); + sres_DeleteChi2 (res->M[i]); + sres_DeleteChi2 (res->R[i]); + sres_DeleteChi2 (res->J[i]); + sres_DeleteChi2 (res->C[i]); + } + util_Free (res->H); + util_Free (res->R); + util_Free (res->M); + util_Free (res->J); + util_Free (res->C); + util_Free (res); +} + + +/*-------------------------------------------------------------------------*/ + +static void InitRes ( + swalk_Res *res, + WorkType *work, + long N, /* Number of replications */ + long L0, /* Shortest walk length considered */ + long L1, /* Longest walk length considered */ + char *nam +) +/* + * Allocates memory for arrays to be used in the swalk_RandomWalk1a and + * swalk_RandomWalk1 tests. Arrays for walk length L will be indexed + * by i = L - L0. + */ +{ + long i, imax, L; + + util_Assert (!(L0 & 1), "InitRes: L0 is odd"); + if (L1 & 1) + L1--; + util_Assert (L1 >= L0, "InitRes: L1 < L0"); + imax = L1 - L0; + + for (i = imax + 2; i <= res->imax; i += 2) { + sres_DeleteChi2 (res->H[i]); + sres_DeleteChi2 (res->M[i]); + sres_DeleteChi2 (res->R[i]); + sres_DeleteChi2 (res->J[i]); + sres_DeleteChi2 (res->C[i]); + } + res->H = util_Realloc (res->H, ((size_t) imax + 1) * sizeof(sres_Chi2 *)); + res->R = util_Realloc (res->R, ((size_t) imax + 1) * sizeof(sres_Chi2 *)); + res->M = util_Realloc (res->M, ((size_t) imax + 1) * sizeof(sres_Chi2 *)); + res->J = util_Realloc (res->J, ((size_t) imax + 1) * sizeof(sres_Chi2 *)); + res->C = util_Realloc (res->C, ((size_t) imax + 1) * sizeof(sres_Chi2 *)); + + for (i = res->imax + 2; i <= imax; i += 2) { + res->H[i] = sres_CreateChi2 (); + res->M[i] = sres_CreateChi2 (); + res->J[i] = sres_CreateChi2 (); + res->R[i] = sres_CreateChi2 (); + res->C[i] = sres_CreateChi2 (); + } + + for (i = 0; i <= imax; i += 2) { + L = i + L0; + sres_InitChi2 (res->H[i], N, L, ""); + sres_InitChi2 (res->M[i], N, L, ""); + sres_InitChi2 (res->R[i], N, L, ""); + sres_InitChi2 (res->J[i], N, L, ""); + sres_InitChi2 (res->C[i], N, L, ""); + res->R[i]->jmax = L / 2; + res->C[i]->jmax = L / 2; + } + res->L1 = L1; + res->L0 = L0; + res->imax = imax; + res->work = work; + res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char)); + strcpy (res->name, nam); +} + + +/*-------------------------------------------------------------------------*/ + +static void Steps ( + unif01_Gen *gen, + swalk_Res *res, + long j, /* will generate j-th random number */ + int r, /* drop the first r bits of each random number */ + int s /* keep only s bits of each random number */ + ) +/* + * Generates a random number Z; each of the s bits of Z kept is a step of + * the random walk. Updates all statistics for these s steps. + */ +{ + int i; + long k; + unsigned long Z, iBit; + const unsigned long SBIT = 1UL << (s - 1); + WorkType *work = res->work; + + Z = unif01_StripB (gen, r, s); + iBit = SBIT; + + for (i = s - 1; i >= 0; i--) { + ++res->L; + if (Z & iBit) /* If i bit of Z is 1 */ + work->X = 1; + else + work->X = -1; + work->S += work->X; + if (work->S > work->M) + work->M = work->S; + if (work->S == 0) + ++work->R; + if ((s * j - i) & 1) { + if (work->S > 0) + ++work->J; + if (work->S * work->S_2 < 0) + ++work->C; + work->S_2 = work->S; + } + + if ((res->L >= res->L0) && !(res->L & 1)) { + k = res->L - res->L0; + ++res->H[k]->Count[res->H[k]->Loc[(res->L + work->S) / 2]]; + ++res->M[k]->Count[res->M[k]->Loc[work->M]]; + ++res->J[k]->Count[res->J[k]->Loc[2 * work->J]]; + ++res->R[k]->Count[res->R[k]->Loc[work->R]]; + ++res->C[k]->Count[res->C[k]->Loc[work->C]]; + } + iBit >>= 1; + } +} + + +/*-------------------------------------------------------------------------*/ + +void swalk_RandomWalk1 (unif01_Gen *gen, swalk_Res *res, + long N, long n, int r, int s, long L0, long L1) +{ + swalk_rwType m; + long DeltaL; + int LMS; + long LDS; + long i, j, k, Rep, Seq; + double khi; + double V[1]; /* Number degrees of freedom for ChiSquare */ + long NbClasses; + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "swalk_RandomWalk1 test"; + WorkType work; + sres_Chi2 *Q; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataWalk1 (gen, TestName, N, n, r, s, L0, L1); + + util_Assert (L0 > 0, "swalk_RandomWalk1: L0 <= 0"); + util_Assert (!(L0 & 1), "swalk_RandomWalk1: L0 must be even"); + util_Assert (!(L1 & 1), "swalk_RandomWalk1: L1 must be even"); + util_Assert (L1 >= L0, "swalk_RandomWalk1: L0 > L1"); + util_Assert (r + s <= PREC, "swalk_RandomWalk1: r + s > 32"); + if (n < 3.0 * gofs_MinExpected) { + util_Warning (TRUE, "swalk_RandomWalk1: n < 3*gofs_MinExpected"); + return; + } + + DeltaL = L1 - L0; + LDS = L1 / s; + LMS = L1 % s; + if (res == NULL) { + localRes = TRUE; + res = swalk_CreateRes (); + } + InitRes (res, &work, N, L0, L1, "swalk_RandomWalk1"); + + /* Compute the expected numbers and merge classes for the ChiSquare */ + for (k = 0; k <= DeltaL; k += 2) { + CalcNbExp (n, L0, k, res); + + for (m = 0; m < swalk_rw_N; m++) { + switch (m) { + case swalk_rwH: + Q = res->H[k]; + break; + case swalk_rwM: + Q = res->M[k]; + break; + case swalk_rwJ: + Q = res->J[k]; + break; + case swalk_rwR: + Q = res->R[k]; + break; + case swalk_rwC: + Q = res->C[k]; + break; + default: + util_Error ("swalk_RandomWalk1: no such case"); + } + if (swrite_Classes) { + if (L1 > L0) { + printf ("===============================================\n"); + printf ("Walk of %3ld steps\n", L0 + k); + } + printf ("===============================================\nThe "); + printf ("%s", swalk_rwName[m]); + printf ("\n"); + gofs_WriteClasses (Q->NbExp, Q->Loc, Q->jmin, Q->jmax, 0); + } + gofs_MergeClasses (Q->NbExp, Q->Loc, &(Q->jmin), &(Q->jmax), + &NbClasses); + + if (swrite_Classes) { + gofs_WriteClasses (Q->NbExp, Q->Loc, Q->jmin, Q->jmax, NbClasses); + } + + /* Set description for second level statistical collectors */ + sprintf (str, "The N statistic values (a ChiSquare with %ld degrees" + " of freedom) ", NbClasses - 1); + statcoll_SetDesc (Q->sVal1, str); + Q->degFree = NbClasses - 1; + } + } + + /* Beginning of test */ + for (Seq = 1; Seq <= N; Seq++) { + + /* Reset counters to zero for each sequence */ + for (k = 0; k <= DeltaL; k += 2) { + for (i = res->H[k]->jmin; i <= res->H[k]->jmax; i++) + res->H[k]->Count[i] = 0; + for (i = res->R[k]->jmin; i <= res->R[k]->jmax; i++) + res->R[k]->Count[i] = 0; + for (i = res->J[k]->jmin; i <= res->J[k]->jmax; i++) + res->J[k]->Count[i] = 0; + for (i = res->M[k]->jmin; i <= res->M[k]->jmax; i++) + res->M[k]->Count[i] = 0; + for (i = res->C[k]->jmin; i <= res->C[k]->jmax; i++) + res->C[k]->Count[i] = 0; + } + + /* A ChiSquare sample of size n */ + for (Rep = 1; Rep <= n; Rep++) { + work.S = 0; + work.S_2 = 0; + work.M = 0; + work.R = 0; + work.J = 0; + work.C = 0; + res->L = 0; + + /* One random walk of length L */ + for (j = 1; j <= LDS; j++) + Steps (gen, res, j, r, s); + /* the last LMS steps of L */ + if (LMS > 0) + Steps (gen, res, LDS + 1, r, LMS); + } + + for (k = 0; k <= DeltaL; k += 2) { + khi = gofs_Chi2 (res->H[k]->NbExp, res->H[k]->Count, res->H[k]->jmin, + res->H[k]->jmax); + statcoll_AddObs (res->H[k]->sVal1, khi); + khi = gofs_Chi2 (res->M[k]->NbExp, res->M[k]->Count, res->M[k]->jmin, + res->M[k]->jmax); + statcoll_AddObs (res->M[k]->sVal1, khi); + khi = gofs_Chi2 (res->R[k]->NbExp, res->R[k]->Count, res->R[k]->jmin, + res->R[k]->jmax); + statcoll_AddObs (res->R[k]->sVal1, khi); + khi = gofs_Chi2 (res->J[k]->NbExp, res->J[k]->Count, res->J[k]->jmin, + res->J[k]->jmax); + statcoll_AddObs (res->J[k]->sVal1, khi); + khi = gofs_Chi2 (res->C[k]->NbExp, res->C[k]->Count, res->C[k]->jmin, + res->C[k]->jmax); + statcoll_AddObs (res->C[k]->sVal1, khi); + if (swrite_Counters) + WriteDetailsWalk (res, k, n); + } + } + + for (k = 0; k <= DeltaL; k += 2) { + for (m = 0; m < swalk_rw_N; m++) { + switch (m) { + case swalk_rwH: + Q = res->H[k]; + break; + case swalk_rwM: + Q = res->M[k]; + break; + case swalk_rwJ: + Q = res->J[k]; + break; + case swalk_rwR: + Q = res->R[k]; + break; + case swalk_rwC: + Q = res->C[k]; + break; + default: + util_Error ("swalk_RandomWalk1: no such case2"); + } + V[0] = Q->degFree; + Q->pVal1->NObs = Q->sVal1->NObs; + gofw_ActiveTests2 (Q->sVal1->V, Q->pVal1->V, N, wdist_ChiSquare, + V, Q->sVal2, Q->pVal2); + sres_GetChi2SumStat (Q); + } + } + + if (swrite_Basic) { + WriteResultWalk (res, N); + swrite_Final (gen, Timer); + } + if (localRes) + swalk_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataWalk1a (unif01_Gen *gen, char *TestName, + long N, long n, int r, int s, int t, long L, bitset_BitSet maskc) +{ + int i; + + swrite_Head (gen, TestName, N, n, r); + printf (", s = %1d, t = %1d, L = %1ld\n\n", s, t, L); + printf (" C = { "); + + util_Assert (t <= 31, "swalk_RandomWalk1a: t > 31"); + for (i = 0; i < t; i++) { + if (bitset_TestBit (maskc, i)) { + printf ("%1d", i); + if (i < t - 1) + printf (", "); + } + } + printf (" }\n\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +void swalk_RandomWalk1a (unif01_Gen *gen, swalk_Res *res, + long N, long n, int r, int s, int t, long L, bitset_BitSet maskc) +{ + swalk_rwType m; + long z2, z1, y; + long C, J, R, M, S_2, S, X; /* Statistics */ + long i, j, pas, Rep, Seq; /* Indices */ + bitset_BitSet ens; + double khi; /* ChiSquare value */ + double V[1]; /* Number deg. of freedom for ChiSquare */ + long NbClasses; + char str[LENGTH + 1]; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "swalk_RandomWalk1a test"; + sres_Chi2 *Q; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataWalk1a (gen, TestName, N, n, r, s, t, L, maskc); + + util_Assert (!(L & 1), "swalk_RandomWalk1a: L is odd"); + util_Assert (L > 0, "swalk_RandomWalk1a: L <= 0"); + util_Assert (r + s <= PREC, "swalk_RandomWalk1a: r + s > 32"); + util_Assert (s <= PREC, "swalk_RandomWalk1a: s > 32"); + if (n < 3.0 * gofs_MinExpected) { + util_Warning (TRUE, "swalk_RandomWalk1a: n < 3*gofs_MinExpected"); + return; + } + if (res == NULL) { + localRes = TRUE; + res = swalk_CreateRes (); + } + InitRes (res, NULL, N, L, L, "swalk_RandomWalk1a"); + + /* Compute the expected numbers */ + CalcNbExp (n, L, 0, res); + + /* Merge classes for the ChiSquare */ + for (m = 0; m < swalk_rw_N; m++) { + switch (m) { + case swalk_rwH: + Q = res->H[0]; + break; + case swalk_rwM: + Q = res->M[0]; + break; + case swalk_rwJ: + Q = res->J[0]; + break; + case swalk_rwR: + Q = res->R[0]; + break; + case swalk_rwC: + Q = res->C[0]; + break; + default: + util_Error ("swalk_RandomWalk1a: no such case"); + } + if (swrite_Classes) { + printf ("===============================================\nThe "); + printf ("%s", swalk_rwName[m]); + printf ("\n"); + gofs_WriteClasses (Q->NbExp, Q->Loc, Q->jmin, Q->jmax, 0); + } + gofs_MergeClasses (Q->NbExp, Q->Loc, &(Q->jmin), &(Q->jmax), &NbClasses); + + if (swrite_Classes) + gofs_WriteClasses (Q->NbExp, Q->Loc, Q->jmin, Q->jmax, NbClasses); + + /* Set description for second level statistical collectors */ + sprintf (str, "The N statistic values (a ChiSquare with %ld degrees of" + " freedom) ", NbClasses - 1); + statcoll_SetDesc (Q->sVal1, str); + Q->degFree = NbClasses - 1; + } + + /* Generate the first t bits */ + z1 = 0; + for (i = 0; i <= (t - 1) / s; i++) { + z2 = unif01_StripB (gen, r, s); + for (j = 1; j <= s; j++) { + z1 = 2 * z1 + (z2 & 1); + z2 /= 2; + } + } + j = 0; + z2 = unif01_StripB (gen, r, s); + + /* Beginning of test */ + for (Seq = 1; Seq <= N; Seq++) { + + /* Reset counters to zero for each sequence */ + for (i = res->H[0]->jmin; i <= res->H[0]->jmax; i++) + res->H[0]->Count[i] = 0; + for (i = res->R[0]->jmin; i <= res->R[0]->jmax; i++) + res->R[0]->Count[i] = 0; + for (i = res->J[0]->jmin; i <= res->J[0]->jmax; i++) + res->J[0]->Count[i] = 0; + for (i = res->M[0]->jmin; i <= res->M[0]->jmax; i++) + res->M[0]->Count[i] = 0; + for (i = res->C[0]->jmin; i <= res->C[0]->jmax; i++) + res->C[0]->Count[i] = 0; + + for (Rep = 1; Rep <= n; Rep++) { + C = J = R = M = S_2 = S = 0; + pas = 0; + + /* Generate a random walk of L steps */ + do { + do { + ++pas; + ++j; + z1 = 2 * z1 + (z2 & 1); + z2 /= 2; + ens = maskc & z1; + y = 0; + for (i = 0; i < t; i++) { + if (bitset_TestBit (ens, i)) + ++y; + } + if (y & 1) + X = 1; + else + X = -1; + S += X; + if (S > M) + M = S; + if (S == 0) + ++R; + if (pas & 1) { + if (S > 0) + ++J; + if (S * S_2 < 0) + ++C; + S_2 = S; + } + } while (!(j == s || pas == L)); + if (j == s) { + j = 0; + z2 = unif01_StripB (gen, r, s); + } + } while (pas != L); + + /* Update counters */ + ++res->H[0]->Count[res->H[0]->Loc[(L + S) / 2]]; + ++res->M[0]->Count[res->M[0]->Loc[M]]; + ++res->J[0]->Count[res->J[0]->Loc[2 * J]]; + ++res->R[0]->Count[res->R[0]->Loc[R]]; + ++res->C[0]->Count[res->C[0]->Loc[C]]; + } + + khi = gofs_Chi2 (res->H[0]->NbExp, res->H[0]->Count, res->H[0]->jmin, + res->H[0]->jmax); + statcoll_AddObs (res->H[0]->sVal1, khi); + khi = gofs_Chi2 (res->M[0]->NbExp, res->M[0]->Count, res->M[0]->jmin, + res->M[0]->jmax); + statcoll_AddObs (res->M[0]->sVal1, khi); + khi = gofs_Chi2 (res->R[0]->NbExp, res->R[0]->Count, res->R[0]->jmin, + res->R[0]->jmax); + statcoll_AddObs (res->R[0]->sVal1, khi); + khi = gofs_Chi2 (res->J[0]->NbExp, res->J[0]->Count, res->J[0]->jmin, + res->J[0]->jmax); + statcoll_AddObs (res->J[0]->sVal1, khi); + khi = gofs_Chi2 (res->C[0]->NbExp, res->C[0]->Count, res->C[0]->jmin, + res->C[0]->jmax); + statcoll_AddObs (res->C[0]->sVal1, khi); + + if (swrite_Counters) + WriteDetailsWalk (res, 0, n); + } + + for (m = 0; m < swalk_rw_N; m++) { + switch (m) { + case swalk_rwH: + Q = res->H[0]; + break; + case swalk_rwM: + Q = res->M[0]; + break; + case swalk_rwJ: + Q = res->J[0]; + break; + case swalk_rwR: + Q = res->R[0]; + break; + case swalk_rwC: + Q = res->C[0]; + break; + default: + util_Error ("swalk_RandomWalk1a: no such case2"); + } + V[0] = Q->degFree; + Q->pVal1->NObs = Q->sVal1->NObs; + gofw_ActiveTests2 (Q->sVal1->V, Q->pVal1->V, N, wdist_ChiSquare, V, + Q->sVal2, Q->pVal2); + sres_GetChi2SumStat (Q); + } + + if (swrite_Basic) { + WriteResultWalk (res, N); + swrite_Final (gen, Timer); + } + if (localRes) + swalk_DeleteRes (res); + chrono_Delete (Timer); +} + + +/*=========================================================================*/ + +static void WriteDataGeo (unif01_Gen *gen, char *TestName, + long N, long n, int r, double Mu, swalk_AlgoType Algo) +{ + swrite_Head (gen, TestName, N, n, r); + printf (", Mu = %10.8f, Algo = ", Mu); + if (Algo == swalk_AlgoP) + printf ("AlgoP\n\n"); + else + printf ("AlgoN\n\n"); + printf (" Expected length of a walk = %14.2f\n\n\n", 1.0 / (1.0 - Mu)); +} + + +/*-------------------------------------------------------------------------*/ + +static void WriteNbExpCount (sres_Chi2 *res, double Prob[]) +/* + * Writes the expected numbers, the observed numbers, and the normalized + * values in swalk_VarGeo. + */ +{ + long L; + double Ecart; + double y; + + printf ("--------------------------------------------------\n" + "Length NumExpected NumObserved Normalized value\n\n"); + for (L = res->jmin; L < res->jmax; L = res->Loc[L + 1]) { + printf ("%4ld %14.2f %10ld ", L, res->NbExp[L], res->Count[L]); + Ecart = sqrt (res->NbExp[L] * (1.0 - Prob[L])); + y = (res->Count[L] - res->NbExp[L]) / Ecart; + printf ("%14.2f\n", y); + } + L = res->jmax; + printf ("%4ld %14.2f %10ld ", L, res->NbExp[L], res->Count[L]); + Ecart = sqrt (res->NbExp[L] * (1.0 - Prob[L])); + y = (res->Count[L] - res->NbExp[L]) / Ecart; + printf ("%14.2f\n\n\n", y); +} + + +/*-------------------------------------------------------------------------*/ + +static void AlgorithmP (unif01_Gen *gen, sres_Chi2 *res, double Prob[], + long N, long n, int r, double Mu) +{ + long j; + long L; + long Seq; + double X; + double U; + + for (Seq = 1; Seq <= N; Seq++) { + for (L = res->jmin; L <= res->jmax; L++) + res->Count[L] = 0; + + for (j = 1; j <= n; j++) { + L = 1; + U = unif01_StripD (gen, r); + while (U < Mu) { + ++L; + U = unif01_StripD (gen, r); + } + if (L >= res->jmax) + ++res->Count[res->Loc[res->jmax]]; + else + ++res->Count[res->Loc[L]]; + } + if (swrite_Counters) + WriteNbExpCount (res, Prob); + + X = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax); + statcoll_AddObs (res->sVal1, X); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void AlgorithmN (unif01_Gen *gen, sres_Chi2 *res, double Prob[], + long N, long n, int r, double Mu) +{ + long j; + long L; + long Seq; + double X; + double U; + + Mu = 1.0 - Mu; + for (Seq = 1; Seq <= N; Seq++) { + for (L = res->jmin; L <= res->jmax; L++) + res->Count[L] = 0; + + for (j = 1; j <= n; j++) { + L = 1; + U = unif01_StripD (gen, r); + while (U >= Mu) { + ++L; + U = unif01_StripD (gen, r); + } + if (L >= res->jmax) + ++res->Count[res->Loc[res->jmax]]; + else + ++res->Count[res->Loc[L]]; + } + if (swrite_Counters) + WriteNbExpCount (res, Prob); + + X = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax); + statcoll_AddObs (res->sVal1, X); + } +} + + +/*-------------------------------------------------------------------------*/ + +static void swalk_VarGeo (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, double Mu, swalk_AlgoType Algo) +{ + const double epsilon = 1.0E-10; + long L; + double nLR = n; + double V[1]; /* Number degrees of freedom for ChiSquare */ + char str[LENGTH + 1]; + long tt; + long NbClasses; + lebool localRes = FALSE; + chrono_Chrono *Timer; + char *TestName = "swalk_VarGeo test"; + double *Prob; + + Timer = chrono_Create (); + if (swrite_Basic) + WriteDataGeo (gen, TestName, N, n, r, Mu, Algo); + + util_Assert (r < PREC, "swalk_VarGeo: r > 52"); + util_Assert (Mu > 0.0 && Mu < 1.0, "swalk_VarGeo: Mu not in (0,1)"); + + /* We consider only the terms of the geometric law with */ + /* probability > epsilon */ + tt = 1 + (log (epsilon) - num2_log1p (-Mu)) / log (Mu); + Prob = util_Calloc (1 + (size_t) tt, sizeof (double)); + + /* The probabilities and the expected numbers: NbExp = n*Prob */ + Prob[1] = 1.0 - Mu; + for (L = 1; L <= tt - 2; L++) + Prob[L + 1] = Mu * Prob[L]; + Prob[tt] = fbar_Geometric (1.0 - Mu, tt); + + if (res == NULL) { + localRes = TRUE; + res = sres_CreateChi2 (); + } + sres_InitChi2 (res, N, tt, "swalk_VarGeo"); + + for (L = 1; L <= tt; L++) + res->NbExp[L] = nLR * Prob[L]; + + res->jmin = 1; + res->jmax = tt; + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, res->Loc, res->jmin, res->jmax, 0); + gofs_MergeClasses (res->NbExp, res->Loc, &res->jmin, &res->jmax, + &NbClasses); + if (swrite_Classes) + gofs_WriteClasses (res->NbExp, res->Loc, res->jmin, res->jmax, + NbClasses); + + sprintf (str, "The N statistic values (a ChiSquare with %1ld degrees" + " of freedom):", NbClasses - 1); + statcoll_SetDesc (res->sVal1, str); + res->degFree = NbClasses - 1; + if (res->degFree < 1) { + if (localRes) + sres_DeleteChi2 (res); + return; + } + + if (Algo == swalk_AlgoP) + AlgorithmP (gen, res, Prob, N, n, r, Mu); + else + AlgorithmN (gen, res, Prob, N, n, r, Mu); + + V[0] = res->degFree; + res->pVal1->NObs = N; + gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V, + res->sVal2, res->pVal2); + sres_GetChi2SumStat (res); + + if (swrite_Collectors) + statcoll_Write (res->sVal1, 5, 14, 4, 3); + + if (swrite_Basic) { + swrite_AddStrChi (str, LENGTH, res->degFree); + gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str); + swrite_Chi2SumTest (N, res); + swrite_Final (gen, Timer); + } + util_Free (Prob); + if (localRes) + sres_DeleteChi2 (res); + chrono_Delete (Timer); +} + + +/*-------------------------------------------------------------------------*/ + +void swalk_VarGeoP (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, double Mu) +{ + swalk_VarGeo (gen, res, N, n, r, Mu, swalk_AlgoP); +} + +/*-------------------------------------------------------------------------*/ + +void swalk_VarGeoN (unif01_Gen * gen, sres_Chi2 * res, + long N, long n, int r, double Mu) +{ + swalk_VarGeo (gen, res, N, n, r, Mu, swalk_AlgoN); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/swalk.tex b/TESTU01/TestU01-1.2.3/testu01/swalk.tex new file mode 100644 index 0000000..8f4d230 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/swalk.tex @@ -0,0 +1,264 @@ +\defmodule {swalk} + +This module implements statistical tests based on discrete random walks +\index{random walk} over the set $\mathbb{Z}$ of all integers. +Similar tests are discussed, e.g., by +Vattulainen \cite{rVAT94a,rVAT95a} and Takashima \cite{rTAK96a}. + +The main function, {\tt swalk\_RandomWalk1}, applies simultaneously +several tests based on a random walk of length $\ell$ over the +integers, for several (even) values of $\ell$. +The random walk is generated from a bit string produced by the +generator by taking $s$ bits per output value. +Each bit determines one step of the walk: move by 1 to the left +if the bit is 0 and by 1 to the right if the bit is 1. +The function {\tt swalk\_RandomWalk1a} implements a variant +where each move of the walk is determined by taking a linear +combination modulo 2 (i.e., exclusive-or) of certain bits in the string. + +The functions {\tt swalk\_VarGeoP} and {\tt swalk\_VarGeoN} implement +``random walk'' tests defined in terms of real numbers. +These tests were proposed in \cite{rSHC97a} and turn out to be special +cases of the gap test implemented in module {\tt sknuth\_gap}. + +\resdef + +\bigskip\hrule + +\code\hide +/* swalk.h for ANSI C */ +#ifndef SWALK_H +#define SWALK_H +\endhide +#include "bitset.h" +#include "unif01.h" +#include "sres.h" +\endcode + + +\ifdetailed %%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Types and structures for test results} + +The types of test statistics and the types of structures +used to store the test results are defined here. +Several tests are applied simultaneously and the results are stored +in arrays. + + +\code + +typedef struct { + + long L0, L1, L; +\endcode + \tabb Results are kept for all random walks of {\em even} length {\tt L} + for {\tt L0} $\le$ {\tt L} $\le$ {\tt L1}. + \endtabb +\code + + sres_Chi2 **H; + sres_Chi2 **M; + sres_Chi2 **J; + sres_Chi2 **R; + sres_Chi2 **C; +\endcode + \tabb {\tt H[i]} contain the results for the {\tt H} statistic + in random walks of {\em even} length {\tt L = i + L0} for + {\tt 0} $\le$ {\tt i} $\le$ {\tt imax}. Only even values of {\tt i} are + meaningfull and we have {\tt L1 = imax + L0}. + Similarly for the {\tt M}, {\tt J}, {\tt R}, and {\tt C} statistics. + \endtabb +\code + + long imax; +\endcode + \tabb Maximal value of the index for the arrays {\tt H}, {\tt M}, + {\tt J}, {\tt R}, and {\tt C}. The minimal value of the index is 0. + \endtabb +\code + + char *name; +\endcode + \tabb + The name of the test which produced the above results. + \endtabb +\code + + void *work; +\endcode + \tabb Work variable used internally. + \endtabb +\code + +} swalk_Res; +\endcode + \tab Structure used to keep the results of + the tests {\tt swalk\_RandomWalk1} or {\tt swalk\_RandomWalk1a}. + \endtab +\code + + +swalk_Res * swalk_CreateRes (void); +\endcode + \tab + Function creating and returning a structure to hold the results + of tests {\tt swalk\_RandomWalk1} or {\tt swalk\_RandomWalk1a}. + \endtab +\code + + +void swalk_DeleteRes (swalk_Res *res); +\endcode + \tab + Procedure freeing the memory allocated by {\tt swalk\_CreateRes}. + \endtab + + +\fi %%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{The tests} + +\code + +void swalk_RandomWalk1 (unif01_Gen *gen, swalk_Res *res, long N, long n, + int r, int s, long L0, long L1); +\endcode + \tab + Applies various tests \index{Test!RandomWalk1} + based on a {\em random walk\/} over the + set of integers $\mathbb{Z}$. The walk starts at 0 and at each step, + it moves by one unit to the left with probability 1/2, + and by one unit to the right with probability 1/2. + The test considers $\ell$-step random walks, for all {\em even\/} + integers $\ell$ in the interval $[L_0, L_1]$. + It first generates a random walk of length $\ell = L_0$, then adds + two steps to obtain a random walk of length $\ell = L_0+2$, + then adds two more steps for a walk of length $\ell = L_0+4$, + and so on until $\ell = L_1$. + + To generate the moves, the test uses one bit $b_i$ at each step $i$. + It takes $s$ bits from each uniform (after dropping the first $r$). + So for the entire walk of length $L_1$, it needs $\lceil L_1/s\rceil$ + uniforms. + Let $X_i = 1$ if $b_i = 1$, and $X_i = -1$ if $b_i = 0$. + Define also $S_0 = 0$ and + $$ + S_k = \sum_{i=1}^k X_i, \quad k\ge 1. + $$ + The process $\{S_k,\, k\ge 0\}$ is a random walk over the integers. + Under $\cH_0$, we have + $$ + p_{k,y} = P[S_k = y] = \cases { + 2^{-k} \pmatrix{ k \cr {(k+y)/2}\cr} & if $k+y$ is even;\cr + 0 \vphantom{\vrule height14pt} & if $k+y$ is odd.\cr} + $$ + For $\ell$ even, we define the statistics: + \begin {eqnarray*} + H &=& \ell/2 + S_\ell/2 ~=~ \sum_{i=1}^\ell I[X_i = 1], \\ + M &=& \max \left\{S_k,\;\; 0\le k\le \ell\right\},\\ + J &=& 2 \sum_{k=1}^{\ell/2} I[S_{2k-1} > 0],\\ + P_y &=& \min \left\{k : S_k = y\right\}, \quad y > 0,\\ + R &=& \sum_{k=1}^\ell I[S_k = 0],\\ + C &=& \sum_{k=3}^\ell I[S_{k-2} S_{k} < 0], + \end {eqnarray*} + where $I$ denotes the indicator function. + Here, $H$ is the number of steps to the right, + $M$ is the maximum value reached by the walk, + $J$ is the fraction of time spent on the right of the origin, + $P_y$ is the first passage time at $y$, + $R$ is the number of returns to 0, and + $C$ is the number of sign changes. + + The test thus generates $n$ random walks and computes the + $n$ values of each of these statistics. + It compares the empirical distribution of these $n$ values with + the corresponding theoretical law, via a chi-square test + (regrouping classes if needed). + + The theoretical probabilities for these statistics under $\cH_0$ + are as follows: + \begin {eqnarray*} + P[H = k] &=& P[S_\ell = 2k-\ell] ~=~ p_{\ell, 2k-\ell} + ~=~ 2^{-\ell} {\ell \choose k}, \quad 0\le k\le \ell,\\ + P[M = y] &=& p_{\ell,y} + p_{\ell, y+1}, \quad + 0\le y\le \ell,\\ + P[J = k] &=& p_{k,0}\; p_{\ell-k, 0}, \quad 0\le k\le \ell, \ k + \mbox{ even},\\ + P[P_y = k] &=& (y/k) p_{k,y}, \\ + P[R = y] &=& p_{\ell-y,y}, \quad 0\le y \le \ell/2,\\ + P[C = y] &=& 2p_{\ell-1, 2y+1}, \quad 0\le y \le (\ell-1)/2. + \end {eqnarray*} + The size of the memory used by the test is approximately + ${6L_1(L_1-L_0+1)}/(10^5)$ megabytes. + Restrictions: $r+s\le 32$, $L_0$ and $L_1$ even, and $L_0 \le L_1$. + \endtab +\code + + +void swalk_RandomWalk1a (unif01_Gen *gen, swalk_Res *res, long N, long n, + int r, int s, int t, long L, bitset_BitSet C); +\endcode + \tab + Applies the same collection of tests \index{Test!RandomWalk1a} + as {\tt swalk\_RandomWalk1}, + except that $\ell$ takes a single value, {\tt L}, and that + the $X_i$'s are defined in a different (more general) way, as follows. + The parameter {\tt C} contains a vector of fixed binary coefficients + (bits) $c_0,\dots,c_{t-1}$, not all zero. + The test generates a long sequence of bits $b_0, b_1, \dots$ and puts + $X_i = 1$ if $y_i = c_0 b_i + \dots + c_{t-1} b_{i+t-1}$ + % = \sum_{j=0}^{t-1} c_j b_{i+j}$ + is odd, $X_i = -1$ otherwise. + \hpierre {Ceci utilise $\ell+t-1$ pour une marche al\'eatoire de + longueur $\ell$. + J'ai regard\'e l'implantation et je ne comprend pas trop ce qui + se passe. C'est loin d'\^etre clair. Il faut mieux expliquer.} + \hpierre {Under what conditions on the $c_j$ are the $X_i$'s + independent under $\cH_0$? It suffices that the $c_j$'s are not + all zero. Because then, for any two indices $i$ and $j$, $y_i$ + is a sum of bits with at least one bit not included in the sum + defining $y_j$, and vice-versa.} + Restrictions: $r+s \le 32$, $t \le 31$, and $L$ even. + \endtab +\code + + +void swalk_VarGeoP (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, double Mu); +\endcode + \tab + Applies a test \index{Test!VarGeoP} + based on the length of a certain ``random walk'', + proposed by \cite{rSHC97a}. + This test turns out to be a special case of the {\em gap test\/} + implemented in {\tt sknuth\_gap}. + It generates uniforms until one of these uniforms is larger or equal + to {\tt Mu} and counts how many uniforms were needed (the number of steps + in the random walk). + This is repeated $n$ times, the number of walks of each length is + counted, and a chi-square test is applied to compare these counts + to the their expectations under $\cH_0$. + Restriction: {\tt Mu} $\in (0, 1)$. + \endtab +\code + + +void swalk_VarGeoN (unif01_Gen *gen, sres_Chi2 *res, + long N, long n, int r, double Mu); +\endcode + \tab + Same as {\tt swalk\_VarGeoP}, \index{Test!VarGeoN} + but with ``larger or equal to + {\tt Mu}'' replaced by ``less than {\tt 1 - Mu}''. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/swrite.c b/TESTU01/TestU01-1.2.3/testu01/swrite.c new file mode 100644 index 0000000..65ba44e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/swrite.c @@ -0,0 +1,169 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: swrite.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + + +#include "gdef.h" +#include "util.h" +#include "chrono.h" + +#include "swrite.h" +#include "unif01.h" +#include "gofw.h" + +#include +#include +#include + + + +#define LEN 100 + + +lebool swrite_Basic = TRUE; +lebool swrite_Parameters = FALSE; +lebool swrite_Collectors = FALSE; +lebool swrite_Counters = FALSE; +lebool swrite_Classes = FALSE; +lebool swrite_Others = FALSE; + +lebool swrite_Host = TRUE; + +char swrite_ExperimentName[LEN + 1] = ""; + + + +/*=========================================================================*/ + +void swrite_SetExperimentName (char Name[]) +{ + strncpy (swrite_ExperimentName, Name, (size_t) LEN); +} + + +/*=========================================================================*/ + +void swrite_Head (unif01_Gen *gen, char *TestName, long N, long n, int r) +{ + printf ("***********************************************************\n"); + printf ("HOST = "); + if (swrite_Host) { + gdef_WriteHostName (); + printf ("\n"); + } else + printf ("\n\n"); + util_Assert (gen != NULL, "No generator has been created"); + unif01_WriteNameGen (gen); + printf ("\n"); + if (swrite_ExperimentName && strcmp (swrite_ExperimentName, "")) { + printf ("%s", swrite_ExperimentName); + printf (":\n\n"); + } + printf ("%s", TestName); + printf (":\n-----------------------------------------------\n"); + printf (" N = %2ld, n = %2ld, r = %2d", N, n, r); + util_Assert (N > 0, " N <= 0"); + util_Assert (n > 0, " n <= 0"); + util_Assert (r >= 0, " r < 0"); +} + + +/*=========================================================================*/ + +void swrite_Final (unif01_Gen *gen, chrono_Chrono *Timer) +{ + printf ("-----------------------------------------------\n"); + printf ("CPU time used : "); + chrono_Write (Timer, chrono_hms); + printf ("\n"); + unif01_WriteState (gen); + printf ("\n\n\n"); +} + + +/*=========================================================================*/ + +void swrite_AddStrChi (char S[], int len, long d) +{ + char str[31]; + int j; + strncpy (S, "Number of degrees of freedom : ", len); + j = strlen (S); + util_Assert (len > j, "swrite_AddStrChi: len <= j"); + sprintf (str, "%4ld", d); + strncat (S, str, len - j); + j = strlen (S); + util_Assert (len > j, "swrite_AddStrChi *: len <= j"); + strncat (S, "\nChi-square statistic :", len - j); + S[len - 1] = '\0'; +} + + +/*=========================================================================*/ + +void swrite_NormalSumTest (long N, sres_Basic *res) +{ + if (N <= 1) + return; + printf ("Tests on the sum of all N observations\n"); + printf ("Standardized normal statistic :"); + gofw_Writep2 (res->sVal2[gofw_Sum]/sqrt((double)N), res->pVal2[gofw_Sum]); + printf ("Sample variance :"); + gofw_Writep2 (res->sVal2[gofw_Var], res->pVal2[gofw_Var]); +} + + +/*=========================================================================*/ +#define LENGTH 200 + +void swrite_Chi2SumTest (long N, sres_Chi2 *res) +{ + char str[LENGTH + 1]; + if (N <= 1) + return; + printf ("Test on the sum of all N observations\n"); + swrite_AddStrChi (str, LENGTH, N*res->degFree); + printf (str); + gofw_Writep2 (res->sVal2[gofw_Sum], res->pVal2[gofw_Sum]); +} + + +/*=========================================================================*/ + +void swrite_Chi2SumTestb (long N, double sval, double pval, long degFree) +{ + char str[LENGTH + 1]; + if (N <= 1) + return; + printf ("Test on the sum of all N observations\n"); + swrite_AddStrChi (str, LENGTH, N*degFree); + printf (str); + gofw_Writep2 (sval, pval); +} + diff --git a/TESTU01/TestU01-1.2.3/testu01/swrite.tex b/TESTU01/TestU01-1.2.3/testu01/swrite.tex new file mode 100644 index 0000000..b76b9ee --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/swrite.tex @@ -0,0 +1,163 @@ +\defmodule {swrite} + +This module contains some functions used in writing statistical +test results, inside the implementation of other modules. + +Each testing function in the {\tt s} modules normally +writes a report (on standard output, by default) +that contains the description of the generator being tested, +the name of the experiment, the name of the test and its parameters, +the values and significance levels of statistics, +and the CPU time used by each test. +This report may contain additional information specific to a given test. +More detailed results in the printouts can be obtained by setting +the {\tt lebool} variables below to {\tt TRUE} before +calling the test. If all {\tt lebool} flags below are set to {\tt FALSE}, then +no output will be printed. + + +\bigskip\hrule +\code\hide +/* swrite.h for ANSI C */ +#ifndef SWRITE_H +#define SWRITE_H +\endhide +#include "gdef.h" +#include "chrono.h" +#include "unif01.h" +#include "sres.h" +\endcode + + +%%%%%%%%%%%%%%%%%%% +\guisec{Environment variables} + +\code + +extern lebool swrite_Basic; /* Prints basic results */ +extern lebool swrite_Parameters; /* Prints details on parameters */ +extern lebool swrite_Collectors; /* Prints statistical collectors */ +extern lebool swrite_Classes; /* Prints classes for ChiSquare */ +extern lebool swrite_Counters; /* Prints counters */ +\endcode + \tab These environment variables (which are {\em boolean switches\/}) are used to + control the level of detail in the output printed by the tests. + By default, all are set to {\tt FALSE}, except for + {\tt swrite\_Basic} which is set to {\tt TRUE}. + When {\tt swrite\_Basic} is {\tt TRUE}, the test results are printed + with a standard level of detail. + If it is {\tt FALSE}, then nothing from the {\tt u} or {\tt s} + modules is printed. + + The other switches permit one to obtain more detailed information than + usual, in a selective way. The details are printed when the + corresponding switch is set to {\tt TRUE}. + This could be useful, for example, to examine more closely the kind of + defect exhibited by a random number generator that fails a test. + + The switch {\tt swrite\_Parameters} controls the printing of + internal parameters that are specific to each test. + The switch {\tt swrite\_Collectors} controls the printing of the + statistical collectors holding the $N$ values of the main statistics + $Y$ of the test. + The switch {\tt swrite\_Classes} controls the printing of details + concerning the regroupings into classes (or categories), + with the expected numbers of observations in each class, + in the situations where such regrouping is performed in order + to apply a chi-square test (see function {\tt gofs\_MergeClasses} + in module {\tt gofs} of library ProbDist). + The switch {\tt swrite\_Counters} controls the printing of the different + counters that hold the numbers of observations. + \endtab +\code + + +extern lebool swrite_Host; +\endcode + \tab If this variable is {\tt TRUE}, the name of the machine on which +the tests are run is printed before each test; otherwise it is not +printed. + \endtab + + +\ifdetailed +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Functions used for printouts} + +\code + +extern char swrite_ExperimentName[]; +\endcode + \tab This environment variable is the name of the current experiment + (a series of tests). It is set by the procedure + {\tt swrite\_SetExperimentName} below. + \endtab +\code + + +void swrite_SetExperimentName (char Name[]); +\endcode + \tab Sets the name of an experiment to {\tt Name} (keeps the name in the + global environment variable {\tt swrite\_ExperimentName}). + This character string will be written at the beginning of the + report for each test. +\endtab +\code + + +void swrite_Head (unif01_Gen *gen, char *TestName, long N, long n, int r); +\endcode + \tab + Prints a header that contains the name of the current machine, + the name of the generator {\tt gen}, + the name of the experiment, the name of the test being applied, + and the values of $N$, $n$, and $r$. Called at the beginning of each test. +\endtab +\code + + +void swrite_Final (unif01_Gen *gen, chrono_Chrono *Timer); +\endcode +\tab Prints the time in {\tt Timer} (total CPU time used by a test), + and also the current state of generator {\tt gen}. + Called at the end of each test. +\endtab +\code + + +void swrite_NormalSumTest (long N, sres_Basic *res); +\endcode +\tab Writes the $s$-value and the $p$-value for the sample sum and the sample + variance of all $N>1$ observations in the case of a {\em normal\/} distribution. + For $N=1$, does nothing. +\endtab +\code + + +void swrite_AddStrChi (char S[], int len, long d); +\endcode +\tab Adds the number of degrees of freedom $d$ to string $S$, + which has length {\tt len}. +\endtab +\code + + +void swrite_Chi2SumTest (long N, sres_Chi2 *res); +\endcode +\tab Writes the $s$-value and the $p$-value for the sample sum + of all $N>1$ observations in the case of a {\em chi-square\/} distribution. + For $N=1$, does nothing. +\endtab +\code + + +void swrite_Chi2SumTestb (long N, double sval, double pval, long deg); +\endcode +\tab Writes the $s$-value {\tt sval} and the $p$-value {\tt pval} for the + sample sum of all $N>1$ observations in the case of a {\em chi-square\/} + distribution with {\tt deg} degrees of freedom. For $N=1$, does nothing. +\endtab +\fi +\code\hide +#endif +\endhide\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/title.tex b/TESTU01/TestU01-1.2.3/testu01/title.tex new file mode 100644 index 0000000..d81f693 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/title.tex @@ -0,0 +1,49 @@ +\begin {titlepage} + +\null +\begin {flushright} \it This version: \today \end {flushright} + +\vfill +\begin{center} + {\Large\bf TestU01} \\ \ \\ + {\large\bf A Software Library in ANSI C \\[6pt] + for Empirical Testing of Random Number Generators}\\ +\vfill +{\bf User's guide, + \ifdetailed detailed version \else compact version \fi } +\vfill + Pierre L'Ecuyer and Richard Simard \\[10pt] +D\'epartement d'Informatique et de Recherche Op\'erationnelle \\ +Universit\'e de Montr\'eal \\ +\end{center} +\vfill + +This document describes the software library {\em TestU01}, +implemented in the ANSI C language, +and offering a collection of utilities for the (empirical) +statistical testing of uniform random number generators (RNG). + +The library implements several types of generators in +generic form, as well as many specific generators proposed in +the literature or found in widely-used software. +It provides general implementations of the classical statistical tests +for random number generators, as well as several others proposed in the +literature, and some original ones. +These tests can be applied to the generators predefined in the library +and to user-defined generators. +Specific tests suites for either sequences of uniform random numbers +in $[0,1]$ or bit sequences are also available. +Basic tools for plotting vectors of points produced by generators +are provided as well. + +Additional software permits one to perform +systematic studies of the interaction between a specific test +and the structure of the point sets produced by a given family of RNGs. +That is, for a given kind of test and a given class of RNGs, +to determine how large should be the sample size of the test, +as a function of the generator's period length, +before the generator starts to fail the test systematically. + +\vfill +\end{titlepage} + diff --git a/TESTU01/TestU01-1.2.3/testu01/tu01_sha1.c b/TESTU01/TestU01-1.2.3/testu01/tu01_sha1.c new file mode 100644 index 0000000..ffda253 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/tu01_sha1.c @@ -0,0 +1,404 @@ +/* +SHA-1 in C +By Steve Reid +100% Public Domain + +----------------- +Modified 7/98 +By James H. Brown +Still 100% Public Domain + +Corrected a problem which generated improper hash values on 16 bit machines +Routine SHA1Update changed from + void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int +len) +to + void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned +long len) + +The 'len' parameter was declared an int which works fine on 32 bit machines. +However, on 16 bit machines an int is too small for the shifts being done +against +it. This caused the hash function to generate incorrect values if len was +greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update(). + +Since the file IO in main() reads 16K at a time, any file 8K or larger would +be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million +"a"s). + +I also changed the declaration of variables i & j in SHA1Update to +unsigned long from unsigned int for the same reason. + +These changes should make no difference to any 32 bit implementations since +an +int and a long are the same size in those environments. + +-- +I also corrected a few compiler warnings generated by Borland C. +1. Added #include for exit() prototype +2. Removed unused variable 'j' in SHA1Final +3. Changed exit(0) to return(0) at end of main. + +ALL changes I made can be located by searching for comments containing 'JHB' +----------------- +Modified 8/98 +By Steve Reid +Still 100% public domain + +1- Removed #include and used return() instead of exit() +2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall) +3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net + +----------------- +Modified 4/01 +By Saul Kravitz +Still 100% PD +Modified to run on Compaq Alpha hardware. + +----------------- +Modified 4/01 +By Jouni Malinen +Minor changes to match the coding style used in Dynamics. + +Modified September 24, 2004 +By Jouni Malinen +Fixed alignment issue in SHA1Transform when SHA1HANDSOFF is defined. + +*/ + +/* +Test Vectors (from FIPS PUB 180-1) +"abc" + A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D +"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 +A million repetitions of "a" + 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F +*/ + + + +/*=========================================================================*/ +#include "tu01_sha1.h" +#include + +#undef SHA1HANDSOFF /* Copies data before messing with it */ + +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) + +/* blk0() and blk() perform the initial expand. */ +/* I got the idea of expanding during the round function from SSLeay */ +#ifndef WORDS_BIGENDIAN +#define blk0(i) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | \ + (rol(block->l[i], 8) & 0x00FF00FF)) +#else +#define blk0(i) block->l[i] +#endif + +#define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ \ + block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1)) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v,w,x,y,z,i) \ + z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \ + w = rol(w, 30); +#define R1(v,w,x,y,z,i) \ + z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \ + w = rol(w, 30); +#define R2(v,w,x,y,z,i) \ + z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30); +#define R3(v,w,x,y,z,i) \ + z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \ + w = rol(w, 30); +#define R4(v,w,x,y,z,i) \ + z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \ + w=rol(w, 30); + + +#ifdef VERBOSE /* SAK */ +#include + +void SHAPrintContext (SHA1_CTX * context, char *msg) +{ + printf ("%s (%d,%d) %x %x %x %x %x\n", + msg, + context->count[0], context->count[1], + context->state[0], + context->state[1], + context->state[2], context->state[3], context->state[4]); +} +#endif + +/* Hash a single 512-bit block. This is the core of the algorithm. */ + +static void SHA1Transform (uint32_t state[5], const unsigned char buffer[64]) +{ + uint32_t a, b, c, d, e; + typedef union + { + unsigned char c[64]; + uint32_t l[16]; + } CHAR64LONG16; + CHAR64LONG16 *block; +#ifdef SHA1HANDSOFF + uint32_t workspace[16]; + block = (CHAR64LONG16 *) workspace; + memcpy (block, buffer, 64); +#else + block = (CHAR64LONG16 *) buffer; +#endif + /* Copy context->state[] to working vars */ + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + /* 4 rounds of 20 operations each. Loop unrolled. */ + R0 (a, b, c, d, e, 0); + R0 (e, a, b, c, d, 1); + R0 (d, e, a, b, c, 2); + R0 (c, d, e, a, b, 3); + R0 (b, c, d, e, a, 4); + R0 (a, b, c, d, e, 5); + R0 (e, a, b, c, d, 6); + R0 (d, e, a, b, c, 7); + R0 (c, d, e, a, b, 8); + R0 (b, c, d, e, a, 9); + R0 (a, b, c, d, e, 10); + R0 (e, a, b, c, d, 11); + R0 (d, e, a, b, c, 12); + R0 (c, d, e, a, b, 13); + R0 (b, c, d, e, a, 14); + R0 (a, b, c, d, e, 15); + R1 (e, a, b, c, d, 16); + R1 (d, e, a, b, c, 17); + R1 (c, d, e, a, b, 18); + R1 (b, c, d, e, a, 19); + R2 (a, b, c, d, e, 20); + R2 (e, a, b, c, d, 21); + R2 (d, e, a, b, c, 22); + R2 (c, d, e, a, b, 23); + R2 (b, c, d, e, a, 24); + R2 (a, b, c, d, e, 25); + R2 (e, a, b, c, d, 26); + R2 (d, e, a, b, c, 27); + R2 (c, d, e, a, b, 28); + R2 (b, c, d, e, a, 29); + R2 (a, b, c, d, e, 30); + R2 (e, a, b, c, d, 31); + R2 (d, e, a, b, c, 32); + R2 (c, d, e, a, b, 33); + R2 (b, c, d, e, a, 34); + R2 (a, b, c, d, e, 35); + R2 (e, a, b, c, d, 36); + R2 (d, e, a, b, c, 37); + R2 (c, d, e, a, b, 38); + R2 (b, c, d, e, a, 39); + R3 (a, b, c, d, e, 40); + R3 (e, a, b, c, d, 41); + R3 (d, e, a, b, c, 42); + R3 (c, d, e, a, b, 43); + R3 (b, c, d, e, a, 44); + R3 (a, b, c, d, e, 45); + R3 (e, a, b, c, d, 46); + R3 (d, e, a, b, c, 47); + R3 (c, d, e, a, b, 48); + R3 (b, c, d, e, a, 49); + R3 (a, b, c, d, e, 50); + R3 (e, a, b, c, d, 51); + R3 (d, e, a, b, c, 52); + R3 (c, d, e, a, b, 53); + R3 (b, c, d, e, a, 54); + R3 (a, b, c, d, e, 55); + R3 (e, a, b, c, d, 56); + R3 (d, e, a, b, c, 57); + R3 (c, d, e, a, b, 58); + R3 (b, c, d, e, a, 59); + R4 (a, b, c, d, e, 60); + R4 (e, a, b, c, d, 61); + R4 (d, e, a, b, c, 62); + R4 (c, d, e, a, b, 63); + R4 (b, c, d, e, a, 64); + R4 (a, b, c, d, e, 65); + R4 (e, a, b, c, d, 66); + R4 (d, e, a, b, c, 67); + R4 (c, d, e, a, b, 68); + R4 (b, c, d, e, a, 69); + R4 (a, b, c, d, e, 70); + R4 (e, a, b, c, d, 71); + R4 (d, e, a, b, c, 72); + R4 (c, d, e, a, b, 73); + R4 (b, c, d, e, a, 74); + R4 (a, b, c, d, e, 75); + R4 (e, a, b, c, d, 76); + R4 (d, e, a, b, c, 77); + R4 (c, d, e, a, b, 78); + R4 (b, c, d, e, a, 79); + /* Add the working vars back into context.state[] */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + /* Wipe variables */ + a = b = c = d = e = 0; +#ifdef SHA1HANDSOFF + memset (block, 0, 64); +#endif +} + + +/* SHA1Init - Initialize new context */ + +void SHA1Init (SHA1_CTX * context) +{ + /* SHA1 initialization constants */ + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; + context->state[4] = 0xC3D2E1F0; + context->count[0] = context->count[1] = 0; +} + + +/* Run your data through this. */ + +void SHA1Update (SHA1_CTX * context, const unsigned char data[], uint32_t len) +{ + uint32_t i, j; + +#ifdef VERBOSE + SHAPrintContext (context, "before"); +#endif + j = (context->count[0] >> 3) & 63; + if ((context->count[0] += len << 3) < (len << 3)) + context->count[1]++; + context->count[1] += (len >> 29); + if ((j + len) > 63) { + memcpy (&context->buffer[j], data, (i = 64 - j)); + SHA1Transform (context->state, context->buffer); + for (; i + 63 < len; i += 64) { + SHA1Transform (context->state, &data[i]); + } + j = 0; + } else + i = 0; + memcpy (&context->buffer[j], &data[i], len - i); +#ifdef VERBOSE + SHAPrintContext (context, "after "); +#endif +} + + +/* Add padding and return the message digest. */ + +void SHA1Final (unsigned char digest[20], SHA1_CTX * context) +{ + uint32_t i; + unsigned char finalcount[8]; + + for (i = 0; i < 8; i++) { + finalcount[i] = (unsigned char) + ((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255); + /* Endian independent */ + } + SHA1Update (context, (unsigned char *) "\200", 1); + while ((context->count[0] & 504) != 448) { + SHA1Update (context, (unsigned char *) "\0", 1); + } + SHA1Update (context, finalcount, 8); /* Should cause a SHA1Transform() */ + for (i = 0; i < 20; i++) { + digest[i] = (unsigned char) + ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); + } + /* Wipe variables */ +/* + i = 0; + memset (context->buffer, 0, 64); + memset (context->state, 0, 20); + memset (context->count, 0, 8); + memset (finalcount, 0, 8); +*/ +} + + +#if 0 + +/*************************************************************/ +/* + * sha1test.c + * + * Description: + * This file will exercise the SHA-1 code performing the three + * tests documented in FIPS PUB 180-1 plus one which calls + * SHA1Input with an exact multiple of 512 bits, plus a few + * error test checks. + * + * Portability Issues: + * None. + * + */ + +#include +#include + +/* + * Define patterns for testing + */ +#define TEST1 "abc" +#define TEST2a "abcdbcdecdefdefgefghfghighijhi" + +#define TEST2b "jkijkljklmklmnlmnomnopnopq" +#define TEST2 TEST2a TEST2b +#define TEST3 "a" +#define TEST4a "01234567012345670123456701234567" +#define TEST4b "01234567012345670123456701234567" + /* an exact multiple of 512 bits */ +#define TEST4 TEST4a TEST4b +char *testarray[4] = { + TEST1, + TEST2, + TEST3, + TEST4 +}; +int repeatcount[4] = { 1, 1, 1000000, 10 }; +char *resultarray[4] = { + "A9 99 3E 36 47 06 81 6A BA 3E 25 71 78 50 C2 6C 9C D0 D8 9D", + "84 98 3E 44 1C 3B D2 6E BA AE 4A A1 F9 51 29 E5 E5 46 70 F1", + "34 AA 97 3C D4 C4 DA A4 F6 1E EB 2B DB AD 27 31 65 34 01 6F", + "DE A3 56 A2 CD DD 90 C7 A7 EC ED C5 EB B5 63 93 4F 46 04 52" +}; + +int main (void) +{ + SHA1_CTX sha; + int i, j; + unsigned char Message_Digest[20]; + + /* Perform SHA-1 tests */ + for (j = 0; j < 4; ++j) { + printf ("\nTest %d: %d, '%s'\n", j + 1, repeatcount[j], testarray[j]); + SHA1Init (&sha); + + for (i = 0; i < repeatcount[j]; ++i) { + SHA1Update (&sha, (const unsigned char *) testarray[j], + strlen (testarray[j])); + } + + SHA1Final (Message_Digest, &sha); + printf ("\t"); + for (i = 0; i < 20; ++i) { + printf ("%02X ", Message_Digest[i]); + } + printf ("\n"); + printf ("Should match:\n"); + printf ("\t%s\n", resultarray[j]); + } + + /* Test some error returns */ + SHA1Update (&sha, (const unsigned char *) testarray[1], 1); + SHA1Init (&sha); + return 0; +} +#endif diff --git a/TESTU01/TestU01-1.2.3/testu01/tu01_sha1.tex b/TESTU01/TestU01-1.2.3/testu01/tu01_sha1.tex new file mode 100644 index 0000000..d8d0623 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/tu01_sha1.tex @@ -0,0 +1,20 @@ +\code +#ifndef TU01_SHA1_H +#define TU01_SHA1_H +#include "gdef.h" + + +typedef struct +{ + uint32_t state[5]; + uint32_t count[2]; + unsigned char buffer[64]; +} SHA1_CTX; + + +void SHA1Init (SHA1_CTX * context); +void SHA1Update (SHA1_CTX * context, const unsigned char data[], uint32_t len); +void SHA1Final (unsigned char digest[20], SHA1_CTX * context); + +#endif +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/uautomata.c b/TESTU01/TestU01-1.2.3/testu01/uautomata.c new file mode 100644 index 0000000..34041cf --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uautomata.c @@ -0,0 +1,418 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uautomata.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "uautomata.h" +#include "unif01.h" + +#include +#include + +/* +#include +*/ + + +#define LEN 200 /* Max length of strings */ + + +typedef struct { + int *F; /* Rule */ + long L; /* Dimension of F */ + int r; /* Radius of neighborhoud */ + int k; /* Number of cells whose values is used to + build the random numbers */ + int imin, imax; /* Minimal and maximal cell numbers used to + build the random numbers: i.e. the k cells numbered imin, imin + cstep, + imin + 2*cstep, ... , imax are the ones used. */ + int cstep; /* Cell spacing */ + int tstep; /* Time spacing */ + int rot; /* Shift parameter */ +} CA1_param; + + +typedef struct { + int *Cell; + int *OldCell; + int N; /* Number of cells */ + unsigned long *Rand; /* Random numbers */ + int nk; /* Index of Rand */ +} CA1_state; + + +/*-------------------------------------------------------------------------*/ + +typedef struct { + int *Cell; + int *OldCell; + int m; /* Number of cells is m + 2 */ +} CA90mp_state; + + +/*-------------------------------------------------------------------------*/ + + + + +/*-----------------------------------------------------------------------*/ + +static void DoOneTimeStep (CA1_param *param, CA1_state *state) +{ + unsigned long ind; + int i; + int s; + int *p; + p = state->Cell; + state->Cell = state->OldCell; + state->OldCell = p; + + for (i = param->r; i < state->N - param->r; i++) { + ind = 0; + for (s = -param->r; s <= param->r; s++) { + ind <<= 1; + ind += state->OldCell[i + s]; + } + state->Cell[i] = param->F[ind]; + } + + /* End of grid */ + for (i = state->N - param->r; i < state->N; i++) { + ind = 0; + for (s = -param->r; s <= param->r; s++) { + ind <<= 1; + ind += state->OldCell[(i + s) % state->N]; + } + state->Cell[i] = param->F[ind]; + } + + /* Beginning of grid */ + for (i = 0; i < param->r; i++) { + ind = 0; + for (s = -param->r; s <= param->r; s++) { + ind <<= 1; + ind += state->OldCell[(i + s + state->N) % state->N]; + } + state->Cell[i] = param->F[ind]; + } +} + + +/*-----------------------------------------------------------------------*/ + +static void RotateCells (CA1_param *param, CA1_state *state) +{ + int i; + int *p; + p = state->Cell; + state->Cell = state->OldCell; + state->OldCell = p; + + if (param->rot > 0) { + for (i = 0; i < state->N - param->rot; i++) + state->Cell[i + param->rot] = state->OldCell [i]; + for (i = state->N - param->rot; i < state->N; i++) + state->Cell[i + param->rot - state->N] = state->OldCell [i]; + + } else if (param->rot < 0) { + for (i = -param->rot; i < state->N; i++) + state->Cell[param->rot + i] = state->OldCell [i]; + for (i = 0; i < -param->rot; i++) + state->Cell[state->N + param->rot + i] = state->OldCell [i]; + + } else { + p = state->Cell; + state->Cell = state->OldCell; + state->OldCell = p; + } +} + + +/*-----------------------------------------------------------------------*/ + +static unsigned long CA1_Bits (void *vpar, void *vsta) +{ + CA1_state *state = vsta; + + if (state->nk <= 0) { + CA1_param *param = vpar; + int i, j, s, t; + for (j = 0; j < param->k; ++j) + state->Rand[j] = 0; + + /* Build k 32-bits random numbers from the bits of the k chosen cells */ + for (s = 0; s < 32; ++s) { + for (t = 0; t < param->tstep; ++t) { + DoOneTimeStep (param, state); + if (param->rot != 0) { + RotateCells (param, state); + } + } + /* Get the bits at the k chosen cells and put them in Rand */ + j = 0; + for (i = param->imin; i <= param->imax; i += param->cstep) { + state->Rand[j] <<= 1; + state->Rand[j] |= state->Cell[i]; + ++j; + } + } + state->nk = param->k; + } + return state->Rand[--state->nk]; +} + + +/*-----------------------------------------------------------------------*/ + +static double CA1_U01 (void *vpar, void *vsta) +{ + return CA1_Bits (vpar, vsta) * unif01_INV32; +} + + +/*-----------------------------------------------------------------------*/ + +static void WrCA1 (void *vsta) +{ + CA1_state *state = vsta; + int j; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < state->N; j++) + printf (" %1d", state->Cell[j]); + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uautomata_CreateCA1 (int N, int S[ ], int r, int F[ ], + int k, int ts, int cs, int rot) +{ + unif01_Gen *gen; + CA1_param *param; + CA1_state *state; + size_t leng; + char name[LEN + 1]; + long i; + unsigned long Z = 0; + long L; /* Dimension of the rule F */ + + i = 4*sizeof(long) - 1; + util_Assert ((long) r < i, "uautomata_CreateCA1: r too large"); + util_Assert (ts >= 0, "uautomata_CreateCA1: ts < 0"); + util_Assert (cs >= 0, "uautomata_CreateCA1: cs < 0"); + util_Assert (k > 0, "uautomata_CreateCA1: k < 1"); + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CA1_param)); + state = util_Malloc (sizeof (CA1_state)); + + strncpy (name, "uautomata_CreateCA1:", (size_t) LEN); + addstr_Long (name, " N = ", (long) N); + addstr_Long (name, ", r = ", (long) r); + L = num_TwoExp[2*r + 1]; + addstr_ArrayInt (name, ", F = ", (int) L, F); + for (i = L-1; i >= 0; i--) { + Z <<= 1; + Z += F[i]; + } + addstr_Ulong(name, " = Rule ", Z); + addstr_Long (name, ", k = ", (long) k); + addstr_Long (name, ", ts = ", (long) ts); + addstr_Long (name, ", cs = ", (long) cs); + addstr_Long (name, ", rot = ", (long) rot); + addstr_ArrayInt (name, ", S = ", N, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, (size_t) leng); + + param->r = r; + param->tstep = ts + 1; + param->cstep = cs + 1; + param->rot = rot; + param->k = k; + param->F = F; + param->L = L; + state->Cell = util_Calloc ((size_t) N, sizeof (int)); + state->OldCell = util_Calloc ((size_t) N, sizeof (int)); + state->Rand = util_Calloc ((size_t) k, sizeof (unsigned long)); + state->N = N; + state->nk = 0; + param->imin = N/2 - k/2 * param->cstep; + param->imax = N/2 + (k - 1)/2 * param->cstep; + util_Assert (param->imin >= 0, "uautomata_CreateCA1: k*cs too large"); + util_Assert (param->imax < N, "uautomata_CreateCA1: k*cs too large"); + + for (i = 0; i < N; i++) { + /* util_Assert (S[i] == 0 || S[i] == 1, + "uautomata_CreateCA1: all S[i] must be in { 0, 1 }."); */ + state->Cell[i] = S[i] & 1; + } + + gen->GetBits = &CA1_Bits; + gen->GetU01 = &CA1_U01; + gen->Write = &WrCA1; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static unsigned long CA90mp_Bits (void *junk, void *vsta) +{ + CA90mp_state *state = vsta; + unsigned long Rand = 0; /* Random number */ + int s, i; + int *p; + + /* Build a 32-bit random integer from the successive bit of cell m */ + for (s = 0; s < 32; ++s) { + p = state->Cell; + state->Cell = state->OldCell; + state->OldCell = p; + + /* Do one time step */ + for (i = 1; i <= state->m; i++) + state->Cell[i] = state->OldCell[i - 1] ^ state->OldCell[i + 1]; + /* Mirror boundary condition */ + state->Cell[state->m + 1] = state->Cell[state->m]; + + Rand <<= 1; + Rand |= state->Cell[state->m]; + } + + return Rand; +} + + +/*-----------------------------------------------------------------------*/ + +static double CA90mp_U01 (void *vpar, void *vsta) +{ + return CA90mp_Bits (vpar, vsta) * unif01_INV32; +} + + +/*-----------------------------------------------------------------------*/ + +static void WrCA90mp (void *vsta) +{ + CA90mp_state *state = vsta; + int j; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 1; j <= state->m; j++) + printf (" %1d", state->Cell[j]); + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uautomata_CreateCA90mp (int m, int S[]) +{ + unif01_Gen *gen; + CA90mp_state *state; + size_t leng; + char name[LEN + 1]; + int i; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CA90mp_state)); + + strncpy (name, "uautomata_CreateCA90mp:", (size_t) LEN); + addstr_Long (name, " m = ", (long) m); + addstr_ArrayInt (name, ", S = ", m, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, (size_t) leng); + + state->Cell = util_Calloc ((size_t) m + 2, sizeof (int)); + state->OldCell = util_Calloc ((size_t) m + 2, sizeof (int)); + state->m = m; + + for (i = 1; i <= m; i++) { + util_Assert (S[i] == 0 || S[i] == 1, + "uautomata_CreateCA90mp: all S[i] must be in { 0, 1 }."); + state->Cell[i] = S[i]; + } + /* Null boundary condition */ + state->Cell[0] = 0; + state->OldCell[0] = 0; + gen->GetBits = &CA90mp_Bits; + gen->GetU01 = &CA90mp_U01; + gen->Write = &WrCA90mp; + gen->state = state; + gen->param = NULL; + return gen; +} + + +/**************************************************************************/ + +void uautomata_DeleteGen (unif01_Gen *gen) +{ + CA1_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->Cell); + util_Free (state->OldCell); + util_Free (state->Rand); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +void uautomata_DeleteCA90mp (unif01_Gen *gen) +{ + CA90mp_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->Cell); + util_Free (state->OldCell); + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + diff --git a/TESTU01/TestU01-1.2.3/testu01/uautomata.tex b/TESTU01/TestU01-1.2.3/testu01/uautomata.tex new file mode 100644 index 0000000..3f36d45 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uautomata.tex @@ -0,0 +1,160 @@ +\defmodule {uautomata} + +This module implements generators based on cellular automata. A cellular +automaton consists of a $d$-dimensional grid of cells, whose coordinates are +the integer points in the \mbox{$d$-dimensional} euclidean lattice + ${\cal L} = \mathbb{Z}^d$. Each cell can hold a value taken from a discrete + set (for now, only binary values 0 and 1 are implemented). +The value $x$ at each cell $i$ evolves deterministically with (discrete) + time according +to a set of rules involving the values of its nearest neighbours. For a +one-dimensional cellular automaton with neighbourhood of radius $r$, the value + of a cell at a given time depends on its value at the previous time + step as well as the values of the $r$ closest cells on + the left and the $r$ closest cells on the right, all at the previous time + step. The evolution of cell $i$ can thus be written as +$$ + x_i^{(t+1)} = F\left[ x_{i-r}^{(t)},\ \ldots, x_{i}^{(t)},\ \ldots, + \ x_{i+r}^{(t)}\right], +$$ +where $t$ represents discrete time. +These rules are applied synchronously to each cell at every time step. +Here, only uniform cellular automata are considered, for which the rules +are identical for all cell. +See \cite{rWOL86a,rWOL86b,rTOM99a} +for the theory of cellular automata. + +In the current implementation, +periodic boundary conditions are imposed on the grid of cells, so that + cells on oppposite boundaries are considered adjacent. For example, for a +one-dimensional grid with $N$ cells, the condition $S_N = S_0$ applies. +Similarly, a two-dimensional grid is considered as a torus. + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* uautomata.h for ANSI C */ +#ifndef UAUTOMAT_H +#define UAUTOMAT_H +\endhide +#include "unif01.h" + +unif01_Gen * uautomata_CreateCA1 (int N, int S[ ], int r, int F[ ], + int k, int ts, int cs, int rot); +\endcode + \tab Initializes a generator based on a 1-dimensional boolean uniform + cellular automaton made up of $N$ cells, with a rule $F$ of radius $r$, + and an initial state $S$. A rule of radius $r$ is such that only the $r$ + nearest neighbors on each side of a cell are involved in determining the + value of the cell at the next time step. Thus each cell has $2r+1$ + neighbors, including itself. + The initial value of cell $i$ is given in $S[i]$ and can take +\index{Generator!cellular automata}% + values 0 and 1 only. + + The rule is specified by the $2^{2r + 1}$ elements + of array $F$ indexed in standard numerical order, with an entry for + every possible neighborhood configuration of states. A given entry is + such that at the next time step, cell + $i$ takes the value obtained from the rule when the $2r+1$ neighbour cell + values are given by the binary representation of $j$. The following + table shows an example of a local rule when $r=1$. + +\begin{center} +\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\hline + $j$ & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\ \hline + $x_{i-1}, x_i, x_{i+1}$ + & 111 & 110 & 101 & 100 & 011 & 010 & 001 & 000 \\ \hline + new $x_i$ & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0 \\ \hline +\end{tabular} +\end{center} + + Each of the $2^{2r + 1} = 8$ possible sets of values for a cell and its + 2 nearest neighbours appear on the middle line, while the lower line + gives the value to be taken + by the central cell on the next time step. For this rule, array $F$ + must have the following form: $F = \{ 0, 1, 1, 1, 1, 0, 0, 0 \}$. + In Wolfram's numbering scheme for one-dimensional automata \cite{rWOL86a} + and in the litterature, this rule is called rule 30 because the + lower line of the table is the binary representation of 30. + + In order to generate random numbers from this automaton, only $k$ cells + are used, starting count at the center of the grid. Assuming that + the parameters + {\tt ts} and {\tt cs} are 0, then 32 time steps will be used + to generate $k$ random integers, the 32 bits of a cell over time + making up one random number. For example, if $N=10$ and $k=3$, then only + cells 4, 5, 6 will be used to generate random numbers, though + all the cells contribute to the evolution of the cellular automaton. + + The parameters {\tt ts} and {\tt cs} implements time spacings and cell + spacings respectively. Thus only the bits generated at every ${\tt ts} + 1$ + time step are considered as part of the random sequence, the bits generated + at the {\tt ts} successive time steps in-between are disregarded. + For example, if {\tt ts} $=1$, one keeps only the bits at 1 time step out + of 2 to build the random numbers. The default value is {\tt ts} $=0$. + Similarly, only cells spaced ${\tt cs} + 1$ apart are used to generate random + numbers; the output of the {\tt cs} cells + in-between is not considered part of the random sequence, though they still + contribute to the evolution of the cellular automaton. + For example, if $N=20$, $k=3$ and {\tt cs} $=2$, then only the bits + generated by cells 7, 10, 13 are used to make up the random numbers + returned by the cellular automaton. The default value is {\tt cs} $=0$. + + The parameter {\tt rot} indicates a circular shift of the cells at + each time step. If {\tt rot} $> 0$, the value of cell $i$ at the end + of each time step will become the value of cell ($i+ {\tt rot}) \bmod N$ + before going to the next time step. If {\tt rot} $< 0$, cell $i$ + will become the value of cell ($i- {\tt rot}) \bmod N$ instead. + There is no shift when {\tt rot} $= 0$. + + Restrictions: $k*({\tt cs} + 1) \le N+ {\tt cs}$. + \endtab +\code + + +unif01_Gen * uautomata_CreateCA90mp (int m, int S[]); +\endcode + \tab Implements Matsumoto's cellular automaton ${\it CA90(m)'}$ + (see \cite{rMAT98b}). \index{Generator!CA90(m)'}% + It is a uniform boolean one-dimensio\-nal automaton with $m$ cells based on + rule 90 (as defined by Wolfram in \cite{rWOL83a}), i.e., the value of a + cell at time $t+1$ + depends only on the state of its two closest neighbors at time $t$ and + is given by $x_i(t+1) = x_{i-1}(t) + x_{i+1}(t) \bmod 2$. There are two + extra cells that implements the boundary conditions at both ends. + The null boundary condition, $x_0(t) \equiv 0$, is applied permanently + at the left end, while the mirror boundary condition, + $x_{m+1}(t) = x_{m}(t) $, is applied permanently at the right end. + The output is the value of cell $m$. Thus each time step generates + one bit of output and 32 time steps generate one 32-bit integer. + The initial state of the cells must be given in $S[j]$ for + $j = 1, 2, \ldots, m$. Restriction: $S[j] \in \{0, 1 \}$. + \endtab + + +\guisec{Clean-up functions} + +\code + +void uautomata_DeleteCA90mp (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory allocated by + {\tt uautomata\_CreateCA90mp}. + \endtab +\code + + +void uautomata_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called when a generator + is no longer in use. + \endtab +\code\hide +#endif +\endhide\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ubrent.c b/TESTU01/TestU01-1.2.3/testu01/ubrent.c new file mode 100644 index 0000000..6c907da --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ubrent.c @@ -0,0 +1,1243 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ubrent.c + * Environment: ANSI C + * + * Comment: I have made mostly cosmetic changes on Brent's code to adapt + * his generators for testing by TestU01. The random numbers + * generated should be the same. The code was taken from Brent's file + * xorgens201.c available on his Web site for version 2004 of the RNG, + * and from xorgens304 for the version 2006. + * + * Richard P. Brent kindly gave us the explicit permission to include + * his code in TestU01 and distribute it. (Richard Simard) + * +\*************************************************************************/ + + +#include "util.h" +#include "addstr.h" +#include "ubrent.h" + +#include +#include + +#define LEN 200 /* Max length of strings */ + + +typedef struct { + unsigned int r, s, a, b, c, d; + unsigned int Mask; + unsigned int weil; + lebool hasWeyl; +} Xorgen32_param; + + +typedef struct { + unsigned int *x; + unsigned int w, r2; + int i; +} Xorgen32_state; + + +#ifdef USE_LONGLONG +typedef struct { + unsigned int r, s, a, b, c, d; + unsigned int Mask; + ulonglong weil; + lebool hasWeyl; +} Xorgen64_param; + + +typedef struct { + ulonglong *x; + ulonglong w; + unsigned int r2; + int i; +} Xorgen64_state; +#endif + + +static int co1 = 0, co2 = 0, co3 = 0, co4 = 0, co5 = 0; /* Counters */ + + +/* xorgens.c - Some long-period random number generators + generalising Marsaglia's Xorshift RNGs +/* +========================================================================== +| | +| Copyright (C) 2004, 2006 R. P. Brent. | +| | +| This program is free software; you can redistribute it and/or | +| modify it under the terms of the GNU General Public License, | +| version 2, June 1991, as published by the Free Software Foundation. | +| For details see http://www.gnu.org/copyleft/gpl.html . | +| | +| If you would like to use this software but the GNU GPL creates legal | +| problems, then please contact the author to negotiate a special | +| agreement. | +| | +========================================================================== +*/ +/* + +Author: Richard P. Brent (random@rpbrent.co.uk) + +Version: 2.01 + +Contents: xor4096s "unsigned long" 32-bit integer RNG, + period (2^4096 - 1)*2^32. + + xor4096f "float" 32-bit real RNG (based on xor4096s). + + xor4096l "unsigned long long" 64-bit integer RNG, + period (2^4096 - 1)*2^64. + + xor4096d "double" 64-bit real RNG (based on xor4096l). + + +Comments: Some fast RNGs with very long periods, using minimal + storage. They use generalisations of (but not exactly the + same as) the xorshift RNGs described by Marsaglia[4]. The + output is combined with a "Weil generator" although + this extra precaution is probably unnecessary. + + The generators are fast, although quality has not been + sacrificed for speed. To speed them up further, the code + could easily be modified to return an array of random numbers + instead of a single number, thus reducing function call + overheads. For the sake of simplicity I have not done this. + + The generators are believed to be of high quality, and have + passed Marsaglia's DIEHARD tests. Of course, users should + apply their own tests. Please inform the author if you + discover any genuine problems. +*/ + + +/*========================================================================*/ + /* +unsigned long xor4096s (unsigned long seed) + + 32-bit random number generator with period at least 2^4096-1. + + Is is assumed that "unsigned long" is a 32-bit integer. + + The method is a generalisation of Marsaglia's xorgen generators, see G. + Marsaglia, "Xorshift RNGs", JSS 8, 14 (2003), Sec. 3.1 (available from + http://www.jstatsoft.org/ ). + + The primary recurrence is x_k = x_{k-r}A + x_{k-s}B, where + + A = (I + L^a)(I + R^b), B = (I + L^c)(I + R^d) + + in the notation of Marsaglia [JSS 8,14 (2003)]. + + We choose r > 1, 0 < s < r, n = 32*r, and (a, b, c, d) such that the n + times n matrix T defining the recurrence has minimal polynomial P which + is of degree n and primitive over GF(2). Thus the period is 2^n-1 and + all possible n-bit sequences (except all zeros) occur in the output over + a full period. Storage is (r + constant) 32-bit words. + + Our generalisation is: + + (1) The block matrix has r times r blocks, where r is a parameter. To + test primitivity we need to be able to factor 2^n-1. Marsaglia + considered some cases with small r. In our implementation r is a power + of 2, but this restriction is easily removed. We use a circular array, + which makes the number of memory references independent of r. + + (2) Marsaglia's block (I + R^c) is replaced by (I + L^c)(I + R^d). + + (3) The block mentioned in (2) is in position (r+1-s,r) instead of + position (r,r) of the block matrix. (Marsaglia considers the case s = + 1.) + + By introducing the additional parameters d and s we increase the set of + candidate recurrences to compensate for the fact that primitive + recurrences get harder to find as n increases. + + The output of the primary recurrence is combined with a Weil generator + to avoid problems with the binary rank test and correlations related to + the sparsity of T. This increases the period by a factor of 2^32. + + Should be called once with nonzero seed, thereafter with zero seed. + + The generator implemented here has parameters (wlen 32, r 128, s 95, a + 17, b 12, c 13, d 15) with Weight(P) 251. Other parameters can be used + by changing the definitions below. + + R. P. Brent, 20040720, last revised 20040802. + */ + +#define wlen 32 +#define r 128 +#define s 95 +#define a 17 +#define b 12 +#define c 13 +#define d 15 + +static unsigned long xor4096s_Bits (void *junk, void *vsta) +{ + static unsigned int w, x[r], weil = 0x61c88647; + unsigned int t, v; + static int i = -1; /* i < 0 indicates first call */ + int k; + if (i < 0) { /* Initialisation necessary */ + int seed = *((unsigned int *) vsta); + v = (seed != 0) ? seed : ~seed; /* v must be nonzero */ + + for (k = wlen; k > 0; k--) /* Avoid correlations for close seeds */ + v ^= (v ^= (v ^= v << 13) >> 17) << 5; /* This recurrence has period + 2^32-1 */ + + for (w = v, k = 0; k < r; k++) + /* Initialise circular array */ + x[k] = (v ^= (v ^= (v ^= v << 13) >> 17) << 5) + (w += weil); + + for (i = r - 1, k = 4 * r; k > 0; k--) { /* Discard first 4*r results + (Gimeno) */ + t = x[i = (i + 1) & (r - 1)]; + v = x[(i + (r - s)) & (r - 1)]; + t ^= (t ^= t << a) >> b; + v ^= v << c; + x[i] = (v ^= t ^ (v >> d)); + } + } + + /* Apart from initialisation (above), this is the generator */ + t = x[i = (i + 1) & (r - 1)]; /* Increment i mod r (r is a power of 2) */ + v = x[(i + (r - s)) & (r - 1)]; /* Index is (i - s) mod r */ + t ^= (t ^= t << a) >> b; /* (I + L^a)(I + R^b) */ + v ^= v << c; /* I + L^c */ + x[i] = (v ^= t ^ (v >> d)); /* Update circular array */ + return (v + (w += weil)); /* Return combination with Weil generator */ +} + +#undef wlen +#undef r +#undef s +#undef a +#undef b +#undef c +#undef d + + +/*-----------------------------------------------------------------------*/ + +static double xor4096s_U01 (void *vpar, void *vsta) +{ + return xor4096s_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void Wr_xor4096 (void *junk) +{ +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ubrent_CreateXor4096s (unsigned int seed) +{ + unif01_Gen *gen; + unsigned int *pseed; + size_t leng; + char name[LEN + 1]; + + util_Assert (co1 == 0, + "ubrent_CreateXor4096s:\n only 1 such generator can be used at a time"); + co1++; + + gen = util_Malloc (sizeof (unif01_Gen)); + pseed = util_Malloc (sizeof (unsigned int)); + *pseed = seed; + strcpy (name, "ubrent_CreateXor4096s:"); + addstr_Uint (name, " seed = ", seed); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &xor4096s_Bits; + gen->GetU01 = &xor4096s_U01; + gen->Write = &Wr_xor4096; + gen->param = NULL; + gen->state = pseed; + /* Discard the first value + xor4096s_Bits (NULL, pseed); */ + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void ubrent_DeleteXor4096s (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); + co1--; +} + + +/*========================================================================*/ + +static unsigned long Xorgen32_Bits (void *vpar, void *vsta) +{ + Xorgen32_param *param = vpar; + Xorgen32_state *state = vsta; + unsigned int t, v; + + /* Increment i mod ... */ + t = state->x[state->i = (state->i + 1) & param->Mask]; + + /* Index is (i - s) mod ... */ + v = state->x[(state->i + (param->r - param->s)) & param->Mask]; + + t ^= (t ^= t << param->a) >> param->b; /* (I + L^a)(I + R^b) */ + v ^= v << param->c; /* I + L^c */ + + /* Update circular array */ + state->x[state->i] = (v ^= t ^ (v >> param->d)); + + if (param->hasWeyl) + /* combination with Weil generator */ + return (v + (state->w += param->weil)); + else + return v; +} + + +/*-----------------------------------------------------------------------*/ + +static double Xorgen32_U01 (void *vpar, void *vsta) +{ + return Xorgen32_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrXorgen32 (void *vsta) +{ + Xorgen32_state *state = vsta; + unsigned int j; + unsigned int s = state->i; + + if (unif01_WrLongStateFlag) { + printf (" i = %u, w = %u\n", state->i, state->w); + printf (" x = {\n "); + for (j = 0; j < state->r2; j++) { + if (++s >= state->r2) + s = 0; + printf (" %12u", state->x[s]); + if (j < state->r2 - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); + +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ubrent_CreateXorgen32 (int r, int s, int a, int b, int c, int d, + lebool hasWeyl, unsigned int seed) +{ + unif01_Gen *gen; + Xorgen32_param *param; + Xorgen32_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int t, v; + const unsigned int wlen = 32; + int i, k; + + util_Assert (r > 1, "ubrent_CreateXorgen32: r <= 1"); + util_Assert (s > 0, "ubrent_CreateXorgen32: s <= 0"); + util_Assert (r > s, "ubrent_CreateXorgen32: r <= s"); + util_Assert (a < 32 && b < 32 && c < 32 && d < 32, + "ubrent_CreateXorgen32: one of a, b, c, d >= 32"); + util_Assert (a > 0 && b > 0 && c > 0 && d > 0, + "ubrent_CreateXorgen32: one of a, b, c, d <= 0"); + + i = 1; + while (i < r) + i <<= 1; + util_Assert (r == i, "ubrent_CreateXorgen32: r is not a power of 2"); + + gen = util_Malloc (sizeof (unif01_Gen)); + + strcpy (name, "ubrent_CreateXorgen32:"); + addstr_Int (name, " r = ", r); + addstr_Int (name, ", s = ", s); + addstr_Int (name, ", a = ", a); + addstr_Int (name, ", b = ", b); + addstr_Int (name, ", c = ", c); + addstr_Int (name, ", d = ", d); + if (hasWeyl) + strncat (name, ", hasWeyl = TRUE", 20); + else + strncat (name, ", hasWeyl = FALSE", 20); + addstr_Uint (name, ", seed = ", seed); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param = util_Malloc (sizeof (Xorgen32_param)); + state = util_Malloc (sizeof (Xorgen32_state)); + + gen->GetBits = &Xorgen32_Bits; + gen->GetU01 = &Xorgen32_U01; + gen->Write = &WrXorgen32; + gen->param = param; + gen->state = state; + + param->hasWeyl = hasWeyl; + param->Mask = r - 1; + state->r2 = r; + state->x = util_Calloc ((size_t) r, sizeof (unsigned int)); + + v = (seed != 0) ? seed : ~seed; /* v must be nonzero */ + + for (k = wlen; k > 0; k--) /* Avoid correlations for close seeds */ + v ^= (v ^= (v ^= v << 13) >> 17) << 5; /* This recurrence has period + 2^32-1 */ + if (hasWeyl) { + param->weil = 0x61c88647; + for (state->w = v, k = 0; k < r; k++) + /* Initialise circular array */ + state->x[k] = (v ^= (v ^= (v ^= v << 13) >> 17) << 5) + + (state->w += param->weil); + } else { + param->weil = 0; + for (k = 0; k < r; k++) + /* Initialise circular array */ + state->x[k] = (v ^= (v ^= (v ^= v << 13) >> 17) << 5); + } + + for (i = r - 1, k = 4 * r; k > 0; k--) { /* Discard first 4*r results + (Gimeno) */ + t = state->x[i = (i + 1) & param->Mask]; + v = state->x[(i + (r - s)) & param->Mask]; + t ^= (t ^= t << a) >> b; + v ^= v << c; + state->x[i] = (v ^= t ^ (v >> d)); + } + + state->i = i; + param->a = a; + param->b = b; + param->c = c; + param->d = d; + param->r = r; + param->s = s; + + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void ubrent_DeleteXorgen32 (unif01_Gen *gen) +{ + Xorgen32_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->x); + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/*========================================================================*/ +#ifdef USE_LONGLONG + +/* unsigned long long xor4096l (unsigned long long seed) + + 64-bit random number generator with period at least 2^4096-1. + + Is is assumed that "unsigned long long" is a 64-bit integer. + + The method is a generalisation of Marsaglia's xorgen generators, see G. + Marsaglia, "Xorshift RNGs", JSS 8, 14 (2003), Sec. 3.1 (available from + http://www.jstatsoft.org/ ). + + The primary recurrence is x_k = x_{k-r}A + x_{k-s}B, where + + A = (I + L^a)(I + R^b), B = (I + L^c)(I + R^d) + + in the notation of Marsaglia [JSS 8,14 (2003)]. + + We choose r > 1, 0 < s < r, n = 64*r, and (a, b, c, d) such that the n + times n matrix T defining the recurrence has minimal polynomial P which + is of degree n and primitive over GF(2). Thus the period is 2^n-1 and + all possible n-bit sequences (except all zeros) occur in the output over + a full period. Storage is (r + constant) 64-bit words. + + Our generalisation is: + + (1) The block matrix has r times r blocks, where r is a parameter. To + test primitivity we need to be able to factor 2^n-1. Marsaglia + considered some cases with small r. In our implementation r is a power + of 2, but this restriction is easily removed. We use a circular array, + which makes the number of memory references independent of r. + + (2) Marsaglia's block (I + R^c) is replaced by (I + L^c)(I + R^d). + + (3) The block mentioned in (2) is in position (r+1-s,r) instead of + position (r,r) of the block matrix. (Marsaglia considers the case s = + 1.) + + By introducing the additional parameters d and s we increase the set of + candidate recurrences to compensate for the fact that primitive + recurrences get harder to find as n increases. + + The output of the primary recurrence is combined with a Weil generator + to avoid problems with the binary rank test and correlations related to + the sparsity of T. This increases the period by a factor of 2^64. + + Should be called once with nonzero seed, thereafter with zero seed. + + The generator implemented here has parameters (wlen 64, r 64, s 53, a + 33, b 26, c 27, d 29) with Weight(P) 961. Other parameters can be used + by changing the definitions below. + + R. P. Brent, 20040721, last revised 20040802. + */ + +#define wlen 64 +#define r 64 +#define s 53 +#define a 33 +#define b 26 +#define c 27 +#define d 29 + +static unsigned long xor4096l_Bits (void *junk, void *vsta) +{ + static ulonglong w, x[r], + weil = ((longlong) 0x61c88646 << 32) + (longlong) 0x80b583eb; + ulonglong t, v; + static int i = -1; /* i < 0 indicates first call */ + int k; + if (i < 0) { /* Initialisation necessary */ + int seed = *((ulonglong *) vsta); + v = (seed != 0) ? seed : ~seed; /* v must be nonzero */ + + for (k = wlen; k > 0; k--) /* Avoid correlations for close seeds */ + v ^= (v ^= v << 7) >> 9; /* This recurrence has period 2^64-1 */ + + for (w = v, k = 0; k < r; k++) + /* Initialise circular array */ + x[k] = (v ^= (v ^= v << 7) >> 9) + (w += weil); + + for (i = r - 1, k = 4 * r; k > 0; k--) { /* Discard first 4*r results + (Gimeno) */ + t = x[i = (i + 1) & (r - 1)]; + v = x[(i + (r - s)) & (r - 1)]; + t ^= (t ^= t << a) >> b; + v ^= v << c; + x[i] = (v ^= t ^ (v >> d)); + } + } + + /* Apart from initialisation (above), this is the generator */ + + t = x[i = (i + 1) & (r - 1)]; /* Increment i mod r (r is a power of 2) */ + v = x[(i + (r - s)) & (r - 1)]; /* Index is (i - s) mod r */ + t ^= (t ^= t << a) >> b; /* (I + L^a)(I + R^b) */ + v ^= v << c; /* I + L^c */ + x[i] = (v ^= t ^ (v >> d)); /* Update circular array */ + t = (v + (w += weil)); /* Return combination with Weil generator */ + return (unsigned long) (t >> 32); +} + +#undef wlen +#undef r +#undef s +#undef a +#undef b +#undef c +#undef d + + +/*-----------------------------------------------------------------------*/ + +static double xor4096l_U01 (void *vpar, void *vsta) +{ + return xor4096l_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ubrent_CreateXor4096l (ulonglong seed) +{ + unif01_Gen *gen; + ulonglong *pseed; + size_t leng; + char name[LEN + 1]; + + util_Assert (co2 == 0, + "ubrent_CreateXor4096l:\n only 1 such generator can be used at a time"); + co2++; + + gen = util_Malloc (sizeof (unif01_Gen)); + pseed = util_Malloc (sizeof (ulonglong)); + *pseed = seed; + strcpy (name, "ubrent_CreateXor4096l:"); + addstr_ULONG (name, " seed = ", seed); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &xor4096l_Bits; + gen->GetU01 = &xor4096l_U01; + gen->Write = &Wr_xor4096; + gen->param = NULL; + gen->state = pseed; + /* Discard the first value + xor4096l_Bits (NULL, pseed); */ + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void ubrent_DeleteXor4096l (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); + co2--; +} + + +/*========================================================================*/ + +static unsigned long Xorgen64_Bits (void *vpar, void *vsta) +{ + Xorgen64_param *param = vpar; + Xorgen64_state *state = vsta; + ulonglong t, v; + + /* Increment i mod r */ + t = state->x[state->i = (state->i + 1) & param->Mask]; + + /* Index is (i - s) mod r */ + v = state->x[(state->i + (param->r - param->s)) & param->Mask]; + + t ^= (t ^= t << param->a) >> param->b; /* (I + L^a)(I + R^b) */ + v ^= v << param->c; /* I + L^c */ + + /* Update circular array */ + state->x[state->i] = (v ^= t ^ (v >> param->d)); + + if (param->hasWeyl) + /* combination with Weil generator */ + return (v + (state->w += param->weil)) >> 32; + else + return v >> 32; +} + + +/*-----------------------------------------------------------------------*/ + +static double Xorgen64_U01 (void *vpar, void *vsta) +{ + return Xorgen64_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrXorgen64 (void *vsta) +{ + Xorgen64_state *state = vsta; + unsigned int j; + unsigned int s = state->i; + + if (unif01_WrLongStateFlag) { + printf (" i = %d, w = %llu\n", state->i, state->w); + printf (" x = {\n "); + for (j = 0; j < state->r2; j++) { + if (++s >= state->r2) + s = 0; + printf (" %20llu", state->x[s]); + if (j < state->r2 - 1) + printf (","); + if ((j % 3) == 2) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); + +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ubrent_CreateXorgen64 (int r, int s, int a, int b, int c, int d, + lebool hasWeyl, ulonglong seed) +{ + unif01_Gen *gen; + Xorgen64_param *param; + Xorgen64_state *state; + size_t leng; + char name[LEN + 1]; + ulonglong t, v; + const unsigned int wlen = 64; + int i, k; + + util_Assert (r > 1, "ubrent_CreateXorgen64: r <= 1"); + util_Assert (s > 0, "ubrent_CreateXorgen64: s <= 0"); + util_Assert (r > s, "ubrent_CreateXorgen64: r <= s"); + util_Assert (a < 64 && b < 64 && c < 64 && d < 64, + "ubrent_CreateXorgen64: one of a, b, c, d >= 64"); + util_Assert (a > 0 && b > 0 && c > 0 && d > 0, + "ubrent_CreateXorgen64: one of a, b, c, d <= 0"); + i = 1; + while (i < r) + i <<= 1; + util_Assert (r == i, "ubrent_CreateXorgen64: r is not a power of 2"); + + gen = util_Malloc (sizeof (unif01_Gen)); + + strcpy (name, "ubrent_CreateXorgen64:"); + addstr_Int (name, " r = ", r); + addstr_Int (name, ", s = ", s); + addstr_Int (name, ", a = ", a); + addstr_Int (name, ", b = ", b); + addstr_Int (name, ", c = ", c); + addstr_Int (name, ", d = ", d); + strncat (name, ", hasWeyl = ", 20); + if (hasWeyl) + strncat (name, "TRUE", 5); + else + strncat (name, "FALSE", 5); + addstr_ULONG (name, ", seed = ", seed); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param = util_Malloc (sizeof (Xorgen64_param)); + state = util_Malloc (sizeof (Xorgen64_state)); + + gen->GetBits = &Xorgen64_Bits; + gen->GetU01 = &Xorgen64_U01; + gen->Write = &WrXorgen64; + gen->param = param; + gen->state = state; + + param->hasWeyl = hasWeyl; + state->r2 = r; + param->Mask = state->r2 - 1; + state->x = util_Calloc ((size_t) state->r2, sizeof (ulonglong)); + + v = (seed != 0) ? seed : ~seed; /* v must be nonzero */ + for (k = wlen; k > 0; k--) /* Avoid correlations for close seeds */ + v ^= (v ^= v << 7) >> 9; /* This recurrence has period 2^64-1 */ + + if (hasWeyl) { + param->weil = ((longlong) 0x61c88646 << 32) + (longlong) 0x80b583eb; + for (state->w = v, k = 0; k < r; k++) + /* Initialise circular array */ + state->x[k] = (v ^= (v ^= v << 7) >> 9) + (state->w += param->weil); + } else { + param->weil = 0; + for (k = 0; k < r; k++) + /* Initialise circular array */ + state->x[k] = (v ^= (v ^= v << 7) >> 9); + } + for (k = r; k < (int) state->r2; k++) + state->x[k] = state->x[k - r]; + + for (i = r - 1, k = 4 * r; k > 0; k--) { /* Discard first 4*r results + (Gimeno) */ + t = state->x[i = (i + 1) & param->Mask]; + v = state->x[(i + (r - s)) & param->Mask]; + t ^= (t ^= t << a) >> b; + v ^= v << c; + state->x[i] = (v ^= t ^ (v >> d)); + } + + state->i = i; + param->a = a; + param->b = b; + param->c = c; + param->d = d; + param->r = r; + param->s = s; + + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void ubrent_DeleteXorgen64 (unif01_Gen *gen) +{ + Xorgen64_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->x); + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/*========================================================================*/ +/* +double xor4096d (unsigned long long seed) + + 64-bit real random number generator with period at least 2^4096-1. + + Is is assumed that "unsigned long long" is a 64-bit integer and "double" + is an IEEE standard 64-bit floating-point number with 52 explicit + 1 + implicit bits in the fraction. + + The method used is as for the 64-bit integer RNG xor4096l, then the high + 53 bits (if nonzero) are scaled to (0.0, 1.0). + + Should be called once with nonzero seed, thereafter with zero seed. + + The result should uniformly distributed in (0.0, 1.0) to the resolution + of the floating-point system. The result is never exactly 0.0 or 1.0. + + R. P. Brent, 20040802. + +*/ + +#define wlen 64 +#define r 64 +#define s 53 +#define a 33 +#define b 26 +#define c 27 +#define d 29 + +static double xor4096d_U01 (void *junk, void *vsta) +{ + static ulonglong w, x[r], + weil = ((longlong) 0x61c88646 << 32) + (longlong) 0x80b583eb; + ulonglong t, v; + static double t53 = (double) 1 / (double)((longlong) 1 << 53); /* 0.5**53*/ + static int i = -1; /* i < 0 indicates first call */ + int k; + if (i < 0) { /* Initialisation necessary */ + int seed = *((ulonglong *) vsta); + v = (seed != 0) ? seed : ~seed; /* v must be nonzero */ + + for (k = wlen; k > 0; k--) /* Avoid correlations for close seeds */ + v ^= (v ^= v << 7) >> 9; /* This recurrence has period 2^64-1 */ + + for (w = v, k = 0; k < r; k++) + /* Initialise circular array */ + x[k] = (v ^= (v ^= v << 7) >> 9) + (w += weil); + + for (i = r - 1, k = 4 * r; k > 0; k--) { /* Discard first 4*r results + (Gimeno) */ + t = x[i = (i + 1) & (r - 1)]; + v = x[(i + (r - s)) & (r - 1)]; + t ^= (t ^= t << a) >> b; + v ^= v << c; + x[i] = (v ^= t ^ (v >> d)); + } + } + + /* Apart from initialisation (above), this is the generator */ + + v = 0; /* Usually execute while loop once */ + while (v == (longlong) 0) { /* Loop until result nonzero */ + t = x[i = (i + 1) & (r - 1)]; /* Increment i mod r (r = power of 2) */ + v = x[(i + (r - s)) & (r - 1)]; /* Index is (i - s) mod r */ + t ^= (t ^= t << a) >> b; /* (I + L^a)(I + R^b) */ + v ^= v << c; /* I + L^c */ + x[i] = (v ^= t ^ (v >> d)); /* Update circular array */ + v += (w += weil); /* 64-bit unsigned integer */ + v >>= 11; /* 53-bit integer (possibly zero) */ + } + return t53 * (double) v; /* Scale to (0.0, 1.0) */ + } + +#undef wlen +#undef r +#undef s +#undef a +#undef b +#undef c +#undef d + +/*-----------------------------------------------------------------------*/ + +static unsigned long xor4096d_Bits (void *vpar, void *vsta) +{ + return xor4096d_U01 (vpar, vsta) * unif01_NORM32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ubrent_CreateXor4096d (ulonglong seed) +{ + unif01_Gen *gen; + ulonglong *pseed; + size_t leng; + char name[LEN + 1]; + + util_Assert (co3 == 0, + "ubrent_CreateXor4096d:\n only 1 such generator can be used at a time"); + co3++; + + gen = util_Malloc (sizeof (unif01_Gen)); + pseed = util_Malloc (sizeof (ulonglong)); + *pseed = seed; + strcpy (name, "ubrent_CreateXor4096d:"); + addstr_ULONG (name, " seed = ", seed); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &xor4096d_Bits; + gen->GetU01 = &xor4096d_U01; + gen->Write = &Wr_xor4096; + gen->param = NULL; + gen->state = pseed; + /* Discard the first value + xor4096d_Bits (NULL, pseed); */ + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void ubrent_DeleteXor4096d (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); + co3--; +} + + +/*========================================================================*/ +#endif + + +/**************************************************************************/ +/********** HERE BEGIN BRENT'S RNGs FROM THE 2006 VERSION *****************/ + + +typedef unsigned long UINT; /* Type for random 32 or 64-bit integer, + e.g. unsigned long, unsigned long long, + uint64_t, unsigned int or uint32_t */ + +typedef double UREAL; /* Type for random 32 or 64-bit real, e.g. + double or float */ + +/* xorgens.c version 3.04, R. P. Brent, 20060628. */ + +/* For type definitions see xorgens.h */ + +static UINT xor4096i (UINT seed) +{ + /* 32-bit or 64-bit integer random number generator with period at least + 2**4096-1. + + It is assumed that "UINT" is a 32-bit or 64-bit integer (see typedef + statements in xorgens.h). + + xor4096i should be called exactly once with nonzero seed, and thereafter + with zero seed. + + One random number uniformly distributed in [0..2**wlen) is returned, + where wlen = 8*sizeof(UINT) = 32 or 64. + + R. P. Brent, 20060628. */ + + /* UINT64 is TRUE if 64-bit UINT, UINT32 is TRUE otherwise (assumed to be + 32-bit UINT). */ + +#define UINT64 (sizeof(UINT)>>3) +#define UINT32 (1 - UINT64) + +#define wlen (64*UINT64 + 32*UINT32) +#define r (64*UINT64 + 128*UINT32) +#define s (53*UINT64 + 95*UINT32) +#define a (33*UINT64 + 17*UINT32) +#define b (26*UINT64 + 12*UINT32) +#define c (27*UINT64 + 13*UINT32) +#define d (29*UINT64 + 15*UINT32) +#define ws (27*UINT64 + 16*UINT32) + + static UINT w, weyl, zero = 0, x[r]; + UINT t, v; + static int i = -1; /* i < 0 indicates first call */ + int k; + if ((i < 0) || (seed != zero)) { /* Initialisation necessary */ + + /* weyl = odd approximation to 2**wlen*(sqrt(5)-1)/2. */ + + if (UINT32) + weyl = 0x61c88647; + else + weyl = ((((UINT) 0x61c88646) << 16) << 16) + (UINT) 0x80b583eb; + + v = (seed != zero) ? seed : ~seed; /* v must be nonzero */ + + for (k = wlen; k > 0; k--) { /* Avoid correlations for close seeds */ + v ^= v << 10; + v ^= v >> 15; /* Recurrence has period 2**wlen-1 */ + v ^= v << 4; + v ^= v >> 13; /* for wlen = 32 or 64 */ + } + for (w = v, k = 0; k < r; k++) { /* Initialise circular array */ + v ^= v << 10; + v ^= v >> 15; + v ^= v << 4; + v ^= v >> 13; + x[k] = v + (w += weyl); + } + for (i = r - 1, k = 4 * r; k > 0; k--) { /* Discard first 4*r results */ + t = x[i = (i + 1) & (r - 1)]; + t ^= t << a; + t ^= t >> b; + v = x[(i + (r - s)) & (r - 1)]; + v ^= v << c; + v ^= v >> d; + x[i] = t ^ v; + } + } + + /* Apart from initialisation (above), this is the generator */ + + t = x[i = (i + 1) & (r - 1)]; /* Assumes that r is a power of two */ + v = x[(i + (r - s)) & (r - 1)]; /* Index is (i-s) mod r */ + t ^= t << a; + t ^= t >> b; /* (I + L^a)(I + R^b) */ + v ^= v << c; + v ^= v >> d; /* (I + L^c)(I + R^d) */ + x[i] = (v ^= t); /* Update circular array */ + w += weyl; /* Update Weyl generator */ + return (v + (w ^ (w >> ws))); /* Return combination */ + +#undef UINT64 +#undef UINT32 +#undef wlen +#undef r +#undef s +#undef a +#undef b +#undef c +#undef d +#undef ws +} + + +/*-----------------------------------------------------------------------*/ + +static UINT xor4096i_Bits (void *junk, void *vsta) +{ + UINT seed = *((UINT *) vsta); + UINT Z = xor4096i(seed); + *((UINT *) vsta) = 0; +#if ULONG_MAX <= 4294967295UL + return Z; +#else + return Z >> 32; +#endif +} + + +static double xor4096i_U01 (void *vpar, void *vsta) +{ + return xor4096i_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ubrent_CreateXor4096i (unsigned long seed) +{ + unif01_Gen *gen; + unsigned long *pseed; + size_t leng; + char name[LEN + 1]; + + util_Assert (co4 == 0, + "ubrent_CreateXor4096i:\n only 1 such generator can be used at a time"); + co4++; + + gen = util_Malloc (sizeof (unif01_Gen)); + pseed = util_Malloc (sizeof (unsigned long)); + *pseed = seed; + strcpy (name, "ubrent_CreateXor4096i:"); + addstr_Ulong (name, " seed = ", seed); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &xor4096i_Bits; + gen->GetU01 = &xor4096i_U01; + gen->Write = &Wr_xor4096; + gen->param = NULL; + gen->state = pseed; + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void ubrent_DeleteXor4096i (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); + co4--; +} + + +/*========================================================================*/ + +static UREAL xor4096r (UINT seed) +{ + /* 64-bit or 32-bit real random number generator with period at least + 2**4096-1. + + It is assumed that "UINT" is a 32-bit or 64-bit integer and "UREAL" is + "double" or "float". If "double" this is an IEEE standard floating-point + number with 53 bits in the fraction; if "single" it has 24 bits in the + fraction (including 1 implicit bit in each case). + + In the 64-bit integer case, the method used is to call xor4096i to get + 64 random bits, then the high 53 (for double) or 24 bits (for float) are + scaled to the open interval (0.0, 1.0), except that they are discarded + if all zero. + + In the 32-bit integer case, one or two calls to xor4096i are made to get + 32 or 64 random bits, some are discarded, and the remaining bits (if + nonzero) are scaled to the open interval (0.0, 1.0). + + xor4096r should be called exactly once with nonzero seed, and thereafter + with zero seed. + + One random number of type UREAL is returned per call. + + The results be should uniformly distributed in (0.0, 1.0) to the + resolution of the floating-point system (0.5**53 or 0.5**24). + + The results are never exactly 0.0 or 1.0. + + R. P. Brent, 20060628. */ + +#define UINT64 (sizeof(UINT)>>3) +#define UINT32 (1 - UINT64) +#define UREAL64 (sizeof(UREAL)>>3) +#define UREAL32 (1 - UREAL64) + +/* sr = number of bits discarded = 11 for double, 40 or 8 for float */ + +#define sr (11*UREAL64 +(40*UINT64 + 8*UINT32)*UREAL32) + +/* ss (used for scaling) is 53 or 21 for double, 24 for float */ + +#define ss ((53*UINT64 + 21*UINT32)*UREAL64 + 24*UREAL32) + +/* SCALE is 0.5**ss, SC32 is 0.5**32 */ + +#define SCALE ((UREAL)1/(UREAL)((UINT)1<> sr); /* Discard sr random bits. */ + seed = (UINT) 0; /* Zero seed for next time. */ + if (UINT32 && UREAL64) /* Need another call to xor4096i. */ + res += SC32 * (UREAL) xor4096i (seed); /* Add low-order 32 bits. */ + } + return (SCALE * res); /* Return result in (0.0, 1.0). */ + +#undef UINT64 +#undef UINT32 +#undef UREAL64 +#undef UREAL32 +#undef SCALE +#undef SC32 +#undef sr +#undef ss +} + + +/*-----------------------------------------------------------------------*/ + +static double xor4096r_U01 (void *junk, void *vsta) +{ + UINT seed = *((UINT *) vsta); + double u = xor4096r(seed); + *((UINT *) vsta) = 0; + return u; +} + + +static unsigned long xor4096r_Bits (void *vpar, void *vsta) +{ + return xor4096r_U01 (vpar, vsta) * unif01_NORM32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ubrent_CreateXor4096r (unsigned long seed) +{ + unif01_Gen *gen; + unsigned long *pseed; + size_t leng; + char name[LEN + 1]; + + util_Assert (co5 == 0, + "ubrent_CreateXor4096r:\n only 1 such generator can be used at a time"); + co5++; + + gen = util_Malloc (sizeof (unif01_Gen)); + pseed = util_Malloc (sizeof (unsigned long)); + *pseed = seed; + strcpy (name, "ubrent_CreateXor4096r:"); + addstr_ULONG (name, " seed = ", seed); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &xor4096r_Bits; + gen->GetU01 = &xor4096r_U01; + gen->Write = &Wr_xor4096; + gen->param = NULL; + gen->state = pseed; + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void ubrent_DeleteXor4096r (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); + co5--; +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ubrent.tex b/TESTU01/TestU01-1.2.3/testu01/ubrent.tex new file mode 100644 index 0000000..abb6d7b --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ubrent.tex @@ -0,0 +1,208 @@ +\defmodule {ubrent} + +This module implements some random number generators proposed by Richard + P. Brent (Web pages at \index{Generator!Xorshift}% +\url{http://web.comlab.ox.ac.uk/oucl/work/richard.brent/} +and \url{http://wwwmaths.anu.edu.au/~brent/random.html}). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* ubrent.h for ANSI C */ +#ifndef UBRENT_H +#define UBRENT_H +\endhide +#include "gdef.h" +#include "unif01.h" +\endcode + +\guisec{The xorgens generators, version 2004} +\code + +unif01_Gen* ubrent_CreateXorgen32 (int r, int s, int a, int b, int c, int d, + lebool hasWeyl, unsigned int seed); +\endcode + \tab Some fast long-period random number generators \cite{rBRE04a} + generalizing Marsaglia's \textit{Xorshift} RNGs \cite{rMAR03a} + (see page \pageref{marsa-xorshift} of this guide). The + output may be combined with a Weyl generator. + % (This is the \textbf{2004 version} of these generators.) + The parameters $r, s, a, b, c, d$ are chosen such that the $n \times n$ + matrix $T$ defining the recurrence has a minimal polynomial which +\index{Generator!Xorgen32}% + is of degree $n$ and primitive over $\mathbb{F}_2$. +The state of the generator is made up of $n= 32 r$ bits. +The primary recurrence is $x_k = x_{k-r}A + x_{k-s}B$, where matrices +$A$ and $B$ implement a combination of left and right shifts; + in the notation of Marsaglia, $A = (I + L^a)(I + R^b)$ and + $B = (I + L^c)(I + R^d)$ with + $I$ the identity matrix, $L^a$ a left shift by $a$ bits, +and $R^b$ a right shift by $b$ bits. If \texttt{hasWeyl} is \texttt{TRUE}, +then the Weyl combination is added to the output as in Brent original +code. If it is \texttt{FALSE}, then no Weyl combination is added; + this is useful for testing these \textit{xorgens} by themselves. +Restrictions: $r > 1$, $0 < s < r$ and $0 < a,b,c,d < 32$, +and $r$ must be a power of 2. +% +The following table gives parameters recommended by Brent +for the \textit{best} 32-bit generators of this kind +according to the criteria given in \url{ftp://ftp.comlab.ox.ac.uk/pub/Documents/techpapers/Richard.Brent/random/xortable.txt}. +\endtab +% +\begin {table} +\centering +\label {tab:brentparam32} +\caption {Good parameters for Brent's \texttt{xorgens} generators} +\begin {tabular}{@{\extracolsep{15pt}}|rrrcccccc|} +\hline + $n$ & $r$ & $s$ & $a$ & $b$ & $c$ & $d$ & Weight & delta \\ +\hline + 64 & 2 & 1 & 17 & 14 & 12 & 19 & \phantom{1}31 & 12 \\ + 128 & 4 & 3 & 15 & 14 & 12 & 17 & \phantom{1}55 & 12 \\ + 256 & 8 & 3 & 18 & 13 & 14 & 15 & 109 & 13 \\ + 512 & 16 & 1 & 17 & 15 & 13 & 14 & 185 & 13 \\ + 1024 & 32 & 15 & 19 & 11 & 13 & 16 & 225 & 11 \\ + 2048 & 64 & 59 & 19 & 12 & 14 & 15 & 213 & 12 \\ + 4096 & 128 & 95 & 17 & 12 & 13 & 15 & 251 & 12 \\ +% 4224 & 132 & 67 & 15 & 14 & 13 & 18 & 243 & 13 \\ +% 4480 & 140 & 19 & 17 & 13 & 15 & 16 & 251 & 13 \\ +\hline +\end {tabular} +\end {table} +\code + +unif01_Gen* ubrent_CreateXor4096s (unsigned int seed); +\endcode + \tab This is the 32-bit generator \textit{xor4096s} with period + $2^{32}(2^{4096}-1)$ proposed by Brent \cite{rBRE04a}. +% (This is the \textbf{2004 version} of this generator.) + It is a generalization of + Marsaglia's \textit{Xorshift} generators \cite{rMAR03a} (see page + \pageref{marsa-xorshift} of this guide). + The initial seed is \texttt{seed}. This generator corresponds to the more +general case above with parameters +$n=4096$, $r=128$, $s=95$, $a=17$, $b=12$, $c=13$, $d=15$, + Weight $=251$, delta $=12$. +\index{Generator!xor4096s}% + \endtab +\code + + +#ifdef USE_LONGLONG + +unif01_Gen* ubrent_CreateXorgen64 (int r, int s, int a, int b, int c, int d, + lebool hasWeyl, ulonglong seed); +\endcode + \tab Similar to \texttt{ubrent\_CreateXorgen32} above but with 64-bit + generators. % (This is the \textbf{2004 version} of these generators.) + The state of the generator is made up of $n= 64 r$ bits, + but only the 32 most significant bits + of each generated number are used here. +\index{Generator!Xorgen64}% + Restrictions: $r > 1$, $0 < s < r$ and $0 < a,b,c,d < 64$, + and $r$ must be a power of 2. +The following table gives parameters recommended by Brent +for the \textit{best} generators of their kind +according to the criteria given in \url{ftp://ftp.comlab.ox.ac.uk/pub/Documents/techpapers/Richard.Brent/random/xortable.txt}. +\endtab +% +\begin {table} +\centering +\label {tab:brentparam64} +\caption {Good parameters for Brent's \texttt{xorgens} generators} +\begin {tabular}{@{\extracolsep{15pt}}|rrrcccccc|} +\hline + $n$ & $r$ & $s$ & $a$ & $b$ & $c$ & $d$ & Weight & delta \\ +\hline + 128 & 2 & 1 & 33 & 31 & 28 & 29 & 65 & 28 \\ + 256 & 4 & 3 & 37 & 27 & 29 & 33 & 127 & 27 \\ + 512 & 8 & 1 & 37 & 26 & 29 & 34 & 231 & 26 \\ + 1024 & 16 & 7 & 34 & 29 & 25 & 31 & 439 & 25 \\ + 2048 & 32 & 1 & 35 & 27 & 26 & 37 & 745 & 26 \\ + 4096 & 64 & 53 & 33 & 26 & 27 & 29 & 961 & 26 \\ +% 4224 & 66 & 41 & 33 & 31 & 27 & 29 & 987 & 27 \\ +% 4480 & 70 & 61 & 34 & 29 & 30 & 31 & 951 & 29 \\ +\hline +\end {tabular} +\end {table} +\code + + +unif01_Gen* ubrent_CreateXor4096l (ulonglong seed); +\endcode + \tab This is the 64-bit generator \textit{xor4096l} with period at least + $(2^{4096}-1)$ proposed by Brent \cite{rBRE04a}. +% (This is the \textbf{2004 version} of this generator.) + It is a generalization of Marsaglia's \textit{Xorshift} generators + \cite{rMAR03a} (see page \pageref{marsa-xorshift} of this guide). + The initial seed is \texttt{seed}. While Brent's original code returns + 64-bit numbers, only the 32 most significant bits + of each generated number are used here. +\index{Generator!xor4096l}% + \endtab +\code + + +unif01_Gen* ubrent_CreateXor4096d (ulonglong seed); +\endcode + \tab This is the 53-bit floating-point generator \textit{xor4096d} + with period at least $(2^{4096}-1)$ proposed by Brent \cite{rBRE04a}. + % (This is the \textbf{2004 version} of this generator.) + It is based on \textit{xor4096l} (implemented in \texttt{ubrent\_CreateXor4096l} + above) and uses its 53 most significant bits. The initial seed is \texttt{seed}. +\index{Generator!xor4096d}% + \endtab +\code + +#endif +\endcode + +\guisec{The xorgens generators, version 2006} +\code + +unif01_Gen* ubrent_CreateXor4096i (unsigned long seed); +\endcode + \tab This is the % 32-bit (on 32-bit machine) or 64-bit (on 64-bit machine) + integer random number generator \textit{xor4096i} with period at least + $(2^{4096}-1)$ proposed by Brent (see + \url{http://wwwmaths.anu.edu.au/~brent/random.html}). This is the + {2006 version} of the generators \textit{xor4096s} and + \textit{xor4096l}. It has a different initialization and a slightly + different algorithm from the 2004 version. +\index{Generator!xor4096i}% + \endtab +\code + + +unif01_Gen* ubrent_CreateXor4096r (unsigned long seed); +\endcode + \tab This is the floating-point generator \textit{xor4096r} proposed by Brent + (see \url{http://wwwmaths.anu.edu.au/~brent/random.html}). + This is the {2006 version} of the generators \textit{xor4096f} and + \textit{xor4096d}. It is based on \textit{xor4096i} implemented in + \texttt{ubrent\_CreateXor4096i} above. The initial seed is \texttt{seed}. +\index{Generator!xor4096r}% + \endtab + + +\guisec{Clean-up functions} +\code + +void ubrent_DeleteXorgen32 (unif01_Gen *); +void ubrent_DeleteXor4096s (unif01_Gen *); +void ubrent_DeleteXor4096i (unif01_Gen *); +void ubrent_DeleteXor4096r (unif01_Gen *); + +#ifdef USE_LONGLONG + void ubrent_DeleteXorgen64 (unif01_Gen *); + void ubrent_DeleteXor4096l (unif01_Gen *); + void ubrent_DeleteXor4096d (unif01_Gen *); +#endif +\endcode + \tab Frees the dynamic memory allocated by the corresponding + \texttt{Create} functions of this module. \endtab +\code\hide +#endif +\endhide\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ucarry.c b/TESTU01/TestU01-1.2.3/testu01/ucarry.c new file mode 100644 index 0000000..683f8cc --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ucarry.c @@ -0,0 +1,1225 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ucarry.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "ucarry.h" +#include "unif01.h" + +#include +#include +#include + + + +/*=============================== Constants ===============================*/ + +#define LEN 300 + +#define IDEF 314159265 /* Constants for Ranlux */ +#define ICONS 2147483563 +#define LUXS 10 +#define LUXR 24 +#define TwoM24 0.596046447753906250E-7 /* 1 / 2^24 */ +#define TwoM12 0.2441406250E-3 /* 1 / 2^12 */ + + +#define MASK16 0xffff /* Mask of 16 bits */ +#define MASK32 0xffffffffU /* Mask of 32 bits */ + + + + +/*=============================== Types =================================*/ + +typedef struct { + unsigned long M; /* Modulus */ + double Norm; /* 1 / M */ + lebool rFlag; /* = TRUE if r >= s, FALSE if r < s */ + int skip; /* For luxury: skip = Lux - S numbers */ +} AWC_param; + +typedef struct { + unsigned long *X; /* State */ + unsigned int C; /* Carry */ + unsigned int R, S; /* Lags */ + unsigned int n; /* how many since last skip */ + unsigned int Order; /* Order */ +} AWC_state; + +/*-----------------------------------------------------------------------*/ + +typedef AWC_param SWB_param; +typedef AWC_state SWB_state; + +/*-----------------------------------------------------------------------*/ + +typedef struct { + int Next[LUXR + 1]; + int skip; +} Ranlux_param; + +typedef struct { + double X[LUXR + 1]; /* State */ + double C; /* Carry */ + unsigned int R, S; /* Lags */ + unsigned int RR; /* Skip index */ +} Ranlux_state; + +/*-----------------------------------------------------------------------*/ +#ifdef USE_LONGLONG + +typedef struct { + unsigned long *A; + unsigned int W; + unsigned int shift; + ulonglong mask; +} MWC_param; + +typedef struct { + unsigned long *X; /* State */ + ulonglong C; /* Carry */ + unsigned int R; + unsigned int Order; /* Order */ +} MWC_state; + +#endif +/*-----------------------------------------------------------------------*/ + +typedef struct { + unsigned long *A; + unsigned int W; + unsigned int shift; + unsigned long mask; + unsigned long aa; /* a0^(-1) mod 2^w */ + double Norm; /* 1 / 2^w */ +} MWCFloat_param; + +typedef struct { + unsigned long *X; /* State */ + unsigned long C; /* Carry */ + unsigned int R; + unsigned int Order; /* Order */ +} MWCFloat_state; + +/*-----------------------------------------------------------------------*/ + +typedef struct { + unsigned int x1, x2, x3, x4, + x5, x6, x7, x8; /* State */ + unsigned int C; /* Carry */ +} MWCfixCouture_state; + +/*-----------------------------------------------------------------------*/ + +typedef struct { + unsigned int *A; + unsigned int Asize; + unsigned int W; + unsigned int shift; + unsigned int mask; +} SWC_param; + +typedef struct { + unsigned int *X; /* State */ + unsigned int C; /* Carry */ + unsigned int R, S; + unsigned int Order; /* Order */ +} SWC_state; + +/*-----------------------------------------------------------------------*/ + +typedef struct { + unsigned int a, b; +} MWC1616_param; + +typedef struct { + unsigned int x, y; +} MWC1616_state; + + + + + + +/*============================= Functions ===============================*/ + +/* CreateGen common to generators AWC et SWB */ + +static unif01_Gen *Create_AWC_SWB (unsigned int r, unsigned int s, + unsigned long c, unsigned long m, unsigned long S[], const char nom[]) +{ + unif01_Gen *gen; + AWC_param *param; + AWC_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int j, rs; + + if ((c != 0 && c != 1) || (s < 1) || (r < 1) || (r == s)) { + strcpy (name, nom); + strcat (name, ": invalid parameter"); + util_Error (name); + } + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (AWC_param)); + state = util_Malloc (sizeof (AWC_state)); + if (r > s) { + param->rFlag = TRUE; + rs = r; + } else { + rs = s; + param->rFlag = FALSE; + } +/* param->skip = Lux - rs; */ + state->X = util_Calloc ((size_t) rs + 1, sizeof (unsigned long)); + + strncpy (name, nom, (size_t) LEN); + strcat (name, ": "); + addstr_Uint (name, "r = ", r); + addstr_Uint (name, ", s = ", s); + addstr_Ulong (name, ", c = ", c); + addstr_Ulong (name, ", m = ", m); +/* if (Lux > 0) + addstr_Int (name, ", Lux = ", Lux); */ + addstr_ArrayUlong (name, ", S = ", (int) rs, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (m == 0) { + for (j = 0; j < rs; j++) + state->X[j] = S[j] & MASK32; + util_Warning (1, "AWC or SWB: m = 0; I will assume m = 2^32"); + } else + for (j = 0; j < rs; j++) + state->X[j] = S[j] % m; + + if (param->rFlag) + state->S = r - s; + else + state->S = s - r; + state->R = 0; + state->C = c; + state->Order = rs; + state->n = 0; + param->M = m; + if (m == 0) + param->Norm = unif01_INV32; + else + param->Norm = 1.0 / m; + gen->param = param; + gen->state = state; + return gen; +} + +/***************************************************************************/ + +static double AWC_U01 (void *vpar, void *vsta) +{ + AWC_param *param = vpar; + AWC_state *state = vsta; + unsigned long x, temp; + + x = state->X[state->R] + state->C; + temp = param->M - state->X[state->S]; + if (x < temp) { + x += state->X[state->S]; + state->C = 0; + } else { + x -= temp; + state->C = 1; + } + state->X[state->R] = x; + state->R = (state->R + 1) % state->Order; + state->S = (state->S + 1) % state->Order; + return (x * param->Norm); +} + +static unsigned long AWC_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * AWC_U01 (vpar, vsta)); +} + +static void WrAWC (void *vsta) +{ + AWC_state *state = vsta; + unsigned int j; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < state->Order; j++) { + printf (" %12lu", state->X[j]); + if (j < state->Order - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n\n"); + printf (" c = %1u\n\n", state->C); + } else + unif01_WrLongStateDef (); +} + +unif01_Gen *ucarry_CreateAWC (unsigned int r, unsigned int s, + unsigned long c, unsigned long m, unsigned long S[]) +{ + unif01_Gen *gen; + + gen = Create_AWC_SWB (r, s, c, m, S, "ucarry_CreateAWC"); + gen->GetBits = &AWC_Bits; + gen->GetU01 = &AWC_U01; + gen->Write = &WrAWC; + return gen; +} + +void ucarry_DeleteAWC (unif01_Gen * gen) +{ + AWC_state *state; + + if (NULL == gen) + return; + state = gen->state; + util_Free (state->X); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/***************************************************************************/ + +static double SWB_U01 (void *vpar, void *vsta) +{ + SWB_param *param = vpar; + SWB_state *state = vsta; + unsigned long x, y; + + if (param->rFlag) { + x = state->X[state->R]; + y = state->X[state->S] + state->C; + } else { + x = state->X[state->S]; + y = state->X[state->R] + state->C; + } + if (x < y) { + x = (param->M - y) + x; + state->C = 1; + } else { + x -= y; + state->C = 0; + } + state->X[state->R] = x; + + state->S++; + if (state->S == state->Order) + state->S = 0; + state->R++; + if (state->R == state->Order) + state->R = 0; +#if 0 + state->n++; + if (state->n == state->Order) { + unsigned long z; + int i; + for (i = 0; i < param->skip; i++) { + if (param->rFlag) { + z = state->X[state->R]; + y = state->X[state->S] + state->C; + } else { + z = state->X[state->S]; + y = state->X[state->R] + state->C; + } + if (z < y) { + z = (param->M - y) + z; + state->C = 1; + } else { + z -= y; + state->C = 0; + } + state->X[state->R] = z; + + state->S++; + if (state->S == state->Order) + state->S = 0; + state->R++; + if (state->R == state->Order) + state->R = 0; + } + state->n = 0; + } +#endif + + return (x * param->Norm); +} + +static unsigned long SWB_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SWB_U01 (vpar, vsta)); +} + +static void WrSWB (void *vsta) +{ + WrAWC (vsta); +} + +unif01_Gen *ucarry_CreateSWB (unsigned int r, unsigned int s, + unsigned long c, unsigned long m, unsigned long S[]) +{ + unif01_Gen *gen; + + gen = Create_AWC_SWB (r, s, c, m, S, "ucarry_CreateSWB"); + gen->GetBits = &SWB_Bits; + gen->GetU01 = &SWB_U01; + gen->Write = &WrSWB; + return gen; +} + +void ucarry_DeleteSWB (unif01_Gen * gen) +{ + ucarry_DeleteAWC (gen); +} + + +/**************************************************************************/ + +static double Ranlux_U01 (void *vpar, void *vsta) +{ + Ranlux_param *param = vpar; + Ranlux_state *state = vsta; + double Uni, wi; + int i; + + Uni = state->X[state->S] - state->X[state->R] - state->C; + state->C = 0.0; + if (Uni < 0.0) { + Uni += 1.0; + state->C = TwoM24; + } + state->X[state->R] = Uni; + state->R = param->Next[state->R]; + state->S = param->Next[state->S]; + + wi = Uni; + if (Uni < TwoM12) { + wi += state->X[state->S] * TwoM24; + if (wi == 0.0) { + wi = TwoM24 * TwoM24; + } + } + /* Skipping to luxury: generate LUXR values and skip (Lux - LUXR) values */ + state->RR++; + if (state->RR == LUXR) { + state->RR = 0; + for (i = 1; i <= param->skip; i++) { + Uni = state->X[state->S] - state->X[state->R] - state->C; + state->C = 0.0; + if (Uni < 0.0) { + Uni += 1.0; + state->C = TwoM24; + } + state->X[state->R] = Uni; + state->R = param->Next[state->R]; + state->S = param->Next[state->S]; + } + } + return wi; +} + +static unsigned long Ranlux_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Ranlux_U01 (vpar, vsta)); +} + +static void WrRanlux (void *vsta) +{ + Ranlux_state *state = vsta; + int j; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 1; j <= LUXR; j++) { + printf (" %10.7f", state->X[j]); + if (j < LUXR) + printf (", "); + if (((j - 1) % 5) == 4) + printf ("\n "); + }; + printf (" }\n\n"); + } else + unif01_WrLongStateDef (); +} + +unif01_Gen *ucarry_CreateRanlux (unsigned int Lux, long s) +{ + unif01_Gen *gen; + Ranlux_param *param; + Ranlux_state *state; + size_t leng; + char name[LEN + 1]; + int i; + long z, x0, temp; + + if (Lux < 24) + util_Error ("ucarry_CreateRanlux: Lux < 24"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Ranlux_param)); + state = util_Malloc (sizeof (Ranlux_state)); + + strncpy (name, "ucarry_CreateRanlux:", (size_t) LEN); + addstr_Ulong (name, " Lux = ", Lux); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->skip = Lux - LUXR; + state->RR = 0; + if (s == 0) + s = IDEF; /* default initial value */ + z = s; + for (i = 1; i <= LUXR; i++) { + x0 = z / 53668; + z = 40014 * (z - x0 * 53668) - x0 * 12211; + if (z < 0) + z += ICONS; + temp = z % 16777216; + state->X[i] = temp * TwoM24; + param->Next[i] = i - 1; + } + param->Next[1] = LUXR; + state->R = LUXR; + state->S = LUXS; + state->C = 0.0; + if (state->X[LUXR] == 0.0) + state->C = TwoM24; + + gen->GetBits = &Ranlux_Bits; + gen->GetU01 = &Ranlux_U01; + gen->Write = &WrRanlux; + gen->param = param; + gen->state = state; + return gen; +} + +void ucarry_DeleteRanlux (unif01_Gen * gen) +{ + unif01_DeleteGen (gen); +} + + +/************************************************************************/ +#ifdef USE_LONGLONG + +static unsigned long MWC_Bits (void *vpar, void *vsta) +{ + MWC_param *param = vpar; + MWC_state *state = vsta; + unsigned int i, j; + unsigned long SomC; + + for (j = 0; j < state->Order; j++) { + if (param->A[j] != 0) { + i = j + state->R; + if (i >= state->Order) + i -= state->Order; + state->C += param->A[j] * (ulonglong) state->X[i]; + } + } + SomC = state->C & param->mask; + state->X[state->R] = SomC; + state->C >>= param->W; + state->R++; + if (state->R >= state->Order) + state->R = 0; + return (SomC << param->shift) & MASK32; +} + +static double MWC_U01 (void *vpar, void *vsta) +{ + return (MWC_Bits (vpar, vsta) * unif01_INV32); +} + + +static void WrMWC (void *vsta) +{ + MWC_state *state = vsta; + unsigned int j; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < state->Order - 1; j++) { + printf ("%10lu, ", state->X[j]); + if (((j + 1) % 5) == 0) + printf ("\n "); + } + printf ("%10lu }\n\n", state->X[state->Order - 1]); + printf (" c = %1" PRIuLEAST64 "\n\n", state->C); + } else + unif01_WrLongStateDef (); +} + +unif01_Gen *ucarry_CreateMWC (unsigned int r, unsigned long c, + unsigned int w, unsigned long A[], unsigned long S[]) +{ + unif01_Gen *gen; + MWC_param *param; + MWC_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int j; + ulonglong Suma; + + if (w > 32) + util_Error ("ucarry_CreateMWC: w > 32"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MWC_param)); + state = util_Malloc (sizeof (MWC_state)); + state->X = util_Calloc ((size_t) r, sizeof (unsigned long)); + param->A = util_Calloc ((size_t) r, sizeof (unsigned long)); + + strncpy (name, "ucarry_CreateMWC:", (size_t) LEN); + addstr_Uint (name, " r = ", r); + addstr_Ulong (name, ", c = ", c); + addstr_Uint (name, ", w = ", w); + addstr_ArrayUlong (name, ", A = ", (int) r, A); + addstr_ArrayUlong (name, ", S = ", (int) r, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + Suma = 0; + for (j = 0; j < r; j++) { + if (A[j] >= num_TwoExp[w]) + util_Error ("ucarry_CreateMWC: A[i] must be < 2^w"); + if (S[j] >= num_TwoExp[w]) + util_Error ("ucarry_CreateMWC: S[i] must be < 2^w"); + Suma += A[j]; + } + /* so that carry c doesn't lose digits of precision */ + Suma = Suma * ((ulonglong) num_TwoExp[w] - 1) + c; + if (Suma >= num_TwoExp[64]) + util_Error ("ucarry_CreateMWC: Sum over A[i] is too big"); + + state->C = (ulonglong) c; + state->R = 0; + state->Order = r; + param->W = w; + param->shift = 32 - w; + if (w < 32) { + param->mask = (ulonglong) num_TwoExp[w] - 1; + } else { + param->mask = (ulonglong) 0xffffffffUL; + } + + for (j = 0; j < r; j++) { + param->A[j] = A[j]; + state->X[j] = S[j]; + } + + gen->param = param; + gen->state = state; + gen->GetBits = &MWC_Bits; + gen->GetU01 = &MWC_U01; + gen->Write = &WrMWC; + return gen; +} + +void ucarry_DeleteMWC (unif01_Gen * gen) +{ + MWC_param *param; + MWC_state *state; + + if (NULL == gen) + return; + state = gen->state; + param = gen->param; + util_Free (state->X); + util_Free (param->A); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +#endif /* USE_LONGLONG */ +/**************************************************************************/ + +static unsigned long MWCFloat_Bits (void *vpar, void *vsta) +{ + MWCFloat_param *param = vpar; + MWCFloat_state *state = vsta; + + unsigned int i, j; + double dv; + unsigned long SomC; + + dv = state->C; + for (j = 0; j < state->Order; j++) { + if (param->A[j] != 0) { + i = j + state->R; + if (i >= state->Order) + i -= state->Order; + state->C += param->A[j] * state->X[i]; + dv += (double) param->A[j] * (double) state->X[i]; + } + } + SomC = state->C & param->mask; + state->X[state->R] = SomC; + state->C = dv * param->Norm; + state->R++; + if (state->R >= state->Order) + state->R = 0; + return (SomC << param->shift) & MASK32; +} + +static double MWCFloat_U01 (void *vpar, void *vsta) +{ + return (MWCFloat_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrMWCFloat (void *vsta) +{ + MWCFloat_state *state = vsta; + unsigned int j; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < state->Order - 1; j++) { + printf ("%10lu, ", state->X[j]); + if (((j + 1) % 5) == 0) + printf ("\n "); + } + printf ("%10lu }\n\n", state->X[state->Order - 1]); + printf (" c = %1lu\n\n", state->C); + } else + unif01_WrLongStateDef (); +} + +unif01_Gen *ucarry_CreateMWCFloat (unsigned int r, unsigned long c, + unsigned int w, unsigned long A[], unsigned long S[]) +{ + unif01_Gen *gen; + MWCFloat_param *param; + MWCFloat_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int j; + double Sum; + + util_Assert (w <= 32, "ucarry_CreateMWCFloat: w > 32"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MWCFloat_param)); + state = util_Malloc (sizeof (MWCFloat_state)); + state->X = util_Calloc ((size_t) r, sizeof (unsigned long)); + param->A = util_Calloc ((size_t) r, sizeof (unsigned long)); + + strncpy (name, "ucarry_CreateMWCFloat:", (size_t) LEN); + addstr_Uint (name, " r = ", r); + addstr_Ulong (name, ", c = ", c); + addstr_Uint (name, ", w = ", w); + addstr_ArrayUlong (name, ", A = ", (int) r, A); + addstr_ArrayUlong (name, ", S = ", (int) r, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + Sum = 0.0; + for (j = 0; j < r; j++) { + if (A[j] >= num_TwoExp[w]) + util_Error ("ucarry_CreateMWCFloat: A[i] must be < 2^w"); + if (S[j] >= num_TwoExp[w]) + util_Error ("ucarry_CreateMWCFloat: S[i] must be < 2^w"); + Sum += A[j]; + } + Sum = Sum * (num_TwoExp[w] - 1.0) + c; + if (Sum >= num_TwoExp[53]) + util_Error + ("ucarry_CreateMWCFloat: c + (2^w - 1) * Sum A[i] >= 2^(53)"); + if (Sum >= num_TwoExp[32 + w]) + util_Error + ("ucarry_CreateMWCFloat: c + (2^w - 1) * Sum A[i] >= 2^(32 + w)"); + + state->C = c; + state->R = 0; + state->Order = r; + param->W = w; + param->shift = 32 - w; + if (w < 32) { + param->Norm = 1.0 / num_TwoExp[w]; + param->mask = (unsigned long) num_TwoExp[w] - 1; + } else { + param->Norm = 1.0 / num_TwoExp[32]; + param->mask = 0xffffffffU; + } + for (j = 0; j < r; j++) { + param->A[j] = A[j]; + state->X[j] = S[j]; + } + + gen->param = param; + gen->state = state; + gen->GetBits = &MWCFloat_Bits; + gen->GetU01 = &MWCFloat_U01; + gen->Write = &WrMWCFloat; + return gen; +} + +void ucarry_DeleteMWCFloat (unif01_Gen * gen) +{ + MWCFloat_param *param; + MWCFloat_state *state; + + if (NULL == gen) + return; + state = gen->state; + param = gen->param; + util_Free (state->X); + util_Free (param->A); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + + + +/**************************************************************************/ +#if 0 +/* These are not used anywhere. Older versions?? (RS) */ + +#ifdef USE_LONGLONG + +static double MWCfix8r4 (void) +{ + ulonglong S2 = UCA; + S2 += 2736 * ((ulonglong) x1) + 7456 * ((ulonglong) x2) + + 76438 * ((ulonglong) x5) + 84739 * ((ulonglong) x7); + x1 = x2; + x2 = x3; + x3 = x4; + x4 = x5; + x5 = x6; + x6 = x7; + x7 = x8; + x8 = S2 & e32m1; + UCA = S2 >> 32; + return (double) x8 *UnSur2e32; +} + +static void WrMWCfix8 (void) +{ + printf + (" (x1, x2, x3, x4, x5, x6, x7, x8) = ( %lu, %lu, %lu,\n %lu, %lu, %lu, %lu, %lu )\n c = %" PRIuLEAST64 "\n\n", + x1, x2, x3, x4, x5, x6, x7, x8, UCA); +} + +unif01_Gen *ucarry_CreateMWCfix8r4 (unsigned long c, unsigned long S[]) +{ + strcpy (name, "ucarry_CreateMWCfix8r4: "); + addstr_Ulong (name, " c = ", c); + addstr_ArrayUlong (name, ", S = ", 8, S); + UCA = c; + x1 = S[0]; + x2 = S[1]; + x3 = S[2]; + x4 = S[3]; + x5 = S[4]; + x6 = S[5]; + x7 = S[6]; + x8 = S[7]; + unif01_Gen = MWCfix8r4; + unif01_WrGen = WrMWCfix8; +} + +/**************************************************************************/ + +static double MWCfix8r8 (void) +{ + unsigned long S1; + ulonglong S2 = UCA; + S2 += 2736 * ((ulonglong) x1) + 7456 * ((ulonglong) x2) + + 76438 * ((ulonglong) x5) + 84739 * ((ulonglong) x7) + + 2736 * ((ulonglong) x3) + 7456 * ((ulonglong) x4) + + 76438 * ((ulonglong) x6) + 84739 * ((ulonglong) x8); + S1 = S2 & e32m1; + UCA = S2 >> 32; + x1 = x2; + x2 = x3; + x3 = x4; + x4 = x5; + x5 = x6; + x6 = x7; + x7 = x8; + x8 = S1; + return ((double) S1 * UnSur2e32); +} + +unif01_Gen *ucarry_CreateMWCfix8r8 (unsigned long c, unsigned long S[]) +{ + strcpy (name, "ucarry_CreateMWCfix8r8: "); + addstr_Ulong (name, " c = ", c); + addstr_ArrayUlong (name, ", S = ", 8, S); + UCA = c; + x1 = S[0]; + x2 = S[1]; + x3 = S[2]; + x4 = S[3]; + x5 = S[4]; + x6 = S[5]; + x7 = S[6]; + x8 = S[7]; + unif01_Gen = MWCfix8r8; + unif01_WrGen = WrMWCfix8; +} + +#endif /* USE_LONGLONG */ + +#endif + +/**************************************************************************/ + +static unsigned long MWCfixCouture_Bits (void *junk, void *vsta) +{ + MWCfixCouture_state *state = vsta; + unsigned int s1, s3; + unsigned int s2 = state->C; + + s2 += 14 * state->x1 + 18 * state->x2 + 144 * state->x3 + 1499 * state->x4 + + 2083 * state->x5 + 5273 * state->x6 + 10550 * state->x7 + + 45539 * state->x8; + s1 = s2 & MASK16; + s3 = s2 >> 16; + s3 += 14 * state->x2 + 18 * state->x3 + 144 * state->x4 + 1499 * state->x5 + + 2083 * state->x6 + 5273 * state->x7 + 10550 * state->x8 + 45539 * s1; + state->C = s3 >> 16; + s3 &= MASK16; + state->x1 = state->x3; + state->x2 = state->x4; + state->x3 = state->x5; + state->x4 = state->x6; + state->x5 = state->x7; + state->x6 = state->x8; + state->x7 = s1; + state->x8 = s3; + return s1 + (s3 << 16); +} + +static double MWCfixCouture_U01 (void *vpar, void *vsta) +{ + return (MWCfixCouture_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrMWCfixCouture (void *vsta) +{ + MWCfixCouture_state *state = vsta; + printf + (" (x1, x2, x3, x4, x5, x6, x7, x8) = ( %u, %u, %u,\n %u, %u, %u, %u, %u )\n c = %u\n\n", + state->x1, state->x2, state->x3, state->x4, state->x5, state->x6, + state->x7, state->x8, state->C); +} + +unif01_Gen *ucarry_CreateMWCfixCouture (unsigned int c, unsigned int S[]) +{ + unif01_Gen *gen; + MWCfixCouture_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MWCfixCouture_state)); + + strncpy (name, "ucarry_CreateMWCfixCouture:", (size_t) LEN); + addstr_Uint (name, " c = ", c); + addstr_ArrayUint (name, ", S = ", 8, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->C = c; + state->x1 = S[0]; + state->x2 = S[1]; + state->x3 = S[2]; + state->x4 = S[3]; + state->x5 = S[4]; + state->x6 = S[5]; + state->x7 = S[6]; + state->x8 = S[7]; + + gen->param = NULL; + gen->state = state; + gen->GetBits = &MWCfixCouture_Bits; + gen->GetU01 = &MWCfixCouture_U01; + gen->Write = &WrMWCfixCouture; + return gen; +} + +void ucarry_DeleteMWCfixCouture (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/****************************************************************************/ + +static unsigned long SWC_Bits (void *vpar, void *vsta) +{ +/* + * Generator Shift With Carry on 32 bits + */ + SWC_param *param = vpar; + SWC_state *state = vsta; + unsigned int Som; + unsigned int j; + + Som = state->C; + state->C = 0; + for (j = 0; j <= param->Asize / 2 - 1; j++) { + state->S = (state->R + param->A[2 * j]) % state->Order; + Som ^= state->X[state->S] << param->A[2 * j + 1]; + state->C ^= state->X[state->S] >> (32 - param->A[2 * j + 1]); + } + + if (param->W != 32) + state->C = (state->C << (32 - param->W)) | (Som >> param->W); + + Som &= param->mask; + state->X[state->R] = Som; + state->R = (state->R + 1) % state->Order; + return Som << param->shift; +} + +static double SWC_U01 (void *vpar, void *vsta) +{ + return (SWC_Bits (vpar, vsta) * unif01_INV32); +} + +static unsigned long SWCshort_Bits (void *vpar, void *vsta) +{ +/* + * Generator Shift With Carry on 16 bits + */ + SWC_param *param = vpar; + SWC_state *state = vsta; + unsigned int Som; + unsigned int j; + + Som = state->C; + for (j = 0; j <= param->Asize / 2 - 1; j++) { + state->S = (state->R + param->A[2 * j]) % state->Order; + Som ^= (state->X[state->S] << param->A[2 * j + 1]); + } + + state->C = Som >> param->W; + Som &= param->mask; + state->X[state->R] = Som; + state->R = (state->R + 1) % state->Order; + return Som << param->shift; +} + +static double SWCshort_U01 (void *vpar, void *vsta) +{ + return (SWCshort_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrSWC (void *vsta) +{ + SWC_state *state = vsta; + unsigned int j; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < state->Order - 1; j++) { + printf ("%10u, ", state->X[j]); + if (((j + 1) % 5) == 0) + printf ("\n "); + } + printf ("%10u }\n\n", state->X[state->Order - 1]); + printf (" c = %1u\n\n", state->C); + } else + unif01_WrLongStateDef (); +} + + +unif01_Gen *ucarry_CreateSWC (unsigned int r, unsigned int h, + unsigned int c, unsigned int w, unsigned int A[], unsigned int S[]) +{ + unif01_Gen *gen; + SWC_param *param; + SWC_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int j; + + if ((w > 32U) || (h > 31U * r)) { + util_Error ("ucarry_CreateSWC: invalid parameter"); + } + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (SWC_param)); + state = util_Malloc (sizeof (SWC_state)); + state->X = util_Calloc ((size_t) r, sizeof (unsigned int)); + param->A = util_Calloc ((size_t) h, sizeof (unsigned int)); + + strncpy (name, "ucarry_CreateSWC:", (size_t) LEN); + addstr_Uint (name, " r = ", r); + addstr_Uint (name, ", h = ", h); + addstr_Uint (name, ", c = ", c); + addstr_Uint (name, ", w = ", w); + addstr_ArrayUint (name, ", A = ", (int) h, A); + addstr_ArrayUint (name, ", S = ", (int) r, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->R = 0; + state->S = r; + state->Order = r; + state->C = c; + param->Asize = h; + param->W = w; + param->shift = 32 - w; + if (w < 32) + param->mask = num_TwoExp[w] - 1; + else + param->mask = 0xffffffffU; /* 2^32 - 1 */ + + for (j = 0; j < h; j++) + param->A[j] = A[j] & 0xff; + for (j = 0; j < r; j++) + state->X[j] = S[j] & param->mask; + + if (w > 15) { + gen->GetBits = &SWC_Bits; + gen->GetU01 = &SWC_U01; + } else { + gen->GetBits = &SWCshort_Bits; + gen->GetU01 = &SWCshort_U01; + } + + gen->param = param; + gen->state = state; + gen->Write = &WrSWC; + return gen; +} + +void ucarry_DeleteSWC (unif01_Gen * gen) +{ + SWC_param *param; + SWC_state *state; + + if (NULL == gen) + return; + state = gen->state; + param = gen->param; + util_Free (state->X); + util_Free (param->A); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/***************************************************************************/ + +static unsigned long MWC1616_Bits (void *par, void *sta) +{ + MWC1616_state *state = sta; + MWC1616_param *param = par; + state->x = param->a * (state->x & MASK16) + (state->x >> 16); + state->y = param->b * (state->y & MASK16) + (state->y >> 16); + return (state->x << 16) + (state->y & MASK16); +} + +/*-----------------------------------------------------------------------*/ + +static double MWC1616_U01 (void *par, void *sta) +{ + return MWC1616_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrMWC1616 (void *sta) +{ + MWC1616_state *state = sta; + printf (" x = %u, y = %u\n", state->x, state->y); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ucarry_CreateMWC1616 (unsigned int a, unsigned int b, + unsigned int x, unsigned int y) +{ + unif01_Gen *gen; + MWC1616_state *state; + MWC1616_param *param; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + gen->state = state = util_Malloc (sizeof (MWC1616_state)); + gen->param = param = util_Malloc (sizeof (MWC1616_param)); + state->x = x & MASK32; + state->y = y & MASK32; + param->a = a & MASK16; + param->b = b & MASK16; + gen->Write = WrMWC1616; + gen->GetU01 = MWC1616_U01; + gen->GetBits = MWC1616_Bits; + + strcpy (name, "ucarry_CreateMWC1616:"); + addstr_Uint (name, " a = ", a); + addstr_Uint (name, ", b = ", b); + addstr_Uint (name, ", x = ", x); + addstr_Uint (name, ", y = ", y); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + return gen; +} + +/***************************************************************************/ + +void ucarry_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ucarry.tex b/TESTU01/TestU01-1.2.3/testu01/ucarry.tex new file mode 100644 index 0000000..f407860 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ucarry.tex @@ -0,0 +1,250 @@ +\defmodule {ucarry} + +Generators based on linear recurrences with carry are implemented +in this module. This includes the +{\em add-with-carry\/} (AWC), +{\em subtract-with-borrow\/} (SWB), +{\em multiply-with-carry\/} (MWC), and +{\em shift-with-carry} (SWC) generators. +For the theoretical properties of these generators and other details, +we refer the reader to \cite{rCOU94a,rCOU95a,rCOU97a,rKOC95a,rTEZ93a}. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule + +\code +\hide +/* ucarry.h for ANSI C */ + +#ifndef UCARRY_H +#define UCARRY_H +\endhide +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen * ucarry_CreateAWC (unsigned int r, unsigned int s, + unsigned long c, unsigned long m, + unsigned long S[]); +\endcode + \tab Implements the add-with-carry (AWC) generator +\index{Generator!add-with-carry}% + proposed by Marsaglia and Zaman \cite{rMAR91a}, based on the + recurrence + \eqs + x_i &=& (x_{i-r} + x_{i-s} + c_{i-1}) \mod m,\\ + c_i &=& (x_{i-r} + x_{i-s} + c_{i-1}) \div m, + \endeqs + with output $u_i = x_i/m$. + The vector {\tt S[0..k-1]} contains the $k$ initial values + $(x_0,\dots,x_{k-1})$, where $k = \max\{r, s\}$, and {\tt c} contains $c_0$. + Restrictions: $0 < s$, $0 < r$, $r \not= s$ and $c = 0$ or 1. + \endtab +\code + + +unif01_Gen * ucarry_CreateSWB (unsigned int r, unsigned int s, + unsigned long c, unsigned long m, + unsigned long S[]); +\endcode + \tab Implements the subtract-with-borrow (SWB) generator +\index{Generator!subtract-with-borrow}\label{gen:SWB}% + proposed by Marsaglia and Zaman \cite{rMAR91a}, based on the + recurrence + \eqs + x_i &=& (x_{i-r} - x_{i-s} - c_{i-1}) \mod m,\\[4pt] + c_i &=& I[(x_{i-r} - x_{i-s} - c_{i-1}) < 0], + \endeqs + with output $u_i = x_i/m$, where $I$ is the indicator function. + The vector {\tt S[0..(k-1)]} contains the $k$ initial values + $(x_0,\dots,$ $x_{k-1})$, where $k = \max\{r, s\}$, and {\tt c} contains $c_0$. +% {\tt Lux} is the luxury level defined as follows: +% generate $k$ successive values, then skip +% the next ${\tt Lux} - k$. If ${\tt Lux} \le k$, no value are skipped. + Restrictions : $0 < s$, $0 < r$, $r \not= s$ and $c = 0$ or 1. + \endtab +\code + + +unif01_Gen * ucarry_CreateRanlux (unsigned int L, long s); +\endcode + \tab Implements the specific modified SWB generator proposed by +\index{Generator!Ranlux} + L\"uscher \cite{rLUS94a}. This is an adapted version of the + FORTRAN implementation of James \cite{rJAM94a}. + The parameter {\tt L} is the luxury level and {\tt s} is the + initial state. Restriction: $24\le L$. + The precision of this generator is only 24 bits. + \endtab +\code + + +#ifdef USE_LONGLONG + unif01_Gen * ucarry_CreateMWC (unsigned int r, unsigned long c, + unsigned int w, unsigned long A[], + unsigned long S[]); +#endif +\endcode + \tab Implements the {\em multiply-with-carry\/} (MWC) generator, + defined by \cite{rCOU97a}: +\eqs + x_n &=& (a_1 x_{n-1} + \cdots + a_r x_{n-r} + c_{n-1}) \mod 2^{w}; + \label {mwcx} \\ + c_n &=& (a_1 x_{n-1} + \cdots + a_r x_{n-r} + c_{n-1}) \div 2^{w}; + \label {mwcc} \\ + u_n &=& x_n /2^w. \label {mwcu} +\endeqs + The array {\tt A[0..(r-1)]} must contain the coefficients + $a_1,\dots, a_r$, \index{Generator!multiply-with-carry} + the array {\tt S[0..(r-1)]} gives the initial values + $(x_0,\dots,x_{-r+1})$, and {\tt c} gives the value of $c_0$. + This implementation uses 64-bit integers and therefore works + only on platforms where these are available. + Restrictions: $w \le 32$, $a_i < 2^w$, $x_i < 2^w$, + and $c + (2^w -1)(|a_1| + \cdots + |a_r|) < 2^{64}$. + \endtab +\code + + +unif01_Gen * ucarry_CreateMWCFloat (unsigned int r, unsigned long c, + unsigned int w, unsigned long A[], + unsigned long S[]); +\endcode + \tab Same as {\tt ucarry\_CreateMWC}, but uses a floating-point + implementation (in {\tt double}). + Restrictions: $w \le 32$, $a_i < 2^w$, $x_i < 2^w$, + and $c + (2^w -1)(|a_1| + \cdots + |a_r|) < \min\{2^{53}, \ 2^{32+w}\}$. + \endtab + + +% +\hide %%%%%%%% +\code + + +#ifdef USE_LONGLONG + unif01_Gen * ucarry_CreateMWCfix8r4 (unsigned long c, unsigned long S[]); +#endif +\endcode + \tab Implements a specific MWC with $k = 8$, $w = 32$, + and with 4 (fixed) nonzero $a_i$'s. + (The current parameters are temporary.) + \endtab +\code + + +#ifdef USE_LONGLONG + unif01_Gen * ucarry_CreateMWCfix8r8 (unsigned long c, unsigned long S[]); +#endif +\endcode + \tab Implements a specific MWC with $k = 8$, $w = 32$, + and with 8 (fixed) nonzero $a_i$'s. + (The current parameters are temporary.) + \endtab +\endhide %%%%%%%% +\code + + +unif01_Gen * ucarry_CreateMWCfixCouture (unsigned int c, + unsigned int S[]); +\endcode + \tab Implements the following specific MWC, suggested by + Couture and L'Ecuyer \cite{rCOU97a}: + \begin {eqnarray*} + x_n &=& (14 x_{n-8} + 18 x_{n-7} + 144 x_{n-6} + 1499 x_{n-5} + + 2083 x_{n-4}\\ + & &{} + 5273 x_{n-3} + 10550 x_{n-2} + 45539 x_{n-1} + + c_{n-1}) \mod 2^{16}, \\[8pt] + c_n &=& (14 x_{n-8} + \cdots + 45539 x_{n-1} + c_{n-1}) \div 2^{16},\\[8pt] + u_n &=& \frac {x_{2n}}{2^{\,32}}\; +\; \frac {x_{2n+1}}{2^{\,16}}. + \end {eqnarray*} + The initial state is in {\tt S[0..7]}, and $c$ is the initial carry. + The lowest 16 bits and the highest 16 bits of each $u_n$ come from + two successive numbers $x_j$. + \endtab +\code + + +unif01_Gen * ucarry_CreateSWC (unsigned int r, unsigned int h, + unsigned int c, unsigned int w, + unsigned int A[], unsigned int S[]); +\endcode + \tab Implements the shift-with-carry (SWC) generator designed by + R.~Couture, based on the recurrence \index{Generator!shift-with-carry} + \eqs + x_n &=& (a_1 x_{n-1} \oplus \cdots \oplus a_r x_{n-r} \oplus c_{n-1}) + \mod 2^{w} \\ + c_n &=& (a_1 x_{n-1} \oplus \cdots \oplus a_r x_{n-r} \oplus c_{n-1}) + \div 2^{w} \\ + u_n &=& x_n /2^w, + \endeqs + The vector $(x_n,\dots,x_{n-r+1},c_n)$ is the state of the generator. + The array {\tt A[0..h-1]} contains the polynomials $a_1,\dots, a_r$. + Each even element stands for a polynomial number and the next + element stands for the corresponding nonzero coefficient number + of that polynomial. + The vector {\tt S[0..r-1]} gives the initial values of + $(x_0,\dots,x_{-r+1})$ and {\tt c} is the initial carry. +% Note: as usual the first element of the vectors {\tt A} +% and {\tt S} must start at index 0. + Restrictions: $0 < r$ and $w \le 32$. + \endtab +\code + + +unif01_Gen * ucarry_CreateMWC1616 (unsigned int a, unsigned int b, + unsigned int x, unsigned int y); +\endcode + \tab Implements the combined generator of two 16-bit + multiply-with-carry generators \cite{rMAR96b} +\index{Generator!multiply-with-carry!combined}% + \eqs + x_n &=& (a x_{n-1} + {\tt carx}_{n-1}) \mod 2^{16}, \\ + {\tt carx}_n &=& (a x_{n-1} + {\tt carx}_{n-1}) \div 2^{16}, \\ + y_n &=& (b y_{n-1} + {\tt cary}_{n-1}) \mod 2^{16}, \\ + {\tt cary}_n &=& (b y_{n-1} + {\tt cary}_{n-1}) \div 2^{16}. + \endeqs + The rightmost 16 bits of the two above product make the new $x$ (or $y$) + and the leftmost 16 bits the new carry {\tt carx} (or {\tt cary}). + The function returns $(x_n \ll 16)+(y_n\ \&\ {\mbox{0xf{f}f{f}}})$; + the output is a 32-bit integer, $x_n$ making up its leftmost 16 bits + and $y_n$ its rightmost 16 bits. + \endtab + + +% \newpage +\guisec{Clean-up functions} + + These functions should be called to clean up generator objects of this + module when they are no longer in use. + +\code + + +void ucarry_DeleteAWC (unif01_Gen *gen); +void ucarry_DeleteSWB (unif01_Gen *gen); +void ucarry_DeleteRanlux (unif01_Gen *gen); +void ucarry_DeleteMWC (unif01_Gen *gen); +void ucarry_DeleteMWCFloat (unif01_Gen *gen); +void ucarry_DeleteMWCfixCouture (unif01_Gen *gen); +void ucarry_DeleteSWC (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by the generators of this module, + and allocated by the corresponding {\tt Create} function. + \endtab +\code + + +void ucarry_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have a specific {\tt Delete} function. + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ucrypto.c b/TESTU01/TestU01-1.2.3/testu01/ucrypto.c new file mode 100644 index 0000000..b616e80 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ucrypto.c @@ -0,0 +1,515 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ucrypto.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" +#include "num.h" + +#include "rijndael-alg-fst.h" +#include "tu01_sha1.h" +#include "ucrypto.h" +#include "unif01.h" + +#include +#include +#include +#include + +#define LEN 200 /* Max length of strings */ +#define MAX_SIZE 64 /* number of ASCII char's in a key */ + + + +/*-------------------------------------------------------------------------*/ + +typedef struct +{ + int Nr; /* Number of rounds */ + int Nk; /* Number of columns (key length in words) */ + int Nb; /* Number of bytes (block size in bytes) */ + int r; /* Number of initial bytes dropped */ + int s; /* Number of bytes kept */ +} AES_param; + +typedef struct +{ + uint32_t *K; /* Key */ + uint8_t *PT; /* Plain text */ + uint8_t *CT; /* Cypher text */ + int i; /* Byte number */ + int Nk; + ucrypto_Mode mode; +} AES_state; + + +typedef struct +{ + SHA1_CTX context; + int i; /* byte used for output */ + int r; /* Number of initial bytes dropped */ + int s; /* Number of bytes kept */ + ucrypto_Mode mode; + unsigned char V[64]; + unsigned char output[20]; +} SHA1_state; + + + +/*============================ functions ==================================*/ + +static void increment8 (uint8_t A[], int n) +{ +/* A is an array of n char's; it is viewed here as an 8n-bit integer. + This function increments the integer by 1 mod 2^(8n). */ + int i; + for (i = n-1; i >= 0; --i) { + ++A[i]; +#if CHAR_BIT > 8 + A[i] &= 0xff; +#endif + if (A[i] > 0) + return; + } +} + + +/*-------------------------------------------------------------------------*/ + +static void increment32 (uint32_t A[], int n) +{ +/* A is an array of n unsigned int's; it is viewed here as an 32n-bit integer. + This function increments this integer by 1 mod 2^(32n). */ + int i; + for (i = n-1; i >= 0; --i) { + ++A[i]; +#if UINT_MAX > 4294967295U + A[i] &= 0xffffffffU; +#endif + if (A[i] > 0) + return; + } +} + + +/*-------------------------------------------------------------------------*/ +#if 0 + +int main () +{ +#if 0 + unsigned char A[] = { 25, 255, 254 }; + unsigned char B[] = { 111, 124 }; +#else + unsigned int A[] = { 25, 255, 0xfffffff9 }; +#endif + int i, j; + for (j = 0; j < 10; ++j) { + increment32 (A, 3); + for (i = 0; i < 3; i++) { + printf (" %13u", (unsigned int) A[i]); + } + printf ("\n"); + } +} +#endif + + +/*=========================================================================*/ + +static unsigned long AES_Bits (void *vpar, void *vsta) +{ + AES_param *param = vpar; + AES_state *state = vsta; + int k; + unsigned long Z = 0; + + /* 4 bytes = one 32-bit random number */ + for (k = 0; k < 4; ++k) { + if (state->i >= param->s) { + int j; + rijndaelEncrypt (state->K, param->Nr, state->PT, state->CT); + + switch (state->mode) { + case ucrypto_OFB: + for (j = 0; j < 16; j++) + state->PT[j] = state->CT[j]; + break; + case ucrypto_CTR: + increment8 (state->PT, 16); /* pt = pt + 1 mod 2^128 */ + break; + case ucrypto_KTR: + increment32 (state->K, param->Nk); /* K = K + 1 mod 2^(32Nk) */ + break; + default: + util_Error ("ucrypto_CreateAES: no such mode"); + } + state->i = param->r; + } + Z <<= 8; + Z |= (unsigned long) state->CT[state->i++]; + } + + return Z; +} + + +/*-------------------------------------------------------------------------*/ + +static double AES_U01 (void *vpar, void *vsta) +{ + return AES_Bits (vpar, vsta) * unif01_INV32; +} + + +/*-------------------------------------------------------------------------*/ + +static void WrAES (void *vsta) +{ + AES_state *state = vsta; + unsigned char A[32]; + int i; + printf (" Char's are written as small decimal integers\n"); + + switch (state->mode) { + case ucrypto_OFB: + case ucrypto_CTR: + printf (" T = {\n "); + for (i = 0; i < 16; i++) { + printf (" %3d", (unsigned int) state->PT[i]); + if ((i + 1) % 8 == 0) + printf ("\n "); + } + break; + + case ucrypto_KTR: + num_Uint2Uchar (A, state->K, state->Nk); + printf (" Key = {\n "); + for (i = 0; i < 4*state->Nk; i++) { + printf (" %3d", (unsigned int) A[i]); + if ((i + 1) % 8 == 0) + printf ("\n "); + } + break; + + default: + util_Error ("ucrypto_CreateAES: no such mode"); + } + printf ("}\n"); +} + + +/*-------------------------------------------------------------------------*/ + +static void getStringMode (ucrypto_Mode mode, char *str) +/* Transforms the mode in a string */ +{ + switch (mode) { + case ucrypto_OFB: + strcpy (str, "OFB"); + break; + case ucrypto_CTR: + strcpy (str, "CTR"); + break; + case ucrypto_KTR: + strcpy (str, "KTR"); + break; + default: + util_Error ("ucrypto_Mode: no such case"); + } +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ucrypto_CreateAES (unsigned char *Key, int KeyLen, + unsigned char *Seed, ucrypto_Mode mode, int r, int s) +{ + unif01_Gen *gen; + AES_param *param; + AES_state *state; + size_t len1; + char name[LEN + 1] = {0}; + char str[16] = {0}; + int i; + unsigned int D[64]; + + util_Assert ((KeyLen == 128) || (KeyLen == 192) || (KeyLen == 256), + "ucrypto_CreateAES: klen must be in { 128, 192, 256 }"); + util_Assert (r < 16, "ucrypto_CreateAES: r > 15"); + util_Assert (0 < s, "ucrypto_CreateAES: s <= 0"); + util_Assert (s <= 16, "ucrypto_CreateAES: s > 16"); + util_Assert (r + s <= 16, "ucrypto_CreateAES: r + s > 16"); + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (AES_param)); + state = util_Malloc (sizeof (AES_state)); + + if (r < 0) r = 0; + switch (KeyLen) { + case 128: + param->Nb = 16; + param->Nk = 4; + param->Nr = 10; + break; + case 192: + param->Nb = 16; + param->Nk = 6; + param->Nr = 12; + break; + case 256: + param->Nb = 16; + param->Nk = 8; + param->Nr = 14; + break; + default: + util_Error ("ucrypto_CreateAES, klen: no such case"); + } + + strncpy (name, "ucrypto_CreateAES: mode = ", (size_t) LEN); + getStringMode (mode, str); + strncat (name, str, (size_t) LEN); + addstr_Int (name, ", r = ", r); + addstr_Int (name, ", s = ", s); + addstr_Long (name, ", klen = ", (long) KeyLen); + for (i = 0; i < KeyLen / 8; i++) + D[i] = Key[i]; + addstr_ArrayUint (name, ", Key = ", KeyLen / 8, D); + for (i = 0; i < param->Nb; i++) + D[i] = Seed[i]; + addstr_ArrayUint (name, ", Seed = ", param->Nb, D); + len1 = strlen (name); + gen->name = util_Calloc (len1 + 1, sizeof (char)); + strncpy (gen->name, name, len1); + + state->PT = util_Calloc ((size_t) param->Nb, sizeof (uint8_t)); + state->CT = util_Calloc ((size_t) param->Nb, sizeof (uint8_t)); + state->K = util_Calloc ((size_t) 4 * (param->Nr + 1), sizeof (uint32_t)); + rijndaelKeySetupEnc (state->K, Key, KeyLen); + + for (i = 0; i < param->Nb; i++) + state->PT[i] = Seed[i]; + state->mode = mode; + param->r = r; + param->s = s + r; + state->i = 16; + state->Nk = param->Nk; + gen->param = param; + gen->state = state; + gen->GetBits = &AES_Bits; + gen->GetU01 = &AES_U01; + gen->Write = &WrAES; + return gen; +} + + +/*-------------------------------------------------------------------------*/ + +void ucrypto_DeleteAES (unif01_Gen * gen) +{ + AES_param *param; + AES_state *state; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + util_Free (state->CT); + util_Free (state->PT); + util_Free (state->K); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/*=========================================================================*/ +#define SLEN 55 + +static unsigned long SHA1_Bits (void *junk, void *vsta) +{ + SHA1_state *state = vsta; + int k; + unsigned long Z = 0; + + /* 4 bytes = one 32-bit random number */ + for (k = 0; k < 4; ++k) { + if (state->i >= state->s) { + switch (state->mode) { + case ucrypto_OFB: + SHA1Init (&state->context); + SHA1Update (&state->context, state->output, 20); + SHA1Final (state->output, &state->context); + break; + case ucrypto_CTR: + SHA1Init (&state->context); + SHA1Update (&state->context, state->V, SLEN); + SHA1Final (state->output, &state->context); + increment8 (state->V, SLEN); /* V = V + 1 mod 2^440 */ + break; + default: + util_Error ("ucrypto_CreateSHA1: no such mode"); + } + + state->i = state->r; + } + + Z <<= 8; + Z |= (unsigned long) state->output[state->i++]; + } + + return Z; +} + +/*-------------------------------------------------------------------------*/ + +static double SHA1_U01 (void *vpar, void *vsta) +{ + return SHA1_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrSHA1 (void *vsta) +{ + SHA1_state *state = vsta; + int i; + printf (" Char's are written as small decimal integers\n"); + printf (" T = {\n "); + + switch (state->mode) { + case ucrypto_OFB: + for (i = 0; i < 20; i++) { + printf (" %3d", (unsigned int) state->output[i]); + if ((i + 1) % 10 == 0) + printf ("\n "); + } + break; + + case ucrypto_CTR: + for (i = 0; i < SLEN; i++) { + printf (" %3d", (unsigned int) state->V[i]); + if ((i + 1) % 10 == 0) + printf ("\n "); + } + break; + + default: + util_Error ("ucrypto_SHA1: no such mode"); + } + printf (" }\n"); +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ucrypto_CreateSHA1 (unsigned char *Seed, int len, ucrypto_Mode mode, + int r, int s) +{ + unif01_Gen *gen; + SHA1_state *state; + int i; + unsigned int D[SLEN]; + size_t len1; + char name[LEN + 1] = {0}; + char str[16] = {0}; + + util_Assert (4 == sizeof (uint32_t), + "ucrypto_CreateSHA1: uint32 must be exactly 32 bits wide"); + util_Assert (r < 20, "ucrypto_CreateSHA1: r > 19"); + util_Assert (0 < s, "ucrypto_CreateSHA1: s <= 0"); + util_Assert (s <= 20, "ucrypto_CreateSHA1: s > 20"); + util_Assert (r + s <= 20, "ucrypto_CreateSHA1: r + s > 20"); + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (SHA1_state)); + memset (state, 0, sizeof (SHA1_state)); + if (r < 0) r = 0; + + strncpy (name, "ucrypto_CreateSHA1: mode = ", (size_t) LEN); + getStringMode (mode, str); + strncat (name, str, (size_t) LEN); + addstr_Int (name, ", r = ", r); + addstr_Int (name, ", s = ", s); + addstr_Int (name, ", len = ", len); + if (len > SLEN) len = SLEN; + for (i = 0; i < len; i++) + D[i] = Seed[i]; + addstr_ArrayUint (name, ", Seed = ", len, D); + len1 = strlen (name); + gen->name = util_Calloc (len1 + 1, sizeof (char)); + strncpy (gen->name, name, len1); + + switch (mode) { + case ucrypto_OFB: + SHA1Init (&state->context); + SHA1Update (&state->context, Seed, len); + SHA1Final (state->output, &state->context); + break; + case ucrypto_CTR: + for (i = 0; i < len; i++) + state->V[i] = Seed[i]; + break; + default: + util_Error ("ucrypto_CreateSHA1: no such mode"); + } + + state->mode = mode; + state->r = r; + state->s = s + r; + state->i = 20; + gen->param = NULL; + gen->state = state; + gen->GetBits = &SHA1_Bits; + gen->GetU01 = &SHA1_U01; + gen->Write = &WrSHA1; + return gen; +} + + +/*-------------------------------------------------------------------------*/ + +void ucrypto_DeleteSHA1 (unif01_Gen * gen) +{ + SHA1_state *state; + + if (NULL == gen) + return; + state = gen->state; + SHA1Final (state->output, &state->context); + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + +#undef SLEN + +/*=========================================================================*/ +/* Generator ISAAC */ + +#include "ucryptoIS.c" diff --git a/TESTU01/TestU01-1.2.3/testu01/ucrypto.tex b/TESTU01/TestU01-1.2.3/testu01/ucrypto.tex new file mode 100644 index 0000000..3123b4d --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ucrypto.tex @@ -0,0 +1,166 @@ +\defmodule{ucrypto} + +This module implements different versions of some random number generators +proposed or used in the world of cryptology. +% \richard{Implanter MD5, \ldots} +% It implements a generator +% based on the Rijndael cipher, upon which is based AES, +% the Advanced Encryption Standard \cite{rDAE02a}. +% For more details, see +% \url{http://www.esat.kuleuven.ac.be/~rijmen/rijndael/}. + +% Les RNG propos\'es au workshop de NIST en 2004: +% \texttt{Hash, HMAC, KHF, cipherOFB, cipherCTR, +% Dual\_EC, MS}. (2004) \url{http://csrc.nist.gov/CryptoToolkit/tkrng.html} +\newcommand{\aes}{\textrm{AES}} +\newcommand{\shaun}{\mbox{\textrm{SHA-1}}} +\newcommand{\calh}{{H}} +\newcommand{\cale}{{E}} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* ucrypto.h for ANSI C */ +#ifndef UCRYPTO_H +#define UCRYPTO_H +\endhide +#include "unif01.h" + + +typedef enum { + ucrypto_OFB, /* Output Feedback mode */ + ucrypto_CTR, /* Counter mode */ + ucrypto_KTR /* Key counter mode */ + } ucrypto_Mode; +\endcode + \tab Block modes of operation \cite{rDWO01a} for this module. Given an algorithm + (for example, encryption or hashing) used as a generator of random numbers, then + the output feedback mode (\texttt{OFB}) uses the result of the last application + of the algorithm as input block for the current application. The counter + mode (\texttt{CTR}) applies the algorithm on a counter used as input and + incremented by 1 at each application. The key counter mode (\texttt{KTR}) + applies the algorithm on the seed with a different key at each application of + the algorithm; the key is incremented by 1 before each application. +% It is assumed that the plain text blocks to encrypt are all 0, except for the +% first one (\emph{the seed}) which is used for initialization. + \endtab +\code + + +unif01_Gen * ucrypto_CreateAES (unsigned char *Key, int klen, + unsigned char *Seed, ucrypto_Mode mode, + int r, int s); +\endcode +\tab Uses the \textit{Advanced Encryption standard} (\aes) as a source of +\index{Generator!AES}\index{Generator!Rijndael}% + random numbers \cite{rDAE02a,rNIS01a,rHEL03a,rBAR06a}, based on the optimized + C code for the Rijndael cipher written by V. Rijmen, + A. Bossel\ae rs and P. Barreto \cite{rRIJ00a}. \texttt{klen} is the number of + bits in the cipher \texttt{Key}, which must be given as an array of $16, 24$ + or $32$ bytes for a key of 128, 192 or 256 bits, respectively. \texttt{Seed} + is the initial state, which must be an array of 16 bytes making in all 128 bits. + At each encryption step $j$, the AES encryption algorithm is applied on the + input block to obtain a new block of 128 bits (16 bytes). Of these, + the first $r$ bytes are dropped and the next $s$ bytes are used to build 32-bit + random numbers. Each call to the generator returns a 32-bit random number. + For example, if $r=2$ and $s=8$, then the 16 ($8r$) most significant bits of + the block are dropped and the next 64 ($8s$) bits are used to make two 32-bit + random numbers which will be returned by the next two calls to the + generator. Restrictions: \texttt{klen} $\in \{ 128, 192, 256\}$, + $0 \le r \le 15$, $1 \le s \le 16$, and $r + s \le 16$. + + Let $C = \cale(K,T)$ denote the \aes\ encryption operation with key $K$ on + plain text $T$ resulting in encrypted text $C$. +\begin{itemize} + +\item For the \texttt{OFB} mode, each new block of 128 bits $C_j$ is + obtained by $C_j = \cale(K,C_{j-1})$, where $C_0 =$ \texttt{Seed}. + +\item The \texttt{CTR} mode uses a 128-bit counter $i$ whose initial value is + equal to \texttt{Seed}, and which is incremented + by 1 at each encryption step $j$. Each new block of 128 bits + $C_j$ is obtained by $C_j = \cale(K,i)$. + +\item The \texttt{KTR} mode uses a counter $i$ as the key which is + incremented by 1 at each encryption step $j$ as $i \leftarrow i + 1$. + Each new block of 128 bits $C_j$ is obtained by + $C_j = \cale(i, \texttt{Seed})$, where the initial value of $i$ is + \texttt{Key} viewed as an integer. +\end{itemize} + \endtab +\code + + +unif01_Gen * ucrypto_CreateSHA1 (unsigned char *Seed, int len, + ucrypto_Mode mode, int r, int s); +\endcode + \tab Uses the \textit{Secure Hash Algorithm} + \shaun\ as a source of random numbers \cite{rNIS02a,rBAR06a}. +\index{Generator!SHA1}% + \texttt{Seed} is an array of size \texttt{len} used to initialize the + generator. At each hashing step $j$, the \shaun\ algorithm is applied on the + input block to obtain a hashed string of 160 bits (20 bytes). Of these, + the first $r$ bytes are dropped and the next $s$ bytes are used to build 32-bit + random numbers. Each call to the generator returns a 32-bit random number. + For example, if $r=2$ and $s=8$, then the 16 ($8r$) most significant bits of + the 160-bit string are dropped and the next 64 ($8s$) bits are used to make + two 32-bit random numbers which will be returned by the next two + calls to the generator. Restrictions: \texttt{len} $\le 55$, + $0 \le r \le 19$, $1 \le s \le 20$, and $r + s \le 20$. + + Let $C = \calh(T)$ denote the \shaun\ operation applied on the original text $T$ + hashed to the 160-bit string $C$. (When $T$ is too short, it is padded + automatically by the \shaun\ algorithm to have the required block length of + 512 bits.) +\begin{itemize} +\item For the \texttt{OFB} mode, each new block of 160 $C_j$ is + obtained by $C_j = \calh(C_{j-1})$, where $C_0 = \calh(\mbox{\texttt{Seed}})$. + +\item The \texttt{CTR} mode uses a 440-bit counter $i$ whose initial value is + equal to \texttt{Seed}, and which is incremented by 1 at each hashing step $j$. + Each new block of 160 bits $C_j$ is obtained by + $C_j = \calh(i)$. +\end{itemize} + \endtab +\code + + +unif01_Gen * ucrypto_CreateISAAC (int flag, unsigned int A[256]); +\endcode + \tab + This is the generator \texttt{ISAAC} +\index{Generator!ISAAC}% + (Indirection, Shift, Accumulate, Add, and Count), + proposed and implemented by Bob Jenkins Jr. in \cite{rJEN96a}. + The version used here is the one recommended for cryptography, + with \texttt{RANDSIZL = 8}. + If \texttt{flag = 0}, the array \texttt{A} is not used and the initial state + is obtained from a complicated initialization procedure used in Jenkins' + implementation. + \richard{In his test program in file \texttt{rand.c}, Jenkins outputs the ISAAC + random numbers as \texttt{randrsl[0], randrsl[1], randrsl[2]}, \ldots + In TestU01, they are outputted in the order { \tt randrsl[255], randrsl[254], + randrsl[253]}, \ldots, because it is simpler.} + If \texttt{flag = 1}, the array \texttt{A} is used and transformed by + Jenkins' initialization procedure to obtain the initial state. + If \texttt{flag = 2}, the array \texttt{A} is used as the starting + state. Restriction: \texttt{flag} $\in \{0, 1, 2\}$. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Clean-up functions} +\code + +void ucrypto_DeleteAES (unif01_Gen * gen); +void ucrypto_DeleteSHA1 (unif01_Gen * gen); +void ucrypto_DeleteISAAC (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory used by the generators of this module, + and allocated by the corresponding \texttt{Create} function. + \endtab +\code\hide +#endif +\endhide\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ucryptoIS.c b/TESTU01/TestU01-1.2.3/testu01/ucryptoIS.c new file mode 100644 index 0000000..d8331f1 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ucryptoIS.c @@ -0,0 +1,387 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ucryptoIS.c + * Environment: ANSI C + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" + +#include "ucrypto.h" +#include "unif01.h" + +#include +#include + + +#define LEN 200 /* Max length of strings */ + + +static int co1 = 0; /* Counter */ + + +/*=========================================================================*/ +/* Generator ISAAC starts here. + * The only changes I have made in Bob Jenkins' code is to add the keyword + * static before functions randinit and isaac to avoid possible name clashes, + * and to remove the #include directives for standard.h and rand.h, since + * I have included these files explicitly here. (R. Simard) + * I have also changed the long int's into int's. + */ + +/* +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +x +x File standard.h, from Bob Jenkins web page, for his generator ISAAC +x +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +*/ + +/* +------------------------------------------------------------------------------ +Standard definitions and types, Bob Jenkins +------------------------------------------------------------------------------ +*/ +#ifndef STANDARD +# define STANDARD +# ifndef STDIO +# include +# define STDIO +# endif +# ifndef STDDEF +# include +# define STDDEF +# endif +typedef unsigned long long ub8; +#define UB8MAXVAL 0xffffffffffffffffLL +#define UB8BITS 64 +typedef signed long long sb8; +#define SB8MAXVAL 0x7fffffffffffffffLL +typedef unsigned int ub4; /* unsigned 4-byte quantities */ +#define UB4MAXVAL 0xffffffff +typedef signed int sb4; +#define UB4BITS 32 +#define SB4MAXVAL 0x7fffffff +typedef unsigned short int ub2; +#define UB2MAXVAL 0xffff +#define UB2BITS 16 +typedef signed short int sb2; +#define SB2MAXVAL 0x7fff +typedef unsigned char ub1; +#define UB1MAXVAL 0xff +#define UB1BITS 8 +typedef signed char sb1; /* signed 1-byte quantities */ +#define SB1MAXVAL 0x7f +typedef int word; /* fastest type available */ + +#define bis(target,mask) ((target) |= (mask)) +#define bic(target,mask) ((target) &= ~(mask)) +#define bit(target,mask) ((target) & (mask)) +#ifndef min +# define min(a,b) (((a)<(b)) ? (a) : (b)) +#endif /* min */ +#ifndef max +# define max(a,b) (((a)<(b)) ? (b) : (a)) +#endif /* max */ +#ifndef align +# define align(a) (((ub4)a+(sizeof(void *)-1))&(~(sizeof(void *)-1))) +#endif /* align */ +#ifndef abs +# define abs(a) (((a)>0) ? (a) : -(a)) +#endif +#define TRUE 1 +#define FALSE 0 +#define SUCCESS 0 /* 1 on VAX */ + +#endif /* STANDARD */ + + +/* +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +x +x File rand.h, from Bob Jenkins web page, for his generator ISAAC +x +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +*/ + +/* +------------------------------------------------------------------------------ +rand.h: definitions for a random number generator +MODIFIED: + 960327: Creation (addition of randinit, really) + 970719: use context, not global variables, for internal state + 980324: renamed seed to flag + 980605: recommend RANDSIZL=4 for noncryptography. +------------------------------------------------------------------------------ + +#ifndef STANDARD +#include "standard.h" +#endif +*/ + +#ifndef RAND +#define RAND +#define RANDSIZL (8) /* I recommend 8 for crypto, 4 for simulations */ +#define RANDSIZ (1<randcnt-- ? \ + (isaac(r), (r)->randcnt=RANDSIZ-1, (r)->randrsl[(r)->randcnt]) : \ + (r)->randrsl[(r)->randcnt]) + +#endif /* RAND */ + + + +/* +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +x +x File rand.c, from Bob Jenkins web page, for his generator ISAAC +x +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +*/ + +/* +------------------------------------------------------------------------------ +rand.c: By Bob Jenkins. My random number generator, ISAAC. +MODIFIED: + 960327: Creation (addition of randinit, really) + 970719: use context, not global variables, for internal state + 980324: added main (ifdef'ed out), also rearranged randinit() +------------------------------------------------------------------------------ + +#ifndef STANDARD +#include "standard.h" +#endif +#ifndef RAND +#include "rand.h" +#endif +*/ + +#define ind(mm,x) (*(ub4 *)((ub1 *)(mm) + ((x) & ((RANDSIZ-1)<<2)))) +#define rngstep(mix,a,b,mm,m,m2,r,x) \ +{ \ + x = *m; \ + a = (a^(mix)) + *(m2++); \ + *(m++) = y = ind(mm,x) + a + b; \ + *(r++) = b = ind(mm,y>>RANDSIZL) + x; \ +} + +static void isaac(ctx) +randctx *ctx; +{ + register ub4 a,b,x,y,*m,*mm,*m2,*r,*mend; + mm=ctx->randmem; r=ctx->randrsl; + a = ctx->randa; b = ctx->randb + (++ctx->randc); + for (m = mm, mend = m2 = m+(RANDSIZ/2); m>6 , a, b, mm, m, m2, r, x); + rngstep( a<<2 , a, b, mm, m, m2, r, x); + rngstep( a>>16, a, b, mm, m, m2, r, x); + } + for (m2 = mm; m2>6 , a, b, mm, m, m2, r, x); + rngstep( a<<2 , a, b, mm, m, m2, r, x); + rngstep( a>>16, a, b, mm, m, m2, r, x); + } + ctx->randb = b; ctx->randa = a; +} + + +#define mix(a,b,c,d,e,f,g,h) \ +{ \ + a^=b<<11; d+=a; b+=c; \ + b^=c>>2; e+=b; c+=d; \ + c^=d<<8; f+=c; d+=e; \ + d^=e>>16; g+=d; e+=f; \ + e^=f<<10; h+=e; f+=g; \ + f^=g>>4; a+=f; g+=h; \ + g^=h<<8; b+=g; h+=a; \ + h^=a>>9; c+=h; a+=b; \ +} + +/* if (flag==TRUE), then use the contents of randrsl[] to initialize mm[]. */ +static void randinit(ctx, flag) +randctx *ctx; +word flag; +{ + word i; + ub4 a,b,c,d,e,f,g,h; + ub4 *m,*r; + ctx->randa = ctx->randb = ctx->randc = 0; + m=ctx->randmem; + r=ctx->randrsl; + a=b=c=d=e=f=g=h=0x9e3779b9UL; /* the golden ratio */ + + for (i=0; i<4; ++i) /* scramble it */ + { + mix(a,b,c,d,e,f,g,h); + } + + if (flag) + { + /* initialize using the contents of r[] as the seed */ + for (i=0; irandcnt=RANDSIZ; /* prepare to use the first set of results */ +} + + + + +/*-------------------------------------------------------------------------*/ +static randctx ctx; + +static unsigned long ISAAC_Bits (void *junk1, void *junk2) +{ + return rand(&ctx); +} + +/*-----------------------------------------------------------------------*/ + +static double ISAAC_U01 (void *vpar, void *vsta) +{ + return ISAAC_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrISAAC (void *junk) { + ub4 i; + if (!unif01_WrLongStateFlag) { + unif01_WrLongStateDef (); + return; + } + printf ("A = {\n "); + for (i=0; iGetBits = &ISAAC_Bits; + gen->GetU01 = &ISAAC_U01; + gen->Write = &WrISAAC; + gen->param = NULL; + gen->state = NULL; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +void ucrypto_DeleteISAAC (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->name = util_Free (gen->name); + util_Free (gen); + co1--; +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ucubic.c b/TESTU01/TestU01-1.2.3/testu01/ucubic.c new file mode 100644 index 0000000..cf60f6a --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ucubic.c @@ -0,0 +1,1109 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ucubic.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "ucubic.h" +#include "unif01.h" + +#include +#include +#include + + + +#define LEN 150 /* Max length of strings */ + + + +/*================================ Types ================================*/ + +typedef struct { + unsigned long m, a, b, c, d; + double Norm; +} Cubic_param; + +typedef struct { + unsigned long X; +} Cubic_state; + + +/*---------------*/ +#ifdef USE_LONGLONG + +typedef struct { + ulonglong m, a, b, c, d; + double Norm; +} CubicL_param; + +typedef struct { + ulonglong X; +} CubicL_state; + +/*---------------*/ +#else + +typedef struct { + long m, a, b, c, d; + double Norm; +} CubicL_param; + +typedef struct { + long X; +} CubicL_state; + +#endif +/*---------------*/ + + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double a, b, c, d, m; + double Norm; +} CubicFloat_param; + +typedef struct { + double X; +} CubicFloat_state; + + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long A, M; + double Norm; +} Cubic1_param; + +typedef struct { + unsigned long X; +} Cubic1_state; + + +typedef struct { + long M, A; + double Norm; +} Cubic1L_param; + +typedef struct { + long X; +} Cubic1L_state; + + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double M, A; + double Norm; +} Cubic1Float_param; + +typedef struct { + double X; +} Cubic1Float_state; + + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long M1, M2, A1, A2; + double Norm1, Norm2; +} CombCubic2_param; + +typedef struct { + unsigned long S1, S2; +} CombCubic2_state; + +typedef struct { + long M1, M2, A1, A2; + double Norm1, Norm2; +} CombCubic2L_param; + +typedef struct { + long S1, S2; +} CombCubic2L_state; + + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long M, A, C; + double Norm; +} CubicOut_param; + +typedef struct { + long X; +} CubicOut_state; + + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double M, A, C; + double Norm; +} CubicOutFloat_param; + +typedef struct { + double X; +} CubicOutFloat_state; + + + + +/**************************************************************************/ + +static double Cubic_U01 (void *vpar, void *vsta) +/* + * Implementation used when all intermediary results hold in an int of 32 + * bits. This is the case when m < 2^{16} since a, b, c, d are all < m. + */ +{ + Cubic_param *param = vpar; + Cubic_state *state = vsta; + + state->X = (param->d + state->X * ((param->c + state->X * ((param->b + + state->X * param->a) % param->m)) % param->m)) % param->m; + return (state->X * param->Norm); +} + + +/*---------------*/ +#ifdef USE_LONGLONG + +static double CubicL_U01 (void *vpar, void *vsta) +/* + * Implementation of Cubic used in the general case. + */ +{ + CubicL_param *param = vpar; + CubicL_state *state = vsta; + + state->X = (param->d + state->X * ((param->c + state->X * ((param->b + + state->X * param->a) % param->m)) % param->m)) % param->m; + return state->X * param->Norm; +} + +/*---------------*/ +#else + +static double CubicL_U01 (void *vpar, void *vsta) +/* + * Implementation of Cubic used in the general case. Very slow. + */ +{ + CubicL_param *param = vpar; + CubicL_state *state = vsta; + long k; + + k = num_MultModL (param->a, state->X, param->b, param->m); + k = num_MultModL (k, state->X, param->c, param->m); + state->X = num_MultModL (k, state->X, param->d, param->m); + return state->X * param->Norm; +} + +#endif +/*---------------*/ + + +static unsigned long Cubic_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Cubic_U01 (vpar, vsta)); +} + +static unsigned long CubicL_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicL_U01 (vpar, vsta)); +} + +static void WrCubic (void *vsta) +{ + Cubic_state *state = vsta; + printf (" X = %lu\n", state->X); +} + +static void WrCubicL (void *vsta) +{ + CubicL_state *state = vsta; + printf (" X = %1lu\n", (unsigned long) state->X); +} + + +static void SetCubic_0 (unif01_Gen * gen, long m, long a, long b, + long c, long d, long s) +{ + Cubic_param *param; + Cubic_state *state; + + param = util_Malloc (sizeof (Cubic_param)); + state = util_Malloc (sizeof (Cubic_state)); + + param->Norm = 1.0 / m; + param->m = m; + param->a = a; + param->b = b; + param->c = c; + param->d = d; + state->X = s; + + gen->GetBits = &Cubic_Bits; + gen->GetU01 = &Cubic_U01; + gen->Write = &WrCubic; + gen->param = param; + gen->state = state; +} + +static void SetCubicL_0 (unif01_Gen * gen, long m, long a, long b, + long c, long d, long s) +{ + CubicL_param *param; + CubicL_state *state; + + param = util_Malloc (sizeof (CubicL_param)); + state = util_Malloc (sizeof (CubicL_state)); + + param->Norm = 1.0 / m; + param->m = m; + param->a = a; + param->b = b; + param->c = c; + param->d = d; + state->X = s; + + gen->GetBits = &CubicL_Bits; + gen->GetU01 = &CubicL_U01; + gen->Write = &WrCubicL; + gen->param = param; + gen->state = state; +} + +unif01_Gen *ucubic_CreateCubic (long m, long a, long b, long c, long d, + long s) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + + util_Assert (m > 0, "ucubic_CreateCubic: m <= 0"); + util_Assert ((a > 0) && (a < m), + "ucubic_CreateCubic: a must be in (0, m)"); + util_Assert ((b >= 0) && (b < m), + "ucubic_CreateCubic: b must be in [0, m)"); + util_Assert ((c >= 0) && (c < m), + "ucubic_CreateCubic: c must be in [0, m)"); + util_Assert ((d >= 0) && (d < m), + "ucubic_CreateCubic: d must be in [0, m)"); + util_Assert ((s >= 0) && (s < m), + "ucubic_CreateCubic: s must be in [0, m)"); + + gen = util_Malloc (sizeof (unif01_Gen)); + + strncpy (name, "ucubic_CreateCubic:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", b = ", b); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", d = ", d); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (m < num_TwoExp[16]) + SetCubic_0 (gen, m, a, b, c, d, s); + else + SetCubicL_0 (gen, m, a, b, c, d, s); + + return gen; +} + + +/**************************************************************************/ + +static void WrCubicFloat (void *vsta) +{ + CubicFloat_state *state = vsta; + printf (" X = %1ld\n", (long) state->X); +} + +static double CubicFloatA_U01 (void *vpar, void *vsta) +/* + * Implementation used when + * [ a*(m-1)^3 + b*(m-1)^2 + c*(m-1) + d ] / m < 2^31 + * else k may not hold in a long int. + */ +{ + CubicFloat_param *param = vpar; + CubicFloat_state *state = vsta; + long k; + + state->X = param->d + state->X * (param->c + state->X * (param->b + + state->X * param->a)); + k = state->X * param->Norm; + state->X -= k * param->m; + return (state->X * param->Norm); +} + +static double CubicFloatB_U01 (void *vpar, void *vsta) +/* + * Implementation used when (m-1)*m < 2^53 + * else, R*R + R may not hold in a double. + */ +{ + CubicFloat_param *param = vpar; + CubicFloat_state *state = vsta; + long k; + double y; + + y = param->a * state->X + param->b; + k = y * param->Norm; + y -= k * param->m; + y = y * state->X + param->c; + k = y * param->Norm; + y -= k * param->m; + state->X = y * state->X + param->d; + k = state->X * param->Norm; + state->X -= k * param->m; + return state->X * param->Norm; +} + +static double CubicFloatC_U01 (void *vpar, void *vsta) +/* + * Implementation used in the general case. + */ +{ + CubicFloat_param *param = vpar; + CubicFloat_state *state = vsta; + double y; + + y = num_MultModD (param->a, state->X, param->b, param->m); + y = num_MultModD (y, state->X, param->c, param->m); + state->X = num_MultModD (y, state->X, param->d, param->m); + return (state->X * param->Norm); +} + +static unsigned long CubicFloatA_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicFloatA_U01 (vpar, vsta)); +} + +static unsigned long CubicFloatB_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicFloatB_U01 (vpar, vsta)); +} + +static unsigned long CubicFloatC_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicFloatC_U01 (vpar, vsta)); +} + + +unif01_Gen *ucubic_CreateCubicFloat (long m, long a, long b, long c, long d, + long s) +{ + unif01_Gen *gen; + CubicFloat_param *param; + CubicFloat_state *state; + size_t leng; + char name[LEN + 1]; + double y, v; + + util_Assert (m > 0, "ucubic_CreateCubicFloat: m <= 0"); + util_Assert ((a > 0) && (a < m), + "ucubic_CreateCubicFloat: a must be in (0, m)"); + util_Assert ((b >= 0) && (b < m), + "ucubic_CreateCubicFloat: b must be in [0, m)"); + util_Assert ((c >= 0) && (c < m), + "ucubic_CreateCubicFloat: c must be in [0, m)"); + util_Assert ((d >= 0) && (d < m), + "ucubic_CreateCubicFloat: d must be in [0, m)"); + util_Assert ((s >= 0) && (s < m), + "ucubic_CreateCubicFloat: s must be in [0, m)"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CubicFloat_param)); + state = util_Malloc (sizeof (CubicFloat_state)); + + strncpy (name, "ucubic_CreateCubicFloat:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", b = ", b); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", d = ", d); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Norm = 1.0 / m; + param->m = m; + param->a = a; + param->b = b; + param->c = c; + param->d = d; + state->X = s; + + gen->Write = &WrCubicFloat; + gen->param = param; + gen->state = state; + + y = m - 1; + v = d + y * (c + y * (b + y * a)); + + if (v / m < num_TwoExp[31]) { + gen->GetU01 = CubicFloatA_U01; + gen->GetBits = CubicFloatA_Bits; + + } else if (y * y < num_TwoExp[53]) { + gen->GetU01 = CubicFloatB_U01; + gen->GetBits = CubicFloatB_Bits; + + } else { + gen->GetU01 = CubicFloatC_U01; + gen->GetBits = CubicFloatC_Bits; + } + + return gen; +} + + +/**************************************************************************/ + +static void WrCubic1 (void *vsta) +{ + Cubic1_state *state = vsta; + printf (" X = %1lu\n", state->X); +} + +static double Cubic1_U01 (void *vpar, void *vsta) +/* + * Implementation used when all intermediary results hold in an int of 32 + * bits. This is the case when M < 2^{16}. + */ +{ + Cubic1_param *param = vpar; + Cubic1_state *state = vsta; + + state->X = (state->X * ((state->X * state->X) % param->M)) % param->M; + state->X = (param->A * state->X + 1) % param->M; + return (state->X * param->Norm); +} + +static double Cubic1L_U01 (void *vpar, void *vsta) +/* + * Implementation of Cubic1 used in the general case. Very slow. + */ +{ + Cubic1L_param *param = vpar; + Cubic1L_state *state = vsta; + long S; + + S = num_MultModL (state->X, state->X, 0L, param->M); + S = num_MultModL (state->X, S, 0L, param->M); + state->X = num_MultModL (param->A, S, 1L, param->M); + return (state->X * param->Norm); +} + +static unsigned long Cubic1_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Cubic1_U01 (vpar, vsta)); +} + +static unsigned long Cubic1L_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Cubic1L_U01 (vpar, vsta)); +} + + +static void SetCubic1_0 (unif01_Gen * gen, long m, long a, long s) +{ + Cubic1_param *param; + Cubic1_state *state; + + param = util_Malloc (sizeof (Cubic1_param)); + state = util_Malloc (sizeof (Cubic1_state)); + + param->Norm = 1.0 / m; + param->M = m; + param->A = a; + state->X = s; + + gen->GetBits = &Cubic1_Bits; + gen->GetU01 = &Cubic1_U01; + gen->Write = &WrCubic1; + gen->param = param; + gen->state = state; +} + +static void SetCubic1L_0 (unif01_Gen * gen, long m, long a, long s) +{ + Cubic1L_param *param; + Cubic1L_state *state; + + param = util_Malloc (sizeof (Cubic1L_param)); + state = util_Malloc (sizeof (Cubic1L_state)); + + param->Norm = 1.0 / m; + param->M = m; + param->A = a; + state->X = s; + + gen->GetBits = &Cubic1L_Bits; + gen->GetU01 = &Cubic1L_U01; + gen->Write = &WrCubic1; + gen->param = param; + gen->state = state; +} + + +unif01_Gen *ucubic_CreateCubic1 (long m, long a, long s) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + + util_Assert ((m > 0), "ucubic_CreateCubic1: m <= 0"); + util_Assert ((a > 0) && (a < m), + "ucubic_CreateCubic1: a must be in (0, m)"); + util_Assert ((s >= 0) && (s < m), + "ucubic_CreateCubic1: s must be in [0, m)"); + + gen = util_Malloc (sizeof (unif01_Gen)); + + strncpy (name, "ucubic_CreateCubic1:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (m < num_TwoExp[16]) + SetCubic1_0 (gen, m, a, s); + else + SetCubic1L_0 (gen, m, a, s); + + return gen; +} + + +/**************************************************************************/ + +static void WrCubic1Float (void *vsta) +{ + Cubic1Float_state *state = vsta; + printf (" X = %1ld\n", (long) state->X); +} + +static double Cubic1FloatA_U01 (void *vpar, void *vsta) +/* + * Used when condition 1 + a*(m-1)^3/m < 2^31; + * else k may not hold in a long. + */ +{ + Cubic1Float_param *param = vpar; + Cubic1Float_state *state = vsta; + long k; + + state->X = param->A * state->X * state->X * state->X + 1.0; + k = state->X * param->Norm; + state->X -= k * param->M; + return (state->X * param->Norm); +} + +static double Cubic1FloatB_U01 (void *vpar, void *vsta) +/* + * Used when condition (m-1)^2 < 2^53; + * else R*R may not hold in a double. + */ +{ + Cubic1Float_param *param = vpar; + Cubic1Float_state *state = vsta; + long k; + double y; + + y = param->A * state->X; + k = y * param->Norm; + y -= k * param->M; + y *= state->X; + k = y * param->Norm; + y -= k * param->M; + state->X = y * state->X + 1.0; + k = state->X * param->Norm; + state->X -= k * param->M; + return (state->X * param->Norm); +} + +static double Cubic1FloatC_U01 (void *vpar, void *vsta) +/* + * Inmplementation used in the general case + */ +{ + Cubic1Float_param *param = vpar; + Cubic1Float_state *state = vsta; + double y; + + y = num_MultModD (state->X, state->X, 0.0, param->M); + y = num_MultModD (state->X, y, 0.0, param->M); + state->X = num_MultModD (param->A, y, 1.0, param->M); + return (state->X * param->Norm); +} + +static unsigned long Cubic1FloatA_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Cubic1FloatA_U01 (vpar, vsta)); +} + +static unsigned long Cubic1FloatB_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Cubic1FloatB_U01 (vpar, vsta)); +} + +static unsigned long Cubic1FloatC_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Cubic1FloatC_U01 (vpar, vsta)); +} + +unif01_Gen *ucubic_CreateCubic1Float (long m, long a, long s) +{ + unif01_Gen *gen; + Cubic1Float_param *param; + Cubic1Float_state *state; + size_t leng; + char name[LEN + 1]; + double y; + + util_Assert ((m > 0), "ucubic_CreateCubic1Float: m <= 0"); + util_Assert ((a > 0) && (a < m), + "ucubic_CreateCubic1Float: a must be in (0, m)"); + util_Assert ((s >= 0) && (s < m), + "ucubic_CreateCubic1Float: s must be in [0, m)"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Cubic1Float_param)); + state = util_Malloc (sizeof (Cubic1Float_state)); + + strncpy (name, "ucubic_CreateCubic1Float:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Norm = 1.0 / m; + param->M = m; + param->A = a; + state->X = s; + + y = m - 1; + if (1.0 + a * y * y * y / m < num_TwoExp[31]) { + gen->GetU01 = Cubic1FloatA_U01; + gen->GetBits = Cubic1FloatA_Bits; + + } else if (y * y < num_TwoExp[53]) { + gen->GetU01 = Cubic1FloatB_U01; + gen->GetBits = Cubic1FloatB_Bits; + + } else { + gen->GetU01 = Cubic1FloatC_U01; + gen->GetBits = Cubic1FloatC_Bits; + } + + gen->Write = &WrCubic1Float; + gen->param = param; + gen->state = state; + + return gen; +} + + +/**************************************************************************/ + +static void WrCombCubic2 (void *vsta) +{ + CombCubic2_state *state = vsta; + printf (" X1 = %1lu, X2 = %1lu\n", state->S1, state->S2); +} + +static double CombCubic2_U01 (void *vpar, void *vsta) +/* + * Implementation used when all intermediary results hold in an int of 32 + * bits. This is the case when M < 2^{16}. + */ +{ + CombCubic2_param *param = vpar; + CombCubic2_state *state = vsta; + unsigned long Y; + double U; + + Y = (state->S1 * ((state->S1 * state->S1) % param->M1)) % param->M1; + state->S1 = (param->A1 * Y + 1) % param->M1; + Y = (state->S2 * ((state->S2 * state->S2) % param->M2)) % param->M2; + state->S2 = (param->A2 * Y + 1) % param->M2; + U = state->S1 * param->Norm1 + state->S2 * param->Norm2; + if (U >= 1.0) + return (U - 1.0); + else + return U; +} + +static double CombCubic2L_U01 (void *vpar, void *vsta) +/* + * Implementation of CombCubic2 used in the general case. Very slow. + */ +{ + CombCubic2L_param *param = vpar; + CombCubic2L_state *state = vsta; + long Y; + double U; + + Y = num_MultModL (state->S1, state->S1, 0L, param->M1); + Y = num_MultModL (state->S1, Y, 0L, param->M1); + state->S1 = num_MultModL (param->A1, Y, 1L, param->M1); + Y = num_MultModL (state->S2, state->S2, 0L, param->M2); + Y = num_MultModL (state->S2, Y, 0L, param->M2); + state->S2 = num_MultModL (param->A2, Y, 1L, param->M2); + U = state->S1 * param->Norm1 + state->S2 * param->Norm2; + if (U >= 1.0) + return (U - 1.0); + else + return U; +} + +static unsigned long CombCubic2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombCubic2_U01 (vpar, vsta)); +} + +static unsigned long CombCubic2L_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombCubic2L_U01 (vpar, vsta)); +} + + +static void SetCombCubic2_0 (unif01_Gen * gen, long m1, long m2, long a1, + long a2, long s1, long s2) +{ + CombCubic2_param *param; + CombCubic2_state *state; + + param = util_Malloc (sizeof (CombCubic2_param)); + state = util_Malloc (sizeof (CombCubic2_state)); + + param->Norm1 = 1.0 / m1; + param->Norm2 = 1.0 / m2; + param->M1 = m1; + param->A1 = a1; + param->M2 = m2; + param->A2 = a2; + state->S1 = s1; + state->S2 = s2; + + gen->GetBits = &CombCubic2_Bits; + gen->GetU01 = &CombCubic2_U01; + gen->Write = &WrCombCubic2; + gen->param = param; + gen->state = state; +} + +static void SetCombCubic2L_0 (unif01_Gen * gen, long m1, long m2, long a1, + long a2, long s1, long s2) +{ + CombCubic2L_param *param; + CombCubic2L_state *state; + + param = util_Malloc (sizeof (CombCubic2L_param)); + state = util_Malloc (sizeof (CombCubic2L_state)); + + param->Norm1 = 1.0 / m1; + param->Norm2 = 1.0 / m2; + param->M1 = m1; + param->A1 = a1; + param->M2 = m2; + param->A2 = a2; + state->S1 = s1; + state->S2 = s2; + + gen->GetBits = &CombCubic2L_Bits; + gen->GetU01 = &CombCubic2L_U01; + gen->Write = &WrCombCubic2; + gen->param = param; + gen->state = state; +} + + +unif01_Gen *ucubic_CreateCombCubic2 (long m1, long m2, long a1, long a2, + long s1, long s2) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + + if ((a1 <= 0) || (a1 >= m1) || (s1 < 0) || (s1 >= m1) || (m1 <= 0) || + (a2 <= 0) || (a2 >= m2) || (s2 < 0) || (s2 >= m2) || (m2 <= 0)) { + printf ("m1 = %1ld, m2 = %1ld, a1 = %1ld, a2 = %1ld," + " s1 = %1ld, s2 = %1ld\n", m1, m2, a1, a2, s1, s2); + util_Error ("ucubic_CreateCombCubic2: Invalid parameter"); + } + + gen = util_Malloc (sizeof (unif01_Gen)); + + strncpy (name, "ucubic_CreateCombCubic2:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", s1 = ", s1); + addstr_Long (name, ", s2 = ", s2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if ((m1 < num_TwoExp[16]) && (m2 < num_TwoExp[16])) + SetCombCubic2_0 (gen, m1, m2, a1, a2, s1, s2); + else + SetCombCubic2L_0 (gen, m1, m2, a1, a2, s1, s2); + return gen; +} + + +/**************************************************************************/ + +static void WrCubicOut (void *vsta) +{ + CubicOut_state *state = vsta; + printf (" X = %1ld\n", state->X); +} + +static double CubicOut_U01 (void *vpar, void *vsta) +{ + CubicOut_param *param = vpar; + CubicOut_state *state = vsta; + long Y; + + state->X = num_MultModL (param->A, state->X, param->C, param->M); + Y = num_MultModL (state->X, state->X, 0L, param->M); + Y = num_MultModL (state->X, Y, 0L, param->M); + return (Y * param->Norm); +} + +static unsigned long CubicOut_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicOut_U01 (vpar, vsta)); +} + + +unif01_Gen *ucubic_CreateCubicOut (long m, long a, long c, long s) +{ + unif01_Gen *gen; + CubicOut_param *param; + CubicOut_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert ((m > 0), "ucubic_CreateCubicOut: m <= 0"); + util_Assert ((a > 0) && (a < m), + "ucubic_CreateCubicOut: a must be in (0, m)"); + util_Assert ((c >= 0) && (c < m), + "ucubic_CreateCubicOut: c must be in [0, m)"); + util_Assert ((s >= 0) && (s < m), + "ucubic_CreateCubicOut: s must be in [0, m)"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CubicOut_param)); + state = util_Malloc (sizeof (CubicOut_state)); + + strncpy (name, "ucubic_CreateCubicOut:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Norm = 1.0 / m; + param->M = m; + param->A = a; + param->C = c; + state->X = s; + + gen->GetU01 = CubicOut_U01; + gen->GetBits = CubicOut_Bits; + gen->Write = &WrCubicOut; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static void WrCubicOutFloat (void *vsta) +{ + CubicOutFloat_state *state = vsta; + printf (" X = %1ld\n", (long) state->X); +} + +static double CubicOutFloatA_U01 (void *vpar, void *vsta) +/* + * Used when condition (m-1)^3/m < 2^31; + * else k may not hold in a long. + */ +{ + CubicOutFloat_param *param = vpar; + CubicOutFloat_state *state = vsta; + long k; + double y; + + state->X = param->A * state->X + param->C; + k = state->X * param->Norm; + state->X -= k * param->M; + y = state->X * state->X * state->X; + k = y * param->Norm; + y -= k * param->M; + return (y * param->Norm); +} + +static double CubicOutFloatB_U01 (void *vpar, void *vsta) +/* + * Floating-point implementation for the case when m <= 94906266 ~ 2^26.5; + * follows the condition (m-1)^2 < 2^53; else, R*R may not hold in a double. + */ +{ + CubicOutFloat_param *param = vpar; + CubicOutFloat_state *state = vsta; + long k; + double y; + + state->X = param->A * state->X + param->C; + k = state->X * param->Norm; + state->X -= k * param->M; + y = state->X * state->X; + k = y * param->Norm; + y -= k * param->M; + y = state->X * y; + k = y * param->Norm; + y -= k * param->M; + return (y * param->Norm); +} + +static double CubicOutFloatC_U01 (void *vpar, void *vsta) +{ + CubicOutFloat_param *param = vpar; + CubicOutFloat_state *state = vsta; + double y; + + state->X = num_MultModD (param->A, state->X, param->C, param->M); + y = num_MultModD (state->X, state->X, 0.0, param->M); + y = num_MultModD (state->X, y, 0.0, param->M); + return (y * param->Norm); +} + +static unsigned long CubicOutFloatA_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicOutFloatA_U01 (vpar, vsta)); +} + +static unsigned long CubicOutFloatB_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicOutFloatB_U01 (vpar, vsta)); +} + +static unsigned long CubicOutFloatC_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CubicOutFloatC_U01 (vpar, vsta)); +} + +unif01_Gen *ucubic_CreateCubicOutFloat (long m, long a, long c, long s) +{ + unif01_Gen *gen; + CubicOutFloat_param *param; + CubicOutFloat_state *state; + size_t leng; + char name[LEN + 1]; + double y; + + util_Assert ((m > 0), "ucubic_CreateCubicOutFloat: m <= 0"); + util_Assert ((a > 0) && (a < m), + "ucubic_CreateCubicOutFloat: a must be in (0, m)"); + util_Assert ((c >= 0) && (c < m), + "ucubic_CreateCubicOutFloat: c must be in [0, m)"); + util_Assert ((s >= 0) && (s < m), + "ucubic_CreateCubicOutFloat: s must be in [0, m)"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CubicOutFloat_param)); + state = util_Malloc (sizeof (CubicOutFloat_state)); + + strncpy (name, "ucubic_CreateCubicOutFloat:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->M = m; + param->A = a; + state->X = s; + param->C = c; + param->Norm = 1.0 / m; + + y = m - 1; + if (y * y * y / m < num_TwoExp[31]) { + gen->GetU01 = CubicOutFloatA_U01; + gen->GetBits = CubicOutFloatA_Bits; + + } else if (y * y < num_TwoExp[53]) { + gen->GetU01 = CubicOutFloatB_U01; + gen->GetBits = CubicOutFloatB_Bits; + + } else { + gen->GetU01 = CubicOutFloatC_U01; + gen->GetBits = CubicOutFloatC_Bits; + } + + gen->Write = &WrCubicOutFloat; + gen->param = param; + gen->state = state; + + return gen; +} + + +/**************************************************************************/ + +void ucubic_DeleteGen (unif01_Gen * gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ucubic.tex b/TESTU01/TestU01-1.2.3/testu01/ucubic.tex new file mode 100644 index 0000000..25eb499 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ucubic.tex @@ -0,0 +1,119 @@ +\defmodule{ucubic} + +This module implements simple and combined cubic congruential +generators, based on recurrences of the form +\eq + x_{n+1} = (a x_n^3 + b x_n^2 + c x_n + d) \mod m, \eqlabel{cubic} +\endeq +with output $u_n = x_n/m$ at step $n$. +See, e.g., \cite{rEIC97a,rLEC98h}. + +Generators based on a linear congruential recurrence, but with +a cubic output transformation, are also available +(see {\tt ucubic\_CreateCubicOut}). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* ucubic.h for ANSI C */ +#ifndef UCUBIC_H +#define UCUBIC_H +\endhide +#include "unif01.h" + + +unif01_Gen * ucubic_CreateCubic (long m, long a, long b, long c, long d, + long s); +\endcode + \tab Initializes a generator of the form (\ref{cubic}), with + initial state $x_0 = s$. +\index{Generator!cubic}% + Depending on the values of the parameters, various implementations + of different speed are used. + In general, this generator is rather slow. + Restrictions: $a$, $b$, $c$, $d$, and $s$ non + negative and less than $m$. + \endtab +\code + + +unif01_Gen * ucubic_CreateCubicFloat (long m, long a, long b, long c, + long d, long s); +\endcode + \tab A floating-point implementation of the same generator as in + {\tt ucubic\_CreateCubic}. + The implementation depends on the parameter values and is slower + when $m(m-1) > 2^{53}$. + The same restrictions as for {\tt ucubic\_CreateCubic} apply. + Also assumes that a {\tt double} has at least 53 bits of precision. + \endtab +\code + + +unif01_Gen * ucubic_CreateCubic1 (long m, long a, long s); +\endcode + \tab Implements a cubic generator which is a special case of + (\ref{cubic}), with recurrence $x_{n+1} = (a x_n^3 + 1) \mod m$. + The initial state is $x_0 = s$ and the $n$-th generated value + is $u_n = x_n/m$. + Restrictions: $a$ and $s$ non negative and less than $m$. + \endtab +\code + + +unif01_Gen * ucubic_CreateCubic1Float (long m, long a, long s); +\endcode + \tab Floating-point implementation of the same generator as in + {\tt ucubic\_CreateCubic1}. The implementation and restrictions are + similar to those in {\tt ucubic\_CreateCubicFloat}. + \endtab +\code + + +unif01_Gen * ucubic_CreateCombCubic2 (long m1, long m2, long a1, long a2, + long s1, long s2); +\endcode + \tab Implements a generator that combines two cubic components + of the same type as in the procedure {\tt ucubic\_CreateCubic1}. + The output is + $ u_n = (x_{1,n}/m_1 + x_{2,m}/m_2) \mod 1, $ + where $x_{1,n}$ and $x_{2,n}$ are the states of the two components + at step $n$. + \endtab +\code + + +unif01_Gen * ucubic_CreateCubicOut (long m, long a, long c, long s); +\endcode + \tab Initializes a generator defined by the linear recurrence + $x_{n+1} = (a x_n + c) \mod m$, with initial state $x_0 = s$, + and with output $u_n = (x_n^3 \mod m) / m$. + Restrictions: $a$, $c$ and $s$ non negative and less than $m$. + \endtab +\code + + +unif01_Gen * ucubic_CreateCubicOutFloat (long m, long a, long c, long s); +\endcode + \tab A floating-point implementation of {\tt ucubic\_CreateCubicOut}. + The implementation and restrictions are similar to those in + {\tt ucubic\_CreateCubicFloat}. + \endtab + + + +\guisec{Clean-up functions} +\code + +void ucubic_DeleteGen (unif01_Gen *gen); +\endcode + \tab \DelGen + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/udeng.c b/TESTU01/TestU01-1.2.3/testu01/udeng.c new file mode 100644 index 0000000..93e7534 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/udeng.c @@ -0,0 +1,252 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: udeng.c + * Environment: ANSI C + * Programmer: Richard Simard. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "addstr.h" +#include "num.h" + +#include "udeng.h" +#include "unif01.h" + +#include +#include +#include +#include + + +#define LEN 200 /* Max length of strings */ + +static int co1 = 0; /* Counters */ + + +typedef struct { + double b, m; +} DX02_param; + +typedef struct { + double *X; + unsigned int s, K; +} DX02_state; + + + + + + + +/*=========================================================================*/ +#define MASK1 127 +#define LAC + +static unif01_Gen *CreateDenga (unsigned long m, unsigned long b, int k, + unsigned long S[], int id); + +#ifndef LAC +static double DX02a_U01 (void *vpar, void *vsta) +{ + DX02_state *state = vsta; + DX02_param *param = vpar; + double Z; + ++state->s; + + Z = param->b * (state->X[(state->s - 1) & MASK1] + + state->X[(state->s - state->K) & MASK1]); + Z = state->X[state->s & MASK1] = fmod (Z, param->m); + return Z / param->m; + /* + Z = state->X[state->s & MASK1] = num_MultModD (param->b, + state->X[(state->s - 1) & MASK1] + state->X[(state->s - state->K) & + MASK1], 0.0, param->m); + return Z / param->m; + */ +} + +#else +static double DX02a_U01 (void *vpar, void *vsta) +{ + /* Generate 3 numbers; discard the next 100 numbers; and so on ... */ + DX02_state *state = vsta; + DX02_param *param = vpar; + double Z; + int i; + static int co = 2; + ++state->s; + + if (co % 3 == 0) { + for (i = 0; i < 100; i++) { + state->X[state->s & MASK1] = num_MultModD (param->b, + state->X[(state->s - 1) & MASK1] + state->X[(state->s - state->K) & + MASK1], 0.0, param->m); + ++state->s; + } + co = 0; + } + co++; + Z = state->X[state->s & MASK1] = num_MultModD (param->b, + state->X[(state->s - 1) & MASK1] + state->X[(state->s - state->K) & + MASK1], 0.0, param->m); + return Z / param->m; +} +#endif + +/*-----------------------------------------------------------------------*/ + +static unsigned long DX02a_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * DX02a_U01 (vpar, vsta)); +} + + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *udeng_CreateDX02a (unsigned long m, unsigned long b, int k, + unsigned long S[]) +{ + return CreateDenga (m, b, k, S, 2); +} + + +/*=========================================================================*/ + +static double DL00a_U01 (void *vpar, void *vsta) +{ + DX02_state *state = vsta; + DX02_param *param = vpar; + double Z; + ++state->s; + + Z = param->b * state->X[(state->s - state->K) & MASK1] - + state->X[(state->s - 1) & MASK1]; + Z = state->X[state->s & MASK1] = fmod (Z + param->m, param->m); + + /* Z = state->X[state->s & MASK1] = num_MultModD (param->b, + state->X[(state->s - state->K) & MASK1], + -state->X[(state->s - 1) & MASK1], param->m); */ + return Z / param->m; +} + + +/*-----------------------------------------------------------------------*/ + +static unsigned long DL00a_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * DL00a_U01 (vpar, vsta)); +} + + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *udeng_CreateDL00a (unsigned long m, unsigned long b, int k, + unsigned long S[]) +{ + return CreateDenga (m, b, k, S, 0); +} + + +/*=========================================================================*/ + +static void WrDX02a (void *vsta) +{ + DX02_state *state = vsta; + unsigned int j; + int s = state->s & MASK1; + + if (unif01_WrLongStateFlag || (state->K < 8)) { + printf (" S = {\n "); + for (j = 0; j < state->K; j++) { + printf (" %12.0f", state->X[s]); + if (--s < 0) + s = MASK1; + if (j < state->K - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +static unif01_Gen *CreateDenga (unsigned long m, unsigned long b, int k, + unsigned long S[], int id) +{ + unif01_Gen *gen; + DX02_state *state; + DX02_param *param; + size_t leng; + char name[LEN + 1]; + int j; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (DX02_state)); + param = util_Malloc (sizeof (DX02_param)); + if (0 == id) { + util_Assert (k < 129, "udeng_CreateDL00a: k > 128"); + } else { + util_Assert (k < 129, "udeng_CreateDX02a: k > 128"); + } + + state->X = util_Calloc (MASK1 + 1, sizeof (double)); + for (j = 0; j < k; j++) + state->X[k - j - 1] = S[j] % m; + state->s = k - 1; + state->K = k; + param->b = b; + param->m = m; + + if (0 == id) + strcpy (name, "udeng_CreateDL00a:"); + else +#ifdef LAC + strcpy (name, "udeng_CreateDX02a, Lac = {0, 101, 102}:"); +#else + strcpy (name, "udeng_CreateDX02a:"); +#endif + addstr_Ulong (name, " m = ", m); + addstr_Ulong (name, ", b = ", b); + addstr_Uint (name, ", k = ", (unsigned) k); + addstr_ArrayUlong (name, ", S = ", k, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + if (0 == id) { + gen->GetBits = &DL00a_Bits; + gen->GetU01 = &DL00a_U01; + } else { + gen->GetBits = &DX02a_Bits; + gen->GetU01 = &DX02a_U01; + } + gen->Write = &WrDX02a; + return gen; +} + + +/*=========================================================================*/ + +void udeng_DeleteGen (unif01_Gen * gen) +{ + DX02_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->X); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/*=========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/udeng.tex b/TESTU01/TestU01-1.2.3/testu01/udeng.tex new file mode 100644 index 0000000..41b3486 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/udeng.tex @@ -0,0 +1,72 @@ +\defmodule {udeng} + +This module collects some generators from Lih-Yuan Deng and his + collaborators.\index{Generator!Deng}% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* udeng.h for ANSI C */ + +#ifndef UDENG_H +#define UDENG_H +\endhide +#include "unif01.h" +\endcode +\code + + +unif01_Gen * udeng_CreateDL00a (unsigned long m, unsigned long b, int k, + unsigned long S[]); +\endcode + \tab Creates a multiple recursive generator proposed by Deng + and Lin \cite{rDEN00a} in the form: + $$ + x_i\ =\ ((m-1)x_{i-1} + b x_{i-k}) \mod m\ =\ + (-x_{i-1} + b x_{i-k}) \mod m. + $$ + The generator returns $u_i = x_i/m$. The initial state + $(x_{-1},\dots,\?x_{-k})$ is in {\tt S[0..(k-1)]}. + Restriction: $k \le 128$. + \endtab +\code + + +unif01_Gen * udeng_CreateDX02a (unsigned long m, unsigned long b, int k, + unsigned long S[]); +\endcode + \tab Creates a multiple recursive generator proposed by Deng + and Xu \cite{rDEN02a} in the form: + $$ + x_i \ =\ b(x_{i-1} + x_{i-k}) \mod m. + $$ + The generator returns $u_i = x_i/m$. The initial state + $(x_{-1},\dots,\?x_{-k})$ is in {\tt S[0..(k-1)]}. + Restriction: $k \le 128$. + \endtab + + + + + +\guisec{Clean-up functions} + +\code + + +void udeng_DeleteGen (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called when a generator + is no longer in use. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ufile.c b/TESTU01/TestU01-1.2.3/testu01/ufile.c new file mode 100644 index 0000000..f9c5eea --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ufile.c @@ -0,0 +1,371 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ufile.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "ufile.h" +#include "unif01.h" + +#include +#include +#include + +/* Length of strings */ +#define LEN 200 + +#define NORM32 2.3283064365386962E-10 /* 1 / 2^32 */ + +#define ARRAYDIM 1048576 /* = 2^20 */ + + + + +/*========================== module variables ============================*/ + +static char S[LEN + 1]; + +static FILE *f1, *f2; + +static int co1 = 0, co2 = 0; /* Counters */ + +/* X1 will contain the numbers read from a text input file */ +static double *X1 = NULL; + +/* X2 will keep the bytes read from a binary input file */ +static unsigned char *X2 = NULL; + +static unsigned long n1, n2, /* Current index of tables */ + MaxBin, MaxText, /* Maximal index in the tables */ + Dim1, Dim2; /* Dimension of tables */ + +static double NBin, NText; /* Number of calls to the generator */ + + + +/*========================================================================*/ + +static void WrReadText (void *junk) +{ + printf (" %.0f numbers have been read\n", NText); +} + +/*-----------------------------------------------------------------------*/ + +static void FillTextArray (void) +/* + * Read numbers (double's) until end of file or until Dim1 (dimension of + * array X1) numbers have been read. + */ +/* + * The standard function setvbuf could be used here to increase the + * speed of reading. Right now, we use default system buffering. + */ +{ + unsigned long i; + + MaxText = Dim1; + i = 0; + while ((i < Dim1) && (fscanf (f1, " %lf", (X1 + i)) == 1)) + ++i; + + if (i < MaxText) + /* The numbers do not fill the whole array: EOF or Error */ + MaxText = i; + + n1 = 0; +} + +/*-----------------------------------------------------------------------*/ + +static double ReadText_U01 (void *junk1, void *junk2) +/* + * Return the n-th element of the array. If at end of array, call + * FillTextArray to fill the array once again, and then return the + * first element. + */ +{ + if (n1 < MaxText) { + NText += 1.0; + return X1[n1++]; + + } else if (MaxText == Dim1) { + FillTextArray (); + NText += 1.0; + return X1[n1++]; + + } else { + X1 = util_Free (X1); + util_Fclose (f1); + sprintf (S, "%.0f numbers have been read.\n", NText); + strncat (S, "End-of-file detected.\n", (size_t) 25); + strncat (S, "Not enough numbers in file for these test parameters.", + (size_t) 60); + util_Error (S); + return -1.0; + } +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long ReadText_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (ReadText_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ufile_CreateReadText (char *A, long dim) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + + util_Assert (dim > 0, "ufile_CreateReadText: nbuf <= 0."); + util_Assert (co1 == 0, + "ufile_CreateReadText: only 1 generator at a time can be in use"); + co1++; + + gen = util_Malloc (sizeof (unif01_Gen)); + + strncpy (name, "ufile_CreateReadText: ", (size_t) LEN); + strncat (name, A, (size_t) (LEN - 30)); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + f1 = util_Fopen (A, "r"); + Dim1 = util_Min (ARRAYDIM, dim); + MaxText = Dim1; + X1 = util_Calloc ((size_t) Dim1, sizeof (double)); + gen->GetBits = &ReadText_Bits; + gen->GetU01 = &ReadText_U01; + gen->Write = &WrReadText; + gen->param = NULL; + gen->state = NULL; + FillTextArray (); + NText = 0; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +void ufile_DeleteReadText (unif01_Gen *gen) +{ + X1 = util_Free (X1); + util_Fclose (f1); + gen->name = util_Free (gen->name); + util_Free (gen); + co1--; +} + + +/*-----------------------------------------------------------------------*/ + +void ufile_InitReadText (void) +{ + int j = 0; + util_Assert (NULL != f1, "ufile_InitReadText: unable to read from file"); + if (NText > Dim1) { + j = fseek (f1, 0L, SEEK_SET); + util_Assert (0 == j, "ufile_InitReadText: file rewind failed"); + FillTextArray (); + } + NText = n1 = 0; +} + + +/*========================================================================*/ + +static void FillBinArray (void) +/* + * Read bits, at most Dim2 bytes. + */ +{ + MaxBin = fread (X2, (size_t) 1, (size_t) Dim2, f2); + n2 = 0; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long ReadBin_Bits (void *vpar, void *vsta) +/* + * Return the n-th element of the array. If at end of the array, call + * FillBinArray to fill the array once again, and then return the first + * element. Each number uses 32 bits in big-endian form: the first byte + * makes the most significant bits, and the fourth one makes the least + * significant. + */ +{ + unsigned long u; + + if (n2 < MaxBin) { + u = (unsigned long) X2[n2++] << 24; + u |= (unsigned long) X2[n2++] << 16; + u |= (unsigned long) X2[n2++] << 8; + u |= (unsigned long) X2[n2++]; + NBin += 1.0; + return u; + + } else if (MaxBin == Dim2) { + FillBinArray (); + return ReadBin_Bits (vpar, vsta); + + } else { + X2 = util_Free (X2); + util_Fclose (f2); + f2 = NULL; + sprintf (S, "%.0f bits have been read.\n", NBin * 32.0); + strncat (S, "End-of-file detected.\n", (size_t) 25); + strncat (S, "Not enough bits in file for these test parameters.", + (size_t) 53); + util_Error (S); + return 0; + } +} + +/*-----------------------------------------------------------------------*/ + +static double ReadBin_U01 (void *vpar, void *vsta) +{ + return ReadBin_Bits (vpar, vsta) * NORM32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrReadBin (void *junk) +{ + printf (" %.0f bits have been read.\n", NBin * 32.0); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ufile_CreateReadBin (char *A, long dim) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + + util_Assert (dim > 0, "ufile_CreateReadBin: nbuf <= 0."); + util_Assert (co2 == 0, + "ufile_CreateReadBin: only 1 generator at a time can be in use"); + co2++; + + gen = util_Malloc (sizeof (unif01_Gen)); + + strncpy (name, "ufile_CreateReadBin: ", (size_t) LEN); + strncat (name, A, (size_t) LEN - 30); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + f2 = util_Fopen (A, "rb"); + + /* Each random number will be built of 32 bits = 4 bytes */ + Dim2 = util_Min (ARRAYDIM, 4*dim); + X2 = util_Calloc ((size_t) Dim2, sizeof (unsigned char)); + FillBinArray (); + NBin = 0; + + gen->GetBits = &ReadBin_Bits; + gen->GetU01 = &ReadBin_U01; + gen->Write = &WrReadBin; + gen->param = NULL; + gen->state = NULL; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +void ufile_DeleteReadBin (unif01_Gen *gen) +{ + X2 = util_Free (X2); + util_Fclose (f2); + gen->name = util_Free (gen->name); + util_Free (gen); + co2--; +} + + +/*-----------------------------------------------------------------------*/ + +void ufile_InitReadBin (void) +{ + int j = 0; + util_Assert (NULL != f2, "ufile_InitReadBin: unable to read from file"); + if (NBin >= Dim2 / 4) { + j = fseek (f2, 0L, SEEK_SET); + util_Assert (0 == j, "ufile_InitReadBin: file rewind failed"); + FillBinArray (); + } + NBin = n2 = 0; +} + + +/*========================================================================*/ + +void ufile_Gen2Bin (unif01_Gen *gen, char *fname, double nbits, + int r, int s) +{ + unsigned long Z; + unsigned long i, n; + unsigned char buffer[4]; + FILE *f; + int k; + const int KMAX = s / 8; + int status; + + util_Assert (nbits > 0.0, "ufile_Gen2Bin: nbits <= 0"); + util_Assert (r >= 0, "ufile_Gen2Bin: r < 0"); + util_Assert (s % 8 == 0, + "ufile_Gen2Bin: s must be in { 8, 16, 24, 32 }"); + util_Assert (nbits / s <= ULONG_MAX, + "ufile_Gen2Bin: nbits is too large"); + + n = 0.5 + nbits / s; + if (n * (double) s < nbits) + n++; + f = util_Fopen (fname, "wb"); + + for (i = 0; i < n; i++) { + Z = unif01_StripB (gen, r, s); + for (k = KMAX - 1; k >= 0; k--) { + buffer[k] = Z & 0xFF; + Z >>= 8; + } + status = fwrite (buffer, (size_t) 1, (size_t) KMAX, f); + if (status != KMAX) { + perror ("ufile_Gen2Bin: fwrite"); + exit (EXIT_FAILURE); + } + } + + util_Fclose (f); +} + diff --git a/TESTU01/TestU01-1.2.3/testu01/ufile.tex b/TESTU01/TestU01-1.2.3/testu01/ufile.tex new file mode 100644 index 0000000..eee355e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ufile.tex @@ -0,0 +1,98 @@ +\defmodule {ufile} + +This module allows the implementation of generators in the form of numbers +read directly from an arbitrary file. No more than one generator of each + type in this module can be in use at any given time. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* ufile.h for ANSI C */ +#ifndef UFILE_H +#define UFILE_H +\endhide +#include "unif01.h" + + +unif01_Gen * ufile_CreateReadText (char *fname, long nbuf); +\endcode + \tab Reads numbers (assumed to be in text format) from input file + \texttt{fname}. \index{Generator!read from file}% + The numbers must be floating-point numbers in [0, 1), separated by + whitespace characters. Numbers in the file can be grouped in any way: + there may be blank lines, some lines may contain many numbers, others + only one. The file must contain only valid real numbers, nothing else. + The numbers are read in batches of {\tt nbuf} at a time and kept in an array + (if {\tt nbuf} is very large, a smaller but still large array will be used + instead). + \endtab +\code + + +void ufile_InitReadText (void); +\endcode + \tab Reinitializes the generator obtained from {\tt ufile\_CreateReadText} + to the beginning of the file. + \endtab +\code + + +unif01_Gen * ufile_CreateReadBin (char *fname, long nbuf); +\endcode + \tab Reads numbers from input file \texttt{fname}. This file is assumed + to be in binary format. The numbers are read in batches of {\tt 4 nbuf} + \texttt{unsigned char}'s at a time, transformed into {\tt nbuf} unsigned + 32-bit integers and kept in an array (if {\tt nbuf} is very large, a + smaller but still large array will be used instead). + This function is used in order to test (random) + bit sequences kept in a file. + \endtab +\code + + +void ufile_InitReadBin (void); +\endcode + \tab Reinitializes the generator obtained from {\tt ufile\_CreateReadBin} + to the beginning of the file. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Clean-up functions} +\code + +void ufile_DeleteReadText (unif01_Gen *); +\endcode + \tab Closes the file and frees the dynamic memory allocated by + \texttt{ufile\_CreateReadText}. + \endtab +\code + + +void ufile_DeleteReadBin (unif01_Gen *); +\endcode + \tab Closes the file and frees the dynamic memory allocated by + \texttt{ufile\_CreateReadBin}. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Useful functions} +\code + +void ufile_Gen2Bin (unif01_Gen *gen, char *fname, double n, int r, int s); +\endcode + \tab Creates the file {\tt fname} containing $n$ random bits using the + output of generator {\tt gen}. From each random number + returned by {\tt gen}, the $r$ most significant bits will be dropped + and the $s$ following bits will be written to the file until $n$ bits + have been written. Restriction: $s \in \{ 8, 16, 24, 32 \}$. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/ugfsr.c b/TESTU01/TestU01-1.2.3/testu01/ugfsr.c new file mode 100644 index 0000000..b4f7989 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ugfsr.c @@ -0,0 +1,1731 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ugfsr.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "ugfsr.h" +#include "unif01.h" + +#include +#include + + + + + +/*=============================== Macros ===============================*/ + +#define LEN 300 /* Max length of strings */ + +#define MATRIX_A 0x9908b0dfUL /* constant vector a for MT19937 */ +#define UPPER_MASK 0x80000000UL /* most significant w - r bits */ +#define LOWER_MASK 0x7fffffff /* least significant r bits */ + +/* for tempering */ +#define TEMPERING_MASK_B 0x9d2c5680UL +#define TEMPERING_MASK_C 0xefc60000UL +#define TEMPERING_SHIFT_U(y) ((y) >> 11) +#define TEMPERING_SHIFT_S(y) ((y) << 7) +#define TEMPERING_SHIFT_T(y) ((y) << 15) +#define TEMPERING_SHIFT_L(y) ((y) >> 18) + + + + + + +/*================================ Types ================================*/ + +typedef struct { + unsigned long Shift, Mask, mag01[2]; + double Norm; +} GFSR_param; + +typedef struct { + unsigned long *X; + unsigned int r, s, K; +} GFSR_state; + +/*------------------------------------*/ + +typedef struct { + unsigned long Shift, Mask, mag01[2]; + unsigned long b, c, S2, T2; +} TGFSR2_param; + +typedef GFSR_state TGFSR2_state; + +/*------------------------------------*/ + +typedef struct { + unsigned long mag01[2]; +} MT19937_param; + +typedef GFSR_state MT19937_state; + +/*------------------------------------*/ + +typedef struct { + unsigned long Shift; +} GFSR5_param; + +typedef struct { + unsigned long *X; + unsigned int r1, r2, r3, s, K; +} GFSR5_state; + +/*------------------------------------*/ + + + + + + +/***************************************************************************/ + +static void PRODUIT (int k, unsigned int F[], unsigned int G[], + unsigned int H[]) +{ + int i, j; + unsigned int Work; + + for (i = 0; i < k; i++) { + Work = 0; + for (j = 0; j < k; j++) { + if (G[j] == 1) + Work += F[i + j]; + } + H[i] = Work % 2; + } +} + + +/***************************************************************************/ + +#define Fushia 69069 /* multiplier */ + +static void InitFushimi (int k, int r, int s, GFSR_state *state) +/* + * Initialization copied from Fushimi90 + */ +{ + unsigned int *x, *x0, *x1, *x2, *x3; + unsigned int E0, E1; + int wi, ix, B[32]; + int i, iMD2, k2, k3, j; + + E0 = 0; + E1 = 1; + k2 = k * 2; + k3 = k * 3; + state->K = k3; + state->r = 3 * (k - r); + state->s = 0; + + x = calloc ((size_t) 3 * (k + 1), sizeof (unsigned int)); + x0 = calloc ((size_t) 2 * (k + 1), sizeof (unsigned int)); + x1 = calloc ((size_t) 2 * (k + 1), sizeof (unsigned int)); + x2 = calloc ((size_t) 1 * (k + 1), sizeof (unsigned int)); + x3 = calloc ((size_t) 3 * (k + 1), sizeof (unsigned int)); + + /* Initialization */ + for (j = 0; j < k2; j++) { + x0[j] = E0; + x3[j] = E0; + } + + /* Table B contains 2^30, 2^29, ... , 1, 0. */ + B[31] = 0; + B[30] = 1; + for (j = 0; j <= 29; j++) + B[29 - j] = B[30 - j] * 2; + + ix = s; + for (j = 0; j < k; j++) { + ix *= Fushia; + if (ix > 0) + x0[j] = E1; + } + for (j = k; j < k2; j++) + x0[j] = x0[j - k] ^ x0[j - r]; + x3[1] = E1; + for (i = 0; i <= k - 2; i++) { + iMD2 = i % 2; + for (j = k - 1; j >= 0; j--) { + x3[2 * j + iMD2] = x3[j]; + x3[2 * j + 1 - iMD2] = E0; + } + for (j = k - 1; j >= 0; j--) { + x3[j] ^= x3[j + k]; + x3[j + k - r] ^= x3[j + k]; + x3[j + k] = E0; + } + } + PRODUIT (k, x0, x3, x1); + for (j = k; j < k2; j++) + x1[j] = x1[j - k] ^ x1[j - r]; + PRODUIT (k, x1, x3, x2); + for (j = 0; j <= k; j++) { + x[3 * j] = x0[j]; + x[3 * j + 1] = x1[j]; + x[3 * j + 2] = x2[j]; + } + for (i = 0; i < k3; i++) { + wi = 0; + for (j = 0; j < 32; j++) { + if (x[state->s] != E0) + wi += B[j]; + x[state->s] ^= x[state->r]; + state->s++; + if (state->s == state->K) + state->s = 0; + state->r++; + if (state->r == state->K) + state->r = 0; + } + state->X[i] = wi & unif01_MASK32; + } + free (x); + free (x0); + free (x1); + free (x2); + free (x3); +} + + +/***************************************************************************/ + +static unsigned long GFSR_Bits (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + + if (++state->s == state->K) + state->s = 0; /* s = (s + 1) % K */ + if (++state->r == state->K) + state->r = 0; /* r = (r + 1) % K */ + state->X[state->s] ^= state->X[state->r]; + return state->X[state->s] << param->Shift; +} + +/*-----------------------------------------------------------------------*/ + +static double GFSR_U01 (void *vpar, void *vsta) +{ + return GFSR_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrGFSR (void *vsta) +{ + GFSR_state *state = vsta; + unsigned int j; + unsigned int s = state->s; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < state->K; j++) { + if (++s >= state->K) + s = 0; + printf (" %12lu", state->X[s]); + if (j < state->K - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +static unif01_Gen *CreateGFSR0 (unsigned int k, unsigned int r, + unsigned int l, unsigned long S[], const char nom[]) +/* + * CreateGen common to many generators GFSR and TGFSR + */ +{ + unif01_Gen *gen; + GFSR_param *param; + GFSR_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int j; + unsigned long Mask; + + strcpy (name, nom); + addstr_Uint (name, " k = ", k); + addstr_Uint (name, ", r = ", r); + addstr_Uint (name, ", l = ", l); + addstr_ArrayUlong (name, ", S = ", (int) k, S); + if ((l < 1) || (r >= k) || (l > 32)) + util_Error (name); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (GFSR_param)); + state = util_Malloc (sizeof (GFSR_state)); + + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (l == 32) + Mask = unif01_MASK32; + else + Mask = num_TwoExp[l] - 1.0; + state->X = util_Calloc ((size_t) k, sizeof (unsigned long)); + for (j = 0; j < k; j++) + state->X[j] = S[j] & Mask; + + state->s = 0; + state->r = k - r; + state->K = k; + param->Shift = 32 - l; + param->Mask = Mask; + + gen->param = param; + gen->state = state; + gen->GetBits = &GFSR_Bits; + gen->GetU01 = &GFSR_U01; + gen->Write = &WrGFSR; + return gen; +} + +/*=========================================================================*/ + +unif01_Gen *ugfsr_CreateGFSR3 (unsigned int k, unsigned int r, + unsigned int l, unsigned long S[]) +{ + return CreateGFSR0 (k, r, l, S, "ugfsr_CreateGFSR3:"); +} + + +/*=========================================================================*/ + +#define RIPa 16807 /* multiplier */ +#define RIPk 521 /* Parametres for */ +#define RIPr 32 /* Ripley90 .... */ +#define RIPk2 (2*RIPk) +#define RIPc 127773 + + +static double Ripley90_U01 (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long temp; + + state->s--; + state->r--; + temp = state->X[state->r]; + state->X[state->r] ^= state->X[state->s]; + if (state->s == 0) + state->s = RIPk; + if (state->r == 0) + state->r = RIPk; + return temp * param->Norm; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long Ripley90_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (Ripley90_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrRipley90 (void *vsta) +{ + GFSR_state *state = vsta; + int j; + int r = state->r; + + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < RIPk; j++) { + r--; + printf (" %12lu", state->X[r]); + if (r <= 0) + r = RIPk; + if (j < RIPk - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * ugfsr_CreateRipley90 (long s) +{ + unif01_Gen *gen; + GFSR_param *param; + GFSR_state *state; + size_t leng; + char name[LEN + 1]; + unsigned long x0[RIPk2]; + unsigned long wi, wt; + long vt, ix, i, j; /* Work variables */ + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (GFSR_param)); + state = util_Malloc (sizeof (GFSR_state)); + + strcpy (name, "ugfsr_CreateRipley90:"); + addstr_Long (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->K = RIPk; + state->r = RIPk - RIPr; + state->s = RIPk; + param->Norm = 1.0 / (num_TwoExp[31] - 1.0); + state->X = util_Calloc ((size_t) RIPk, sizeof (unsigned long)); + + /* Initialization */ + ix = s; + for (j = 0; j < RIPk; j++) { + x0[j] = 0; + vt = ix / RIPc; + ix = RIPa * (ix - RIPc * vt) - 2836 * vt; + if (ix < 0) + ix += 2147483647; + if (ix > 1073741824) + x0[j] = 1; + } + for (j = RIPk; j < RIPk2; j++) + x0[j] = x0[j - RIPk] ^ x0[j - RIPr]; + for (i = 0; i < RIPk; i++) { + wi = 0; + for (j = 0; j <= 30; j++) { + wt = x0[i + 16 * (j + 1)]; + wt <<= j; +#ifndef IS_ULONG32 + wt &= unif01_MASK32; +#endif + wi += wt; +#ifndef IS_ULONG32 + wi &= unif01_MASK32; +#endif + } + state->X[i] = wi & unif01_MASK32; + } + gen->param = param; + gen->state = state; + gen->GetBits = &Ripley90_Bits; + gen->GetU01 = &Ripley90_U01; + gen->Write = &WrRipley90; + return gen; +} + + +/***************************************************************************/ + +unif01_Gen * ugfsr_CreateToot73 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + GFSR_state *state; + size_t leng; + char name[LEN + 1]; + long q, l, m, n; + int h, t, j, i, K = 607, R = 273; + unsigned long Q[700], Mask; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (GFSR_param)); + state = util_Malloc (sizeof (GFSR_state)); + + strcpy (name, "ugfsr_CreateToot73:"); + addstr_ArrayUlong (name, " S = ", K, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->X = util_Calloc ((size_t) 700, sizeof (unsigned long)); + state->r = K - R; + state->s = 0; + state->K = K; + Mask = num_TwoExp[23] - 1.0; + param->Shift = 9; + param->Mask = Mask; + + q = S[19]; + m = S[10]; + for (j = 1; j <= 19; j++) + Q[j] = S[j]; + for (j = 19; j <= K; j++) { + l = (long) Q[j - 18]; + n = (long) Q[j - 8]; + Q[j] = (((unsigned long) q) << 1) + (((unsigned long) l) >> 31); + Q[j] ^= (((unsigned long) m) << 15) + (((unsigned long) n) >> 17); + Q[j] &= unif01_MASK32; + q = l; + m = n; + Q[j - 18] = l & Mask; + } + + for (j = 590; j <= K; j++) + Q[j] &= Mask; + i = 1; + t = 0; + do { + for (j = i; j <= K; j += 16) { + state->X[t] = Q[j]; + t++; + } + i++; + /* Recompute table Q so that the equation */ + /* Q(n) =( ( x^15*Q(n- 9)+x^- 17*Q(n- 8) ) XOR */ + /* ( x*Q(n-19)+x^- 31*Q(n-18) ) */ + /* remains valid */ + for (h = 1; h <= R; h++) + Q[h] ^= Q[h + K - R]; + for (h = R + 1; h <= K; h++) + Q[h] ^= Q[h - R]; + } while (t <= K); + + gen->param = param; + gen->state = state; + gen->GetBits = &GFSR_Bits; + gen->GetU01 = &GFSR_U01; + gen->Write = &WrGFSR; + return gen; +} + + +/**************************************************************************/ + +static unsigned long Fushimi90_Bits (void *junk, void *vsta) +{ + GFSR_state *state = vsta; + unsigned long V; + + V = state->X[state->s]; + state->X[state->s] ^= state->X[state->r]; + if (++state->s == state->K) + state->s = 0; + if (++state->r == state->K) + state->r = 0; + return V << 1; +} + +/*-----------------------------------------------------------------------*/ + +static double Fushimi90_U01 (void *vpar, void *vsta) +{ + return Fushimi90_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateFushimi90 (int s) +{ + unif01_Gen *gen; + GFSR_state *state; + GFSR_param *param; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (GFSR_param)); + state = util_Malloc (sizeof (GFSR_state)); + + state->K = 521; + state->r = 521 - 32; + state->s = 0; + + strcpy (name, "ugfsr_CreateFushimi90:"); + addstr_Int (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->X = util_Calloc ((size_t) 3 * 522, sizeof (unsigned long)); + InitFushimi (521, 32, s, state); + gen->param = param; + gen->state = state; + gen->GetBits = &Fushimi90_Bits; + gen->GetU01 = &Fushimi90_U01; + gen->Write = &WrGFSR; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateFushimi (int k, int r, int s) +{ + unif01_Gen *gen; + GFSR_state *state; + GFSR_param *param; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (GFSR_param)); + state = util_Malloc (sizeof (GFSR_state)); + + state->K = k; + state->r = k - r; + state->s = 0; + + strcpy (name, "ugfsr_CreateFushimi:"); + addstr_Int (name, " k = ", k); + addstr_Int (name, ", r = ", r); + addstr_Int (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->X = util_Calloc ((size_t) k * 3, sizeof (unsigned long)); + InitFushimi (k, r, s, state); + gen->param = param; + gen->state = state; + gen->GetBits = &Fushimi90_Bits; + gen->GetU01 = &Fushimi90_U01; + gen->Write = &WrGFSR; + return gen; +} + + +/**************************************************************************/ + +unif01_Gen *ugfsr_CreateKirk81 (long s) +{ + unif01_Gen *gen; + GFSR_state *state; + GFSR_param *param; + size_t leng; + char name[LEN + 1]; + unsigned long mask, msb; + unsigned int j, k; + long vt; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (GFSR_param)); + state = util_Malloc (sizeof (GFSR_state)); + + strcpy (name, "ugfsr_CreateKirk81:"); + addstr_Long (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->K = 250; + state->s = 0; + state->r = 147; + state->X = util_Calloc ((size_t) state->K, sizeof (unsigned long)); + + msb = 2147483648UL; /* TwoExp31 */ + mask = 4294967295UL; /* TwoExp32 - 1 */ + for (j = 0; j < state->K; j++) { + vt = s / 127773; + s = 16807 * (s - 127773 * vt) - 2836 * vt; + if (s < 0) + s += 2147483647; + state->X[j] = 2 * ((unsigned long) s); + if (s > 1000000000) + state->X[j] += 1; + /* When s > 1000000000, then set last bit to 1 */ + } + for (j = 1; j <= 31; j++) { + k = 7 * j + 3; + state->X[k] = (state->X[k] & mask) | msb; + mask >>= 1; + msb >>= 1; + } + param->Shift = 0; + gen->param = param; + gen->state = state; + gen->GetBits = &GFSR_Bits; + gen->GetU01 = &GFSR_U01; + gen->Write = &WrGFSR; + return gen; +} + + +/**************************************************************************/ + +static unsigned long TGFSR_Bits (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long v; + + state->X[state->s] = state->X[state->r] ^ (state->X[state->s] >> 1) + ^ param->mag01[state->X[state->s] % 2]; + v = state->X[state->s] & param->Mask; + if (++state->s == state->K) + state->s = 0; /* s = (s + 1) % K */ + if (++state->r == state->K) + state->r = 0; /* r = (r + 1) % K */ + return v << param->Shift; +} + +/*-----------------------------------------------------------------------*/ + +static double TGFSR_U01 (void *vpar, void *vsta) +{ + return TGFSR_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTGFSR (unsigned int k, unsigned int r, + unsigned int l, unsigned long Av, unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + char name[LEN + 1] = ""; + size_t leng; + + gen = CreateGFSR0 (k, r, l, S, "ugfsr_CreateTGFSR:"); + addstr_Ulong (name, ", Av = ", Av); + leng = strlen (gen->name) + strlen (name); + gen->name = util_Realloc (gen->name, (leng + 1) * sizeof (char)); + strncat (gen->name, name, leng); + + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = Av; + gen->GetBits = &TGFSR_Bits; + gen->GetU01 = &TGFSR_U01; + return gen; +} + + +/**************************************************************************/ + +static unsigned long T800_Bits (void *vpar, void *vsta) +{ + GFSR_state *state = vsta; + GFSR_param *param = vpar; + unsigned long v; + + state->X[state->s] = state->X[state->r] ^ (state->X[state->s] >> 1) + ^ param->mag01[state->X[state->s] % 2]; + v = state->X[state->s]; +#ifndef IS_ULONG32 + v &= 0xffffffffUL; /* you may delete this line if word size = 32 */ +#endif + if (++state->s == state->K) + state->s = 0; /* s = (s + 1) % K */ + if (++state->r == state->K) + state->r = 0; /* r = (r + 1) % K */ + return v; +} + +/*-----------------------------------------------------------------------*/ + +static double T800_U01 (void *vpar, void *vsta) +{ + return T800_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateT800 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + char name[LEN + 1] = ""; + size_t leng; + + gen = CreateGFSR0 (25, 18, 32, S, "ugfsr_CreateT800:"); + addstr_Ulong (name, ", Av = ", 2394935336UL); + leng = strlen (gen->name) + strlen (name); + gen->name = util_Realloc (gen->name, (leng + 1) * sizeof (char)); + strncat (gen->name, name, leng); + + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = 0x8ebfd028UL; /* this is magic vector 'a' */ + gen->GetBits = &T800_Bits; + gen->GetU01 = &T800_U01; + return gen; +} + + +/***************************************************************************/ + +static unsigned long TGFSR2_Bits (void *vpar, void *vsta) +{ + TGFSR2_param *param = vpar; + TGFSR2_state *state = vsta; + unsigned long v; + + v = state->X[state->s]; + state->X[state->s] = + state->X[state->r] ^ (v >> 1) ^ param->mag01[v % 2]; + if (++state->s == state->K) + state->s = 0; /* s = (s + 1) % K */ + if (++state->r == state->K) + state->r = 0; /* r = (r + 1) % K */ + v ^= (v << param->S2) & param->b; /* s and b, magic vectors */ + v ^= (v << param->T2) & param->c; /* t and c, magic vectors */ + v &= param->Mask; /* l least significant bits */ + return v << param->Shift; +} + +/*-----------------------------------------------------------------------*/ + +static double TGFSR2_U01 (void *vpar, void *vsta) +{ + return TGFSR2_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTGFSR2 (unsigned int k, unsigned int r, + unsigned int l, unsigned int s, unsigned int t, unsigned long Av, + unsigned long Bv, unsigned long Cv, unsigned long S[]) +{ + unif01_Gen *gen; + TGFSR2_param *param; + char name[LEN + 1]; + size_t leng; + + gen = CreateGFSR0 (k, r, l, S, ""); + util_Free (gen->name); + strcpy (name, "ugfsr_CreateTGFSR2:"); + addstr_Uint (name, " k = ", k); + addstr_Uint (name, ", r = ", r); + addstr_Uint (name, ", l = ", l); + addstr_Ulong (name, ", Av = ", Av); + addstr_Ulong (name, ", Bv = ", Bv); + addstr_Ulong (name, ", Cv = ", Cv); + addstr_Uint (name, ", s = ", s); + addstr_Uint (name, ", t = ", t); + addstr_ArrayUlong (name, ", S", (int) k, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + util_Free (gen->param); + gen->param = param = util_Malloc (sizeof (TGFSR2_param)); + param->S2 = s; + param->T2 = t; + param->mag01[0] = 0x0; + param->mag01[1] = Av; /* this is magic vector 'a' */ + param->b = Bv; + param->c = Cv; + param->Shift = 32 - l; + param->Mask = num_TwoExp[l] - 1.0; + if (l == 32) + param->Mask = unif01_MASK32; + gen->GetBits = &TGFSR2_Bits; + gen->GetU01 = &TGFSR2_U01; + gen->Write = &WrGFSR; + return gen; +} + + +/***************************************************************************/ + +static double TT400_U01 (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long v; + + v = state->X[state->s]; + state->X[state->s] = state->X[state->r] ^ (v >> 1) ^ param->mag01[v % 2]; + v ^= (v << 2) & 0x6A68; /* s and b, magic vectors */ + v ^= (v << 7) & 0x7500; /* t and c, magic vectors */ + v &= 0xffff; + if (++state->s == state->K) + state->s = 0; + if (++state->r == state->K) + state->r = 0; + return (double) v / 0xffff; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long TT400_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (TT400_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTT400 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + unsigned int N, M; + + N = 25; + M = 25 - 11; + gen = CreateGFSR0 (N, M, 16, S, "ugfsr_CreateTT400:"); + + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = 0xA875; /* this is magic vector 'a' */ + gen->GetBits = &TT400_Bits; + gen->GetU01 = &TT400_U01; + return gen; +} + + +/***************************************************************************/ + +static double TT403_U01 (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long v; + + v = state->X[state->s]; + state->X[state->s] = state->X[state->r] ^ (v >> 1) ^ param->mag01[v % 2]; + v ^= (v << 8) & 0x102D1200; /* s and b, magic vectors */ + v ^= (v << 14) & 0x66E50000; /* t and c, magic vectors */ + v &= 0x7fffffff; + if (++state->s == state->K) + state->s = 0; + if (++state->r == state->K) + state->r = 0; + return (double) v / 0x7fffffff; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long TT403_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (TT403_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTT403 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + unsigned int N, M; + + N = 13; + M = 13 - 2; + gen = CreateGFSR0 (N, M, 31, S, "ugfsr_CreateTT403:"); + + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = 0x6B5ECCF6; /* this is magic vector 'a' */ + gen->GetBits = &TT403_Bits; + gen->GetU01 = &TT403_U01; + return gen; +} + + +/***************************************************************************/ + +static double TT775_U01 (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long v; + + v = state->X[state->s]; + state->X[state->s] = state->X[state->r] ^ (v >> 1) ^ param->mag01[v % 2]; + v ^= (v << 6) & 0x1ABD5900; /* s and b, magic vectors */ + v ^= (v << 14) & 0x776A0000; /* t and c, magic vectors */ + v &= 0x7fffffff; + if (++state->s == state->K) + state->s = 0; + if (++state->r == state->K) + state->r = 0; + return (double) v / 0x7fffffff; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long TT775_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (TT775_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTT775 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + unsigned int N, M; + + N = 25; + M = 25 - 8; + gen = CreateGFSR0 (N, M, 31, S, "ugfsr_CreateTT775:"); + + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = 0x6C6CB38C; /* this is magic vector 'a' */ + gen->GetBits = &TT775_Bits; + gen->GetU01 = &TT775_U01; + return gen; +} + + +/************************************************************************** + * + * Our version of TT800 + * + **************************************************************************/ + +static unsigned long TT800_Bits (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long v; + + v = state->X[state->s]; + state->X[state->s] = state->X[state->r] ^ (v >> 1) ^ param->mag01[v % 2]; + v ^= (v << 7) & 0x2b5b2500; /* s and b, magic vectors */ + v ^= (v << 15) & 0xdb8b0000UL; /* t and c, magic vectors */ +#ifndef IS_ULONG32 + v &= 0xffffffffUL; /* you may delete this line if word size = 32 */ +#endif + if (++state->s == state->K) + state->s = 0; + if (++state->r == state->K) + state->r = 0; + return v; +} + +/*-----------------------------------------------------------------------*/ + +static double TT800_U01 (void *vpar, void *vsta) +{ + return TT800_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTT800 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + unsigned int N, M; + + N = 25; + M = 25 - 7; + gen = CreateGFSR0 (N, M, 32, S, "ugfsr_CreateTT800:"); + + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = 0x8ebfd028UL; /* this is magic vector 'a' */ + gen->GetBits = &TT800_Bits; + gen->GetU01 = &TT800_U01; + return gen; +} + + +/***************************************************************************/ + +/* A C-program for TT800 : July 8th 1994 Version */ +/* by M. Matsumoto, email: matumoto@math.keio.ac.jp */ +/* genrand() generate one pseudorandom number with double precision */ +/* which is uniformly distributed on [0,1]-interval */ +/* for each call. One may choose any initial 25 seeds */ +/* except all zeros. */ + +#define NN 25 +#define MM 7 + +static double TT800M94_U01 (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long y; + unsigned int j; + + if (state->s == NN) { + /* generate NN words at one time */ + for (j = 0; j < NN - MM; j++) { + state->X[j] = state->X[j + MM] ^ (state->X[j] >> 1) ^ + param->mag01[state->X[j] % 2]; + } + for (; j < NN; j++) { + state->X[j] = state->X[j + (MM - NN)] ^ (state->X[j] >> 1) ^ + param->mag01[state->X[j] % 2]; + } + state->s = 0; + } + y = state->X[state->s++]; + y ^= (y << 7) & 0x2b5b2500; /* s and b, magic vectors */ + y ^= (y << 15) & 0xdb8b0000UL; /* t and c, magic vectors */ +#ifndef IS_ULONG32 + y &= 0xffffffffUL; /* you may delete this line if word size = 32 */ +#endif + + return (double) y / 0xffffffffUL; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long TT800M94_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (TT800M94_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + + +/* A C-program for TT800 : July 8th 1996 Version */ +/* by M. Matsumoto, email: matumoto@math.keio.ac.jp */ +/* genrand() generate one pseudorandom number with double precision */ +/* which is uniformly distributed on [0,1]-interval */ +/* for each call. One may choose any initial 25 seeds */ +/* except all zeros. */ + +static double TT800M96_U01 (void *vpar, void *vsta) +{ + GFSR_param *param = vpar; + GFSR_state *state = vsta; + unsigned long y; + unsigned int j; + + if (state->s == NN) { + /* generate NN words at one time */ + for (j = 0; j < NN - MM; j++) { + state->X[j] = state->X[j + MM] ^ (state->X[j] >> 1) ^ + param->mag01[state->X[j] % 2]; + } + for (; j < NN; j++) { + state->X[j] = state->X[j + (MM - NN)] ^ (state->X[j] >> 1) ^ + param->mag01[state->X[j] % 2]; + } + state->s = 0; + } + y = state->X[state->s++]; + y ^= (y << 7) & 0x2b5b2500; /* s and b, magic vectors */ + y ^= (y << 15) & 0xdb8b0000UL; /* t and c, magic vectors */ +#ifndef IS_ULONG32 + y &= 0xffffffffUL; /* you may delete this line if word + size = 32 */ +#endif + + /* the following line was added by Makoto Matsumoto in the 1996 version + to improve lower bit's correlation. This line differs from the code + published in 1994. */ + y ^= (y >> 16); /* added to the 1994 version */ + + return (double) y / 0xffffffffUL; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long TT800M96_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (TT800M96_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTT800M94 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + + gen = CreateGFSR0 (NN, MM, 32, S, "ugfsr_CreateTT800M94:"); + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = 0x8ebfd028UL; /* this is magic vector 'a' */ + gen->GetBits = &TT800M94_Bits; + gen->GetU01 = &TT800M94_U01; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateTT800M96 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_param *param; + + gen = CreateGFSR0 (NN, MM, 32, S, "ugfsr_CreateTT800M96:"); + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = 0x8ebfd028UL; /* this is magic vector 'a' */ + gen->GetBits = &TT800M96_Bits; + gen->GetU01 = &TT800M96_U01; + return gen; +} + + +/************************************************************************** + * + * The code for the two versions of MT19937 is copyrighted by Makoto + * Matsumoto and Takuji Nishimura. I have changed the name of some variables + * to make it consistent with TestU01. (R. Simard) + */ + +/* + A C-program for MT19937, with initialization improved 2002/1/26. + Coded by Takuji Nishimura and Makoto Matsumoto. + + Before using, initialize the state by using init_genrand(seed) + or init_by_array(init_key, key_length). + + Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + Any feedback is very welcome. + http://www.math.keio.ac.jp/matumoto/emt.html + email: matumoto@math.keio.ac.jp +*/ + +/* Period parameters */ +#undef NN +#undef MM +#define NN 624 +#define MM 397 +#define MATRIX_A 0x9908b0dfUL /* constant vector a */ +#define UPPER_MASK 0x80000000UL /* most significant w-r bits */ +#undef LOWER_MASK +#define LOWER_MASK 0x7fffffffUL /* least significant r bits */ + + +/*-----------------------------------------------------------------------*/ + +/* initializes mt[NN] with a seed */ +static void init_genrand (void *vsta, unsigned long s) +{ + MT19937_state *state = vsta; + int j; + + state->X[0] = s & 0xffffffffUL; + for (j = 1; j < NN; j++) { + state->X[j] = + (1812433253UL * (state->X[j - 1] ^ (state->X[j - 1] >> 30)) + j); + /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ + /* In the previous versions, MSBs of the seed affect */ + /* only MSBs of the array state->X[]. */ + /* 2002/01/09 modified by Makoto Matsumoto */ + state->X[j] &= 0xffffffffUL; + /* for >32 bit machines */ + } + state->s = NN; +} + + +/*-----------------------------------------------------------------------*/ + +/* initialize by an array with array-length */ +/* init_key is the array for initializing keys */ +/* key_length is its length */ +static void init_by_array (void *vsta, unsigned long init_key[], + int key_length) +{ + MT19937_state *state = vsta; + int i, j, k; + init_genrand (vsta, 19650218UL); + i = 1; + j = 0; + k = (NN > key_length ? NN : key_length); + for (; k; k--) { + state->X[i] = (state->X[i] ^ ((state->X[i - 1] ^ (state->X[i - 1] >> + 30)) * 1664525UL)) + init_key[j] + j; /* non linear */ + state->X[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ + i++; + j++; + if (i >= NN) { + state->X[0] = state->X[NN - 1]; + i = 1; + } + if (j >= key_length) + j = 0; + } + for (k = NN - 1; k; k--) { + state->X[i] = (state->X[i] ^ ((state->X[i - 1] ^ (state->X[i - 1] >> + 30)) * 1566083941UL)) - i; /* non linear */ + state->X[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ + i++; + if (i >= NN) { + state->X[0] = state->X[NN - 1]; + i = 1; + } + } + + state->X[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial + array */ +} + + +/*-----------------------------------------------------------------------*/ + +/* generates a random number on [0,0xffffffff]-interval +unsigned long genrand_int32(void) */ +static unsigned long MT19937_02_Bits (void *vpar, void *vsta) +{ + MT19937_param *param = vpar; + MT19937_state *state = vsta; + unsigned long y; + + if (state->s >= NN) { /* generate NN words at one time */ + int kk; + + if (state->s == NN + 1) /* if init_genrand() has not been called, */ + init_genrand (state, 5489UL); /* a default initial seed is used */ + + for (kk = 0; kk < NN - MM; kk++) { + y = (state->X[kk] & UPPER_MASK) | (state->X[kk + 1] & LOWER_MASK); + state->X[kk] = + state->X[kk + MM] ^ (y >> 1) ^ param->mag01[y & 0x1UL]; + } + for (; kk < NN - 1; kk++) { + y = (state->X[kk] & UPPER_MASK) | (state->X[kk + 1] & LOWER_MASK); + state->X[kk] = state->X[kk + (MM - NN)] ^ (y >> 1) ^ + param->mag01[y & 0x1UL]; + } + y = (state->X[NN - 1] & UPPER_MASK) | (state->X[0] & LOWER_MASK); + state->X[NN - 1] = + state->X[MM - 1] ^ (y >> 1) ^ param->mag01[y & 0x1UL]; + + state->s = 0; + } + + y = state->X[state->s++]; + + /* Tempering */ + y ^= (y >> 11); + y ^= (y << 7) & 0x9d2c5680UL; + y ^= (y << 15) & 0xefc60000UL; + y ^= (y >> 18); + + return y; +} + + +/*-----------------------------------------------------------------------*/ + +/* generates a random number on (0,1)-real-interval +double genrand_real3(void) */ +static double MT19937_02_U01 (void *vpar, void *vsta) +{ + return ((double) MT19937_02_Bits (vpar, vsta) + 0.5) * + (1.0 / 4294967296.0); /* divided by 2^32 */ +} + +/* These real versions are due to Isaku Wada, 2002/01/09 added */ + + +/*-----------------------------------------------------------------------*/ + +static void WrMT19937 (void *); + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateMT19937_02 (unsigned long seed, + unsigned long Key[], int len) +{ + unif01_Gen *gen; + MT19937_param *param; + MT19937_state *state; + unsigned long S[NN]; + char name[LEN + 1]; + size_t leng; + + gen = CreateGFSR0 (NN, MM, 32, S, ""); + param = gen->param; + state = gen->state; + param->mag01[0] = 0x0UL; + param->mag01[1] = MATRIX_A; + gen->GetBits = &MT19937_02_Bits; + gen->GetU01 = &MT19937_02_U01; + gen->Write = &WrMT19937; + strcpy (name, "ugfsr_CreateMT19937_02:"); + if ((len <= 0) || (NULL == Key)) { + init_genrand (state, seed); + addstr_Ulong (name, " seed = ", seed); + } else { + state->s = NN + 1; + init_by_array (state, Key, len); + addstr_ArrayUlong (name, " Key = ", len, Key); + } + leng = strlen (name); + gen->name = util_Realloc (gen->name, (leng + 1) * sizeof (char)); + strncpy (gen->name, name, leng); + gen->name[leng] = '\0'; + return gen; +} + + + +/**************************************************************************/ +/* A C-program for MT19937: Real number version - */ +/* generates one pseudorandom number with double precision */ +/* which is uniformly distributed on [0,1]-interval for each call. */ +/* CreateMT19937(seed) set initial values to the working area of 624 words. */ +/* (seed is any integer except for 0). */ + +#undef NN +#undef MM +#define NN 624 +#define MM 397 + +static double MT19937_98_U01 (void *vpar, void *vsta) +{ + MT19937_param *param = vpar; + MT19937_state *state = vsta; + unsigned long y; + unsigned int j; + + if (state->s == NN) { /* generate NN words at one time */ + for (j = 0; j < NN - MM; j++) { + y = (state->X[j] & UPPER_MASK) | (state->X[j + 1] & LOWER_MASK); + state->X[j] = state->X[j + MM] ^ (y >> 1) ^ param->mag01[y & 0x1]; + } + for (; j < NN - 1; j++) { + y = (state->X[j] & UPPER_MASK) | (state->X[j + 1] & LOWER_MASK); + state->X[j] = state->X[j + (MM - NN)] ^ (y >> 1) ^ + param->mag01[y & 0x1]; + } + y = (state->X[NN - 1] & UPPER_MASK) | (state->X[0] & LOWER_MASK); + state->X[NN - 1] = state->X[MM - 1] ^ (y >> 1) ^ param->mag01[y & 0x1]; + + state->s = 0; + } + y = state->X[state->s++]; + y ^= TEMPERING_SHIFT_U (y); + y ^= TEMPERING_SHIFT_S (y) & TEMPERING_MASK_B; + y ^= TEMPERING_SHIFT_T (y) & TEMPERING_MASK_C; +#ifndef IS_ULONG32 + y &= 0xffffffffUL; /* you may delete this line if word size = 32 */ +#endif + y ^= TEMPERING_SHIFT_L (y); + return (double) y / 0xffffffffUL; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long MT19937_98_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (MT19937_98_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrMT19937 (void *vsta) +{ + GFSR_state *state = vsta; + unsigned int j; + if (unif01_WrLongStateFlag) { + printf ("S = {\n "); + for (j = 0; j < state->K; j++) { + printf (" %12lu", state->X[j]); + if (j < state->K - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateMT19937_98 (unsigned long seed) +/* + * Setting initial seeds to X[NN] using + * the generator Line 25 of Table 1 in + * [KNUTH 1981, The Art of Computer Programming + * Vol. 2 (2nd Ed.), pp102] + */ +{ + unif01_Gen *gen; + MT19937_param *param; + unsigned int j; + unsigned long S[NN]; + char name[LEN + 1]; + size_t leng; + + S[0] = seed & 0xffffffffUL; + for (j = 1; j < NN; j++) + S[j] = (69069 * S[j - 1]) & 0xffffffffUL; + gen = CreateGFSR0 (NN, MM, 32, S, ""); + param = gen->param; + param->mag01[0] = 0x0; + param->mag01[1] = MATRIX_A; + gen->GetBits = &MT19937_98_Bits; + gen->GetU01 = &MT19937_98_U01; + gen->Write = &WrMT19937; + strcpy (name, "ugfsr_CreateMT19937_98:"); + addstr_Ulong (name, " seed = ", seed); + leng = strlen (name); + gen->name = util_Realloc (gen->name, (leng + 1) * sizeof (char)); + strncpy (gen->name, name, leng); + gen->name[leng] = '\0'; + return gen; +} + + +/**************************************************************************/ + +static unsigned long GFSR5_Bits (void *vpar, void *vsta) +{ + GFSR5_param *param = vpar; + GFSR5_state *state = vsta; + + if (++state->s == state->K) + state->s = 0; + if (++state->r1 == state->K) + state->r1 = 0; + if (++state->r2 == state->K) + state->r2 = 0; + if (++state->r3 == state->K) + state->r3 = 0; + state->X[state->s] ^= state->X[state->r1] ^ state->X[state->r2] ^ + state->X[state->r3]; + return state->X[state->s] << param->Shift; +} + +/*-----------------------------------------------------------------------*/ + +static double GFSR5_U01 (void *vpar, void *vsta) +{ + return GFSR5_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateGFSR5 (unsigned int k, unsigned int r1, + unsigned int r2, unsigned int r3, unsigned int l, unsigned long S[]) +{ + unif01_Gen *gen; + GFSR5_param *param; + GFSR5_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int j; + unsigned long Mask; + + util_Assert ((l >= 1) && (l <= 32), + "ugfsr_CreateGFSR5: l must be in [1..32]"); + util_Assert ((r3 > 0) && (r3 < r2), + "ugfsr_CreateGFSR5: we must have 0 < r3 < r2"); + util_Assert ((r1 > r2) && (r1 < k), + "ugfsr_CreateGFSR5: we must have r2 < r1 < k"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (GFSR5_param)); + state = util_Malloc (sizeof (GFSR5_state)); + + strcpy (name, "ugfsr_CreateGFSR5:"); + addstr_Uint (name, " k = ", k); + addstr_Uint (name, ", r1 = ", r1); + addstr_Uint (name, ", r2 = ", r2); + addstr_Uint (name, ", r3 = ", r3); + addstr_Uint (name, ", l = ", l); + addstr_ArrayUlong (name, ", S = ", (int) k, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (l == 32) + Mask = unif01_MASK32; + else + Mask = num_TwoExp[l] - 1.0; + state->X = util_Calloc ((size_t) k, sizeof (unsigned long)); + for (j = 0; j < k; j++) + state->X[j] = S[j] & Mask; + + state->r1 = k - r1; + state->r2 = k - r2; + state->r3 = k - r3; + state->s = 0; + state->K = k; + param->Shift = 32 - l; + + gen->param = param; + gen->state = state; + gen->GetBits = &GFSR5_Bits; + gen->GetU01 = &GFSR5_U01; + gen->Write = &WrGFSR; + return gen; +} + + +/**************************************************************************/ + +#define A 471 +#define B 1586 +#define C 6988 +#define D 9689 +#define M 16383 + +#define RandomInteger (++state->s, state->X[state->s & M] = \ + state->X[(state->s-A) & M] ^ state->X[(state->s-B) & M] ^ \ + state->X[(state->s-C) & M] ^ state->X[(state->s-D) & M]) + +static void WrZiff98 (void *vsta) +{ + GFSR_state *state = vsta; + unsigned int j; + int s = state->s; + + s = (s - D) % (M + 1); + if (unif01_WrLongStateFlag) { + printf (" S = {\n "); + for (j = 0; j < state->K; j++) { + if (++s > M) + s = 0; + printf (" %12lu", state->X[s]); + if (j < state->K - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long Ziff98_Bits (void *junk, void *vsta) +{ + GFSR_state *state = vsta; + return RandomInteger; +} + +/*-----------------------------------------------------------------------*/ + +static double Ziff98_U01 (void *junk, void *vsta) +{ + GFSR_state *state = vsta; + return RandomInteger * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *ugfsr_CreateZiff98 (unsigned long S[]) +{ + unif01_Gen *gen; + GFSR_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int j, l = 32, Mask; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (GFSR_state)); + + Mask = unif01_MASK32; + state->X = util_Calloc ((size_t) M + 1, sizeof (unsigned long)); + for (j = 0; j < D; j++) + state->X[j] = S[j] & Mask; + state->s = D; + state->K = D; + + strcpy (name, "ugfsr_CreateZiff98:"); + addstr_Uint (name, " k = ", D); + addstr_Uint (name, ", r1 = ", C); + addstr_Uint (name, ", r2 = ", B); + addstr_Uint (name, ", r3 = ", A); + addstr_Uint (name, ", l = ", l); + addstr_ArrayUlong (name, ", S = ", D, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = NULL; + gen->state = state; + gen->GetBits = &Ziff98_Bits; + gen->GetU01 = &Ziff98_U01; + gen->Write = &WrZiff98; + return gen; +} + +/**************************************************************************/ + +void ugfsr_DeleteGFSR5 (unif01_Gen *gen) +{ + GFSR5_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->X); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +void ugfsr_DeleteGen (unif01_Gen *gen) +{ + GFSR_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->X); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ugfsr.tex b/TESTU01/TestU01-1.2.3/testu01/ugfsr.tex new file mode 100644 index 0000000..aba368c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ugfsr.tex @@ -0,0 +1,369 @@ +\defmodule {ugfsr} + +This module implements +generalized feedback shift register (GFSR) generators, +twisted GFSR (TGFSR) generators, and tempered TGFSR generators +(TTGFSR). + +The following table points to some specific generators based +on trinomials, taken from the literature. + +\begin {table}[htb] +\centering +\label {tab:listgfsr} +\caption {Some specific GFSRs and TGFSRs} +\begin {tabular}{|@{\extracolsep{15pt}}rrr|l|l|} +\hline + $k$ & $r$ & $\ell$ & Type & Reference \\ +\hline +\quad 607 & 273 & 23 & GFSR & \cite{rTOO73a,rMAT94a} \\ + 521 & 32 & 31 & GFSR & \cite{rRIP90a} \\ + 521 & 32 & 31 & GFSR & \cite{rFUS90a} \\ + 250 & 103 & 32 & GFSR & \cite{rKIR81a} \\ + 25 & 7 & 32 & TGFSR & T800 \cite{rMAT94a} \\ + 25 & 14 & 32 & TTGFSR & TT400 \cite{rMAT94a} \\ + 13 & 11 & 31 & TTGFSR & TT403 \cite{rMAT94a} \\ + 25 & 17 & 31 & TTGFSR & TT775 \cite{rMAT94a} \\ + 25 & 7 & 32 & TTGFSR & TT800 \cite{rMAT94a} \\ + 624 & 397 & 32 & TTGFSR & MT19937 \cite{rMAT98a} \\ +\hline +\end {tabular} +\end {table} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* ugfsr.h for ANSI C */ + +#ifndef UGFSR_H +#define UGFSR_H +\endhide +#include "unif01.h" +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{GFSR generators} + +\code + +unif01_Gen * ugfsr_CreateGFSR3 (unsigned int k, unsigned int r, + unsigned int l, unsigned long S[]); +\endcode + \tab Implements a generator GFSR based on the recurrence + \eq + x_i = x_{i-r} \oplus x_{i-k} \eqlabel{GFSR} + \endeq + where each $x_i$ is a 32-bit vector, $\oplus$ stands for +\index{Generator!shift-register}% + bitwise addition modulo $2$, and $r < k$. + The output at step $i$ is $u_i = \tilde x_i/2^l$, where + $\tilde x_i$ is the integer formed by the first $l$ bits of $x_i$. + The array {\tt S[0..(k-1)]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. + Proper initialization techniques for this generator are discussed, + e.g., in \cite{rFUS83a} and \cite{rTEZ95a}. + Restrictions: $0 < r < k$ and $l \le 32$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateToot73 (unsigned long S[]); +\endcode + \tab Implements the Tausworthe generator + of parameters $(k,r,s,l) = (607, 273, 512, 23)$ proposed + in \cite{rTOO73a}, under the form of a GFSR. + The generator is initialized as in \cite{rTOO73a} +\index{Generator!Tootill}% + from the ``arbitrary'' bits given in {\tt S[0..k-1]}. + This generator is the same as G607 in \cite{rMAT94a}. +% , whose parameters are $(k, r', l) = (607, 334, 23)$. +\endtab +\code + + +unif01_Gen * ugfsr_CreateKirk81 (long s); +\endcode + \tab Implements the GFSR generator proposed by + Kirkpatrick and Stoll \cite{rKIR81a}, with their +\index{Generator!Kirkpatrick-Stoll}% + initialization procedure. + The parameters are $(k,r,l) = (250, 103, 32)$ and $s$ is the seed. + \endtab +\code + + +unif01_Gen * ugfsr_CreateRipley90 (long s); +\endcode + \tab Implements the GFSR generator given in the appendix + of Ripley \cite{rRIP90a}. +\index{Generator!Ripley}% + It is a GFSR with parameters $(k, r, l) = (521, 32, 31)$. + The state of this GFSR is initialized as in \cite{rRIP90a} + from a MLCG of modulus $m=2^{31}-1$ and multiplier + $a = 16807$, whose initial state is $s$. The returned value + is $y_i/(2^{31} - 1)$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateFushimi (int k, int r, int s); +\endcode + \tab Implements a GFSR generator with $l = 31$, with the +\index{Generator!Fushimi}% + initialization procedure proposed by Fushimi \cite{rFUS90a}, + using {\tt s} as a seed to construct the initial state. + \endtab +\code + + +unif01_Gen * ugfsr_CreateFushimi90 (int s); +\endcode + \tab Implements a specific GFSR generator proposed by + Fushimi \cite{rFUS90a}, with parameters $(k,r,l) = (1563, 1467, 31)$ + and using {\tt s} as a seed to construct the initial state. + \endtab +\code + + +unif01_Gen * ugfsr_CreateGFSR5 (unsigned int k, unsigned int r1, + unsigned int r2, unsigned int r3, + unsigned int l, unsigned long S[]); +\endcode + \tab Implements a GFSR generator whose characteristic polynomial + is a pentanomial, i.e., based on the recurrence + $$ x_i = x_{i-r_3} \oplus x_{i-r_2} \oplus x_{i-r_1} \oplus x_{i-k} $$ + where the $x_i$'s are vectors of 32 bits whose first $l$ + bits are used to create the output, as described in + {\tt ugfsr\_CreateGFSR3}. The array {\tt S[0..(k-1)]} + contains the $k$ initial bit vectors $x_0, \dots, x_{k-1}$. +% The output at step $i$ is $y_i/2^l$ where $y_i$ is the integer which +% corresponds to the first $l$ bits of $x_i$. + Restrictions: $1 \le l \le 32$ and $0 < r_3 < r_2 < r_1 < k$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateZiff98 (unsigned long S[]); +\endcode + \tab Implements a specific pentanomial-based GFSR generator proposed +\index{Generator!Ziff}% + by Ziff \cite{rZIF98a}, with parameters $(k, r_1, r_2, r_3, l) = + (9689, 6988, 1586, 471, 32)$. + The array {\tt S[0..9688]} must contain the initial state. + \endtab + +% \newpage +%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Twisted GFSR generators} + +\code + +unif01_Gen * ugfsr_CreateTGFSR (unsigned int k, unsigned int r, + unsigned int l, unsigned long Av, + unsigned long S[]); +\endcode + \tab Implements the original form of TGFSR generator proposed by + Matsumoto and Kurita \cite{rMAT92a}. It is based on the recurrence + \eq + x_i = x_{i-k} \oplus (x_{i-r} A), + \endeq + where $k, r, l$ and the $x_i$'s are as in (\ref{GFSR}), + and $A$ is a binary matrix of dimension $l \times l$ whose first + superdiagonal has all its elements equal to 1, the last + row is the vector {\tt Av}, and all other elements are 0. + The output at step $i$ is $u_i = \tilde x_i/2^l$, where + $\tilde x_i$ is the integer formed by the first $l$ bits of $x_i$. + Matsumoto and Kurita \cite{rMAT94a} later reported deficiencies + of this generator. + The array {\tt S[0..(k-1)]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. + Remark: the notation + $$ x_{i+k} = x_{i-r'} \oplus x_{i}, $$ + where $r' = k-r$, is used in \cite{rMAT94a}. + In other words, their $r$ correspond to our $k-r$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateT800 (unsigned long S[]); +\endcode + \tab Implements the TGFSR generator T800 proposed by +\index{Generator!T800}% + Matsumoto and Kurita \cite{rMAT94a}, whose parameters are + $(k,r,l) = (25,18,32)$ and {\tt Av = 0x8EBD028}. + The array {\tt S[0..(k-1)]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateTGFSR2 (unsigned int k, unsigned int r, + unsigned int l, unsigned int s, + unsigned int t, unsigned long Av, + unsigned long Bv, unsigned long Cv, + unsigned long S[]); +\endcode + \tab Implements the generator TGFSR-II proposed by + Matsumoto and Kurita \cite{rMAT94a}, based on the same recurrence + as their original TGFSR, but where a {\em tempering\/} is + added to improve the statistical quality of the output. + It is defined by + \begin {eqnarray} + x_i &=& x_{i-k} \oplus (x_{i-r}A), \label {tgfsr2a} \\ + y_i &=& x_i \oplus ((x_i \ll s)\ \&\ b), \label {tgfsr2b} \\ + z_i &=& y_i \oplus ((y_i \ll t)\ \&\ c), \label {tgfsr2c} + \end {eqnarray} + where $\ll s$ means a left shift by $s$ bits, + $\&$ means the bitwise-and operation, and the bit vectors + $b$ and $c$ are given by {\tt Bv} and {\tt Cv}. + The output $u_i$ is constructed as described in {\tt ugfsr\_CreateTGFSR}, + but using $z_i$ instead of $x_i$. + The array {\tt S[0..(k-1)]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateTT400 (unsigned long S[]); +\endcode + \tab Implements the generator TT400 proposed by +\index{Generator!TT400}% + Matsumoto and Kurita \cite{rMAT94a}, whose parameters are + ($k,k-r,l) = (25,11,16)$, $s = 2$, $t = 7$, + {\tt Av = 0xA875} , {\tt Bv = 0x6A68}, {\tt Cv = 0x7500}. + The array {\tt S[0..(k-1)]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. The returned value is $z_i/(2^{16} - 1)$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateTT403 (unsigned long S[]); +\endcode + \tab Implements the generator TT403 proposed by +\index{Generator!TT403}% + Matsumoto and Kurita \cite{rMAT94a}, whose parameters are + ($k,k-r,l) = (13,2,31)$, $s = 8$, $t = 14$, + {\tt Av = 0x6B5ECCF6}, {\tt Bv = 0x102D1200}, {\tt Cv = 0x66E50000}. + The array {\tt S[0..(k-1)]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. + The returned value is $z_i/(2^{31} - 1)$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateTT775 (unsigned long S[]); +\endcode + \tab Implements the generator TT775 proposed by +\index{Generator!TT775}% + Matsumoto and Kurita \cite{rMAT94a}, whose parameters are + ($k,k-r,l) = (25,8,31)$, $s = 6$, $t = 14$, {\tt Av = 0x6C6CB38C}, + {\tt Bv = 0x1ABD5900}, {\tt Cv = 0x776A0000}. + The array {\tt S[0..(k-1)]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. The returned value is $z_i/(2^{31} - 1)$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateTT800 (unsigned long S[]); +\endcode + \tab Implements the generator TT800 proposed by +\index{Generator!TT800}% + Matsumoto and Kurita \cite{rMAT94a}, whose parameters are + $(k,r,l) = (25,18,32)$, $s = 7$, $t = 15$, + {\tt Av = 0x8EBFD028}, {\tt Bv = 0x2B5B2500}, {\tt Cv = 0xDB8D0000}. + The array {\tt S[0..24]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. The returned value is $z_i/2^{32}$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateTT800M94 (unsigned long S[]); +\endcode + \tab The original implementation of TT800 provided by + Matsumoto and Kurita \cite{rMAT94a}, in 1994. + The array {\tt S[0..24]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. The returned value is $z_i/(2^{32} - 1)$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateTT800M96 (unsigned long S[]); +\endcode + \tab A second implementation of TT800, provided by Matsumoto + and Kurita in 1996. + The array {\tt S[0..24]} contains the $k$ initial bit vectors + $x_0, \dots, x_{k-1}$. The returned value is $z_i/(2^{32} - 1)$. + \endtab +\code + + +unif01_Gen * ugfsr_CreateMT19937_98 (unsigned long seed); +\endcode + \tab The original implementation of the Mersenne twister generator +\index{Generator!MT19937}\index{Generator!Mersenne twister}% + of Matsumoto and Nishimura \cite{rMAT98a}. + Its period length is $2^{19937}-1$. + The returned value is $z_i/(2^{32} - 1)$. This is the 1998 version. + \endtab +\code + + +unif01_Gen * ugfsr_CreateMT19937_02 (unsigned long seed, + unsigned long Key[], int len); +\endcode + \tab The 2002 version of the Mersenne twister generator \label{rng:MT19937} + of Matsumoto and Nishimura \cite{rMAT98a}, which has a better + initialization procedure than the original 1998 version. + If {\tt len} $ \le 0$ or {\tt Key = NULL}, then {\tt seed} is used to + initialize the state vector. If {\tt len > 0}, the array {\tt Key} of + length {\tt len} is used instead. + If {\tt len} is smaller than 624, + then each array of 32-bit integers gives distinct initial + state vectors. This is useful if one wants a larger seed space + than a single 32-bit word. + \endtab + + + + +\guisec{Clean-up functions} +\code + +void ugfsr_DeleteGFSR5 (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory allocated by + {\tt ugfsr\_CreateGFSR5}. + \endtab +\code + + +void ugfsr_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called when a generator + is no longer in use. + \endtab +\code +\hide +#endif +\endhide +\endcode + + +\iffalse %%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\bigskip +{ +For other GFSR generators, see also + +\begin{itemize} +\item {\tt uwu\_CreatePentaWuC} % Encore confidentiel. +\end{itemize} +} +\fi %%%% diff --git a/TESTU01/TestU01-1.2.3/testu01/ugranger.c b/TESTU01/TestU01-1.2.3/testu01/ugranger.c new file mode 100644 index 0000000..5f1abc2 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ugranger.c @@ -0,0 +1,251 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ugranger.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "ugranger.h" +#include "utaus.h" +#include "ulcg.h" +#include "uinv.h" +#include "ucubic.h" +#include "unif01.h" +#include "num.h" + +#ifdef USE_GMP +#include +#endif + + + + +/*========================================================================*/ + +unif01_Gen * ugranger_CreateCombLCGInvExpl ( + long m1, long a1, long c1, long s1, long m2, long a2, long c2) +{ + unif01_Gen *gen1, *gen2; + double x = m1 * (double) a1; + + if (x + c1 >= num_TwoExp[53] || -x >= num_TwoExp[53]) { + gen1 = ulcg_CreateLCG (m1, a1, c1, s1); + } else + gen1 = ulcg_CreateLCGFloat (m1, a1, c1, s1); + + gen2 = uinv_CreateInvExpl (m2, a2, c2); + return unif01_CreateCombAdd2 (gen1, gen2, "ugranger_CreateCombLCGInvExpl:"); +} + +void ugranger_DeleteCombLCGInvExpl (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteGen (param->gen1); + uinv_DeleteGen (param->gen2); + unif01_DeleteCombGen (gen); +} + + +/*========================================================================*/ +#ifdef USE_GMP + +unif01_Gen * ugranger_CreateCombBigLCGInvExpl ( + char * m1, char * a1, char * c1, char * s1, long m2, long a2, long c2) +{ + unif01_Gen *gen1, *gen2; + + gen1 = ulcg_CreateBigLCG (m1, a1, c1, s1); + gen2 = uinv_CreateInvExpl (m2, a2, c2); + return unif01_CreateCombAdd2 (gen1, gen2, "ugranger_CreateCombBigLCGInvExpl:"); +} + +void ugranger_DeleteCombBigLCGInvExpl (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteBigLCG (param->gen1); + uinv_DeleteGen (param->gen2); + unif01_DeleteCombGen (gen); +} + +#endif + +/*========================================================================*/ + +unif01_Gen * ugranger_CreateCombLCGCub ( + long m1, long a1, long c1, long s1, long m2, long a2, long s2) +{ + unif01_Gen *gen1, *gen2; + double x = m1 * (double) a1; + + if (x + c1 >= num_TwoExp[53] || -x >= num_TwoExp[53]) { + gen1 = ulcg_CreateLCG (m1, a1, c1, s1); + } else + gen1 = ulcg_CreateLCGFloat (m1, a1, c1, s1); + + gen2 = ucubic_CreateCubic1Float (m2, a2, s2); + return unif01_CreateCombAdd2 (gen1, gen2, "ugranger_CreateCombLCGCub:"); +} + +void ugranger_DeleteCombLCGCub (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteGen (param->gen1); + ucubic_DeleteGen (param->gen2); + unif01_DeleteCombGen (gen); +} + + +/*========================================================================*/ + +#ifdef USE_GMP +unif01_Gen * ugranger_CreateCombBigLCGCub ( + char * m1, char * a1, char * c1, char * s1, long m2, long a2, long s2) +{ + unif01_Gen *gen1, *gen2; + + gen1 = ulcg_CreateBigLCG (m1, a1, c1, s1); + gen2 = ucubic_CreateCubic1Float (m2, a2, s2); + return unif01_CreateCombAdd2 (gen1, gen2, "ugranger_CreateCombBigLCGCub:"); +} + +void ugranger_DeleteCombBigLCGCub (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteBigLCG (param->gen1); + ucubic_DeleteGen (param->gen2); + unif01_DeleteCombGen (gen); +} + + +/*========================================================================*/ + +unif01_Gen * ugranger_CreateCombTausBigLCG ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + char * m, char * a, char * c, char * SS3) +{ + unif01_Gen *gen1, *gen2; + + gen1 = utaus_CreateCombTaus2 (k1, k2, q1, q2, s1, s2, SS1, SS2); + gen2 = ulcg_CreateBigLCG (m, a, c, SS3); + return unif01_CreateCombAdd2 (gen1, gen2, "ugranger_CreateCombTausBigLCG:"); +} + +void ugranger_DeleteCombTausBigLCG (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteBigLCG (param->gen2); + utaus_DeleteGen (param->gen1); + unif01_DeleteCombGen (gen); +} + +#endif + +/*========================================================================*/ + +unif01_Gen * ugranger_CreateCombTausLCG21xor ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + long m, long a, long c, long SS3) +{ + unif01_Gen *gen1, *gen2; + double x = m * (double) a; + + gen1 = utaus_CreateCombTaus2 (k1, k2, q1, q2, s1, s2, SS1, SS2); + if (x + c >= num_TwoExp[53] || -x >= num_TwoExp[53]) { + gen2 = ulcg_CreateLCG (m, a, c, SS3 % m); + } else + gen2 = ulcg_CreateLCGFloat (m, a, c, SS3 % m); + return unif01_CreateCombXor2 (gen1, gen2, + "ugranger_CreateCombTausLCG21xor:"); +} + +void ugranger_DeleteCombTausLCG21xor (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteGen (param->gen2); + utaus_DeleteGen (param->gen1); + unif01_DeleteCombGen (gen); +} + + +/*========================================================================*/ + +unif01_Gen * ugranger_CreateCombTausCub21xor ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + long m, long a, long SS3) +{ + unif01_Gen *gen1, *gen2; + + gen1 = utaus_CreateCombTaus2 (k1, k2, q1, q2, s1, s2, SS1, SS2); + gen2 = ucubic_CreateCubic1Float (m, a, m % SS3); + return unif01_CreateCombXor2 (gen1, gen2, + "ugranger_CreateCombTausCub21xor:"); +} + +void ugranger_DeleteCombTausCub21xor (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ucubic_DeleteGen (param->gen2); + utaus_DeleteGen (param->gen1); + unif01_DeleteCombGen (gen); +} + + +/*========================================================================*/ + +unif01_Gen * ugranger_CreateCombTausInvExpl21xor ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + long m, long a, long c) +{ + unif01_Gen *gen1, *gen2; + + gen1 = utaus_CreateCombTaus2 (k1, k2, q1, q2, s1, s2, SS1, SS2); + gen2 = uinv_CreateInvExpl (m, a, c); + return unif01_CreateCombXor2 (gen1, gen2, + "ugranger_CreateCombTausInvExpl21xor:"); +} + +void ugranger_DeleteCombTausInvExpl21xor (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + uinv_DeleteGen (param->gen2); + utaus_DeleteGen (param->gen1); + unif01_DeleteCombGen (gen); +} + + +/*========================================================================*/ diff --git a/TESTU01/TestU01-1.2.3/testu01/ugranger.tex b/TESTU01/TestU01-1.2.3/testu01/ugranger.tex new file mode 100644 index 0000000..30a5f5e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ugranger.tex @@ -0,0 +1,189 @@ +\defmodule {ugranger} + +This module collects combined generators implemented by +Jacinthe Granger-Pich\'e for her master thesis. +Some of the generators in this module use the GNU multiprecision package GMP. +%% (see the web site at \url{http://www.gnu.org/software/gmp/gmp.html}). +The macro {\tt USE\_GMP} is defined in module {\tt gdef} in directory +{\tt mylib}. \index{Generator!Granger-Pich\'e}% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +#ifndef UGRANGER_H +#define UGRANGER_H +/* ugranger.h for ANSI C */ +\endhide +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen * ugranger_CreateCombLCGInvExpl ( + long m1, long a1, long c1, long s1, long m2, long a2, long c2); +\endcode + \tab + Combines an LCG of parameters $(m_1, a_1, c_1)$ and initial + state $s_1$ with a non-linear explicit inversive generator + with parameters $(m_2, a_2, c_2)$. The implementation of the LCG uses either + {\tt ulcg\_CreateLCGFloat} or {\tt ulcg\_CreateLCG}, + depending on the parameters + $(m_1, a_1, c_1)$, and the implementation of the inversive generator uses + {\tt uinv\_CreateInvExpl}. The combination is done by adding mod 1 the + outputs of the two generators. + Restrictions: the same as those for {\tt ulcg\_CreateLCG} and + {\tt uinv\_CreateInvExpl}. + \endtab +\code + + +#ifdef USE_GMP + unif01_Gen * ugranger_CreateCombBigLCGInvExpl ( + char *m1, char *a1, char *c1, char *s1, long m2, long a2, long c2); +\endcode + \tab + Same as {\tt ugranger\_CreateCombLCGInvExpl}, but the LCG is implemented + using arbitrary large integers with {\tt ulcg\_CreateBigLCG}. + Restrictions: the same as those for {\tt ulcg\_CreateBigLCG} and + {\tt uinv\_CreateInvExpl}. + \endtab +\code +#endif + + +unif01_Gen * ugranger_CreateCombLCGCub ( + long m1, long a1, long c1, long s1, long m2, long a2, long s2); +\endcode + \tab Combines an LCG of parameters $(m_1, a_1, c_1)$ and initial + state $s_1$ with a cubic generator of parameters $(m_2, a_2)$ and + initial state $s_2$. The LCG implementation is either + {\tt ulcg\_CreateLCGFloat} or {\tt ulcg\_CreateLCG}, depending on the + parameters $(m_1, a_1, c_1)$, and the implementation of the + cubic generator is {\tt ucubic\_CreateCubic1Float}. + The combination is done by adding mod 1 the outputs of the two generators. + Restrictions: the same as those for {\tt ulcg\_CreateLCG} and + {\tt ucubic\_CreateCubic1Float}. + \endtab +\code + + +#ifdef USE_GMP + unif01_Gen * ugranger_CreateCombBigLCGCub ( + char *m1, char *a1, char *c1, char *s1, long m2, long a2, long c2); +\endcode + \tab Same as {\tt ugranger\_CreateCombCubLCG}, but the LCG is implemented + using arbitrary large integers with {\tt ulcg\_CreateBigLCG}. + Restrictions: the same as those for {\tt ulcg\_CreateBigLCG} and + {\tt ucubic\_CreateCubic1Float}. + \endtab +\code + + + unif01_Gen * ugranger_CreateCombTausBigLCG ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + char *m, char *a, char *c, char *SS3); +\endcode + \tab Combines a Tausworthe generator with two components of parameters + $(k_1, q_1, s_1)$, $(k_2, q_2, s_2)$ and + initial states $\mathit{SS1}$, $\mathit{SS2}$ with an LCG of parameters + $(m, a, c)$ and initial state $\mathit{SS3}$. + The combination is done by adding + mod 1 the outputs of the LCG and of the combined Tausworthe. + The implementation of the LCG is the one in + {\tt ulcg\_CreateBigLCG}, and the implementation of the + combined Tausworthe is the one in {\tt utaus\_CreateCombTaus2}. + Restrictions: the same as those for {\tt utaus\_CreateCombTaus2} and + {\tt ulcg\_CreateBigLCG}. + \endtab +\code +#endif + + +unif01_Gen * ugranger_CreateCombTausLCG21xor ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + long m, long a, long c, long SS3); +\endcode + \tab Combines a Tausworthe generator with two components of parameters + $(k_1, q_1, s_1)$, $(k_2, q_2, s_2)$ and + initial states $\mathit{SS1}$, $\mathit{SS2}$ with an LCG of parameters + $(m, a, c)$ and initial state $\mathit{SS3}$. The combination is done + using a + bitwise exclusive-or of the outputs of the two generators. + The implementation of the LCG is either the one in + {\tt ulcg\_CreateLCGFloat} or in {\tt ulcg\_CreateLCG}, + depending on the parameters $(m, a, c)$, and the implementation of the + combined Tausworthe is the one in {\tt utaus\_CreateCombTaus2}. + Restrictions: the same as those for {\tt utaus\_CreateCombTaus2} and + {\tt ulcg\_CreateLCG}. + \endtab +\code + + +unif01_Gen * ugranger_CreateCombTausCub21xor ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + long m, long a, long SS3); +\endcode + \tab + Combines a Tausworthe generator with two components of parameters + $(k_1, q_1, s_1)$, $(k_2, q_2, s_2)$ and + initial states $\mathit{SS1}$, $\mathit{SS2}$ with a cubic generator of + parameters $(m, a)$ and initial state $\mathit{SS3}$. + The combination is done using a + bitwise exclusive-or of the outputs of the two generators. + The implementation of the + combined Tausworthe is the one in {\tt utaus\_CreateCombTaus2}, + and the implementation of the cubic generator + is the one in {\tt ucubic\_CreateCubic1Float}. + Restrictions: the same as those for {\tt utaus\_CreateCombTaus2} and + {\tt ucubic\_CreateCubic1Float}. + \endtab +\code + + +unif01_Gen * ugranger_CreateCombTausInvExpl21xor ( + unsigned int k1, unsigned int q1, unsigned int s1, unsigned int SS1, + unsigned int k2, unsigned int q2, unsigned int s2, unsigned int SS2, + long m, long a, long c); +\endcode + \tab Combines a Tausworthe generator with two components of parameters + $(k_1, q_1, s_1)$, $(k_2, q_2, s_2)$ and + initial states $\mathit{SS1}$, $\mathit{SS2}$ with an + explicit inversive generator + of parameters $(m, a, c)$. The combination is done using a + bitwise exclusive-or of the outputs of the two generators. + The implementation of the + combined Tausworthe is the one in {\tt utaus\_CreateCombTaus2}, + and the implementation of the inversive generator + is the one in {\tt uinv\_CreateInvExpl}. + Restrictions: the same as those for {\tt utaus\_CreateCombTaus2} and + {\tt uinv\_CreateInvExpl}. + \endtab + + +\guisec{Clean-up functions} +\code + +void ugranger_DeleteCombLCGInvExpl (unif01_Gen *gen); +void ugranger_DeleteCombLCGCub (unif01_Gen *gen); +void ugranger_DeleteCombTausLCG21xor (unif01_Gen *gen); +void ugranger_DeleteCombTausCub21xor (unif01_Gen *gen); +void ugranger_DeleteCombTausInvExpl21xor (unif01_Gen *gen); + +#ifdef USE_GMP + void ugranger_DeleteCombBigLCGInvExpl (unif01_Gen *gen); + void ugranger_DeleteCombBigLCGCub (unif01_Gen *gen); + void ugranger_DeleteCombTausBigLCG (unif01_Gen *gen); +#endif +\endcode + \tab Frees the dynamic memory allocated by the corresponding {\tt Create} + function of this module. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/uintro.tex b/TESTU01/TestU01-1.2.3/testu01/uintro.tex new file mode 100644 index 0000000..812ac74 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uintro.tex @@ -0,0 +1,336 @@ +\chapter{UNIFORM GENERATORS} + +This chapter contains a description of various uniform generators +already programmed in this library and which were proposed by various +authors over the past several years, as well as tools for managing +and implementing additional types of generators. +Related generators are regrouped in the same module. +For example, the linear congruential generators (LCGs) are in module +{\tt ulcg}, the multiple recursive generators (MRGs) are in {\tt umrg}, +the inversive generators in {\tt uinv}, +the cubic generators in {\tt ucubic}, etc. +We emphasize that the generators provided here are not all recommendable; +in fact, {\em most of them are not}. + +The module {\tt unif01} contains the basic utilities for defining, +manipulating, filtering, combining, and timing generators. +Each generator must be implemented as an +object of type {\tt unif01\_Gen}. To implement one's own generator, +one should create such an object and define all its fields. +For each generator, the structure {\tt unif01\_Gen} must contain a +function {\tt GetU01} that returns values in the interval $[0,1)$ +and a function {\tt GetBits} that returns a block of 32 bits. +Most of the tests in the {\tt s} modules call the generators +to be tested only indirectly, through the use of the interface +functions {\tt unif01\_StripD}, {\tt unif01\_StripL} and +{\tt unif01\_StripB}. +These functions drop the $r$ most significant bits of each random number +generated and returns a number built out of the remaining bits. + +It is also possible to test one's own or an external generator +(that is, a generator that is not predefined in TestU01) very easily with +the help of the functions {\tt unif01\_CreateExternGen01} and +{\tt unif01\_CreateExternGenBits} (see page \pageref{externgen} +of this guide), as long as this generator is programmed in C. + +Figure~\ref{fig:usegen} gives simple examples of how to use predefined +generators. The program creates a LCG with modulus $m = 2^{31}-1$, +multiplier $a = 16807$, and initial state $s = 12345$, +generates and adds 100 uniforms produced by this generator, +prints the sum, and deletes the generator. +To illustrate the fact that there are different ways of getting the +uniforms from the generator, we have generated the first 50 by calling +the {\tt GetU01} function and the next 50 via {\tt unif01\_StripD}. +These two methods are equivalent. +The program then instantiates the generator {\tt lfsr113} available in +module {\tt ulec}, with the vector $(12345, \ldots, 12345)$ as initial seed, +generates and prints five integers in the range $\{0,\dots,2^{10}-1\}$ +(i.e., 10-bit integers) obtained by taking five successive output values +from the generator, stripping out the four most significant bits from +each value, and retaining the next 10 bits. + +For each public identifier used in programs, it is important to +include the corresponding header file before using it, +so as to inform the compiler about the type and signature of functions +and exported variables. For instance, in the following examples, the header +files \texttt{unif01.h}, \texttt{ulcg.h} and \texttt{ulec.h} contain the +declarations of \texttt{unif01\_Gen}, \texttt{ulcg\_CreateLCG} and +\texttt{ulec\_Createlfsr113}, respectively. + +Other examples on how to use the facilities of module {\tt unif01} are given +at the end of its description. + + +\setbox0=\vbox {\hsize = 6.0in +\smallc +\verbatiminput{../examples/ex1.c} +} + +\begin{figure} +\centering +\myboxit{\box0} +\caption {Using pre-programmed generators\label {fig:usegen}} +\end{figure} + + +\iffalse %%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\section {La vitesse des generators} + +Les Tableaux \ref{vitesse1}--\ref{vitesse10} donnent une idee +du temps d'execution moyen +par appel (en micro-secondes), pour un certain number de generators +fournis par the modules {\tt u...}. +Ces values sont en fait le number de secondes +requises pour un million $(10^6)$ d'appels, +donne ici a une seconde pres. +La machine utilisee etait un SUN UltraSparc 150. +%% 80386 avec coprocesseur 80387, tous deux a 16 MHz. +Pour fins de comparaison, pour un million d'appels a une procedure +``bidon'' ne faisant rien, dans le m\^eme contexte, il a fallu 0.26 secondes. + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module ulcg.} +\label {vitesse1} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + LCG$^1$ & 1.03 && CombLEC2$^2$ & 4.55\\ + LCG$^2$ & 2.33 && CombLEC2$^3$ & 20.22\\ + LCG$^3$ & 10.91 && CombLEC3$^2$ & 6.60\\ + LCGFloat & 0.80 && & \\ + BigLCG & 45.24 && CombWH2$^1$ & 2.49\\ + LCG2e31 & 0.98 && CombWH2$^2$ & 4.67\\ + LCG2e32 & 0.95 && CombWH2$^3$ & 20.40\\ + LCG2e31m1HD & 1.73 && CombWH3$^2$ & 7.25\\ + CombLEC2$^1$ & 2.22 && & \\ +&&&&\\ +\hline +\end{tabular} + +\begin {verse} + $^1$ : $(m-1)a + c$ representable en {\tt LONGINT} (implantation directe).\\ + $^2$ : implantation utilisee lorsque $a (m\mod a) < m$.\\ + $^3$ : implantation utilisee dans the autres cas.\\ +\end {verse} +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module umrg.} +\label {vitesse2} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + MRG$^1$ & 12.36 && MRG$^3$ & 6.35\\ + MRG$^2$ & 4.13 && C2MRG & 10.71\\ + LagFib & 0.59 && &\\ +\hline +\end{tabular} + +\begin {verse} + $^1$ : implantation generale.\\ + $^2$ : implantation plus rapide mentionnee dans {\tt SetMRG}.\\ + $^3$ : varie selon que $p - d < 32$ ou non et que $d < 32$ ou non.\\ +\end {verse} +\end {table} + + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators du + module utaus.} +\label {vitesse3} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + Taus & 0.69 && CombTaus3 & 1.60\\ + TausJ & 3.52 && Tez95 & 1.48\\ + LongTaus & 1.07 && TezLec91 & 1.17\\ + CombTaus2 & 1.17 && Tausme3a & 1.49\\ +&&&&\\ +\hline +\end{tabular} + +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module ugfsr.} +\label {vitesse4} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + GFSR & 0.66 && Toot73 & 0.62\\ + TGFSR & 0.81 && Fushimi90 & 0.67\\ + Ripley90 & 0.53 && Kirk81 & 0.65\\ +&&&&\\ +\hline +\end{tabular} + +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module uinv.} +\label {vitesse5} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + InvImpl & 14.18 && InvExpl & 14.77\\ + InvImpl2a & 22.95 && InvExpl2a & 35.21\\ + InvImpl2b & 22.82 && InvExpl2b & 27.46\\ + InvMRG & 23.12 && & \\ +&&&&\\ +\hline +\end{tabular} + +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module uquad.} +\label {vitesse6} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + Quadratic & 13.81 && Quadratic2$^1$& 14.77\\ + Quadratic2 & 1.63 && & \\ +&&&&\\ +\hline +\end{tabular} + +\begin {verse} +$^1$ : implantation rapide : e = 32.\\ +\end {verse} +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module ulec.} +\label {vitesse7} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + CombLec88 & 2.98 && CombMRG96 & 5.47\\ + MRG93 & 3.31 && CombMRG96d & 11.22\\ + CombLec88Float & 1.38 && CombMRG96Float & 2.60\\ + & && CombMRG96dFloat & 5.13\\ +&&&&\\ +\hline +\end{tabular} + +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module ucarry.} +\label {vitesse8a} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + AWC & 0.85 && MWC$^1$ & 13.03\\ + SWC & 0.85 && SWC$^1$ & 3.79\\ +&&&&\\ +\hline +\end{tabular} + +\begin {verse} + $^1$ : implantation generale, e = 32.\\ +\end {verse} +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module umarsa.} +\label {vitesse8} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + KISS & 0.76 && Combo & 1.15\\ + Marsa90a & 0.87 && ECG1 & 1.34\\ + Marsa90b & 0.83 && ECG2 & 1.31\\ + Mother0 & 1.77 && ECG3 & 1.39\\ + &&& ECG4 & 1.36 \\ +% Mother1$^1$ & 5.95 && & \\ +&&&&\\ +\hline +\end{tabular} +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + du module unumrec.} +\label {vitesse9} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + Setran0 & 2.33 && Setran2 & 5.25\\ + Setran1 & 2.91 && & \\ +&&&&\\ +\hline +\end{tabular} + +\end {table} + +\begin{table}[htb] \centering \tt +\caption {\rm Vitesse moyenne par appel pour the generators + des modules uvaria et ufile.} +\label {vitesse10} +\begin{tabular}{|l|r|c|l|r|} +\hline +&&&&\\ +\multicolumn{1}{|c|}{\rm Generator} & $\mu$-sec. && {\rm Generator} + & $\mu$-sec.\\ +\hline \hline +&&&&\\ + Tindo & 64.31 && ACORN & 75.33\\ + CSD & 6.03 && ReadFile & 13.82\\ +&&&&\\ +\hline +\end{tabular} + +\end {table} + +\fi %%%%%%%%%%%%%%%%%%%% diff --git a/TESTU01/TestU01-1.2.3/testu01/uinv.c b/TESTU01/TestU01-1.2.3/testu01/uinv.c new file mode 100644 index 0000000..f1eee94 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uinv.c @@ -0,0 +1,1212 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uinv.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "uinv.h" +#include "unif01.h" + +#include +#include +#include +#include + + + + +/*============================= Constants ===============================*/ + +#define LEN 300 /* Max string length */ +#define MASK31 0x7fffffffUL /* Mask of 31 bits */ +#define MASK32 0xffffffffUL /* Mask of 32 bits */ + + + + +/*============================== Types ==================================*/ +/* + * Different styles for generators of same type: Small, Medium, Large + */ + +typedef enum { + StyleS, StyleM, StyleL +} GenStyle; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long A1, A2, M, Q, R; + double Norm; +} InvImpl_param; + +typedef struct { + long Z; + GenStyle Style; +} InvImpl_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long A1, A2, Mask, Shift, M; +} InvImpl2a_param; + +typedef struct { + unsigned long Z; +} InvImpl2a_state; + +/*-------------------------------------------------------------------------*/ + +typedef InvImpl2a_param InvImpl2b_param; + +typedef InvImpl2a_state InvImpl2b_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long M, MmA, A2; + double Norm; +} InvExpl_param; + +typedef struct { + long Z; +} InvExpl_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long A2, E, Mask, Shift; +} InvExpl2a_param; + +typedef struct { + unsigned long Z; +} InvExpl2a_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long A1, A2, E, Mask, Shift; +} InvExpl2b_param; + +typedef struct { + unsigned long N; +} InvExpl2b_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long *A, *Q, *R; + long M; + double Norm; +} InvMRG_param; + +typedef struct { + long *S; + int Order; +} InvMRG_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double *A; + double M; + double Norm; +} InvMRGFloat_param; + +typedef struct { + double *S; + int Order; +} InvMRGFloat_state; + + + + + +/*============================= Functions ===============================*/ + + +/********************************************************************** + * + * Non-linear Generator with inversion in the form + * Z = (a1 + a2 * Zm1^(-1) ) % m + * as mentionned in L'Ecuyer (1990). + * + * The values returned by the generators implemented below are + * in the following set: { 0/m, 1/m, 2/m, ..., (m-1)/m }. + * + *********************************************************************/ + +static double SmallInvImpl_U01 (void *vpar, void *vsta) +/* + * Direct Implementation used when (A1 + A2*(M - 1)) fits in a long int + */ +{ + InvImpl_param *param = vpar; + InvImpl_state *state = vsta; + + if (state->Z == 0) + state->Z = param->A1; + else + state->Z = (param->A1 + param->A2 * num_InvEuclid (param->M, state->Z)) + % param->M; + return (state->Z * param->Norm); +} + +static unsigned long SmallInvImpl_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SmallInvImpl_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double MediumInvImpl_U01 (void *vpar, void *vsta) +/* + * Implementation used when a2 * (m % a2) < m + */ +{ + InvImpl_param *param = vpar; + InvImpl_state *state = vsta; + long Zinv, k; + + if (state->Z == 0) + state->Z = param->A1; + else { + Zinv = num_InvEuclid (param->M, state->Z); + k = Zinv / param->Q; + state->Z = param->A2 * (Zinv - k * param->Q) - k * param->R; + if (state->Z < 0) + state->Z += param->A1; + else + state->Z = (state->Z - param->M) + param->A1; + if (state->Z < 0) + state->Z += param->M; + } + return (state->Z * param->Norm); +} + +static unsigned long MediumInvImpl_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumInvImpl_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double LargeInvImpl_U01 (void *vpar, void *vsta) +/* + * Implementation used when the last 2 above cannot be used + */ +{ + InvImpl_param *param = vpar; + InvImpl_state *state = vsta; + + if (state->Z == 0) + state->Z = param->A1; + else + state->Z = num_MultModL (param->A2, + num_InvEuclid (param->M, state->Z), param->A1, param->M); + return (state->Z * param->Norm); +} + +static unsigned long LargeInvImpl_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LargeInvImpl_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrInvImpl (void *vsta) +{ + InvImpl_state *state = vsta; + + if (state->Style == StyleS) + printf ("Small InvImpl,"); + else if (state->Style == StyleM) + printf ("Medium InvImpl,"); + else if (state->Style == StyleL) + printf ("Large InvImpl,"); + printf (" Z = %1ld\n", state->Z); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvImpl (long m, long a1, long a2, long z0) +{ + unif01_Gen *gen; + InvImpl_param *param; + InvImpl_state *state; + size_t leng; + char name[LEN + 1]; + + if ((z0 < 0) || (z0 >= m) || (a1 <= 0) || (a1 >= m) || + (a2 <= 0) || (a2 >= m) || (m < 2) || ((m % 2) == 0)) + util_Error ("uinv_CreateInvImpl: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvImpl_param)); + state = util_Malloc (sizeof (InvImpl_state)); + + strcpy (name, "uinv_CreateInvImpl:"); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", z0 = ", z0); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Norm = 1.0 / m; + param->M = m; + param->A1 = a1; + param->A2 = a2; + state->Z = z0; + + if (m - 1 <= (LONG_MAX - a1) / a2) { /* First case */ + state->Style = StyleS; + gen->GetBits = &SmallInvImpl_Bits; + gen->GetU01 = &SmallInvImpl_U01; + + } else { + param->Q = m / a2; + param->R = m % a2; + if (param->R <= param->Q) { /* Second case */ + state->Style = StyleM; + gen->GetBits = &MediumInvImpl_Bits; + gen->GetU01 = &MediumInvImpl_U01; + + } else { /* Third case */ + state->Style = StyleL; + gen->GetBits = &LargeInvImpl_Bits; + gen->GetU01 = &LargeInvImpl_U01; + } + } + gen->param = param; + gen->state = state; + gen->Write = &WrInvImpl; + return gen; +} + + +/**************************************************************************/ +/* + * Non-linear Generator with inversion in the form + * Z = (a1 + a2 * Zm1^(-1) ) % m avec m = 2^e + * as mentionned in Eichenauer-Herrmann (1992). + * + * The values returned by the generators implemented below are + * in the following set: { 1/m, 3/m, 5/m, ..., (m-1)/m }. + * + * N.B. For e = 31 ou 32, the inverse is computed according to the formula: + * X^(-1) = X^(m-1) = X^((m / 4) - 1) + */ + + +static unsigned long InvImpl2a_Bits (void *vpar, void *vsta) +/* + * Implementation used when M = 2^e with 3 <= e <= 30. + * Compute the inverse by the modified Euclide algorithm. + */ +{ + InvImpl2a_param *param = vpar; + InvImpl2a_state *state = vsta; + + state->Z = (param->A1 + param->A2 * + num_InvEuclid ((long) param->M, (long) state->Z)) & param->Mask; + return (state->Z << param->Shift); +} + +/*-------------------------------------------------------------------------*/ + +static double InvImpl2a_U01 (void *vpar, void *vsta) +{ + return InvImpl2a_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long InvImpl2a31_Bits (void *vpar, void *vsta) +/* + * Special Implementation used when M = 2^31. + * The inverse must be computed by exponentiation even if it is slower. + * Given the special value of the exponent ( 2^29 - 1 ) + * ( = 536870911 ), it is done in a very direct way ... + */ +{ + InvImpl2a_param *param = vpar; + InvImpl2a_state *state = vsta; + unsigned int res = state->Z; + int fc; + + for (fc = 1; fc <= 28; fc++) + res = res * res * state->Z; /* res = Z^(-1) */ + + res &= MASK31; + state->Z = (param->A1 + param->A2 * res) & MASK31; + return (state->Z << 1); +} + +/*-------------------------------------------------------------------------*/ + +static double InvImpl2a31_U01 (void *vpar, void *vsta) +{ + return InvImpl2a31_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long InvImpl2a32_Bits (void *vpar, void *vsta) +/* + * Special Implementation used when M = 2^32. + * The inverse must be computed by exponentiation even if it is slower. + * Given the special value of the exponent ( 2^30 - 1 ) + * ( = 1073741823 ), it is done in a very direct way ... + */ +{ + InvImpl2a_param *param = vpar; + InvImpl2a_state *state = vsta; + unsigned int res = state->Z; + int fc; + + for (fc = 1; fc <= 29; fc++) + res = res * res * state->Z; /* res = Z^(-1) */ + res &= MASK32; + + state->Z = (param->A1 + param->A2 * res) & MASK32; + return state->Z; +} + +/*-------------------------------------------------------------------------*/ + +static double InvImpl2a32_U01 (void *vpar, void *vsta) +{ + return InvImpl2a32_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrInvImpl2a (void *vsta) +{ + InvImpl2a_state *state = vsta; + printf (" Z = %1lu\n", state->Z); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvImpl2a (int e, unsigned long a1, unsigned long a2, + unsigned long z0) +{ + unif01_Gen *gen; + InvImpl2a_param *param; + InvImpl2a_state *state; + size_t leng; + char name[LEN + 1]; + unsigned long M; + + if (((z0 % 2) == 0) || ((a2 % 2) == 0) || ((a1 % 2) != 0) || + (e < 3) || (e > 32)) + util_Error ("uinv_CreateInvImpl2a: Invalid parameter *"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvImpl2a_param)); + state = util_Malloc (sizeof (InvImpl2a_state)); + + if (e < 32) + M = num_TwoExp[e]; + if ((e <= 31) && ((z0 >= M) || (a1 >= M) || (a2 >= M))) + util_Error ("uinv_CreateInvImpl2a: Invalid parameter **"); + + strcpy (name, "uinv_CreateInvImpl2a:"); + addstr_Long (name, " e = ", e); + addstr_Ulong (name, ", a1 = ", a1); + addstr_Ulong (name, ", a2 = ", a2); + addstr_Ulong (name, ", z0 = ", z0); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Shift = 32 - e; + param->M = M; + param->A1 = a1; + param->A2 = a2; + state->Z = z0; + if (e < 32) + param->Mask = M - 1; + else + param->Mask = MASK32; + + if (e == 32) { + gen->GetBits = &InvImpl2a32_Bits; + gen->GetU01 = &InvImpl2a32_U01; + + } else if (e == 31) { + gen->GetBits = &InvImpl2a31_Bits; + gen->GetU01 = &InvImpl2a31_U01; + + } else { /* e <= 30 */ + gen->GetBits = &InvImpl2a_Bits; + gen->GetU01 = &InvImpl2a_U01; + } + gen->param = param; + gen->state = state; + gen->Write = &WrInvImpl2a; + return gen; +} + + +/**************************************************************************/ + +static unsigned long InvImpl2b_Bits (void *vpar, void *vsta) +{ + InvImpl2b_param *param = vpar; + InvImpl2b_state *state = vsta; + unsigned long div0; /* Greatest common divisor of Z and 2^e */ + unsigned long mod0; /* Remainder of division of Zc by div0 */ + + mod0 = state->Z % 2; + div0 = 1; + while ((mod0 == 0) && (state->Z != 0)) { + state->Z /= 2; + div0 *= 2; + mod0 = state->Z % 2; + } + /* Compute the next state */ + state->Z = param->A1 + div0 * param->A2 * + num_InvEuclid ((long) param->M, (long) state->Z); + state->Z &= param->Mask; + return state->Z << param->Shift; +} + +/*-------------------------------------------------------------------------*/ + +static double InvImpl2b_U01 (void *vpar, void *vsta) +{ + return InvImpl2b_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long InvImpl2b31_Bits (void *vpar, void *vsta) +{ + InvImpl2b_param *param = vpar; + InvImpl2b_state *state = vsta; + unsigned long div0; /* Greatest common divisor of Z and 2^e */ + unsigned long mod0; /* Remainder of division of Zc by div0 */ + + mod0 = state->Z % 2; + div0 = 1; + while ((mod0 == 0) && (state->Z != 0)) { + state->Z /= 2; + div0 *= 2; + mod0 = state->Z % 2; + } + /* Compute the next state */ + state->Z = param->A1 + div0 * param->A2 * num_InvExpon (31, state->Z); + state->Z &= MASK31; + return state->Z << 1; +} + +/*-------------------------------------------------------------------------*/ + +static double InvImpl2b31_U01 (void *vpar, void *vsta) +{ + return InvImpl2b31_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long InvImpl2b32_Bits (void *vpar, void *vsta) +{ + InvImpl2b_param *param = vpar; + InvImpl2b_state *state = vsta; + unsigned long div0; /* Greatest common divisor of Z and 2^e */ + unsigned long mod0; /* Remainder of division of Zc by div0 */ + + mod0 = state->Z % 2; + div0 = 1; + while ((mod0 == 0) && (state->Z != 0)) { + state->Z /= 2; + div0 *= 2; + mod0 = state->Z % 2; + } + /* Compute the next state */ + state->Z = param->A1 + div0 * param->A2 * num_InvExpon (32, state->Z); + state->Z &= MASK32; + return state->Z; + +} + +/*-------------------------------------------------------------------------*/ + +static double InvImpl2b32_U01 (void *vpar, void *vsta) +{ + return InvImpl2b32_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrInvImpl2b (void *vsta) +{ + InvImpl2b_state *state = vsta; + printf (" Z = %1lu\n", state->Z); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvImpl2b (int e, unsigned long a1, unsigned long a2, + unsigned long z0) +{ + unif01_Gen *gen; + InvImpl2b_param *param; + InvImpl2b_state *state; + size_t leng; + char name[LEN + 1]; + unsigned long M; + + M = num_TwoExp[e]; + + if ((((a1 >= M) || (a2 >= M) || (z0 >= M)) && (e < 32)) || + ((a1 % 2) != 1) || ((a2 % 2) != 1) || (e < 3) || (e > 32)) + util_Error ("uinv_CreateInvImpl2b: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvImpl2b_param)); + state = util_Malloc (sizeof (InvImpl2b_state)); + + strcpy (name, "uinv_CreateInvImpl2b:"); + addstr_Long (name, " e = ", e); + addstr_Ulong (name, ", a1 = ", a1); + addstr_Ulong (name, ", a2 = ", a2); + addstr_Ulong (name, ", z0 = ", z0); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Shift = 32 - e; + param->M = M; + param->A1 = a1; + param->A2 = a2; + state->Z = z0; + param->Mask = M - 1; + + if (e == 32) { + gen->GetBits = &InvImpl2b32_Bits; + gen->GetU01 = &InvImpl2b32_U01; + + } else if (e == 31) { + gen->GetBits = &InvImpl2b31_Bits; + gen->GetU01 = &InvImpl2b31_U01; + + } else { /* e <= 30 */ + gen->GetBits = &InvImpl2b_Bits; + gen->GetU01 = &InvImpl2b_U01; + } + gen->param = param; + gen->state = state; + gen->Write = &WrInvImpl2b; + return gen; +} + + +/**************************************************************************/ +/* + * Non-linear Generator with "explicit" inversion in the form + * Z = Xn^(-1) when Xn # 0 , else 0 and + * with Xn = a*n + c as mentionned in L'Ecuyer (1993). + * + * The values returned by the generator implemented below are + * in the following set: { 0/m, 1/m, 2/m, ..., (m-1)/m }. + */ + +static double InvExpl_U01 (void *vpar, void *vsta) +{ + InvExpl_param *param = vpar; + InvExpl_state *state = vsta; + + if (state->Z >= param->MmA) + state->Z -= param->M; + state->Z += param->A2; + + if (state->Z == 0) + return 0.0; + else + return (num_InvEuclid (param->M, state->Z) * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long InvExpl_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * InvExpl_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrInvExpl (void *vsta) +{ + InvExpl_state *state = vsta; + printf (" Z = %1ld\n", state->Z); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvExpl (long m, long a, long c) +{ + unif01_Gen *gen; + InvExpl_param *param; + InvExpl_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a <= 0) || (c < 0) || (a >= m) || (c >= m) || ((m % 2) == 0)) + util_Error ("uinv_CreateInvExpl: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvExpl_param)); + state = util_Malloc (sizeof (InvExpl_state)); + + strcpy (name, "uinv_CreateInvExpl:"); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->Z = c; + param->M = m; + param->A2 = a; + param->MmA = m - a; + param->Norm = 1.0 / m; + + gen->param = param; + gen->state = state; + gen->Write = &WrInvExpl; + gen->GetBits = &InvExpl_Bits; + gen->GetU01 = &InvExpl_U01; + + return gen; +} + + +/**************************************************************************/ + +static unsigned long InvExpl2a_Bits (void *vpar, void *vsta) +{ + InvExpl2a_param *param = vpar; + InvExpl2a_state *state = vsta; + + if (param->E < 31) { + state->Z += param->A2; + state->Z &= param->Mask; + if (state->Z == 0) + return 0; + else + return num_InvExpon (param->E, state->Z) << param->Shift; + + } else if (param->E == 31) { + state->Z += param->A2; + state->Z &= MASK31; + if (state->Z == 0) + return 0; + else + return num_InvExpon (31, state->Z) << 1; + + } else { /* param->E == 32 */ + state->Z += param->A2; + state->Z &= MASK32; + if (state->Z == 0) + return 0; + else + return num_InvExpon (32, state->Z); + } +} + +/*-------------------------------------------------------------------------*/ + +static double InvExpl2a_U01 (void *vpar, void *vsta) +{ + return InvExpl2a_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrInvExpl2a (void *vsta) +{ + InvExpl2a_state *state = vsta; + printf (" Z = %1lu\n", state->Z); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvExpl2a (int e, long a, long c) +{ + unif01_Gen *gen; + InvExpl2a_param *param; + InvExpl2a_state *state; + size_t leng; + char name[LEN + 1]; + unsigned long M; + + M = num_TwoExp[e]; + if ((a <= 0) || (c <= 0) || (a % 4 != 2) || (c % 2 != 1) || + ((((unsigned long) a >= M) || ((unsigned long) c >= M)) + && (e < 32)) || (e < 3) || (e > 32)) + util_Error ("uinv_CreateInvExpl2a: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvExpl2a_param)); + state = util_Malloc (sizeof (InvExpl2a_state)); + + state->Z = c; + param->A2 = a; + param->Mask = M - 1; + param->E = e; + param->Shift = 32 - e; + + strcpy (name, "uinv_CreateInvExpl2a:"); + addstr_Long (name, " e = ", e); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &InvExpl2a_Bits; + gen->GetU01 = &InvExpl2a_U01; + gen->param = param; + gen->state = state; + gen->Write = &WrInvExpl2a; + return gen; +} + + +/**************************************************************************/ + +static unsigned long InvExpl2b_Bits (void *vpar, void *vsta) +{ + InvExpl2b_param *param = vpar; + InvExpl2b_state *state = vsta; + unsigned long Z; + + state->N++; + if (param->E < 31) { + Z = state->N * num_InvExpon (param->E, + (param->A1 + param->A2 * state->N) & param->Mask); +#ifndef IS_ULONG32 + Z &= param->Mask; +#endif + return Z << param->Shift; + + } else if (param->E == 31) { + Z = state->N * num_InvExpon (31, + (param->A1 + param->A2 * state->N) & MASK31); +#ifndef IS_ULONG32 + Z &= MASK31; +#endif + return Z << 1; + + } else { /* E == 32 */ + Z = state->N * num_InvExpon (32, param->A1 + param->A2 * state->N); +#ifndef IS_ULONG32 + Z &= MASK32; +#endif + return Z; + } +} + +/*-------------------------------------------------------------------------*/ + +static double InvExpl2b_U01 (void *vpar, void *vsta) +{ + return InvExpl2b_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrInvExpl2b (void *vsta) +{ + InvExpl2b_state *state = vsta; + printf (" N = %1lu\n", state->N); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvExpl2b (int e, long a, long c) +{ + unif01_Gen *gen; + InvExpl2b_param *param; + InvExpl2b_state *state; + size_t leng; + char name[LEN + 1]; + unsigned long M; + + M = num_TwoExp[e]; + + if ((a <= 0) || (c <= 0) || (a % 4 != 2) || (c % 2 != 1) || + ((((unsigned long) a >= M) || ((unsigned long) c >= M)) + && (e < 32)) || (e < 3) || (e > 32)) + util_Error ("uinv_CreateInvExpl2b: parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvExpl2b_param)); + state = util_Malloc (sizeof (InvExpl2b_state)); + + strcpy (name, "uinv_CreateInvExpl2b:"); + addstr_Long (name, " e = ", e); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->A1 = c; + param->A2 = a; + param->E = e; + param->Shift = 32 - e; + param->Mask = M - 1; + state->N = 0; + + gen->GetBits = &InvExpl2b_Bits; + gen->GetU01 = &InvExpl2b_U01; + gen->param = param; + gen->state = state; + gen->Write = &WrInvExpl2b; + return gen; +} + + +/**************************************************************************/ +/* + * INVERSIVE Multiple recursive generator (MRG): Z = Xn^(-1) + * + * The values returned by the generator InvMRG are + * in the following set: { 1/(m+1), 2/(m+1), ... , m/(m+1) }. + */ + +static double InvMRG_U01 (void *vpar, void *vsta) +{ + InvMRG_param *param = vpar; + InvMRG_state *state = vsta; + int i; + long h, t, p = 0; + + for (i = state->Order; i > 0; i--) { + if (param->A[i] != 0) { + h = state->S[i] / param->Q[i]; + t = labs (param->A[i]) * (state->S[i] - h * param->Q[i]) - + h * param->R[i]; + if (t < 0) + t += param->M; + if (param->A[i] < 0) + p -= t; + else + p += (t - param->M); + if (p < 0) + p += param->M; + } + if (i > 1) + state->S[i] = state->S[i - 1]; + else + state->S[i] = p; + } + if (p == 0) + return param->M * param->Norm; + else + return num_InvEuclid (param->M, p) * param->Norm; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long InvMRG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * InvMRG_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrInvMRG (void *vsta) +{ + InvMRG_state *state = vsta; + int i; + + for (i = 1; i <= state->Order; i++) { + printf (" S[%1d] = %10ld ", i, state->S[i]); + if (i % 3 == 0) + printf ("\n"); + } + if ((state->Order % 3) != 0) + printf ("\n"); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvMRG (long m, int k, long A[], long S[]) +{ + unif01_Gen *gen; + InvMRG_param *param; + InvMRG_state *state; + size_t leng; + char name[LEN + 1]; + int i, n; + long *aa, *ss, *qq, *rr; + + if ((k < 2) || (m < 2) || (m % 2 == 0)) + util_Error ("uinv_CreateInvMRG: Invalid parameter *"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvMRG_param)); + state = util_Malloc (sizeof (InvMRG_state)); + + strcpy (name, "uinv_CreateInvMRG:"); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", k = ", k); + addstr_ArrayLong (name, ", A = ", k, A); + addstr_ArrayLong (name, ", S = ", k, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + aa = util_Calloc ((size_t) k + 1, sizeof (long)); + rr = util_Calloc ((size_t) k + 1, sizeof (long)); + qq = util_Calloc ((size_t) k + 1, sizeof (long)); + ss = util_Calloc ((size_t) k + 1, sizeof (long)); + + n = 0; + for (i = 1; i <= k; i++) { + aa[i] = A[i - 1]; + ss[i] = S[i - 1]; + if ((labs (aa[i]) >= m) || (ss[i] >= m) || (ss[i] < 0)) + util_Error ("uinv_CreateInvMRG: Invalid parameter **"); + if (aa[i] != 0) { + rr[i] = m % labs (aa[i]); + qq[i] = m / labs (aa[i]); + if (rr[i] > qq[i]) + util_Error ("uinv_CreateInvMRG: Invalid parameter ***"); + } + if (ss[i] != 0) + n++; + } + if (n == 0) + util_Error ("uinv_CreateInvMRG: Invalid parameter ****"); + + param->M = m; + param->Norm = 1.0 / (m + 1.0); + param->A = aa; + param->R = rr; + param->Q = qq; + state->Order = k; + state->S = ss; + + gen->param = param; + gen->state = state; + gen->GetBits = &InvMRG_Bits; + gen->GetU01 = &InvMRG_U01; + gen->Write = &WrInvMRG; + + return gen; +} + +/*-------------------------------------------------------------------------*/ + +void uinv_DeleteInvMRG (unif01_Gen * gen) +{ + InvMRG_param *param; + InvMRG_state *state; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + util_Free (state->S); + util_Free (param->A); + util_Free (param->Q); + util_Free (param->R); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +static double InvMRGFloat_U01 (void *vpar, void *vsta) +/* + * Generator InvMRG of order k. The implementation uses floating-point + * arithmetic. Similar to umrg_MultRecKFloat + */ +{ + InvMRGFloat_param *param = vpar; + InvMRGFloat_state *state = vsta; + long k; + int i; + double p = 0.0; + + p = 0.0; + for (i = state->Order; i > 0; i--) { + if (param->A[i] != 0.0) + p += param->A[i] * state->S[i]; + if (i > 1) + state->S[i] = state->S[i - 1]; + } + k = p / param->M; + if (p >= 0.0) + p -= k * param->M; /* p = sum ... % m */ + else + p += (1 - k) * param->M; + + k = state->S[1] = p; + if (k == 0) + return (param->M * param->Norm); + else + return (num_InvEuclid ((long) param->M, k) * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long InvMRGFloat_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * InvMRGFloat_U01 (vpar, vsta)); +} + +/*------------------------------------------------------------------------*/ + +static void WrInvMRGFloat (void *vsta) +{ + InvMRGFloat_state *state = vsta; + int i; + + for (i = 1; i <= state->Order; i++) { + printf (" S[%1d] = %10ld ", i, (long) state->S[i]); + if ((i % 3) == 0) + printf ("\n"); + } + if (state->Order % 3 != 0) + printf ("\n"); +} + +/*------------------------------------------------------------------------*/ + +unif01_Gen *uinv_CreateInvMRGFloat (long m, int k, long A[], long S[]) +{ + unif01_Gen *gen; + InvMRGFloat_param *param; + InvMRGFloat_state *state; + size_t leng; + char name[LEN + 1]; + int i; + unsigned int n; + double pr1, pr2; + double *ar, *sr; + + if ((k < 2) || (m < 2) || (m % 2 == 0)) + util_Error + ("uinv.CreateInvMRGFloat: k or m invalid"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (InvMRGFloat_param)); + state = util_Malloc (sizeof (InvMRGFloat_state)); + + ar = util_Calloc ((size_t) k + 1, sizeof (double)); + sr = util_Calloc ((size_t) k + 1, sizeof (double)); + + n = 0; + pr2 = pr1 = 0.0; + for (i = 1; i <= k; i++) { + ar[i] = A[i - 1]; + sr[i] = S[i - 1]; + if ((A[i - 1] >= m) || (-A[i - 1] >= m)) + util_Error ("uinv.CreateInvMRGFloat: |a_i| >= m"); + else if ((S[i - 1] >= m) || (S[i - 1] < 0)) + util_Error ("uinv.CreateInvMRGFloat: S_i >= m or S_i < 0"); + else if (A[i - 1] < 0) + pr2 -= ar[i]; + else + pr1 += ar[i]; + + if (S[i - 1] != 0) + n++; + } + if (n == 0) + util_Error ("uinv.CreateInvMRGFloat: all S[i] = 0"); + if ((pr1 * m >= num_TwoExp[53]) || (pr2 * m >= num_TwoExp[53])) + util_Error ("uinv.CreateInvMRGFloat: invalid a_i"); + + strcpy (name, "uinv_CreateInvMRGFloat:"); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", k = ", k); + addstr_ArrayLong (name, ", A = ", k, A); + addstr_ArrayLong (name, ", S = ", k, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->M = m; + param->Norm = 1.0 / (m + 1.0); + param->A = ar; + state->Order = k; + state->S = sr; + + gen->param = param; + gen->state = state; + gen->GetBits = &InvMRGFloat_Bits; + gen->GetU01 = &InvMRGFloat_U01; + gen->Write = &WrInvMRGFloat; + + return gen; +} + +/*------------------------------------------------------------------------*/ + +void uinv_DeleteInvMRGFloat (unif01_Gen * gen) +{ + InvMRGFloat_param *param; + InvMRGFloat_state *state; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + util_Free (state->S); + util_Free (param->A); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/***************************************************************************/ + +void uinv_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} + diff --git a/TESTU01/TestU01-1.2.3/testu01/uinv.tex b/TESTU01/TestU01-1.2.3/testu01/uinv.tex new file mode 100644 index 0000000..6cb83de --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uinv.tex @@ -0,0 +1,181 @@ +\defmodule {uinv} + +This module implements different types of inversive generators. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* uinv.h for ANSI C */ +#ifndef UINV_H +#define UINV_H +\endhide +#include "unif01.h" + + +unif01_Gen * uinv_CreateInvImpl (long m, long a1, long a2, long z0); +\endcode + \tab Implements a nonlinear inversive generator as + defined in \cite{rEIC92c} and \cite[p.93]{rLEC90a}, with + \begin{eqnarray*} + z_n &=& \left\{ \begin{array}{ll} + (a_1 + a_2\cdot z_{n-1}^{-1})\bmod m & \mbox{if $z_{n-1}\not=0$}\\[6pt] + a_1 & \mbox{if $z_{n-1} = 0$} + \end{array} \right.\\ + u_n &=& z_n / m. + \end{eqnarray*} + The generator computes $z_{n-1}^{-1}$ via the modified +\index{Generator!inversive}% + Euclid algorithm (see \cite{rKNU81a} p.~325). + If $m$ is prime and if $p(x) = x^2 - a_1 x - a_2$ is a + primitive polynomial modulo $m$, then the generator has + maximal period $m$. + Restrictions: $0 \le z_0 < m$, + $0 < a_1 < m$ and $0 < a_2 < m$. Furthermore, $m$ must be a prime + number, preferably large. %, but inferior to $2^{31}$. + \endtab +\code + + +unif01_Gen * uinv_CreateInvImpl2a (int e, unsigned long a1, + unsigned long a2, unsigned long z0); +\endcode + \tab Implements a nonlinear inversive generator similar to + {\tt uinv\_CreateInvImpl}, but with $m = 2^e$ + (see \cite{rEIC92c} p.~172). + The domain is limited to odd positive integers since + the inverse modulo $2^e$ of a given $x$ exists only if $x$ is odd. + For $e = 31$ or $32$, the generator computes + the inverse by exponentiation according to the formula: + $x^{-1} = x^{m-1} = x^{(m \div 4) - 1}$. + For $e \le 30$, the inverse is computed via the modified + Euclid algorithm (faster than exponentiation, + but our implementation of it is only valid in the domain + of {\tt long}, i.e. if $m \le 2^{31}-1$). + If $e\ge 3$ and if $a_2-1$ and $a_1-2$ are multiples of 4, + then the period is maximal and equal to $m/2$. + \emph{Restrictions}: $3 \le e \le 32$; $z_0$, $a_1$ and $a_2$ less than + $m$; $z_0$ and $a_2$ must be odd and $a_1$ must be even. + \endtab +\code + + +unif01_Gen * uinv_CreateInvImpl2b (int e, unsigned long a1, + unsigned long a2, unsigned long z0); +\endcode + \tab Implements a nonlinear inversive generator with $m = 2^e$ + as described in \cite{rEIC92d}. + The recurrence is: + $$ z_n = T(z_{n-1}) $$ + where + $$ T(2^\ell z) = (a_1 + 2^\ell a_2 z^{-1}) \mod 2^e $$ + whenever $z$ is odd. + For $e = 31$ or $32$, the inverse is computed by exponentiation + according to the formula: + $x^{-1} = x^{m-1} = x^{(m \div 4) - 1}$. + For $e\ge 3$, if $a_2-1$ is a multiple of 4 and if $a_1$ is odd, + then the period is maximal and equal to $m$. + \emph{Restrictions}: $3 \le e \le 32$; $z_0$, $a_1$ and $a_2$ less than + $m$ and odd. + \endtab +\code + + +unif01_Gen * uinv_CreateInvExpl (long m, long a, long c); +\endcode + \tab Implements an {\em explicit\/} nonlinear inversive generator, + as described in \cite{rEIC93a} and + \cite{rLEC94a} (Section 10.2), with + \[ z_n = \left\{ + \begin{array}{ll} + x_n^{-1} & \mbox{si $x_n\not=0$}\\[6pt] + 0 & \mbox{si $x_n = 0$} + \end{array} \right. \] + where $x_n = (an+c) \mod m$ for $n \ge 0$. + The generator computes + $x_n^{-1}$ by the modified Euclid algorithm (see \cite{rKNU81a} + p.~325). The initial state of the generator, $x_0$, is given by + $c$. \emph{Restrictions}: $0 < a < m$, $0 \le c < m$ and $m$ must be a prime + number. In this case, the period has length $m$. + \endtab +\code + + +unif01_Gen * uinv_CreateInvExpl2a (int e, long a, long c); +\endcode + \tab Implements an {\em explicit\/} nonlinear inversive generator, + similar to {\tt uinv\_CreateInvExpl}, but with + $m = 2^e$, as described in \cite{rEIC94b}. + \emph{Restrictions}: $3 \le e \le 32$; $a$ and $c$ less than $m$, + $a-2$ multiple of 4 and $c$ odd. + \endtab +\code + + +unif01_Gen * uinv_CreateInvExpl2b (int e, long a, long c); +\endcode + \tab Implements an {\em explicit modified\/} + nonlinear inversive generator, with $m = 2^e$, as proposed + in \cite{rEIC95d}. The recurrence has the form + $$ x_n = n(an + c)^{-1} \mod 2^e; \qquad u_n = x_n 2^{-e}. $$ + \emph{Restrictions}: $3 \le e \le 32$, $a < m$, $c < m$, + $a-2$ multiple of 4, and $c$ odd. + With these restrictions, the period is equal to $m$. + \endtab +\code + + +unif01_Gen * uinv_CreateInvMRG (long m, int k, long A[], long S[]); +\endcode + \tab Implements an inversive multiple recursive generator (MRG), + based on the recurrence + $$ x_n = (a_1 x_{n-1} + \cdots + a_k x_{n-k}) \mod m $$ + as in {\tt umrg\_CreateMRG}, except that the output $u_n$ is + constructed using $x_n^{-1} \mod m$ instead of $x_n$. + \emph{Restrictions}: The same restrictions as for {\tt umrg\_CreateMRG} + apply here and $m$ must be a prime number. + \endtab +\code + + +unif01_Gen * uinv_CreateInvMRGFloat (long m, int k, long A[], long S[]); +\endcode + \tab Provides a floating-point implementation of the same generator + as in {\tt uinv\_CreateInvMRG}. + The implementation is similar to that in {\tt umrg\_CreateMRGFloat}. + \emph{Restrictions}: The same restrictions apply here as for + {\tt umrg\_CreateMRGFloat} and $m$ must be a prime number. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Clean-up functions} +\code + +void uinv_DeleteInvMRG (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory allocated by + {\tt uinv\_CreateInvMRG}. + \endtab +\code + + +void uinv_DeleteInvMRGFloat (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory allocated by + {\tt uinv\_CreateInvMRGFloat}. + \endtab +\code + + +void uinv_DeleteGen (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory allocated by the other {\tt Create} + functions of this module. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/uknuth.c b/TESTU01/TestU01-1.2.3/testu01/uknuth.c new file mode 100644 index 0000000..74c119c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uknuth.c @@ -0,0 +1,809 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uknuth.c + * Environment: ANSI C + * Programmer: Richard Simard. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" + +#include "uknuth.h" +#include "unif01.h" + +#include +#include + + +#define LEN 200 /* Max length of strings */ + + +static int co1 = 0, co2 = 0, co3 = 0, co4 = 0; /* Counters */ + + +/*========================= WARNING: + +I HAVE CHANGED Knuth's code for the following version of rng.c. Thus it is +NOT Knuth's original code. I have renamed the variables because those of the +new version have the same name as those of the old version and we include +both versions in our file. (R. Simard) + +===========================*/ + + +/* This program is copyright (c) 2000 by D E Knuth; + * you may copy it freely AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES! + * You could also change it, but then you must rename the file and + * tell people clearly that your version is not the same as mine. + * It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6 + * (or in the errata to the 2nd edition --- see + * http://www-cs-faculty.stanford.edu/~knuth/taocp.html + * in the changes to pages 171 and following of Volume 2). */ + +/* If you find any bugs, please report them immediately to + * taocp@cs.stanford.edu + * (and you will be rewarded if the bug is genuine). Thanks! */ + +/************ see the book for explanations and caveats! *******************/ +/************ in particular, you need two's complement arithmetic **********/ + +/* old-style C function declarations appear here for reasons of portability */ + +#define KK 100 /* the long lag */ +#define LL 37 /* the short lag */ +#define MM (1L<<30) /* the modulus */ +#define mod_diff(x,y) (((x)-(y))&(MM-1)) /* subtraction mod MM */ + +long ran_x1[KK]; /* the generator state */ + +/* void ran_array(long aa[],int n) */ +void ran_array1(aa,n) /* put n new random numbers in aa */ + long *aa; /* destination */ + int n; /* array length (must be at least KK) */ +{ + register int i,j; + for (j=0;j=MM) ss-=MM-2; /* cyclic shift 29 bits */ + } + for (;j0;j--) x[j+j]=x[j]; /* "square" */ + for (j=KK+KK-2;j>KK-LL;j-=2) x[KK+KK-1-j]=evenize(x[j]); + for (j=KK+KK-2;j>=KK;j--) if(is_odd(x[j])) { + x[j-(KK-LL)]=mod_diff(x[j-(KK-LL)],x[j]); + x[j-KK]=mod_diff(x[j-KK],x[j]); + } + if (is_odd(ss)) { /* "multiply by z" */ + for (j=KK;j>0;j--) x[j]=x[j-1]; + x[0]=x[KK]; /* shift the buffer cyclically */ + if (is_odd(x[KK])) x[LL]=mod_diff(x[LL],x[KK]); + } + if (ss) ss>>=1; else t--; + } + for (j=0;j=0? *ran_arr_ptr1++: ran_arr_cycle1()) +long ran_arr_cycle1() +{ + ran_array1(ran_arr_buf1,QUALITY); + ran_arr_buf1[100]=-1; + ran_arr_ptr1=ran_arr_buf1+1; + return ran_arr_buf1[0]; +} + + +/*-----------------------------------------------------------------------*/ + +static unsigned long Ran_array1_Bits (void *junk1, void *junk2) +{ + return ran_arr_next1 () << 2; +} + +/*-----------------------------------------------------------------------*/ + +static double Ran_array1_U01 (void *vpar, void *vsta) +{ + return Ran_array1_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrRan_array1 (void *junk) +{ + int j; + if (unif01_WrLongStateFlag) { + printf ("ran_x1 = {\n "); + for (j = 0; j < KK; j++) { + printf ("%12ld", ran_x1[j]); + if (j < KK - 1) + printf (", "); + if ((j % 5) == 4) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *uknuth_CreateRan_array1 (long s, long A[]) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + int j; + + util_Assert (s <= 1073741821, + "uknuth_CreateRan_array1: s must be <= 1073741821"); + util_Assert (co1 == 0, + "uknuth_CreateRan_array1:\n only 1 such generator can be in use at a time"); + co1++; + + gen = util_Malloc (sizeof (unif01_Gen)); + strcpy (name, "uknuth_CreateRan_array1:"); + + if (s < 0) { + /* Restart with the last state A[] obtained from a previous run */ + addstr_ArrayLong (name, " A = ", KK, A); + for (j = 0; j < KK; j++) + ran_x1[j] = A[j]; + *ran_arr_ptr1 = ran_arr_sentinel1; + } else { + /* initialize by Knuth ran_start */ + addstr_Long (name, " s = ", s); + ran_start1 (s); + } + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &Ran_array1_Bits; + gen->GetU01 = &Ran_array1_U01; + gen->Write = &WrRan_array1; + gen->param = NULL; + gen->state = NULL; + return gen; +} + + +#undef is_odd + +/*=========================================================================*/ + +/*========================= WARNING: + +I HAVE CHANGED Knuth's code for the following version of rng-double.c. Thus +it is NOT Knuth's original code. I have renamed the variables because those +of the new version have the same name as those of the old version and we +include both versions in our file. (R. Simard) + +===========================*/ + + +/***************************** Knuth's code ********************************/ + +/* This program is copyright (c) 2000 by D E Knuth; + * you may copy it freely AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES! + * You could also change it, but then you must rename the file and + * tell people clearly that your version is not the same as mine. + * It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6 + * (or in the errata to the 2nd edition --- see + * http://www-cs-faculty.stanford.edu/~knuth/taocp.html + * in the changes to pages 171 and following of Volume 2). */ + +/* If you find any bugs, please report them immediately to + * taocp@cs.stanford.edu + * (and you will be rewarded if the bug is genuine). Thanks! */ + +/************ see the book for explanations and caveats! *******************/ +/************ in particular, you need two's complement arithmetic **********/ + +/* old-style C function declarations appear here for reasons of portability */ + +#define KK 100 /* the long lag */ +#define LL 37 /* the short lag */ +#define mod_sum(x,y) (((x)+(y))-(int)((x)+(y))) /* (x+y) mod 1.0 */ + +double ran_u1[KK]; /* the generator state */ + +/* void ranf_array1(double aa[], int n) */ +void ranf_array1(aa,n) /* put n new random fractions in aa */ + double *aa; /* destination */ + int n; /* array length (must be at least KK) */ +{ + register int i,j; + for (j=0;j=1.0) ss-=1.0-2*ulp; /* cyclic shift of 51 bits */ + } + for (;j0;j--) ul[j+j]=ul[j],u[j+j]=u[j]; /* "square" */ + for (j=KK+KK-2;j>KK-LL;j-=2) + ul[KK+KK-1-j]=0.0,u[KK+KK-1-j]=u[j]-ul[j]; + for (j=KK+KK-2;j>=KK;j--) if(ul[j]) { + ul[j-(KK-LL)]=ulp-ul[j-(KK-LL)], + u[j-(KK-LL)]=mod_sum(u[j-(KK-LL)],u[j]); + ul[j-KK]=ulp-ul[j-KK],u[j-KK]=mod_sum(u[j-KK],u[j]); + } + if (is_odd(s)) { /* "multiply by z" */ + for (j=KK;j>0;j--) ul[j]=ul[j-1],u[j]=u[j-1]; + ul[0]=ul[KK],u[0]=u[KK]; /* shift the buffer cyclically */ + if (ul[KK]) ul[LL]=ulp-ul[LL],u[LL]=mod_sum(u[LL],u[KK]); + } + if (s) s>>=1; else t--; + } + for (j=0;j=0? *ranf_arr_ptr1++: ranf_arr_cycle1()) +double ranf_arr_cycle1() +{ + ranf_array1(ranf_arr_buf1,QUALITY); + ranf_arr_buf1[100]=-1; + ranf_arr_ptr1=ranf_arr_buf1+1; + return ranf_arr_buf1[0]; +} + + +/* ========================= end of Knuth's code ========================= */ + + + +/*------------------------------- Our code --------------------------------*/ + +static double Ranf_array1_U01 (void *junk1, void *junk2) +{ + return ranf_arr_next1 (); +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long Ranf_array1_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (Ranf_array1_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrRanf_array1 (void *junk) +{ + int j; + if (unif01_WrLongStateFlag) { + printf ("ran_u1 = {\n"); + for (j = 0; j < KK; j++) { + printf (" %22.16f", ran_u1[j]); + if (j < KK - 1) + printf (","); + if ((j % 3) == 2) + printf ("\n"); + }; + printf ("\n }"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uknuth_CreateRanf_array1 (long s, double B[]) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + int j; + + util_Assert (s <= 1073741821, + "uknuth_CreateRanf_array1: s must be <= 1073741821"); + util_Assert (co2 == 0, + "uknuth_CreateRanf_array1:\n only 1 such generator can be in use at a time"); + co2++; + + gen = util_Malloc (sizeof (unif01_Gen)); + strcpy (name, "uknuth_CreateRanf_array1:"); + + if (s < 0) { + /* Restart with the last state B[] obtained from a previous run */ + addstr_ArrayDouble (name, " A = ", KK, B); + for (j = 0; j < KK; j++) + ran_u1[j] = B[j]; + *ranf_arr_ptr1 = ranf_arr_sentinel1; + } else { + /* initialize by Knuth ranf_start */ + addstr_Long (name, " s = ", s); + ranf_start1 (s); + } + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &Ranf_array1_Bits; + gen->GetU01 = &Ranf_array1_U01; + gen->Write = &WrRanf_array1; + gen->param = NULL; + gen->state = NULL; + return gen; +} + +#undef is_odd + + + +/*=========================================================================*/ + +/*========================= WARNING: + I have not made any change in the following version of Knuth's rng.c + (R. Simard) +===========================*/ + + + +/***************************** Knuth's code ********************************/ + +/* This program by D E Knuth is in the public domain and freely copyable + * AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES! + * It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6 + * (or in the errata to the 2nd edition --- see + * http://www-cs-faculty.stanford.edu/~knuth/taocp.html + * in the changes to Volume 2 on pages 171 and following). */ + +/* N.B. The MODIFICATIONS introduced in the 9th printing (2002) are + included here; there's no backwards compatibility with the original. */ + +/* If you find any bugs, please report them immediately to + * taocp@cs.stanford.edu + * (and you will be rewarded if the bug is genuine). Thanks! */ + +/************ see the book for explanations and caveats! *******************/ +/************ in particular, you need two's complement arithmetic **********/ + +#define KK 100 /* the long lag */ +#define LL 37 /* the short lag */ +#define MM (1L<<30) /* the modulus */ +#define mod_diff(x,y) (((x)-(y))&(MM-1)) /* subtraction mod MM */ + +long ran_x[KK]; /* the generator state */ + +#ifdef __STDC__ +void ran_array(long aa[],int n) +#else +void ran_array(aa,n) /* put n new random numbers in aa */ + long *aa; /* destination */ + int n; /* array length (must be at least KK) */ +#endif +{ + register int i,j; + for (j=0;j=0? *ran_arr_ptr++: ran_arr_cycle()) +long ran_arr_cycle() +{ + ran_array(ran_arr_buf,QUALITY); + ran_arr_buf[100]=-1; + ran_arr_ptr=ran_arr_buf+1; + return ran_arr_buf[0]; +} + +#define TT 70 /* guaranteed separation between streams */ +#define is_odd(x) ((x)&1) /* units bit of x */ + +#ifdef __STDC__ +void ran_start(long seed) +#else +void ran_start(seed) /* do this before using ran_array */ + long seed; /* selector for different streams */ +#endif +{ + register int t,j; + long x[KK+KK-1]; /* the preparation buffer */ + register long ss=(seed+2)&(MM-2); + for (j=0;j=MM) ss-=MM-2; /* cyclic shift 29 bits */ + } + x[1]++; /* make x[1] (and only x[1]) odd */ + for (ss=seed&(MM-1),t=TT-1; t; ) { + for (j=KK-1;j>0;j--) x[j+j]=x[j], x[j+j-1]=0; /* "square" */ + for (j=KK+KK-2;j>=KK;j--) + x[j-(KK-LL)]=mod_diff(x[j-(KK-LL)],x[j]), + x[j-KK]=mod_diff(x[j-KK],x[j]); + if (is_odd(ss)) { /* "multiply by z" */ + for (j=KK;j>0;j--) x[j]=x[j-1]; + x[0]=x[KK]; /* shift the buffer cyclically */ + x[LL]=mod_diff(x[LL],x[KK]); + } + if (ss) ss>>=1; else t--; + } + for (j=0;j=0? *ranf_arr_ptr++: ranf_arr_cycle()) +double ranf_arr_cycle() +{ + ranf_array(ranf_arr_buf,QUALITY); + ranf_arr_buf[100]=-1; + ranf_arr_ptr=ranf_arr_buf+1; + return ranf_arr_buf[0]; +} + +#define TT 70 /* guaranteed separation between streams */ +#define is_odd(s) ((s)&1) + +#ifdef __STDC__ +void ranf_start(long seed) +#else +void ranf_start(seed) /* do this before using ranf_array */ + long seed; /* selector for different streams */ +#endif +{ + register int t,s,j; + double u[KK+KK-1]; + double ulp=(1.0/(1L<<30))/(1L<<22); /* 2 to the -52 */ + double ss=2.0*ulp*((seed&0x3fffffff)+2); + + for (j=0;j=1.0) ss-=1.0-2*ulp; /* cyclic shift of 51 bits */ + } + u[1]+=ulp; /* make u[1] (and only u[1]) "odd" */ + for (s=seed&0x3fffffff,t=TT-1; t; ) { + for (j=KK-1;j>0;j--) + u[j+j]=u[j],u[j+j-1]=0.0; /* "square" */ + for (j=KK+KK-2;j>=KK;j--) { + u[j-(KK-LL)]=mod_sum(u[j-(KK-LL)],u[j]); + u[j-KK]=mod_sum(u[j-KK],u[j]); + } + if (is_odd(s)) { /* "multiply by z" */ + for (j=KK;j>0;j--) u[j]=u[j-1]; + u[0]=u[KK]; /* shift the buffer cyclically */ + u[LL]=mod_sum(u[LL],u[KK]); + } + if (s) s>>=1; else t--; + } + for (j=0;j +#include +#include + +#ifdef USE_GMP +#include +#endif + + +/*============================== constants ================================*/ + +#define LEN 300 /* Max length of strings */ + +#define DeuxExp32m1 4294967295UL /* 2^32 - 1 */ +#define DeuxExp31m1 2147483647 /* 2^31 - 1 */ +#define UnSur2e31m1 4.656612875245797E-10 /* 1 / (2^31 - 1) */ +#define DeuxExp53 9007199254740992.0 /* 2^53 */ +#define DeuxExp48 281474976710656ULL /* 2^48 */ +#define MASK32 0xffffffffUL /* 2^32 - 1 */ +#define MASK31 0x7fffffffUL /* 2^31 - 1 */ + + + + +/*================================= Types =================================*/ + +typedef struct { + long M, A, C, q, r; + double Norm; +} LCG_param; + +typedef struct { + long S; +} LCG_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double M, A, C; + double Norm; +} LCGFloat_param; + +typedef struct { + double S; +} LCGFloat_state; + +/*-------------------------------------------------------------------------*/ +#ifdef USE_GMP + +typedef struct { + mpz_t M, A, C; + mpq_t U; /* U = S / M */ + int cflag; /* cflag = 0 means C = 0 */ +} BigLCG_param; + +typedef struct { + mpz_t S; +} BigLCG_state; + +#endif +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long A, C, Mask, Shift; +} Pow2LCG_param; + +typedef struct { + unsigned long S; +} Pow2LCG_state; + +/*-------------------------------------------------------------------------*/ +#ifdef USE_GMP + +typedef struct { + mpz_t M, A, C; + mpq_t U; /* U = S / M */ + unsigned long E; /* M = 2^E */ + int cflag; /* cflag = 0 means C = 0 */ +} BigPow2LCG_param; + +typedef struct { + mpz_t S; +} BigPow2LCG_state; + +#endif +/*-------------------------------------------------------------------------*/ + +typedef Pow2LCG_param LCG2e31_param; +typedef Pow2LCG_state LCG2e31_state; + +typedef Pow2LCG_param LCG2e32_param; +typedef Pow2LCG_state LCG2e32_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long ahi, alo, Dalo; +} LCG2e31m1HD_param; + +typedef struct { + unsigned long S; +} LCG2e31m1HD_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long a, c; +} LCGPayne_param; + +typedef struct { + unsigned long S; +} LCGPayne_state; + +/*-------------------------------------------------------------------------*/ + +#ifdef USE_LONGLONG + +typedef struct { + ulonglong A, C; + ulonglong Mask, Shift; +} Pow2LCGL_param; + +typedef struct { + ulonglong S; +} Pow2LCGL_state; + +typedef Pow2LCGL_param LCG2e48L_param; +typedef Pow2LCGL_state LCG2e48L_state; + +#endif + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long M, H, Q, R, mask1, mask2, emq, emr; + double norm; +} Wu2_param; + +typedef struct { + unsigned long S; +} Wu2_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long A1, A2, C1, C2, M1, M2, M1m1, q1, q2, r1, r2; + double Norm; +} CombLEC2_param; + +typedef struct { + long S1, S2; +} CombLEC2_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double A1, A2, C1, C2, M1, M2, M1m1; + double Norm; +} CombLEC2Float_param; + +typedef struct { + double S1, S2; +} CombLEC2Float_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long A1, A2, A3, C1, C2, C3, M1, M2, M3, M1m1, M1mM3; + long q1, q2, q3, r1, r2, r3; + double Norm; +} CombLEC3_param; + +typedef struct { + long S1, S2, S3; +} CombLEC3_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long A1, A2, C1, C2, M1, M2, q1, q2, r1, r2; + double Norm1, Norm2; +} CombWH2_param; + +typedef struct { + long S1, S2; +} CombWH2_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double A1, A2, C1, C2, M1, M2; + double Norm1, Norm2; +} CombWH2Float_param; + +typedef struct { + double S1, S2; +} CombWH2Float_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long A1, A2, A3, C1, C2, C3, M1, M2, M3, q1, q2, q3, r1, r2, r3; + double Norm1, Norm2, Norm3; +} CombWH3_param; + +typedef struct { + long S1, S2, S3; +} CombWH3_state; + + + + + + + +/*============================ fonctions ===================================*/ + +static double SmallLCG_U01 (void *vpar, void *vsta) +/* + * Implementation used when (a*(m-1) + c) holds in a long int + */ +{ + LCG_param *param = vpar; + LCG_state *state = vsta; + + state->S = (param->A * state->S + param->C) % param->M; + return (state->S * param->Norm); +} + +static double MediumLCG_U01 (void *vpar, void *vsta) +/* + * Implementation used when a * (m % a) < m and c != 0 + */ +{ + LCG_param *param = vpar; + LCG_state *state = vsta; + long k; + + k = state->S / param->q; + state->S = param->A * (state->S - k * param->q) - k * param->r; + if (state->S < 0) + state->S += param->C; + else + state->S = (state->S - param->M) + param->C; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +static double MediumMLCG_U01 (void *vpar, void *vsta) +/* + * Implementation used when a * (m % a) < m and c = 0 + */ +{ + LCG_param *param = vpar; + LCG_state *state = vsta; + long k; + + k = state->S / param->q; + state->S = param->A * (state->S - k * param->q) - k * param->r; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +static double LargeLCG_U01 (void *vpar, void *vsta) +/* + * Implementation used when none of the three above (SmallLCG, MediumMLCG, + * MediumLCG) can be used + */ +{ + LCG_param *param = vpar; + LCG_state *state = vsta; + + state->S = num_MultModL (param->A, state->S, param->C, param->M); + return (state->S * param->Norm); +} + + +static unsigned long SmallLCG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SmallLCG_U01 (vpar, vsta)); +} + +static unsigned long MediumLCG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumLCG_U01 (vpar, vsta)); +} + +static unsigned long MediumMLCG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumMLCG_U01 (vpar, vsta)); +} + +static unsigned long LargeLCG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LargeLCG_U01 (vpar, vsta)); +} + +static void WrLCG (void *vsta) +{ + LCG_state *state = vsta; + printf (" s = %ld\n", state->S); +} + + +unif01_Gen *ulcg_CreateLCG (long m, long a, long c, long s) +{ + unif01_Gen *gen; + LCG_param *param; + LCG_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a < 0) || (c < 0) || (s < 0) || (a >= m) || (c >= m) || + (s >= m) || (m <= 0)) + util_Error ("ulcg_CreateLCG: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LCG_param)); + state = util_Malloc (sizeof (LCG_state)); + + strncpy (name, "ulcg_CreateLCG:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Norm = 1.0 / m; + param->M = m; + param->A = a; + param->C = c; + state->S = s; + + gen->param = param; + gen->state = state; + gen->Write = &WrLCG; + + if (m - 1 <= (LONG_MAX - c) / a) { + gen->GetBits = &SmallLCG_Bits; + gen->GetU01 = &SmallLCG_U01; + } else { + param->q = m / a; + param->r = m % a; + if (param->r <= param->q) { + if (c != 0) { + gen->GetBits = &MediumLCG_Bits; + gen->GetU01 = &MediumLCG_U01; + } else { + gen->GetBits = &MediumMLCG_Bits; + gen->GetU01 = &MediumMLCG_U01; + } + } else { + gen->GetBits = &LargeLCG_Bits; + gen->GetU01 = &LargeLCG_U01; + } + } + return gen; +} + + +/**************************************************************************/ +#ifdef USE_GMP + +static double BigLCG_U01 (void *vpar, void *vsta) +{ + BigLCG_param *param = vpar; + BigLCG_state *state = vsta; + + mpz_mul (state->S, param->A, state->S); /* S = A * S */ + if (param->cflag) + mpz_add (state->S, state->S, param->C); /* S = S + C */ + mpz_mod (state->S, state->S, param->M); /* S = S % M */ + mpq_set_num (param->U, state->S); /* Numerator of U */ + mpq_set_den (param->U, param->M); /* Denominator of U */ + return mpq_get_d (param->U); /* U = S / M */ +} + +static unsigned long BigLCG_Bits (void *vpar, void *vsta) +{ + return BigLCG_U01 (vpar, vsta) * unif01_NORM32; +} + +static void WrBigLCG (void *vsta) +{ + BigLCG_state *state = vsta; + printf (" s = "); + mpz_out_str (NULL, 10, state->S); + printf ("\n"); +} + +unif01_Gen *ulcg_CreateBigLCG (char *m, char *a, char *c, char *s) +{ + unif01_Gen *gen; + BigLCG_param *param; + BigLCG_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (BigLCG_param)); + state = util_Malloc (sizeof (BigLCG_state)); + + strncpy (name, "ulcg_CreateBigLCG:", (size_t) LEN); + leng = 36 + strlen (name) + strlen (m) + strlen (a) + strlen (c) + + strlen (s); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncat (gen->name, name, leng); + strcat (gen->name, " m = "); + strcat (gen->name, m); + strcat (gen->name, ", a = "); + strcat (gen->name, a); + strcat (gen->name, ", c = "); + strcat (gen->name, c); + strcat (gen->name, ", s = "); + strcat (gen->name, s); + + mpz_init (state->S); + if (mpz_set_str (state->S, s, 10)) + util_Error ("ulcg_CreateBigLCG: s is not a valid decimal number"); + if (mpz_sgn (state->S) < 0) + util_Error ("ulcg_CreateBigLCG: s < 0"); + + mpz_init (param->M); + if (mpz_set_str (param->M, m, 10)) + util_Error ("ulcg_CreateBigLCG: m is not a valid decimal number"); + + mpz_init (param->A); + if (mpz_set_str (param->A, a, 10)) + util_Error ("ulcg_CreateBigLCG: a is not a valid decimal number"); + if (mpz_sgn (param->A) < 0) + util_Error ("ulcg_CreateBigLCG: a < 0"); + + /* Checks if c = 0 */ + if (strcmp (c, "0") == 0) + param->cflag = 0; + else { + param->cflag = 1; + mpz_init (param->C); + if (mpz_set_str (param->C, c, 10)) + util_Error ("ulcg_CreateBigLCG: c is not a valid decimal number"); + if (mpz_sgn (param->C) < 0) + util_Error ("ulcg_CreateBigLCG: c < 0"); + } + + mpq_init (param->U); + + gen->param = param; + gen->state = state; + gen->Write = &WrBigLCG; + gen->GetBits = &BigLCG_Bits; + gen->GetU01 = &BigLCG_U01; + return gen; +} + +void ulcg_DeleteBigLCG (unif01_Gen * gen) +{ + BigLCG_param *param; + BigLCG_state *state; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + mpz_clear (state->S); + mpz_clear (param->M); + mpz_clear (param->A); + if (param->cflag) + mpz_clear (param->C); + mpq_clear (param->U); + unif01_DeleteGen (gen); +} + +#endif +/**************************************************************************/ + +static double LCGFloat_U01 (void *vpar, void *vsta) +{ + LCGFloat_param *param = vpar; + LCGFloat_state *state = vsta; + long k; + + state->S = param->A * state->S + param->C; + k = state->S / param->M; + state->S -= k * param->M; + return (state->S * param->Norm); +} + +static double LCGFloatNeg_U01 (void *vpar, void *vsta) +/* + * When a < 0 and c = 0. + */ +{ + LCGFloat_param *param = vpar; + LCGFloat_state *state = vsta; + long k; + + state->S = param->A * state->S; + k = state->S / param->M; + state->S += (1 - k) * param->M; + return (state->S * param->Norm); +} + +static unsigned long LCGFloat_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LCGFloat_U01 (vpar, vsta)); +} + +static unsigned long LCGFloatNeg_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LCGFloatNeg_U01 (vpar, vsta)); +} + + +static void WrLCGFloat (void *vsta) +{ + LCGFloat_state *state = vsta; + printf (" s = %ld\n", (long) state->S); +} + +unif01_Gen *ulcg_CreateLCGFloat (long m, long a, long c, long s) +{ + unif01_Gen *gen; + LCGFloat_param *param; + LCGFloat_state *state; + size_t leng; + char name[LEN + 1]; + + if ((c < 0) || ((a < 0) && (c != 0)) || (a >= m) || (c >= m) || (s >= m)) + util_Error ("ulcg_CreateLCGFloat: Invalid parameter"); + if (((double) a * m + c >= DeuxExp53) || (-a * (double) m >= DeuxExp53)) + util_Error ("ulcg_CreateLCGFloat: |am| + c >= 2^{53}"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LCGFloat_param)); + state = util_Malloc (sizeof (LCGFloat_state)); + + strncpy (name, "ulcg_CreateLCGFloat:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + gen->Write = &WrLCGFloat; + + param->Norm = 1.0 / m; + param->M = m; + param->A = a; + param->C = c; + state->S = s; + + if (a < 0) { + gen->GetBits = &LCGFloatNeg_Bits; + gen->GetU01 = &LCGFloatNeg_U01; + } else { + gen->GetBits = &LCGFloat_Bits; + gen->GetU01 = &LCGFloat_U01; + } + return gen; +} + + +/**************************************************************************/ +#ifdef USE_GMP + +static double BigPow2LCG_U01 (void *vpar, void *vsta) +{ + BigPow2LCG_param *param = vpar; + BigPow2LCG_state *state = vsta; + + mpz_mul (state->S, param->A, state->S); /* S = A * S */ + if (param->cflag) + mpz_add (state->S, state->S, param->C); /* S = S + C */ + mpz_tdiv_r_2exp (state->S, state->S, param->E); /* S = S % 2^E */ + mpq_set_num (param->U, state->S); /* Numerator of U */ + mpq_set_den (param->U, param->M); /* Denominator of U */ + return mpq_get_d (param->U); /* U = S / M */ +} + +static unsigned long BigPow2LCG_Bits (void *vpar, void *vsta) +{ + return (BigPow2LCG_U01 (vpar, vsta) * unif01_NORM32); +} + +static void WrBigPow2LCG (void *vsta) +{ + BigPow2LCG_state *state = vsta; + printf (" s = "); + mpz_out_str (stdout, 10, state->S); + printf ("\n"); +} + +unif01_Gen *ulcg_CreateBigPow2LCG (long e, char *a, char *c, char *s) +{ + unif01_Gen *gen; + BigPow2LCG_param *param; + BigPow2LCG_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (e > 0, "ulcg_CreateBigPow2LCG: e < 1"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (BigPow2LCG_param)); + state = util_Malloc (sizeof (BigPow2LCG_state)); + + strncpy (name, "ulcg_CreateBigPow2LCG: ", (size_t) LEN); + addstr_Long (name, "e = ", e); + leng = 30 + strlen (name) + strlen (a) + strlen (c) + strlen (s); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + strcat (gen->name, ", a = "); + strcat (gen->name, a); + strcat (gen->name, ", c = "); + strcat (gen->name, c); + strcat (gen->name, ", s = "); + strcat (gen->name, s); + + param->E = e; + mpz_init (param->M); + mpz_ui_pow_ui (param->M, 2, (unsigned long) e); /* M = 2^E */ + + mpz_init (state->S); + if (mpz_set_str (state->S, s, 10)) + util_Error ("ulcg_CreateBigPow2LCG: s is not a valid decimal number"); + if (mpz_sgn (state->S) < 0) + util_Error ("ulcg_CreateBigPow2LCG: s < 0"); + + mpz_init (param->A); + if (mpz_set_str (param->A, a, 10)) + util_Error ("ulcg_CreateBigPow2LCG: a is not a valid decimal number"); + if (mpz_sgn (param->A) < 0) + util_Error ("ulcg_CreateBigPow2LCG: a < 0"); + + /* Checks if c = 0 */ + if (strcmp (c, "0") == 0) + param->cflag = 0; + else { + param->cflag = 1; + mpz_init (param->C); + if (mpz_set_str (param->C, c, 10)) + util_Error ("ulcg_CreateBigPow2LCG: c is not a valid decimal number"); + if (mpz_sgn (param->C) < 0) + util_Error ("ulcg_CreateBigPow2LCG: c < 0"); + } + + mpq_init (param->U); + + gen->param = param; + gen->state = state; + gen->Write = &WrBigPow2LCG; + gen->GetBits = &BigPow2LCG_Bits; + gen->GetU01 = &BigPow2LCG_U01; + return gen; +} + +void ulcg_DeleteBigPow2LCG (unif01_Gen * gen) +{ + BigPow2LCG_param *param; + BigPow2LCG_state *state; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + mpz_clear (state->S); + mpz_clear (param->M); + mpz_clear (param->A); + if (param->cflag) + mpz_clear (param->C); + mpq_clear (param->U); + unif01_DeleteGen (gen); +} + +#endif +/**************************************************************************/ + +static unsigned long Pow2LCG_Bits (void *vpar, void *vsta) +{ + Pow2LCG_param *param = vpar; + Pow2LCG_state *state = vsta; + state->S = (param->A * state->S + param->C) & param->Mask; + return state->S << param->Shift; +} + +static double Pow2LCG_U01 (void *vpar, void *vsta) +{ + return (Pow2LCG_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrPow2LCG (void *vsta) +{ + Pow2LCG_state *state = vsta; + printf (" s = %1lu\n", state->S); +} + +unif01_Gen *ulcg_CreatePow2LCG (int e, long a, long c, long s) +{ + unif01_Gen *gen; + Pow2LCG_param *param; + Pow2LCG_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (e <= 31, "ulcg_CreatePow2LCG: e > 31"); + if (((a <= 0 || c < 0) || s < 0) || e < 0) { + util_Error ("ulcg_CreatePow2LCG: parameter < 0"); + } + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Pow2LCG_param)); + state = util_Malloc (sizeof (Pow2LCG_state)); + + strncpy (name, "ulcg_CreatePow2LCG: ", (size_t) LEN); + addstr_Int (name, " e = ", e); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Mask = (unsigned long) (num_TwoExp[e] - 1.0); + param->Shift = 32 - e; + param->A = a; + param->C = c; + state->S = s; + + gen->param = param; + gen->state = state; + gen->Write = &WrPow2LCG; + gen->GetBits = &Pow2LCG_Bits; + gen->GetU01 = &Pow2LCG_U01; + return gen; +} + + +/**************************************************************************/ + +static unsigned long LCG2e31_Bits (void *vpar, void *vsta) +{ + LCG2e31_param *param = vpar; + LCG2e31_state *state = vsta; + + state->S = (param->A * state->S + param->C) & MASK31; + return state->S << 1; +} + +static double LCG2e31_U01 (void *vpar, void *vsta) +{ + return (LCG2e31_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrLCG2e31 (void *vsta) +{ + LCG2e31_state *state = vsta; + printf (" s = %1lu\n", state->S); +} + +unif01_Gen *ulcg_CreateLCG2e31 (long a, long c, long s) +{ + unif01_Gen *gen; + LCG2e31_param *param; + LCG2e31_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a <= 0) || (c < 0) || (s <= 0) || (s >= DeuxExp31m1) + || (c >= DeuxExp31m1) || (a >= DeuxExp31m1)) + util_Error ("ulcg_CreateLCG2e31: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LCG2e31_param)); + state = util_Malloc (sizeof (LCG2e31_state)); + + strncpy (name, "ulcg_CreateLCG2e31: ", (size_t) LEN); + addstr_Long (name, " a = ", a); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->A = a; + param->C = c; + state->S = s; + + gen->param = param; + gen->state = state; + gen->Write = &WrLCG2e31; + gen->GetBits = &LCG2e31_Bits; + gen->GetU01 = &LCG2e31_U01; + return gen; +} + + +/**************************************************************************/ + +static unsigned long LCG2e32_Bits (void *vpar, void *vsta) +{ + LCG2e32_param *param = vpar; + LCG2e32_state *state = vsta; +#ifdef IS_ULONG32 + state->S = (param->A * state->S + param->C); +#else + state->S = (param->A * state->S + param->C) & MASK32; +#endif + return state->S; +} + +static double LCG2e32_U01 (void *vpar, void *vsta) +{ + return (LCG2e32_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrLCG2e32 (void *vsta) +{ + LCG2e32_state *state = vsta; + printf (" s = %1lu\n", state->S); +} + + +unif01_Gen *ulcg_CreateLCG2e32 (unsigned long a, unsigned long c, + unsigned long s) +{ + unif01_Gen *gen; + LCG2e32_param *param; + LCG2e32_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a > DeuxExp32m1) || (c > DeuxExp32m1) || (s > DeuxExp32m1)) + util_Error ("ulcg_CreateLCG2e32: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LCG2e32_param)); + state = util_Malloc (sizeof (LCG2e32_state)); + + strncpy (name, "ulcg_CreateLCG2e32: ", (size_t) LEN); + addstr_Ulong (name, " a = ", a); + addstr_Ulong (name, ", c = ", c); + addstr_Ulong (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->A = a; + param->C = c; + state->S = s; + gen->param = param; + gen->state = state; + gen->Write = &WrLCG2e32; + gen->GetBits = &LCG2e32_Bits; + gen->GetU01 = &LCG2e32_U01; + return gen; +} + + +/**************************************************************************/ + +static double LCGPayne_U01 (void *vpar, void *vsta) +{ + LCGPayne_param *param = vpar; + LCGPayne_state *state = vsta; + unsigned long q; +#ifdef USE_LONGLONG + ulonglong res; + res = state->S * (ulonglong) param->a + param->c; +#else + unsigned long res; + res = state->S * param->a + param->c; +#endif + q = (res & MASK31) + (res >> 31); + if (q >= DeuxExp31m1) + q -= DeuxExp31m1; + state->S = q; + return (q * UnSur2e31m1); +} + + +static unsigned long LCGPayne_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LCGPayne_U01 (vpar, vsta)); +} + + +static void WrLCGPayne (void *vsta) +{ + LCGPayne_state *state = vsta; + printf (" s = %1lu\n", state->S); +} + + +unif01_Gen *ulcg_CreateLCGPayne (long a, long c, long s) +{ + unif01_Gen *gen; + LCGPayne_param *param; + LCGPayne_state *state; + size_t leng; + char name[LEN + 1]; + +#ifndef USE_LONGLONG +#ifdef IS_ULONG32 + util_Error ("ulcg_CreateLCGPayne will not work"); +#endif +#endif + if ((a < 1) || (s < 0) || (s >= DeuxExp31m1)) + util_Error ("ulcg_CreateLCGPayne: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LCGPayne_param)); + state = util_Malloc (sizeof (LCGPayne_state)); + + strncpy (name, "ulcg_CreateLCGPayne:", (size_t) LEN); + addstr_Long (name, " a = ", a); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->a = a; + param->c = c; + state->S = s; + gen->param = param; + gen->state = state; + gen->Write = &WrLCGPayne; + gen->GetBits = &LCGPayne_Bits; + gen->GetU01 = &LCGPayne_U01; + return gen; +} + + +/**************************************************************************/ + +static double LCG2e31m1HD_U01 (void *vpar, void *vsta) +{ + LCG2e31m1HD_param *param = vpar; + LCG2e31m1HD_state *state = vsta; + unsigned long xhi, xlo, mid; + + xhi = state->S >> 16; + xlo = state->S & 0xffff; + mid = param->ahi * xlo + param->Dalo * xhi; + state->S = param->ahi * xhi + mid / 65536 + param->alo * xlo; + if (state->S > DeuxExp31m1) + state->S -= DeuxExp31m1; + state->S += (32768 * (mid & 0xffff)); + if (state->S > DeuxExp31m1) + state->S -= DeuxExp31m1; + return (state->S * UnSur2e31m1); +} + + +static unsigned long LCG2e31m1HD_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LCG2e31m1HD_U01 (vpar, vsta)); +} + + +static void WrLCG2e31m1HD (void *vsta) +{ + LCG2e31m1HD_state *state = vsta; + printf (" s = %1lu\n", state->S); +} + + +unif01_Gen *ulcg_CreateLCG2e31m1HD (long a, long s) +{ + unif01_Gen *gen; + LCG2e31m1HD_param *param; + LCG2e31m1HD_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a <= 1) || (s <= 0) || (s >= DeuxExp31m1) + || (a >= 1073741824)) /* must have a < 2^30 */ + util_Error ("ulcg_CreateLCG2e31m1HD: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LCG2e31m1HD_param)); + state = util_Malloc (sizeof (LCG2e31m1HD_state)); + + strncpy (name, "ulcg_CreateLCG2e31m1HD: ", (size_t) LEN); + addstr_Long (name, " a = ", a); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->ahi = a >> 15; + param->alo = a & 0x7fff; + param->Dalo = 2 * param->alo; + state->S = s; + gen->param = param; + gen->state = state; + gen->Write = &WrLCG2e31m1HD; + gen->GetBits = &LCG2e31m1HD_Bits; + gen->GetU01 = &LCG2e31m1HD_U01; + return gen; +} + + +/**************************************************************************/ +#ifdef USE_LONGLONG + +static unsigned long LCG2e48L_Bits (void *vpar, void *vsta) +{ + LCG2e48L_param *param = vpar; + LCG2e48L_state *state = vsta; + + state->S = (param->A * state->S + param->C) & 0xffffffffffffULL; + /* We return the bits in a 32 bits int; thus shift right. */ + return (unsigned long) (state->S >> 16); +} + +static double LCG2e48L_U01 (void *vpar, void *vsta) +{ + return (LCG2e48L_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrLCG2e48L (void *vsta) +{ + LCG2e48L_state *state = vsta; + printf (" s = %" PRIuLEAST64 "\n\n", state->S); +} + +unif01_Gen *ulcg_CreateLCG2e48L (ulonglong a, ulonglong c, ulonglong s) +{ + unif01_Gen *gen; + LCG2e48L_param *param; + LCG2e48L_state *state; + size_t leng; + char name[LEN + 1]; + + if ((s >= DeuxExp48) || (a >= DeuxExp48) || (c >= DeuxExp48)) + util_Error ("ulcg_CreateLCG2e48L: parameter >= 281474976710656"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LCG2e48L_param)); + state = util_Malloc (sizeof (LCG2e48L_state)); + + strncpy (name, "ulcg_CreateLCG2e48L:", (size_t) LEN); + addstr_ULONG (name, " a = ", a); + addstr_ULONG (name, ", c = ", c); + addstr_ULONG (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->A = a; + param->C = c; + state->S = s; + gen->param = param; + gen->state = state; + gen->Write = &WrLCG2e48L; + gen->GetBits = &LCG2e48L_Bits; + gen->GetU01 = &LCG2e48L_U01; + return gen; +} + + +/**************************************************************************/ + +static unsigned long Pow2LCGLB_Bits (void *vpar, void *vsta) +{ + /* e >= 32 */ + Pow2LCGL_param *param = vpar; + Pow2LCGL_state *state = vsta; + state->S = (param->A * state->S + param->C) & param->Mask; + return state->S >> param->Shift; +} + +static unsigned long Pow2LCGLA_Bits (void *vpar, void *vsta) +{ + /* e < 32 */ + Pow2LCGL_param *param = vpar; + Pow2LCGL_state *state = vsta; + state->S = (param->A * state->S + param->C) & param->Mask; + return state->S << param->Shift; +} + +static double Pow2LCGLB_U01 (void *vpar, void *vsta) +{ + return (Pow2LCGLB_Bits (vpar, vsta) * unif01_INV32); +} + +static double Pow2LCGLA_U01 (void *vpar, void *vsta) +{ + return (Pow2LCGLA_Bits (vpar, vsta) * unif01_INV32); +} + +static void WrPow2LCGL (void *vsta) +{ + Pow2LCGL_state *state = vsta; + printf (" s = %1" PRIuLEAST64 "\n", state->S); +} + +unif01_Gen *ulcg_CreatePow2LCGL (int e, ulonglong a, ulonglong c, ulonglong s) +{ + unif01_Gen *gen; + Pow2LCGL_param *param; + Pow2LCGL_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (e <= 64, "ulcg_CreatePow2LCGL: e > 64"); + util_Assert (e > 0, "ulcg_CreatePow2LCGL: e <= 0"); + util_Assert (a != 0, "ulcg_CreatePow2LCGL: a = 0"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Pow2LCGL_param)); + state = util_Malloc (sizeof (Pow2LCGL_state)); + + strncpy (name, "ulcg_CreatePow2LCGL: ", (size_t) LEN); + addstr_Int (name, " e = ", e); + addstr_ULONG (name, ", a = ", a); + addstr_ULONG (name, ", c = ", c); + addstr_ULONG (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (e < 64) + param->Mask = (1ULL << e) - 1; + else + param->Mask = 0xffffffffffffffffULL; + if (e <= 32) { + param->Shift = 32 - e; + gen->GetBits = &Pow2LCGLA_Bits; + gen->GetU01 = &Pow2LCGLA_U01; + } else { + param->Shift = e - 32; + gen->GetBits = &Pow2LCGLB_Bits; + gen->GetU01 = &Pow2LCGLB_U01; + } + param->A = a; + param->C = c; + state->S = s; + + gen->param = param; + gen->state = state; + gen->Write = &WrPow2LCGL; + return gen; +} + +#endif + + +/**************************************************************************/ + +static double Wu2pp_U01 (void *vpar, void *vsta) +{ + Wu2_param *param = vpar; + Wu2_state *state = vsta; + unsigned long k, k1, x0, x1; + + x0 = state->S & param->mask1; + x1 = state->S >> param->emq; + k = (x0 << param->Q) + param->H * x1; + if (k >= param->M) + k -= param->M; + x0 = state->S & param->mask2; + x1 = state->S >> param->emr; + k1 = (x0 << param->R) + param->H * x1; + if (k1 >= param->M) + k1 -= param->M; + state->S = k + k1; + if (state->S >= param->M) + state->S -= param->M; + return state->S * param->norm; +} + +static double Wu2mm_U01 (void *vpar, void *vsta) +{ + Wu2_param *param = vpar; + Wu2_state *state = vsta; + unsigned long k, k1, x0, x1; + + x0 = state->S & param->mask1; + x1 = state->S >> param->emq; + k = (x0 << param->Q) + param->H * x1; + if (k >= param->M) + k -= param->M; + x0 = state->S & param->mask2; + x1 = state->S >> param->emr; + k1 = (x0 << param->R) + param->H * x1; + if (k1 >= param->M) + k1 -= param->M; + k += k1; + if (k < param->M) + state->S = param->M - k; + else + state->S = 2 * param->M - k; + return state->S * param->norm; +} + +static double Wu2pm_U01 (void *vpar, void *vsta) +{ + Wu2_param *param = vpar; + Wu2_state *state = vsta; + unsigned long k, k1, x0, x1; + + x0 = state->S & param->mask1; + x1 = state->S >> param->emq; + k = (x0 << param->Q) + param->H * x1; + if (k >= param->M) + k -= param->M; + x0 = state->S & param->mask2; + x1 = state->S >> param->emr; + k1 = (x0 << param->R) + param->H * x1; + if (k1 >= param->M) + k1 -= param->M; + if (k >= k1) + state->S = k - k1; + else + state->S = param->M + k - k1; + return state->S * param->norm; +} + +static unsigned long Wu2pp_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Wu2pp_U01 (vpar, vsta)); +} + +static unsigned long Wu2mm_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Wu2mm_U01 (vpar, vsta)); +} + +static unsigned long Wu2pm_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Wu2pm_U01 (vpar, vsta)); +} + + +static void WrWu2 (void *vsta) +{ + Wu2_state *state = vsta; + printf (" s = %lu\n", state->S); +} + +unif01_Gen *ulcg_CreateLCGWu2 (long m, char o1, unsigned int q, char o2, + unsigned int r, long s) +{ + unif01_Gen *gen; + Wu2_param *param; + Wu2_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int E = 1; + double w; + + util_Assert (s < m, "ulcg_CreateLCGWu2: s >= m"); + util_Assert ((unsigned long) m <= MASK31, "ulcg_CreateLCGWu2: m > 2^31 - 1"); + util_Assert ((o1 == '+') || (o1 == '-'), + "ulcg_CreateLCGWu2: o1 must be '+' or '-'"); + util_Assert ((o2 == '+') || (o2 == '-'), + "ulcg_CreateLCGWu2: o2 must be '+' or '-'"); + + /* find the smallest power of 2 > m */ + while (num_TwoExp[E] < m) + E++; + util_Assert (q <= E, "ulcg_CreateLCGWu2: q > E"); + util_Assert (r <= E, "ulcg_CreateLCGWu2: r > E"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Wu2_param)); + state = util_Malloc (sizeof (Wu2_state)); + + strncpy (name, "ulcg_CreateLCGWu2: ", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Char (name, ", o1 = ", o1); + addstr_Long (name, ", q = ", (long) q); + addstr_Char (name, ", o2 = ", o2); + addstr_Long (name, ", r = ", (long) r); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->H = num_TwoExp[E] - m; + param->R = r; + param->Q = q; + + util_Assert (param->H < num_TwoExp[q], "ulcg_CreateLCGWu2: h >= 2^q"); + w = param->H*(num_TwoExp[q] - (param->H + 1)/num_TwoExp[E-q]); + util_Assert (w < m, "ulcg_CreateLCGWu2: parameters (q)"); + util_Assert (param->H < num_TwoExp[r], "ulcg_CreateLCGWu2: h >= 2^r"); + w = param->H*(num_TwoExp[r] - (param->H + 1)/num_TwoExp[E-r]); + util_Assert (w < m, "ulcg_CreateLCGWu2: parameters (r)"); + + w = num_TwoExp[E] - num_TwoExp[q] + param->H * ((m - 1) >> (E - q)); + util_Assert (w < 2.0 * m, "ulcg_CreateLCGWu2: parameters (Q)"); + w = num_TwoExp[E] - num_TwoExp[r] + param->H * ((m - 1) >> (E - r)); + util_Assert (w < 2.0 * m, "ulcg_CreateLCGWu2: parameters (R)"); + + if (o1 == '-') { + if (o2 == '-') { + gen->GetBits = &Wu2mm_Bits; + gen->GetU01 = &Wu2mm_U01; + } else { + param->R = q; + param->Q = r; + gen->GetBits = &Wu2pm_Bits; + gen->GetU01 = &Wu2pm_U01; + } + } else { + if (o2 == '-') { + gen->GetBits = &Wu2pm_Bits; + gen->GetU01 = &Wu2pm_U01; + } else { + gen->GetBits = &Wu2pp_Bits; + gen->GetU01 = &Wu2pp_U01; + } + } + + param->emq = E - q; + param->emr = E - r; + param->mask1 = num_TwoExp[param->emq] - 1.0; + param->mask2 = num_TwoExp[param->emr] - 1.0; + param->M = m; + param->norm = 1.0 / m; + state->S = s % m; + + gen->param = param; + gen->state = state; + gen->Write = &WrWu2; + return gen; +} + +/**************************************************************************/ + +/********************************************************************** + * + * Combined generators LCG following L'Ecuyer's method (1988). + * The state of each generator is in {1, 2, ..., Mi-1}. + * The returned values are in {1/M1, 2/M1, ..., (M1-1)/M1}. + * + **********************************************************************/ + +static double SmallCombLEC2_U01 (void *vpar, void *vsta) +{ + CombLEC2_param *param = vpar; + CombLEC2_state *state = vsta; + long z; + + state->S1 = ((param->A1 * state->S1) + param->C1) % param->M1; + state->S2 = ((param->A2 * state->S2) + param->C2) % param->M2; + z = state->S1 - state->S2; + if (z < 1) + z += param->M1m1; + return (z * param->Norm); +} + + +static double MediumMCombLEC2_U01 (void *vpar, void *vsta) +{ + CombLEC2_param *param = vpar; + CombLEC2_state *state = vsta; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->M1; + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->M2; + k = state->S1 - state->S2; + if (k < 1) + k += param->M1m1; + return (k * param->Norm); +} + + +static double MediumCombLEC2_U01 (void *vpar, void *vsta) +{ + CombLEC2_param *param = vpar; + CombLEC2_state *state = vsta; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->C1; + else + state->S1 = (state->S1 - param->M1) + param->C1; + if (state->S1 < 0) + state->S1 += param->M1; + + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->C2; + else + state->S2 = (state->S2 - param->M2) + param->C2; + if (state->S2 < 0) + state->S2 += param->M2; + + k = state->S1 - state->S2; + if (k < 1) + k += param->M1m1; + + return (k * param->Norm); +} + + +static double LargeCombLEC2_U01 (void *vpar, void *vsta) +{ + CombLEC2_param *param = vpar; + CombLEC2_state *state = vsta; + long z; + + state->S1 = num_MultModL (param->A1, state->S1, param->C1, param->M1); + state->S2 = num_MultModL (param->A2, state->S2, param->C2, param->M2); + z = state->S1 - state->S2; + if (z < 1) + z += param->M1m1; + return (z * param->Norm); +} + +static unsigned long SmallCombLEC2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SmallCombLEC2_U01 (vpar, vsta)); +} + +static unsigned long MediumCombLEC2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumCombLEC2_U01 (vpar, vsta)); +} + +static unsigned long MediumMCombLEC2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumMCombLEC2_U01 (vpar, vsta)); +} + +static unsigned long LargeCombLEC2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LargeCombLEC2_U01 (vpar, vsta)); +} + +static void WrCombLEC2 (void *vsta) +{ + CombLEC2_state *state = vsta; + printf (" s1 = %1ld, s2 = %1ld\n", state->S1, state->S2); +} + + +unif01_Gen *ulcg_CreateCombLEC2 (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2) +{ + unif01_Gen *gen; + CombLEC2_param *param; + CombLEC2_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a1 < 0) || (c1 < 0) || (s1 < 0) || (a1 >= m1) || (c1 >= m1) || + (s1 >= m1) || (a2 < 0) || (c2 < 0) || (s2 < 0) || (a2 >= m2) || + (c2 >= m2) || (s2 >= m2) || (m2 > m1) || (m2 <= 0) || (m1 <= 0)) + util_Error ("ulcg_CreateCombLEC2: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CombLEC2_param)); + state = util_Malloc (sizeof (CombLEC2_state)); + + strncpy (name, "ulcg_CreateCombLEC2:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", c1 = ", c1); + addstr_Long (name, ", s1 = ", s1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", c2 = ", c2); + addstr_Long (name, ", s2 = ", s2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + gen->Write = &WrCombLEC2; + + if ((m1 - 1 <= (LONG_MAX - c1) / a1) && (m2 - 1 <= (LONG_MAX - c2) / a2)) { + gen->GetBits = &SmallCombLEC2_Bits; + gen->GetU01 = &SmallCombLEC2_U01; + } else { + param->q1 = m1 / a1; + param->r1 = m1 % a1; + param->q2 = m2 / a2; + param->r2 = m2 % a2; + if ((param->r1 <= param->q1) && (param->r2 <= param->q2)) { + if ((c1 == 0) && (c2 == 0)) { + gen->GetBits = &MediumMCombLEC2_Bits; + gen->GetU01 = &MediumMCombLEC2_U01; + } else { + gen->GetBits = &MediumCombLEC2_Bits; + gen->GetU01 = &MediumCombLEC2_U01; + } + } else { + gen->GetBits = &LargeCombLEC2_Bits; + gen->GetU01 = &LargeCombLEC2_U01; + } + } + param->M1 = m1; + param->M2 = m2; + param->A1 = a1; + param->A2 = a2; + param->C1 = c1; + param->C2 = c2; + state->S1 = s1 % m1; + state->S2 = s2 % m2; + param->M1m1 = m1 - 1; + param->Norm = 1.0 / m1; + + return gen; +} + + +/**************************************************************************/ + +static double CombLEC2Float_U01 (void *vpar, void *vsta) +{ + CombLEC2Float_param *param = vpar; + CombLEC2Float_state *state = vsta; + double z; + long k; + + state->S1 = param->A1 * state->S1 + param->C1; + k = state->S1 / param->M1; + state->S1 -= k * param->M1; + state->S2 = param->A2 * state->S2 + param->C2; + k = state->S2 / param->M2; + state->S2 -= k * param->M2; + z = state->S1 - state->S2; + if (z < 1.0) + z = z + param->M1m1; + return (z * param->Norm); +} + +static unsigned long CombLEC2Float_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombLEC2Float_U01 (vpar, vsta)); +} + +static void WrCombLEC2Float (void *vsta) +{ + CombLEC2Float_state *state = vsta; + printf (" s1 = %ld, s2 = %ld\n", (long) state->S1, (long) state->S2); +} + +unif01_Gen *ulcg_CreateCombLEC2Float (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2) +{ + unif01_Gen *gen; + CombLEC2Float_param *param; + CombLEC2Float_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a1 < 0) || (c1 < 0) || (s1 < 0) || (a1 >= m1) || (c1 >= m1) || + (s1 >= m1) || (a2 < 0) || (c2 < 0) || (s2 < 0) || (a2 >= m2) || + (c2 >= m2) || (s2 >= m2) || (m2 > m1)) + util_Error ("ulcg_CreateCombLEC2Float: Invalid parameter"); + + if ((a1 * (m1 - 1.0) + c1) >= num_TwoExp[53]) + util_Error ("ulcg_CreateCombLEC2Float: a1m1 + c1 - a1 >= 2^{53}"); + if ((a2 * (m2 - 1.0) + c2) >= num_TwoExp[53]) + util_Error ("ulcg_CreateCombLEC2Float: a2m2 + c2 - a2 >= 2^{53}"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CombLEC2Float_param)); + state = util_Malloc (sizeof (CombLEC2Float_state)); + + strncpy (name, "ulcg_CreateCombLEC2Float:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", c1 = ", c1); + addstr_Long (name, ", s1 = ", s1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", c2 = ", c2); + addstr_Long (name, ", s2 = ", s2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + gen->Write = &WrCombLEC2Float; + gen->GetBits = &CombLEC2Float_Bits; + gen->GetU01 = &CombLEC2Float_U01; + + param->M1 = m1; + param->A1 = a1; + param->C1 = c1; + state->S1 = s1 % m1; + param->M2 = m2; + param->A2 = a2; + param->C2 = c2; + state->S2 = s2 % m2; + param->M1m1 = m1 - 1; + param->Norm = 1.0 / m1; + + return gen; +} + + +/**************************************************************************/ + +static double SmallCombLEC3_U01 (void *vpar, void *vsta) +{ + CombLEC3_param *param = vpar; + CombLEC3_state *state = vsta; + long z; + + state->S1 = ((param->A1 * state->S1) + param->C1) % param->M1; + state->S2 = ((param->A2 * state->S2) + param->C2) % param->M2; + state->S3 = ((param->A3 * state->S3) + param->C3) % param->M3; + + z = state->S1 - state->S2; + if (z > param->M1mM3) + z -= param->M1m1; + z += state->S3; + if (z < 1) + z += param->M1m1; + + return (z * param->Norm); +} + + +static double MediumCombLEC3_U01 (void *vpar, void *vsta) +{ + CombLEC3_param *param = vpar; + CombLEC3_state *state = vsta; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->C1; + else + state->S1 = (state->S1 - param->M1) + param->C1; + if (state->S1 < 0) + state->S1 += param->M1; + + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->C2; + else + state->S2 = (state->S2 - param->M2) + param->C2; + if (state->S2 < 0) + state->S2 += param->M2; + + k = state->S3 / param->q3; + state->S3 = param->A3 * (state->S3 - k * param->q3) - k * param->r3; + if (state->S3 < 0) + state->S3 += param->C3; + else + state->S3 = (state->S3 - param->M3) + param->C3; + if (state->S3 < 0) + state->S3 += param->M3; + + k = state->S1 - state->S2; + if (k > param->M1mM3) + k -= param->M1m1; + k += state->S3; + if (k < 1) + k += param->M1m1; + + return (k * param->Norm); +} + + +static double MediumMCombLEC3_U01 (void *vpar, void *vsta) +{ + CombLEC3_param *param = vpar; + CombLEC3_state *state = vsta; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->M1; + + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->M2; + + k = state->S3 / param->q3; + state->S3 = param->A3 * (state->S3 - k * param->q3) - k * param->r3; + if (state->S3 < 0) + state->S3 += param->M3; + + k = state->S1 - state->S2; + if (k > param->M1mM3) + k -= param->M1m1; + k += state->S3; + if (k < 1) + k += param->M1m1; + + return (k * param->Norm); +} + + +static double LargeCombLEC3_U01 (void *vpar, void *vsta) +{ + CombLEC3_param *param = vpar; + CombLEC3_state *state = vsta; + long z; + + state->S1 = num_MultModL (param->A1, state->S1, param->C1, param->M1); + state->S2 = num_MultModL (param->A2, state->S2, param->C2, param->M2); + state->S3 = num_MultModL (param->A3, state->S3, param->C3, param->M3); + + z = state->S1 - state->S2; + if (z > param->M1mM3) + z -= param->M1m1; + z += state->S3; + if (z < 1) + z += param->M1m1; + + return (z * param->Norm); +} + + +static unsigned long SmallCombLEC3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SmallCombLEC3_U01 (vpar, vsta)); +} + +static unsigned long MediumCombLEC3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumCombLEC3_U01 (vpar, vsta)); +} + +static unsigned long MediumMCombLEC3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumMCombLEC3_U01 (vpar, vsta)); +} + +static unsigned long LargeCombLEC3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LargeCombLEC3_U01 (vpar, vsta)); +} + +static void WrCombLEC3 (void *vsta) +{ + CombLEC3_state *state = vsta; + printf (" s1 = %1ld, s2 = %1ld, s3 = %1ld\n", + state->S1, state->S2, state->S3); +} + + +unif01_Gen *ulcg_CreateCombLEC3 (long m1, long m2, long m3, long a1, + long a2, long a3, long c1, long c2, long c3, long s1, long s2, long s3) +{ + unif01_Gen *gen; + CombLEC3_param *param; + CombLEC3_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a1 < 0) || (c1 < 0) || (s1 < 0) || (a1 >= m1) || (c1 >= m1) || + (s1 >= m1) || (a2 < 0) || (c2 < 0) || (s2 < 0) || (a2 >= m2) || + (c2 >= m2) || (s2 >= m2) || (a3 < 0) || (c3 < 0) || (s3 < 0) || + (a3 >= m3) || (c3 >= m3) || (s3 >= m3) || (m2 > m1) || (m3 > m2) || + (m3 <= 0) || (m2 <= 0) || (m1 <= 0)) + util_Error ("ulcg_CreateCombLEC3: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CombLEC3_param)); + state = util_Malloc (sizeof (CombLEC3_state)); + + strncpy (name, "ulcg_CreateCombLEC3:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", c1 = ", c1); + addstr_Long (name, ", s1 = ", s1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", c2 = ", c2); + addstr_Long (name, ", s2 = ", s2); + addstr_Long (name, ", m3 = ", m3); + addstr_Long (name, ", a3 = ", a3); + addstr_Long (name, ", c3 = ", c3); + addstr_Long (name, ", s3 = ", s3); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + gen->Write = &WrCombLEC3; + + if ((m1 - 1 <= (LONG_MAX - c1) / a1) && (m2 - 1 <= (LONG_MAX - c2) / a2) && + (m3 - 1 <= (LONG_MAX - c3) / a3)) { + gen->GetBits = &SmallCombLEC3_Bits; + gen->GetU01 = &SmallCombLEC3_U01; + } else { + param->q1 = m1 / a1; + param->r1 = m1 % a1; + param->q2 = m2 / a2; + param->r2 = m2 % a2; + param->q3 = m3 / a3; + param->r3 = m3 % a3; + if ((param->r1 <= param->q1) && (param->r2 <= param->q2) && + (param->r3 <= param->q3)) { + if ((c1 == 0) && (c2 == 0) && (c3 == 0)) { + gen->GetBits = &MediumMCombLEC3_Bits; + gen->GetU01 = &MediumMCombLEC3_U01; + } else { + gen->GetBits = &MediumCombLEC3_Bits; + gen->GetU01 = &MediumCombLEC3_U01; + } + } else { + gen->GetBits = &LargeCombLEC3_Bits; + gen->GetU01 = &LargeCombLEC3_U01; + } + } + param->M1 = m1; + param->M2 = m2; + param->M3 = m3; + param->A1 = a1; + param->A2 = a2; + param->A3 = a3; + param->C1 = c1; + param->C2 = c2; + param->C3 = c3; + state->S1 = s1 % m1; + state->S2 = s2 % m2; + state->S3 = s3 % m3; + param->M1mM3 = m1 - m3; + param->M1m1 = m1 - 1; + param->Norm = 1.0 / m1; + + return gen; +} + + +/**************************************************************************/ + +static double SmallCombWH2_U01 (void *vpar, void *vsta) +{ + CombWH2_param *param = vpar; + CombWH2_state *state = vsta; + double Sum; + + state->S1 = (param->A1 * state->S1 + param->C1) % param->M1; + state->S2 = (param->A2 * state->S2 + param->C2) % param->M2; + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2; + if (Sum >= 1.0) + return Sum - 1.0; + else + return Sum; +} + + +static double MediumMCombWH2_U01 (void *vpar, void *vsta) +{ + CombWH2_param *param = vpar; + CombWH2_state *state = vsta; + double Sum; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->M1; + + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->M2; + + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2; + if (Sum >= 1.0) + return Sum - 1.0; + else + return Sum; +} + + +static double MediumCombWH2_U01 (void *vpar, void *vsta) +{ + CombWH2_param *param = vpar; + CombWH2_state *state = vsta; + double Sum; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->C1; + else + state->S1 = (state->S1 - param->M1) + param->C1; + if (state->S1 < 0) + state->S1 += param->M1; + + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->C2; + else + state->S2 = (state->S2 - param->M2) + param->C2; + if (state->S2 < 0) + state->S2 += param->M2; + + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2; + if (Sum >= 1.0) + return Sum - 1.0; + else + return Sum; +} + + +static double LargeCombWH2_U01 (void *vpar, void *vsta) +{ + CombWH2_param *param = vpar; + CombWH2_state *state = vsta; + double Sum; + + state->S1 = num_MultModL (param->A1, state->S1, param->C1, param->M1); + state->S2 = num_MultModL (param->A2, state->S2, param->C2, param->M2); + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2; + if (Sum >= 1.0) + return Sum - 1.0; + else + return Sum; +} + + +static unsigned long SmallCombWH2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SmallCombWH2_U01 (vpar, vsta)); +} + +static unsigned long MediumCombWH2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumCombWH2_U01 (vpar, vsta)); +} + +static unsigned long MediumMCombWH2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumMCombWH2_U01 (vpar, vsta)); +} + +static unsigned long LargeCombWH2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LargeCombWH2_U01 (vpar, vsta)); +} + +static void WrCombWH2 (void *vsta) +{ + CombWH2_state *state = vsta; + printf (" s1 = %1ld, s2 = %1ld\n", state->S1, state->S2); +} + + +unif01_Gen *ulcg_CreateCombWH2 (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2) +{ + unif01_Gen *gen; + CombWH2_param *param; + CombWH2_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a1 < 0) || (c1 < 0) || (s1 < 0) || (a1 >= m1) || (c1 >= m1) || + (s1 >= m1) || (a2 < 0) || (c2 < 0) || (s2 < 0) || (a2 >= m2) || + (c2 >= m2) || (s2 >= m2) || (m2 <= 0) || (m1 <= 0)) + util_Error ("ulcg_CreateCombWH2: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CombWH2_param)); + state = util_Malloc (sizeof (CombWH2_state)); + + strncpy (name, "ulcg_CreateCombWH2:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", c1 = ", c1); + addstr_Long (name, ", s1 = ", s1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", c2 = ", c2); + addstr_Long (name, ", s2 = ", s2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + gen->Write = &WrCombWH2; + + if ((m1 - 1 <= (LONG_MAX - c1) / a1) && (m2 - 1 <= (LONG_MAX - c2) / a2)) { + gen->GetBits = &SmallCombWH2_Bits; + gen->GetU01 = &SmallCombWH2_U01; + } else { + param->q1 = m1 / a1; + param->r1 = m1 % a1; + param->q2 = m2 / a2; + param->r2 = m2 % a2; + if ((param->r1 <= param->q1) && (param->r2 <= param->q2)) { + if ((c1 == 0) && (c2 == 0)) { + gen->GetBits = &MediumMCombWH2_Bits; + gen->GetU01 = &MediumMCombWH2_U01; + } else { + gen->GetBits = &MediumCombWH2_Bits; + gen->GetU01 = &MediumCombWH2_U01; + } + } else { + gen->GetBits = &LargeCombWH2_Bits; + gen->GetU01 = &LargeCombWH2_U01; + } + } + param->M1 = m1; + param->M2 = m2; + param->A1 = a1; + param->A2 = a2; + param->C1 = c1; + param->C2 = c2; + state->S1 = s1 % m1; + state->S2 = s2 % m2; + param->Norm1 = 1.0 / m1; + param->Norm2 = 1.0 / m2; + return gen; +} + + +/**************************************************************************/ + +static double CombWH2Float_U01 (void *vpar, void *vsta) +{ + CombWH2Float_param *param = vpar; + CombWH2Float_state *state = vsta; + double Sum; + long k; + + state->S1 = param->A1 * state->S1 + param->C1; + k = state->S1 / param->M1; + state->S1 -= k * param->M1; + state->S2 = param->A2 * state->S2 + param->C2; + k = state->S2 / param->M2; + state->S2 -= k * param->M2; + + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2; + if (Sum >= 1.0) + return Sum - 1.0; + else + return Sum; +} + +static unsigned long CombWH2Float_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombWH2Float_U01 (vpar, vsta)); +} + +static void WrCombWH2Float (void *vsta) +{ + CombWH2Float_state *state = vsta; + printf (" s1 = %ld, s2 = %ld\n", (long) state->S1, (long) state->S2); +} + +unif01_Gen *ulcg_CreateCombWH2Float (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2) +{ + unif01_Gen *gen; + CombWH2Float_param *param; + CombWH2Float_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a1 < 0) || (c1 < 0) || (s1 < 0) || (a1 >= m1) || (c1 >= m1) || + (s1 >= m1) || (a2 < 0) || (c2 < 0) || (s2 < 0) || (a2 >= m2) || + (c2 >= m2) || (s2 >= m2) || (m2 > m1)) + util_Error ("ulcg_CreateCombWH2Float: Invalid parameter"); + + if ((a1 * (m1 - 1.0) + c1) >= num_TwoExp[53]) + util_Error ("ulcg_CreateCombWH2Float: a1m1 + c1 - a1 >= 2^{53}"); + + if ((a2 * (m2 - 1.0) + c2) >= num_TwoExp[53]) + util_Error ("ulcg_CreateCombWH2Float: a2m2 + c2 - a2 >= 2^{53}"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CombWH2Float_param)); + state = util_Malloc (sizeof (CombWH2Float_state)); + + strncpy (name, "ulcg_CreateCombWH2Float:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", c1 = ", c1); + addstr_Long (name, ", s1 = ", s1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", c2 = ", c2); + addstr_Long (name, ", s2 = ", s2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + gen->Write = &WrCombWH2Float; + + param->M1 = m1; + param->A1 = a1; + param->C1 = c1; + state->S1 = s1 % m1; + param->M2 = m2; + param->A2 = a2; + param->C2 = c2; + state->S2 = s2 % m2; + param->Norm1 = 1.0 / m1; + param->Norm2 = 1.0 / m2; + + gen->GetBits = &CombWH2Float_Bits; + gen->GetU01 = &CombWH2Float_U01; + return gen; +} + +/**************************************************************************/ + +static double SmallCombWH3_U01 (void *vpar, void *vsta) +{ + CombWH3_param *param = vpar; + CombWH3_state *state = vsta; + double Sum; + + state->S1 = (param->A1 * state->S1 + param->C1) % param->M1; + state->S2 = (param->A2 * state->S2 + param->C2) % param->M2; + state->S3 = (param->A3 * state->S3 + param->C3) % param->M3; + + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2 + + state->S3 * param->Norm3; + if (Sum >= 2.0) + return Sum - 2.0; + if (Sum >= 1.0) + return Sum - 1.0; + return Sum; +} + +static double MediumMCombWH3_U01 (void *vpar, void *vsta) +{ + CombWH3_param *param = vpar; + CombWH3_state *state = vsta; + double Sum; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->M1; + + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->M2; + + k = state->S3 / param->q3; + state->S3 = param->A3 * (state->S3 - k * param->q3) - k * param->r3; + if (state->S3 < 0) + state->S3 += param->M3; + + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2 + + state->S3 * param->Norm3; + if (Sum >= 2.0) + return Sum - 2.0; + if (Sum >= 1.0) + return Sum - 1.0; + return Sum; +} + +static double MediumCombWH3_U01 (void *vpar, void *vsta) +{ + CombWH3_param *param = vpar; + CombWH3_state *state = vsta; + double Sum; + long k; + + k = state->S1 / param->q1; + state->S1 = param->A1 * (state->S1 - k * param->q1) - k * param->r1; + if (state->S1 < 0) + state->S1 += param->C1; + else + state->S1 = (state->S1 - param->M1) + param->C1; + if (state->S1 < 0) + state->S1 += param->M1; + + k = state->S2 / param->q2; + state->S2 = param->A2 * (state->S2 - k * param->q2) - k * param->r2; + if (state->S2 < 0) + state->S2 += param->C2; + else + state->S2 = (state->S2 - param->M2) + param->C2; + if (state->S2 < 0) + state->S2 += param->M2; + + k = state->S3 / param->q3; + state->S3 = param->A3 * (state->S3 - k * param->q3) - k * param->r3; + if (state->S3 < 0) + state->S3 += param->C3; + else + state->S3 = (state->S3 - param->M3) + param->C3; + if (state->S3 < 0) + state->S3 += param->M3; + + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2 + + state->S3 * param->Norm3; + if (Sum >= 2.0) + return Sum - 2.0; + if (Sum >= 1.0) + return Sum - 1.0; + return Sum; +} + + +static double LargeCombWH3_U01 (void *vpar, void *vsta) +{ + CombWH3_param *param = vpar; + CombWH3_state *state = vsta; + double Sum; + + state->S1 = num_MultModL (param->A1, state->S1, param->C1, param->M1); + state->S2 = num_MultModL (param->A2, state->S2, param->C2, param->M2); + state->S3 = num_MultModL (param->A3, state->S3, param->C3, param->M3); + + Sum = state->S1 * param->Norm1 + state->S2 * param->Norm2 + + state->S3 * param->Norm3; + if (Sum >= 2.0) + return Sum - 2.0; + if (Sum >= 1.0) + return Sum - 1.0; + return Sum; +} + +static unsigned long SmallCombWH3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SmallCombWH3_U01 (vpar, vsta)); +} + +static unsigned long MediumCombWH3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumCombWH3_U01 (vpar, vsta)); +} + +static unsigned long MediumMCombWH3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MediumMCombWH3_U01 (vpar, vsta)); +} + +static unsigned long LargeCombWH3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LargeCombWH3_U01 (vpar, vsta)); +} + +static void WrCombWH3 (void *vsta) +{ + CombWH3_state *state = vsta; + printf (" s1 = %1ld, s2 = %1ld, s3 = %1ld\n", + state->S1, state->S2, state->S3); +} + + +unif01_Gen *ulcg_CreateCombWH3 (long m1, long m2, long m3, long a1, + long a2, long a3, long c1, long c2, long c3, long s1, long s2, long s3) +{ + unif01_Gen *gen; + CombWH3_param *param; + CombWH3_state *state; + size_t leng; + char name[LEN + 1]; + + if ((a1 < 0) || (c1 < 0) || (s1 < 0) || (a1 >= m1) || (c1 >= m1) || + (s1 >= m1) || (a2 < 0) || (c2 < 0) || (s2 < 0) || (a2 >= m2) || + (c2 >= m2) || (s2 >= m2) || (a3 < 0) || (c3 < 0) || (s3 < 0) || + (a3 >= m3) || (c3 >= m3) || (s3 >= m3) || + (m2 <= 0) || (m1 <= 0) || (m3 <= 0)) + util_Error ("ulcg_CreateCombWH3: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CombWH3_param)); + state = util_Malloc (sizeof (CombWH3_state)); + + strncpy (name, "ulcg_CreateCombWH3:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", a1 = ", a1); + addstr_Long (name, ", c1 = ", c1); + addstr_Long (name, ", s1 = ", s1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", a2 = ", a2); + addstr_Long (name, ", c2 = ", c2); + addstr_Long (name, ", s2 = ", s2); + addstr_Long (name, ", m3 = ", m3); + addstr_Long (name, ", a3 = ", a3); + addstr_Long (name, ", c3 = ", c3); + addstr_Long (name, ", s3 = ", s3); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->param = param; + gen->state = state; + gen->Write = &WrCombWH3; + + if ((m1 - 1 <= (LONG_MAX - c1) / a1) && (m2 - 1 <= (LONG_MAX - c2) / a2) && + (m3 - 1 <= (LONG_MAX - c3) / a3)) { + gen->GetBits = &SmallCombWH3_Bits; + gen->GetU01 = &SmallCombWH3_U01; + } else { + param->q1 = m1 / a1; + param->r1 = m1 % a1; + param->q2 = m2 / a2; + param->r2 = m2 % a2; + param->q3 = m3 / a3; + param->r3 = m3 % a3; + if ((param->r1 <= param->q1) && (param->r2 <= param->q2) && + (param->r3 <= param->q3)) { + if ((c1 == 0) && (c2 == 0) && (c3 == 0)) { + gen->GetBits = &MediumMCombWH3_Bits; + gen->GetU01 = &MediumMCombWH3_U01; + } else { + gen->GetBits = &MediumCombWH3_Bits; + gen->GetU01 = &MediumCombWH3_U01; + } + } else { + gen->GetBits = &LargeCombWH3_Bits; + gen->GetU01 = &LargeCombWH3_U01; + } + } + param->M1 = m1; + param->M2 = m2; + param->M3 = m3; + param->A1 = a1; + param->A2 = a2; + param->A3 = a3; + param->C1 = c1; + param->C2 = c2; + param->C3 = c3; + state->S1 = s1 % m1; + state->S2 = s2 % m2; + state->S3 = s3 % m3; + param->Norm1 = 1.0 / m1; + param->Norm2 = 1.0 / m2; + param->Norm3 = 1.0 / m3; + return gen; +} + + +/**************************************************************************/ + +void ulcg_DeleteGen (unif01_Gen * gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ulcg.tex b/TESTU01/TestU01-1.2.3/testu01/ulcg.tex new file mode 100644 index 0000000..a5d9d29 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ulcg.tex @@ -0,0 +1,376 @@ +\defmodule {ulcg} + +This module implements linear congruential generators (LCGs), +simple or combined, in generic form. +The simple LCG is defined by the recurrence +\eq + x_i = (a x_{i-1} + c) \ \mod m, \label {lcg} +\endeq +and the output at step $i$ is $u_i = x_i / m$. +Two types of combinations are implemented: +\index{Generator!linear congruential}% +the one proposed by L'Ecuyer \cite{rLEC88a}, and the one proposed +by Wichmann and Hill \cite{rWIC82a}. +See \cite{rLEC91b} for details. +Some of the implementations use the GNU multiprecision package GMP. +%% (see the web site at \url{http://www.gnu.org/software/gmp/gmp.html}). +The macro {\tt USE\_GMP} is defined in module {\tt gdef} in directory +{\tt mylib}. + +The following table gives specific parameters taken from +the literature or from widely available software. +See also \cite{sFIS96a,rLEC99c} for other LCG parameters. +Parameters for combined LCGs can be found in +\cite{rLEC88a,rLEC91b,rLEC97d}. + + +\begin{center} +\topcaption {Some specific (popular) LCGs\label {tab:listgen}} +\tablehead{ \hline \multicolumn{1}{|c}{$m$} & \multicolumn{1}{|c}{$a$} & + \multicolumn{1}{|c}{$c$} & \multicolumn{1}{|c|}{Reference}\\ \hline \hline} +\begin {supertabular}{|l|r|r|l|} + $2^{24}$ & 1140671485 & 12820163 & in Microsoft VisualBasic\\ + $2^{31}-1$ & 742938285 & 0 & \cite{rFIS86a} \\ + $2^{31}-1$ & 950706376 & 0 & \cite{rFIS86a} \\ + $2^{31}-1$ & 630360016 & 0 & \cite{sLAW91a,rPAY69a} \\ + $2^{31}-1$ & 397204094 & 0 & in SAS \cite{iSAS90a}\\ + $2^{31}-1$ & 16807 & 0 & \cite{rLEW69a,sBRA87a,sLAW91a,rPAR88a}\\ + $2^{31}-1$ & 45991 & 0 & \cite{rLEC94e} \\ + & & & \\ + $2^{31}$ & 65539 & 0 & RANDU \cite{sKAR91a,sLAW91a} \\ + $2^{31}$ & 134775813 & 1 & in Turbo Pascal \\ + $2^{31}$ & 1103515245 & 12345 & {\tt rand()} in BSD ANSI C \\ + $2^{31}$ & 452807053 & 0 & \cite[URN11]{sKAR91a} \\ + $2^{32}$ & 1099087573 & 0 & \cite{rFIS90a}\\ + $2^{32}$ & 4028795517 & 0 & \cite{rFIS90a}\\ + $2^{32}$ & 663608941 & 0 & \cite[URN13]{sKAR91a}\\ + $2^{32}$ & 69069 & 0 & component of original SuperDuper \\ + $2^{32}$ & 69069 & 1 & on VAX/VMS \cite[URN22]{sKAR91a} \\ + $2^{32}$ & 2147001325 & 715136305 & in BCLP language \\ + & & & \\ + $2^{35}$ & $5^{13}$ & 0 & Apple \\ + $2^{35}$ & $5^{15}$ & 7261067085 & \cite[p.102]{rKNU81a} \\ + $10^{12}-11$ & 427419669081 & 0 & {\tt rand()} in {Maple 9.5 or earlier}\\ + $2^{47}-115$ & 71971110957370 & 0 & \cite{rLEC93a} \\ + $2^{47}-115$ & $-10018789$ & 0 & \cite{rLEC93a} \\ + $2^{48}$ & 68909602460261 & 0 & \cite{rFIS90a}\\ + $2^{48}$ & 25214903917 & 11 & Unix's {\tt rand48()} \\ + $2^{48}$ & 44485709377909 & 0 & on CRAY system \cite{rDEM90a} \\ + $2^{59}$ & $13^{13}$ & 0 & in NAG Fortran/C library \\ + $2^{63}-25$ & 2307085864 & 0 & \cite{rLEC93a} \\ + $2^{64}$ & $11^{13}$ &\phantom{12345} $c$ & + {\tt prng} at Cornell Theory Center \cite{rPER89a} \\ +\hline +\end {supertabular} +\end{center} + + +\bigskip\hrule +\code +\hide +/* ulcg.h for ANSI C */ + +#ifndef ULCG_H +#define ULCG_H +\endhide +#include "gdef.h" +#include "unif01.h" +\endcode + +%%%%%%%%%%%%%%%%%%%% +\guisec{Simple LCGs} + +\code + +unif01_Gen * ulcg_CreateLCG (long m, long a, long c, long s); +\endcode + \tab Initializes a LCG of the form (\ref{lcg}). + The initial state is $x_0 = s$ and the output at step $i$ + is $x_i/m$. The actual implementation + depends on the values of $(m, a, c)$. + Restrictions: $a$, $c$ and $s$ must be non-negative and + less than $m$. + \endtab +\code + + +unif01_Gen * ulcg_CreateLCGFloat (long m, long a, long c, long s); +\endcode + \tab The same as {\tt ulcg\_CreateLCG}, except that the implementation + is in floating-point arithmetic. Valid only if the + IEEE floating-point standard is respected (all integers smaller than + $ 2^{53}$ are represented exactly as {\tt double}). + Restrictions : $-m < a < m$, $0 \le c < m$, $-m < s < m$, + $|am|+c < 2^{53}$, and $c=0$ when $a < 0$. + \endtab +\code + + +#ifdef USE_GMP + unif01_Gen * ulcg_CreateBigLCG (char *m, char *a, char *c, char *s); +\endcode + \tab The same as {\tt ulcg\_CreateLCG}, + but using arbitrary large integers. The integers are given as + strings of decimal digits. The implementation uses GMP. + Restrictions: $a$, $c$ and $s$ non negative and less than $m$. + \endtab +\code +#endif + + +unif01_Gen * ulcg_CreateLCGWu2 (long m, char o1, unsigned int q, char o2, + unsigned int r, long s); +\endcode + \tab Implements a LCG of the kind proposed by Wu \cite{rWU97a}, + and generalized by L'Ecuyer and Simard \cite{rLEC99e}, for which + the modulus and multiplier can be written as + $m = 2^e -h$ and $a = \pm 2^q \pm 2^r$. +\index{Generator!Wu}% + The parameters $o1$ and $o2$ can be {\tt '+'} or {\tt '-'}; + they give the sign in front of $2^q$ and $2^r$, respectively. + Uses an implementation proposed in \cite{rLEC99e,rWU97a}, + which uses shifts instead of multiplications. + The initial state is $x_0 = s$ and the output at step $i$ is $x_i/m$. + We use a fast implementation with shifts instead of multiplications, + whenever possible. + Restrictions: $0 < s < m$, $m < 2^{31}$, + and the parameters must also satisfy the conditions $h < 2^q$, + $h(2^q - (h+1)/{2^{e-q}}) < m$ and $h < 2^r$, + $h(2^r - (h+1)/{2^{e-r}}) < m$. + \hpierre{V\'erifier que ce sont exactement les m\^emes conditions et la + m\^eme implantation.} + \hrichard {L'implantation est tr\`es semblable, mais il y a de petites + diff\'erences parce que le programme dans l'article est pour $q=15, r=13$, +et si ma m\'emoire ne me trompe pas, je ne crois pas qu'il fonctionnera encore +pour des $q,r < 32$ arbitraires. Les diff\'erences sont des if pour tester +si un nombre d\'epasse $m$. Quant aux conditions: + $h - 2^q + h \left\lfloor {(m - 1)}/{2^{e-q}}\right\rfloor < m$ and + $h - 2^r + h \left\lfloor {(m - 1)}/{2^{e-r}}\right\rfloor < m$, + je crois qu'elles sont moins contraignantes que celles de l'article. +These conditions are slightly more general than those given in \cite{rLEC99e}}. + \endtab +\code + + +unif01_Gen * ulcg_CreateLCGPayne (long a, long c, long s); +\endcode + \tab Same as {\tt ulcg\_CreateLCG}, with the additional restriction that + $m=2^{31}-1$. +\index{Generator!Payne}% + Uses the fast implementation proposed by Payne et al. \cite{rPAY69a,rCAR90a}. + See also Robin Whittle's WWW page at \url{http://www.firstpr.com.au/dsp/rand31/}. + \endtab +\code + + +unif01_Gen * ulcg_CreateLCG2e31m1HD (long a, long s); +\endcode + \tab Same as {\tt ulcg\_CreateLCG}, with the additional restrictions that + $m=2^{31}-1$, $c=0$ and $1< a < 2^{30}$. +\index{Generator!H\"ormann-Derflinger}% + Uses the specialized implementation proposed + by H\"ormann et Derflinger \cite{rHOR93a}. + \endtab +\code + + +unif01_Gen * ulcg_CreateLCG2e31 (long a, long c, long s); +\endcode + \tab Same as {\tt ulcg\_CreateLCG}, but with + $m=2^{31}$. Uses a specialized implementation. + \endtab +\code + + +unif01_Gen * ulcg_CreateLCG2e32 (unsigned long a, unsigned long c, + unsigned long s); +\endcode + \tab Same as {\tt ulcg\_CreateLCG}, but with + $m=2^{32}$. Uses a specialized implementation. + \endtab +\code + + +unif01_Gen * ulcg_CreatePow2LCG (int e, long a, long c, long s); +\endcode + \tab Implements a LCG as in {\tt ulcg\_CreateLCG}, but with $m = 2^e$. + Restrictions: $a$, $c$ and $s$ non negative and smaller than $m$, + and $e \le 31$. + \endtab +\code + + +#ifdef USE_LONGLONG +unif01_Gen * ulcg_CreateLCG2e48L (ulonglong a, ulonglong c, ulonglong s); +\endcode + \tab A simple LCG of the form $x_{i+1} = (ax_i +c) \bmod 2^{48}$, where + $x_0 = s$ is the seed. +\index{Generator!drand48}% + The generator {\tt drand48} of the SUN + C library is obtained with the parameters + $$ + a = 25214903917, \qquad c = 11. + $$ + Only the 32 most significant bits are kept. + Restrictions: $a, c, s < 281474976710656 = 2^{48}$. + \endtab +\code + + +unif01_Gen * ulcg_CreatePow2LCGL (int e, ulonglong a, ulonglong c, + ulonglong s); +\endcode + \tab Implements a LCG as in {\tt ulcg\_CreatePow2LCG}, but with + $e \le 64$. Only the 32 most significant bits are kept. + \endtab +\code +#endif +\endcode +\code + + +#ifdef USE_GMP +unif01_Gen * ulcg_CreateBigPow2LCG (long e, char *a, char *c, char *s); +\endcode + \tab Implements the same type of generator as {\tt ulcg\_CreatePow2LCG}, + but using arbitrary large integers. The integers $a$, $c$ and $s$ are + given as strings of decimal digits. + \endtab +\code +#endif +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Combined LCGs} + +\code + +unif01_Gen * ulcg_CreateCombLEC2 (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2); +\endcode + \tab Combines two LCGs by the method of L'Ecuyer \cite{rLEC88a}. + The first LCG has parameters {\tt (m1, a1, c1, s1)} and the + second has parameters {\tt (m2, a2, c2, s2)}. +\index{Generator!L'Ecuyer}% + The combination is via $x_i = (s_{i1} - s_{i2}) \mod (m_1-1)$, + where $s_{i1}$ are $s_{i2}$ are the states of the two components + at step $i$. + The output is $u_i = x_i/m_1$ if $x_i\not=0$, and + $u_i = (m_1-1)/m_1$ if $x_i=0$. + As for {\tt ulcg\_CreateLCG}, the implementation depends on the parameters. + The same restrictions as for {\tt ulcg\_CreateLCG} apply to the two components + and one must also have {\tt m1 $>$ m2}. + \endtab +\code + + +unif01_Gen * ulcg_CreateCombLEC2Float (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2); +\endcode + \tab Floating-point version of {\tt ulcg\_CreateCombLEC2}. + Valid only if any positive integer smaller than + $2^{53}$ is represented exactly as a {\tt double} + (this holds, e.g., if the IEEE floating-point standard is respected). + Restrictions: $a_1m_1+c_1 - a_1 < 2^{53}$ and $a_2m_2+c_2 - a_2< 2^{53}$. + \endtab +\code + + +unif01_Gen * ulcg_CreateCombLEC3 (long m1, long m2, long m3, long a1, + long a2, long a3, long c1, long c2, + long c3, long s1, long s2, long s3); +\endcode + \tab Same as {\tt ulcg\_CreateCombLEC2}, but combines 3 LCGs instead of 2. + The combination is via + $x_i = (s_{i1} - s_{i2} + s_{i3}) \mod (m_1-1)$, + where $s_{i1}$, $s_{i2}$ et $s_{i3}$ + are the states of the components. + One must have {\tt m1 $>$ m2 $>$ m3}. + \endtab +\code + + +unif01_Gen * ulcg_CreateCombWH2 (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2); +\endcode + \tab Combines two LCGs as in {\tt ulcg\_CreateCombLEC2}, but using the + Wichmann and Hill approach \cite {rWIC82a}: +\index{Generator!Wichmann-Hill} \label{gen:Wichmann-Hill}% + By adding modulo 1 the outputs of the two LCGs. + The same restrictions apply. + \endtab +\code + + +unif01_Gen * ulcg_CreateCombWH2Float (long m1, long m2, long a1, long a2, + long c1, long c2, long s1, long s2); +\endcode + \tab Floating-point version of {\tt ulcg\_CreateCombWH2}. Valid only if the + IEEE floating-point standard is respected (all integers smaller than + $ 2^{53}$ are represented exactly as {\tt double}). + Restrictions: $a_1m_1+c_1 - a_1 < 2^{53}$ and $a_2m_2+c_2 - a_2< 2^{53}$. + \endtab +\code + + +unif01_Gen * ulcg_CreateCombWH3 (long m1, long m2, long m3, long a1, + long a2, long a3, long c1, long c2, + long c3, long s1, long s2, long s3); +\endcode + \tab Same as {\tt ulcg\_CreateCombWH2}, but combines three LCGs. + The recent version of Excel uses the original Wichmann-Hill combination + of three small LCGs \cite {rWIC82a} for its new random number + generator (see \texttt{usoft\_CreateExcel2003} + on page \pageref{gen:Excel2003} of this guide). + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Clean-up functions} +\code + + +#ifdef USE_GMP + void ulcg_DeleteBigLCG (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by the {\tt BigLCG} + generator and allocated by the corresponding {\tt Create} function + above. + \endtab +\code + + + void ulcg_DeleteBigPow2LCG (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by the {\tt BigPow2LCG} + generator and allocated by the corresponding {\tt Create} function + above. + \endtab +\code +#endif + + +void ulcg_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called to clean up a generator object + when it is no longer in use. + \endtab +\code +\hide +#endif +\endhide +\endcode +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Other related generators} + + +{ For other specific LCGs, see also + +\begin{itemize} +\item {\tt uwu\_CreateLCGWu61a} +\item {\tt uwu\_CreateLCGWu61b} +\end{itemize} +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ulec.c b/TESTU01/TestU01-1.2.3/testu01/ulec.c new file mode 100644 index 0000000..11d291a --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ulec.c @@ -0,0 +1,2209 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: ulec.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" +#include "mystr.h" + +#include "ulec.h" +#include "utaus.h" +#include "ulcg.h" +#include "unif01.h" + +#include +#include +#include + +#define LEN 255 + + + +/*================================ Types ================================*/ + +typedef struct { + long S1, S2; +} CombLec88_state; + + +typedef struct { + double S1, S2; +} CombLec88Float_state; + + +typedef struct { + long S1, S2, S3, S4; +} CLCG4_state; + + +typedef struct { + double S1, S2, S3, S4; +} CLCG4Float_state; + + +typedef struct { + long S1, S2, S3, S4, S5; +} MRG93_state; + + +typedef struct { + long s10, s11, s12, s20, s21, s22; +} CombMRG96_state; + + +typedef struct { + double s10, s11, s12, s20, s21, s22; +} CombMRG96Float_state; + + +typedef struct { + double S10, S11, S12, S20, S21, S22; +} MRG32k3_state; + + +typedef struct { + long S10, S11, S12, S20, S21, S22; +} MRG32k3_L_state; + + +typedef struct { + double S10, S11, S12, S13, S14, S20, S21, S22, S23, S24; +} MRG32k5_state; + + +#ifdef USE_LONGLONG +typedef struct { + longlong S10, S11, S12, S20, S21, S22; +} MRG63k3_state; + + +typedef struct { + ulonglong y1, y2, y3, y4, y5; +} lfsr258_state; +#endif + + +typedef struct { + unsigned int z1, z2, z3; +} lfsr88_state; + + +typedef struct { + unsigned int z1, z2, z3, z4; +} lfsr113_state; + + +typedef struct { + unsigned long x10, x11, x12, x20, x21, x22; +} MRG31k3p_state; + + + + + + +/*============================== Functions ================================*/ + +#define UnSurM1 4.65661305739176919E-10 + +static double CombLec88_U01 (void *junk, void *vsta) +{ + CombLec88_state *state = vsta; + long k; +#if LONG_MAX >= 87385394472108L + state->S1 = (40014 * state->S1) % 2147483563; + state->S2 = (40692 * state->S2) % 2147483399; +#else + k = state->S1 / 53668; + state->S1 = 40014 * (state->S1 - k * 53668) - k * 12211; + if (state->S1 < 0) + state->S1 += 2147483563; + k = state->S2 / 52774; + state->S2 = 40692 * (state->S2 - k * 52774) - k * 3791; + if (state->S2 < 0) + state->S2 += 2147483399; +#endif + k = state->S1 - state->S2; + if (k < 1) + k += 2147483562; + return (k * UnSurM1); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombLec88_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombLec88_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrCombLec88 (void *vsta) +{ + CombLec88_state *state = vsta; + printf (" S1 = %1ld", state->S1); + printf (", S2 = %1ld\n\n", state->S2); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ulec_CreateCombLec88 (long S1, long S2) +{ + unif01_Gen *gen; + CombLec88_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert ((0 < S1) && (S1 < 2147483563), + "ulec_CreateCombLec88: S1 must be in [1, 2147483562]"); + util_Assert ((0 < S2) && (S2 < 2147483399), + "ulec_CreateCombLec88: S2 must be in [1, 2147483399]"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CombLec88_state)); + + strncpy (name, "ulec_CreateCombLec88:", (size_t) LEN); + addstr_Long (name, " S1 = ", S1); + addstr_Long (name, ", S2 = ", S2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = S1; + state->S2 = S2; + + gen->GetBits = &CombLec88_Bits; + gen->GetU01 = &CombLec88_U01; + gen->Write = &WrCombLec88; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*************************************************************************/ + +static double CombLec88Float_U01 (void *junk, void *vsta) +{ + CombLec88Float_state *state = vsta; + long k; + double Z; + + state->S1 *= 40014.0; + k = state->S1 / 2147483563.0; + state->S1 -= k * 2147483563.0; + + state->S2 *= 40692.0; + k = state->S2 / 2147483399.0; + state->S2 -= k * 2147483399.0; + + Z = state->S1 - state->S2; + if (Z < 1.0) + Z += 2147483562.0; + return Z * UnSurM1; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombLec88Float_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombLec88Float_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrCombLec88Float (void *vsta) +{ + CombLec88Float_state *state = vsta; + printf (" S1 = %1ld", (long) state->S1); + printf (", S2 = %1ld\n\n", (long) state->S2); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ulec_CreateCombLec88Float (long S1, long S2) +{ + unif01_Gen *gen; + CombLec88Float_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert ((0 < S1) && (S1 < 2147483563), + "ulec_CreateCombLec88Float: S1 must be in [1, 2147483562]"); + util_Assert ((0 < S2) && (S2 < 2147483399), + "ulec_CreateCombLec88Float: S2 must be in [1, 2147483399]"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CombLec88Float_state)); + + strncpy (name, "ulec_CreateCombLec88Float:", (size_t) LEN); + addstr_Long (name, " S1 = ", S1); + addstr_Long (name, ", S2 = ", S2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = S1; + state->S2 = S2; + + gen->GetBits = &CombLec88Float_Bits; + gen->GetU01 = &CombLec88Float_U01; + gen->Write = &WrCombLec88Float; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*************************************************************************/ + +static double CLCG4_U01 (void *junk, void *vsta) +{ + CLCG4_state *state = vsta; + double U; + +#if LONG_MAX >= 446047364265901L + state->S1 = (45991 * state->S1) % 2147483647; +#else + long k; + k = state->S1 / 46693; + state->S1 = 45991 * (state->S1 - k * 46693) - k * 25884; +#endif + if (state->S1 < 0) + state->S1 += 2147483647; + U = 4.65661287524579692E-10 * state->S1; + +#if LONG_MAX >= 446047364265901L + state->S2 = (207707 * state->S2) % 2147483543; +#else + k = state->S2 / 10339; + state->S2 = 207707 * (state->S2 - k * 10339) - k * 870; +#endif + if (state->S2 < 0) + state->S2 += 2147483543; + U -= 4.65661310075985993E-10 * state->S2; + if (U < 0.0) + U += 1.0; + +#if LONG_MAX >= 446047364265901L + state->S3 = (138556 * state->S3) % 2147483423; +#else + k = state->S3 / 15499; + state->S3 = 138556 * (state->S3 - k * 15499) - k * 3979; +#endif + if (state->S3 < 0) + state->S3 += 2147483423; + U += 4.65661336096842131E-10 * state->S3; + if (U > 1.0) + U -= 1.0; + +#if LONG_MAX >= 446047364265901L + state->S4 = (49689 * state->S4) % 2147483323; +#else + k = state->S4 / 43218; + state->S4 = 49689 * (state->S4 - k * 43218) - k * 24121; +#endif + if (state->S4 < 0) + state->S4 += 2147483323; + U -= 4.65661357780891134E-10 * state->S4; + if (U < 0.0) + U += 1.0; + return U; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CLCG4_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CLCG4_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrCLCG4 (void *vsta) +{ + CLCG4_state *state = vsta; + printf (" S1 = %1ld", state->S1); + printf (", S2 = %1ld", state->S2); + printf (", S3 = %1ld", state->S3); + printf (", S4 = %1ld\n\n", state->S4); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ulec_CreateCLCG4 (long S1, long S2, long S3, long S4) +{ + unif01_Gen *gen; + CLCG4_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CLCG4_state)); + + strncpy (name, "ulec_CreateCLCG4:", (size_t) LEN); + addstr_Long (name, " S1 = ", S1); + addstr_Long (name, ", S2 = ", S2); + addstr_Long (name, ", S3 = ", S3); + addstr_Long (name, ", S4 = ", S4); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = S1; + state->S2 = S2; + state->S3 = S3; + state->S4 = S4; + + gen->GetBits = &CLCG4_Bits; + gen->GetU01 = &CLCG4_U01; + gen->Write = &WrCLCG4; + gen->param = NULL; + gen->state = state; + return gen; +} + +/*******************************************************************/ + +#undef UnSurM1 + +#define m1r 2147483647.0 +#define m2r 2147483543.0 +#define m3r 2147483423.0 +#define m4r 2147483323.0 +#define UnSurM1 (1.0 / m1r) +#define UnSurM2 (1.0 / m2r) +#define UnSurM3 (1.0 / m3r) +#define UnSurM4 (1.0 / m4r) +#define a1r 45991.0 +#define a2r 207707.0 +#define a3r 138556.0 +#define a4r 49689.0 + +static double CLCG4Float_U01 (void *junk, void *vsta) +{ + CLCG4Float_state *state = vsta; + double U; + long k; + + state->S1 = a1r * state->S1; + k = state->S1 * UnSurM1; + state->S1 -= k * m1r; + U = state->S1 * UnSurM1; + + state->S2 *= a2r; + k = state->S2 * UnSurM2; + state->S2 -= k * m2r; + U -= state->S2 * UnSurM2; + if (U < 0.0) + U += 1.0; + + state->S3 *= a3r; + k = state->S3 * UnSurM3; + state->S3 -= k * m3r; + U += state->S3 * UnSurM3; + if (U > 1.0) + U -= 1.0; + + state->S4 *= a4r; + k = state->S4 * UnSurM4; + state->S4 -= k * m4r; + U -= state->S4 * UnSurM4; + if (U < 0.0) + U += 1.0; + + return U; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CLCG4Float_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CLCG4Float_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrCLCG4Float (void *vsta) +{ + CLCG4Float_state *state = vsta; + printf (" S1 = %1ld", (long) state->S1); + printf (", S2 = %1ld", (long) state->S2); + printf (", S3 = %1ld", (long) state->S3); + printf (", S4 = %1ld\n\n", (long) state->S4); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ulec_CreateCLCG4Float (long S1, long S2, long S3, long S4) +{ + unif01_Gen *gen; + CLCG4Float_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert ((0 <= S1) && (S1 < 2147483647), + "ulec_CreateCLCG4Float: S1 must be in [0, 2147483646]"); + util_Assert ((0 <= S2) && (S2 < 2147483543), + "ulec_CreateCLCG4Float: S2 must be in [0, 2147483542]"); + util_Assert ((0 <= S3) && (S3 < 2147483423), + "ulec_CreateCLCG4Float: S3 must be in [0, 2147483422]"); + util_Assert ((0 <= S4) && (S4 < 2147483323), + "ulec_CreateCLCG4Float: S4 must be in [0, 2147483322]"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CLCG4Float_state)); + + strncpy (name, "ulec_CreateCLCG4Float:", (size_t) LEN); + addstr_Long (name, " S1 = ", S1); + addstr_Long (name, ", S2 = ", S2); + addstr_Long (name, ", S3 = ", S3); + addstr_Long (name, ", S4 = ", S4); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = S1; + state->S2 = S2; + state->S3 = S3; + state->S4 = S4; + + gen->GetBits = &CLCG4Float_Bits; + gen->GetU01 = &CLCG4Float_U01; + gen->Write = &WrCLCG4Float; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*******************************************************************/ + +#undef norm +#define norm 4.656612873077393E-10 + +static double MRG93_U01 (void *junk, void *vsta) +{ + MRG93_state *state = vsta; + long p1, p5; +#if LONG_MAX < 230584299847627572L + long h; +#endif + + if (state->S1 == 2147483647) + state->S1 = 0; + +#if LONG_MAX >= 230584299847627572L + p5 = (104480 * state->S5) % 2147483647; +#else + h = state->S5 / 20554; + p5 = 104480 * (state->S5 - h * 20554) - h * 1727; +#endif + state->S5 = state->S4; + state->S4 = state->S3; + state->S3 = state->S2; + state->S2 = state->S1; + +#if LONG_MAX >= 230584299847627572L + p1 = (107374182 * state->S1) % 2147483647; +#else + h = state->S1 / 20; + p1 = 107374182 * (state->S1 - h * 20) - h * 7; +#endif + if (p1 < 0) + p1 += 2147483647; + if (p5 > 0) + p5 -= 2147483647; + state->S1 = p1 + p5; + if (state->S1 <= 0) + state->S1 += 2147483647; + return (state->S1 * norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG93_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG93_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG93 (void *vsta) +{ + MRG93_state *state = vsta; + printf (" S1 = %10ld, S2 = %10ld, S3 = %10ld,\n", + state->S1, state->S2, state->S3); + printf (" S4 = %10ld, S5 = %10ld\n\n", state->S4, state->S5); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ulec_CreateMRG93 (long S1, long S2, long S3, long S4, long S5) +{ + unif01_Gen *gen; + MRG93_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG93_state)); + + strncpy (name, "ulec_CreateMRG93:", (size_t) LEN); + addstr_Long (name, " S1 = ", S1); + addstr_Long (name, ", S2 = ", S2); + addstr_Long (name, ", S3 = ", S3); + addstr_Long (name, ", S4 = ", S4); + addstr_Long (name, ", S5 = ", S5); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = S1; + state->S2 = S2; + state->S3 = S3; + state->S4 = S4; + state->S5 = S5; + + gen->GetBits = &MRG93_Bits; + gen->GetU01 = &MRG93_U01; + gen->Write = &WrMRG93; + gen->param = NULL; + gen->state = state; + return gen; +} + +/*******************************************************************/ +/* Combined MRGs */ + +#undef norm +#undef m2r + +#define m1 2147483647 +#define m1r 2147483647.0 +#define m2 2145483479 +#define m2r 2145483479.0 +#define a12 63308 +#define q12 33921 +#define r12 12979 +#define a13 -183326 +#define q13 11714 +#define r13 2883 +#define a21 86098 +#define q21 24919 +#define r21 7417 +#define a23 -539608 +#define q23 3976 +#define r23 2071 +#define a12r 63308.0 +#define a13r -183326.0 +#define a21r 86098.0 +#define a23r -539608.0 +#define norm 4.656612873077393e-10 + + +static double CombMRG96_U01 (void *junk, void *vsta) +{ + CombMRG96_state *state = vsta; + long p12, p21; +#if LONG_MAX < 1342441885711174L + long h, p13, p23; +#endif + +#if LONG_MAX >= 1342441885711174L + p12 = (a12 * state->s11 + a13 * state->s10) % m1; + if (p12 < 0) + p12 += m1; +#else + h = state->s10 / q13; + p13 = -a13 * (state->s10 - h * q13) - h * r13; + h = state->s11 / q12; + p12 = a12 * (state->s11 - h * q12) - h * r12; + if (p13 < 0) + p13 += m1; + if (p12 < 0) + p12 += m1; +#endif + state->s10 = state->s11; + state->s11 = state->s12; +#if LONG_MAX >= 1342441885711174L + state->s12 = p12; +#else + state->s12 = p12 - p13; + if (state->s12 < 0) + state->s12 += m1; +#endif + +#if LONG_MAX >= 1342441885711174L + p21 = (a21 * state->s22 + a23 * state->s20) % m2; + if (p21 < 0) + p21 += m2; +#else + h = state->s20 / q23; + p23 = -a23 * (state->s20 - h * q23) - h * r23; + h = state->s22 / q21; + p21 = a21 * (state->s22 - h * q21) - h * r21; + if (p23 < 0) + p23 += m2; + if (p21 < 0) + p21 += m2; +#endif + state->s20 = state->s21; + state->s21 = state->s22; + +#if LONG_MAX >= 1342441885711174L + state->s22 = p21; +#else + state->s22 = p21 - p23; + if (state->s22 < 0) + state->s22 += m2; +#endif + + if (state->s12 <= state->s22) + return ((state->s12 - state->s22 + m1) * norm); + else + return ((state->s12 - state->s22) * norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombMRG96_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombMRG96_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrCombMRG96 (void *vsta) +{ + CombMRG96_state *state = vsta; + printf (" s11 = %10ld", state->s10); + printf (", s12 = %10ld", state->s11); + printf (", s13 = %10ld,\n", state->s12); + printf (" s21 = %10ld", state->s20); + printf (", s22 = %10ld", state->s21); + printf (", s23 = %10ld\n\n", state->s22); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateCombMRG96 (long S11, long S12, long S13, + long S21, long S22, long S23) +{ + unif01_Gen *gen; + CombMRG96_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CombMRG96_state)); + + strncpy (name, "ulec_CreateCombMRG96:", (size_t) LEN); + addstr_Long (name, " (S11, ..., S23) = (", S11); + addstr_Long (name, ", ", S12); + addstr_Long (name, ", ", S13); + addstr_Long (name, ", ", S21); + addstr_Long (name, ", ", S22); + addstr_Long (name, ", ", S23); + addstr_Char (name, ")", ' '); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->s10 = S11; + state->s11 = S12; + state->s12 = S13; + state->s20 = S21; + state->s21 = S22; + state->s22 = S23; + + gen->param = NULL; + gen->state = state; + gen->GetBits = &CombMRG96_Bits; + gen->GetU01 = &CombMRG96_U01; + gen->Write = &WrCombMRG96; + return gen; +} + + +/***************************************************************************/ + +#undef m1 +#undef m2 +#undef a12 +#undef a21 + +#define m1 2147483647.0 +#define m2 2145483479.0 +#define a12 63308.0 +#define a13n 183326.0 +#define a21 86098.0 +#define a23n 539608.0 + +static double CombMRG96Float_U01 (void *junk, void *vsta) +{ + CombMRG96Float_state *state = vsta; + long k; + double p1, p2; + + /* Component 1 */ + p1 = a12 * state->s11 - a13n * state->s10; + k = p1 / m1; + p1 -= k * m1; + if (p1 < 0.0) + p1 += m1; + state->s10 = state->s11; + state->s11 = state->s12; + state->s12 = p1; + + /* Component 2 */ + p2 = a21 * state->s22 - a23n * state->s20; + k = p2 / m2; + p2 -= k * m2; + if (p2 < 0.0) + p2 += m2; + state->s20 = state->s21; + state->s21 = state->s22; + state->s22 = p2; + + /* Combination */ + if (p1 <= p2) + return ((p1 - p2 + m1) * norm); + else + return ((p1 - p2) * norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombMRG96Float_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombMRG96Float_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrCombMRG96Float (void *vsta) +{ + CombMRG96Float_state *state = vsta; + printf (" s11 = %10ld", (long) state->s10); + printf (", s12 = %10ld", (long) state->s11); + printf (", s13 = %10ld,\n", (long) state->s12); + printf (" s21 = %10ld", (long) state->s20); + printf (", s22 = %10ld", (long) state->s21); + printf (", s23 = %10ld\n\n", (long) state->s22); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateCombMRG96Float (long S11, long S12, long S13, + long S21, long S22, long S23) +{ + unif01_Gen *gen; + CombMRG96Float_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CombMRG96Float_state)); + + strncpy (name, "ulec_CreateCombMRG96Float:", (size_t) LEN); + addstr_Long (name, " (S11, ..., S23) = (", S11); + addstr_Long (name, ", ", S12); + addstr_Long (name, ", ", S13); + addstr_Long (name, ", ", S21); + addstr_Long (name, ", ", S22); + addstr_Long (name, ", ", S23); + addstr_Char (name, ")", ' '); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->s10 = S11; + state->s11 = S12; + state->s12 = S13; + state->s20 = S21; + state->s21 = S22; + state->s22 = S23; + + gen->param = NULL; + gen->state = state; + gen->GetBits = &CombMRG96Float_Bits; + gen->GetU01 = &CombMRG96Float_U01; + gen->Write = &WrCombMRG96Float; + return gen; +} + + +/***************************************************************************/ + +#define FAC24 0.59604644775390625e-7 /* 1 / 2^24 */ + +static double CombMRG96D_U01 (void *vpar, void *vsta) +{ + double U; + U = CombMRG96_U01 (vpar, vsta); + U += CombMRG96_U01 (vpar, vsta) * FAC24; + if (U < 1.0) + return U; + else + return U - 1.0; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombMRG96D_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (CombMRG96D_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateCombMRG96D (long S11, long S12, long S13, + long S21, long S22, long S23) +{ + unif01_Gen *gen; + size_t j; + + gen = ulec_CreateCombMRG96 (S11, S12, S13, S21, S22, S23); + j = strlen (gen->name); + gen->name = util_Realloc (gen->name, (j + 2) * sizeof (char)); + j = strcspn (gen->name, ":"); + mystr_Insert (gen->name, "D", (unsigned int) j); + gen->GetU01 = &CombMRG96D_U01; + gen->GetBits = &CombMRG96D_Bits; + + return gen; +} + + +/***************************************************************************/ +#undef FAC24 +#define FAC24 0.59604644775390625e-7 /* 1 / 2^24 */ + +static double CombMRG96FloatD_U01 (void *vpar, void *vsta) +{ + double U; + U = CombMRG96Float_U01 (vpar, vsta); + U += CombMRG96Float_U01 (vpar, vsta) * FAC24; + if (U < 1.0) + return U; + else + return U - 1.0; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombMRG96FloatD_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (CombMRG96FloatD_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateCombMRG96FloatD (long S11, long S12, long S13, + long S21, long S22, long S23) +{ + unif01_Gen *gen; + size_t j; + + gen = ulec_CreateCombMRG96Float (S11, S12, S13, S21, S22, S23); + j = strlen (gen->name); + gen->name = util_Realloc (gen->name, (j + 2) * sizeof (char)); + j = strcspn (gen->name, ":"); + mystr_Insert (gen->name, "D", (unsigned int) j); + gen->GetU01 = &CombMRG96FloatD_U01; + gen->GetBits = &CombMRG96FloatD_Bits; + return gen; +} + + +/***************************************************************************/ + +#undef m1 +#undef m2 +#undef a12 +#undef a13n +#undef a21 +#undef a23n + +#define norm1p1 2.328306549295727688e-10 +#define norm1 2.32830654983782883e-10 +#define norm2 2.328318825240739e-10 + +#if LONG_MAX >= 9007199254740992L +#define m1 4294967087L +#define m2 4294944443L +#define a12 1403580L +#define a13n 810728L +#define a21 527612L +#define a23n 1370589L +#else +#define m1 1 +#define m2 1 +#define a12 0 +#define a13n 0 +#define a21 0 +#define a23n 0 +#endif + + + +/*-------------------------------------------------------------------------*/ + +static void WrMRG32k3_L (void *vsta) +{ + MRG32k3_L_state *state = vsta; + printf (" (s12, s11, s10, s22, s21, s20) = \n"); + printf (" ( %12ld, %12ld, %12ld,\n %12ld, %12ld, %12ld )\n", + state->S10, state->S11, state->S12, state->S20, + state->S21, state->S22); +} + +/*-------------------------------------------------------------------------*/ + +static unif01_Gen *CreateMRG32k3ii_L (long x10, long x11, long x12, + long x20, long x21, long x22, char *nom) +{ + unif01_Gen *gen; + MRG32k3_L_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG32k3_L_state)); + + strcpy (name, nom); + addstr_Long (name, " (s10, s11, s12, s20, s21, s22) = (", x10); + addstr_Long (name, ", ", x11); + addstr_Long (name, ", ", x12); + addstr_Long (name, ", ", x20); + addstr_Long (name, ", ", x21); + addstr_Long (name, ", ", x22); + addstr_Char (name, "", ')'); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + util_Assert (x10 < m1 && x10 >= 0, + "ulec_CreateMRG32k3aL: x10 not in [0, m1)"); + util_Assert (x11 < m1 && x11 >= 0, + "ulec_CreateMRG32k3aL: x11 not in [0, m1)"); + util_Assert (x12 < m1 && x12 >= 0, + "ulec_CreateMRG32k3aL: x12 not in [0, m1)"); + util_Assert (x20 < m2 && x20 >= 0, + "ulec_CreateMRG32k3aL: x20 not in [0, m2)"); + util_Assert (x21 < m2 && x21 >= 0, + "ulec_CreateMRG32k3aL: x21 not in [0, m2)"); + util_Assert (x22 < m2 && x22 >= 0, + "ulec_CreateMRG32k3aL: x22 not in [0, m2)"); + state->S10 = x10; + state->S11 = x11; + state->S12 = x12; + state->S20 = x20; + state->S21 = x21; + state->S22 = x22; + + gen->param = NULL; + gen->state = state; + gen->Write = &WrMRG32k3_L; + return gen; +} + +/*-------------------------------------------------------------------------*/ + +static double MRG32k3a_L_U01 (void *junk, void *vsta) +{ + MRG32k3_L_state *state = vsta; + long p; + + /* Component 1 */ + p = (a12 * state->S11 - a13n * state->S10) % m1; + if (p < 0) + p += m1; + state->S10 = state->S11; + state->S11 = state->S12; + state->S12 = p; + + /* Component 2 */ + p = (a21 * state->S22 - a23n * state->S20) % m2; + if (p < 0) + p += m2; + state->S20 = state->S21; + state->S21 = state->S22; + state->S22 = p; + + /* Combination */ + if (state->S12 <= state->S22) + return (state->S12 - state->S22 + m1) * norm1p1; + else + return (state->S12 - state->S22) * norm1p1; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG32k3a_L_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG32k3a_L_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateMRG32k3aL (long x10, long x11, long x12, + long x20, long x21, long x22) +{ + unif01_Gen *gen; + util_Assert (sizeof (long) > 6, + "ulec_CreateMRG32k3aL: LONG_MAX is too small for this implementation"); + gen = CreateMRG32k3ii_L (x10, x11, x12, x20, x21, x22, + "ulec_CreateMRG32k3aL:"); + gen->GetBits = &MRG32k3a_L_Bits; + gen->GetU01 = &MRG32k3a_L_U01; + return gen; +} + + +/***************************************************************************/ + +#undef m1 +#undef m2 +#undef a12 +#undef a13n +#undef a21 +#undef a23n + +#define norm1p1 2.328306549295727688e-10 +#define norm1 2.32830654983782883e-10 +#define norm2 2.328318825240739e-10 +#define m1 4294967087.0 +#define m2 4294944443.0 +#define a12 1403580.0 +#define a13n 810728.0 +#define a21 527612.0 +#define a23n 1370589.0 + + +/*-------------------------------------------------------------------------*/ + +static void WrMRG32k3 (void *vsta) +{ + MRG32k3_state *state = vsta; + printf (" (s12, s11, s10, s22, s21, s20) = \n"); + printf (" ( %12.0f, %12.0f, %12.0f,\n %12.0f, %12.0f, %12.0f )\n", + state->S10, state->S11, state->S12, state->S20, + state->S21, state->S22); +} + +/*-------------------------------------------------------------------------*/ + +static unif01_Gen *CreateMRG32k3ii (double x10, double x11, double x12, + double x20, double x21, double x22, char *nom) +{ + unif01_Gen *gen; + MRG32k3_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG32k3_state)); + + strcpy (name, nom); + addstr_Double (name, " (s10, s11, s12, s20, s21, s22) = (", x10); + addstr_Double (name, ", ", x11); + addstr_Double (name, ", ", x12); + addstr_Double (name, ", ", x20); + addstr_Double (name, ", ", x21); + addstr_Double (name, ", ", x22); + addstr_Char (name, "", ')'); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + util_Assert (x10 < m1 && x10 >= 0, "ulec_CreateMRG32k3: x10 not in [0, m1)"); + util_Assert (x11 < m1 && x11 >= 0, "ulec_CreateMRG32k3: x11 not in [0, m1)"); + util_Assert (x12 < m1 && x12 >= 0, "ulec_CreateMRG32k3: x12 not in [0, m1)"); + util_Assert (x20 < m2 && x20 >= 0, "ulec_CreateMRG32k3: x20 not in [0, m2)"); + util_Assert (x21 < m2 && x21 >= 0, "ulec_CreateMRG32k3: x21 not in [0, m2)"); + util_Assert (x22 < m2 && x22 >= 0, "ulec_CreateMRG32k3: x22 not in [0, m2)"); + state->S10 = x10; + state->S11 = x11; + state->S12 = x12; + state->S20 = x20; + state->S21 = x21; + state->S22 = x22; + + gen->param = NULL; + gen->state = state; + gen->Write = &WrMRG32k3; + return gen; +} + +/*-------------------------------------------------------------------------*/ + +static double MRG32k3a_U01 (void *junk, void *vsta) +{ + MRG32k3_state *state = vsta; + long k; + double p; + + /* Component 1 */ + p = a12 * state->S11 - a13n * state->S10; + k = p / m1; + p -= k * m1; + if (p < 0.0) + p += m1; + state->S10 = state->S11; + state->S11 = state->S12; + state->S12 = p; + + /* Component 2 */ + p = a21 * state->S22 - a23n * state->S20; + k = p / m2; + p -= k * m2; + if (p < 0.0) + p += m2; + state->S20 = state->S21; + state->S21 = state->S22; + state->S22 = p; + + /* Combination */ + if (state->S12 <= state->S22) + return (state->S12 - state->S22 + m1) * norm1p1; + else + return (state->S12 - state->S22) * norm1p1; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG32k3a_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG32k3a_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateMRG32k3a (double x10, double x11, double x12, + double x20, double x21, double x22) +{ + unif01_Gen *gen; + gen = CreateMRG32k3ii (x10, x11, x12, x20, x21, x22, + "ulec_CreateMRG32k3a:"); + gen->GetBits = &MRG32k3a_Bits; + gen->GetU01 = &MRG32k3a_U01; + return gen; +} + + +/***************************************************************************/ + +static double MRG32k3b_U01 (void *junk, void *vsta) +{ + MRG32k3_state *state = vsta; + long k; + double p; + + /* Component 1 */ + p = a12 * state->S11 - a13n * state->S10; + k = p / m1; + p -= k * m1; + if (p < 0.0) + p += m1; + state->S10 = state->S11; + state->S11 = state->S12; + state->S12 = p; + + /* Component 2 */ + p = a21 * state->S22 - a23n * state->S20; + k = p / m2; + p -= k * m2; + if (p < 0.0) + p += m2; + state->S20 = state->S21; + state->S21 = state->S22; + state->S22 = p; + + /* Combination */ + p = state->S12 * norm1 - state->S22 * norm2; + if (p < 0.0) + return (p + 1.0); + else + return p; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG32k3b_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG32k3b_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateMRG32k3b (double x10, double x11, double x12, + double x20, double x21, double x22) +{ + unif01_Gen *gen; + gen = CreateMRG32k3ii (x10, x11, x12, x20, x21, x22, + "ulec_CreateMRG32k3b:"); + gen->GetBits = &MRG32k3b_Bits; + gen->GetU01 = &MRG32k3b_U01; + return gen; +} + + +/***************************************************************************/ + +#undef norm1 +#undef norm2 +#undef m1 +#undef m2 +#undef a12 +#undef a21 +#undef a23 + +#define norm1 2.3283163396834613e-10 +#define norm2 2.3283243092066027e-10 +#define m1 4294949027.0 +#define m2 4294934327.0 +#define a12 1154721.0 +#define a14 1739991.0 +#define a15n 1108499.0 +#define a21 1776413.0 +#define a23 865203.0 +#define a25n 1641052.0 + + +static double MRG32k5a_U01 (void *junk, void *vsta) +{ + MRG32k5_state *state = vsta; + long k; + double p; + + /* Component 1 */ + p = a12 * state->S13 - a15n * state->S10; + if (p > 0.0) + p -= a14 * m1; + p += a14 * state->S11; + k = p / m1; + p -= k * m1; + if (p < 0.0) + p += m1; + state->S10 = state->S11; + state->S11 = state->S12; + state->S12 = state->S13; + state->S13 = state->S14; + state->S14 = p; + + /* Component 2 */ + p = a21 * state->S24 - a25n * state->S20; + if (p > 0.0) + p -= a23 * m2; + p += a23 * state->S22; + k = p / m2; + p -= k * m2; + if (p < 0.0) + p += m2; + state->S20 = state->S21; + state->S21 = state->S22; + state->S22 = state->S23; + state->S23 = state->S24; + state->S24 = p; + + /* Combination */ + if (state->S14 <= state->S24) + return ((state->S14 - state->S24 + m1) * norm1); + else + return ((state->S14 - state->S24) * norm1); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG32k5a_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG32k5a_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double MRG32k5b_U01 (void *junk, void *vsta) +{ + MRG32k5_state *state = vsta; + long k; + double p; + + /* Component 1 */ + p = a12 * state->S13 - a15n * state->S10; + if (p > 0.0) + p -= a14 * m1; + p += a14 * state->S11; + k = p / m1; + p -= k * m1; + if (p < 0.0) + p += m1; + state->S10 = state->S11; + state->S11 = state->S12; + state->S12 = state->S13; + state->S13 = state->S14; + state->S14 = p; + + /* Component 2 */ + p = a21 * state->S24 - a25n * state->S20; + if (p > 0.0) + p -= a23 * m2; + p += a23 * state->S22; + k = p / m2; + p -= k * m2; + if (p < 0.0) + p += m2; + state->S20 = state->S21; + state->S21 = state->S22; + state->S22 = state->S23; + state->S23 = state->S24; + state->S24 = p; + + /* Combination */ + p = state->S14 * norm1 - state->S24 * norm2; + if (p < 0.0) + return (p + 1.0); + else + return p; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG32k5b_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG32k5b_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG32k5 (void *vsta) +{ + MRG32k5_state *state = vsta; + printf ("(s14, s13, s12, s11, s10) = \n"); + printf ("( %12.0f, %12.0f, %12.0f, %12.0f, %12.0f )\n", + state->S14, state->S13, state->S12, state->S11, state->S10); + printf ("\n(s24, s23, s22, s21, s20) = \n"); + printf ("( %12.0f, %12.0f, %12.0f, %12.0f, %12.0f )\n", + state->S24, state->S23, state->S22, state->S21, state->S20); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateMRG32k5a (double x10, double x11, double x12, + double x13, double x14, double x20, double x21, double x22, + double x23, double x24) +{ + unif01_Gen *gen; + MRG32k5_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG32k5_state)); + + strcpy (name, "ulec_CreateMRG32k5a:"); + addstr_Double (name, " x10 = ", x10); + addstr_Double (name, ", x11 = ", x11); + addstr_Double (name, ", x12 = ", x12); + addstr_Double (name, ", x13 = ", x13); + addstr_Double (name, ", x14 = ", x14); + addstr_Double (name, ", x20 = ", x20); + addstr_Double (name, ", x21 = ", x21); + addstr_Double (name, ", x22 = ", x22); + addstr_Double (name, ", x23 = ", x23); + addstr_Double (name, ", x24 = ", x24); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S10 = x10; + state->S11 = x11; + state->S12 = x12; + state->S13 = x13; + state->S14 = x14; + state->S20 = x20; + state->S21 = x21; + state->S22 = x22; + state->S23 = x23; + state->S24 = x24; + + gen->param = NULL; + gen->state = state; + gen->Write = &WrMRG32k5; + gen->GetBits = &MRG32k5a_Bits; + gen->GetU01 = &MRG32k5a_U01; + return gen; +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateMRG32k5b (double x10, double x11, double x12, + double x13, double x14, double x20, double x21, double x22, + double x23, double x24) +{ + unif01_Gen *gen; + MRG32k5_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG32k5_state)); + + strcpy (name, "ulec_CreateMRG32k5b:"); + addstr_Double (name, " x10 = ", x10); + addstr_Double (name, ", x11 = ", x11); + addstr_Double (name, ", x12 = ", x12); + addstr_Double (name, ", x13 = ", x13); + addstr_Double (name, ", x14 = ", x14); + addstr_Double (name, ", x20 = ", x20); + addstr_Double (name, ", x21 = ", x21); + addstr_Double (name, ", x22 = ", x22); + addstr_Double (name, ", x23 = ", x23); + addstr_Double (name, ", x24 = ", x24); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S10 = x10; + state->S11 = x11; + state->S12 = x12; + state->S13 = x13; + state->S14 = x14; + state->S20 = x20; + state->S21 = x21; + state->S22 = x22; + state->S23 = x23; + state->S24 = x24; + + gen->param = NULL; + gen->state = state; + gen->Write = &WrMRG32k5; + gen->GetBits = &MRG32k5b_Bits; + gen->GetU01 = &MRG32k5b_U01; + return gen; +} + + +/***************************************************************************/ +#ifdef USE_LONGLONG + +#undef norm1 +#undef norm2 +#undef m1 +#undef m2 +#undef a12 +#undef q12 +#undef r12 +#undef a13n +#undef q13 +#undef r13 +#undef a21 +#undef q21 +#undef r21 +#undef a23n +#undef q23 +#undef r23 + +#define norm1 1.0842021724855052e-19 +#define norm2 1.0842021724855071e-19 +#define m1 9223372036854769163LL +#define m2 9223372036854754679LL +#define a12 1754669720LL +#define q12 5256471877LL +#define r12 251304723LL +#define a13n 3182104042ULL +#define q13 2898513661ULL +#define r13 394451401LL +#define a21 31387477935LL +#define q21 293855150LL +#define r21 143639429LL +#define a23n 6199136374LL +#define q23 1487847900LL +#define r23 985240079LL + + +static double MRG63k3a_U01 (void *junk, void *vsta) +{ + MRG63k3_state *state = vsta; + longlong h, p12, p13, p21, p23; + + /* Component 1 */ + h = state->S10 / q13; + p13 = a13n * (state->S10 - h * q13) - h * r13; + h = state->S11 / q12; + p12 = a12 * (state->S11 - h * q12) - h * r12; + if (p13 < 0) + p13 += m1; + if (p12 < 0) + p12 += m1; + state->S10 = state->S11; + state->S11 = state->S12; + state->S12 = p12 - p13; + if (state->S12 < 0) + state->S12 += m1; + + /* Component 2 */ + h = state->S20 / q23; + p23 = a23n * (state->S20 - h * q23) - h * r23; + h = state->S22 / q21; + p21 = a21 * (state->S22 - h * q21) - h * r21; + if (p23 < 0) + p23 += m2; + if (p21 < 0) + p21 += m2; + state->S20 = state->S21; + state->S21 = state->S22; + state->S22 = p21 - p23; + if (state->S22 < 0) + state->S22 += m2; + + /* Combination */ + if (state->S12 - state->S22 > 0) + return ((state->S12 - state->S22) * norm1); + else + return ((state->S12 - state->S22 + m1) * norm1); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG63k3a_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG63k3a_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double MRG63k3b_U01 (void *junk, void *vsta) +{ + MRG63k3_state *state = vsta; + longlong h, p12, p13, p21, p23; + double p; + + /* Component 1 */ + h = state->S10 / q13; + p13 = a13n * (state->S10 - h * q13) - h * r13; + h = state->S11 / q12; + p12 = a12 * (state->S11 - h * q12) - h * r12; + if (p13 < 0) + p13 += m1; + if (p12 < 0) + p12 += m1; + state->S10 = state->S11; + state->S11 = state->S12; + state->S12 = p12 - p13; + if (state->S12 < 0) + state->S12 += m1; + + /* Component 2 */ + h = state->S20 / q23; + p23 = a23n * (state->S20 - h * q23) - h * r23; + h = state->S22 / q21; + p21 = a21 * (state->S22 - h * q21) - h * r21; + if (p23 < 0) + p23 += m2; + if (p21 < 0) + p21 += m2; + state->S20 = state->S21; + state->S21 = state->S22; + state->S22 = p21 - p23; + if (state->S22 < 0) + state->S22 += m2; + + /* Combination */ + p = state->S12 * norm1 - state->S22 * norm2; + if (p < 0.0) + return (p + 1.0); + else + return p; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG63k3b_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG63k3b_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG63k3 (void *vsta) +{ + MRG63k3_state *state = vsta; + printf + ("(s12, s11, s10, s22, s21, s20) = \n( %20" PRIdLEAST64 + ", %20" PRIdLEAST64 ", %20" PRIdLEAST64 ",\n %20" PRIdLEAST64 + ", %20" PRIdLEAST64 ", %20" PRIdLEAST64 " )\n", + state->S12, state->S11, state->S10, state->S22, state->S21, + state->S20); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_CreateMRG63k3a (longlong s10, longlong s11, longlong s12, + longlong s20, longlong s21, longlong s22) +{ + unif01_Gen *gen; + MRG63k3_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG63k3_state)); + + strcpy (name, "ulec_CreateMRG63k3a:"); + addstr_LONG (name, " s10 = ", s10); + addstr_LONG (name, ", s11 = ", s11); + addstr_LONG (name, ", s12 = ", s12); + addstr_LONG (name, ", s20 = ", s20); + addstr_LONG (name, ", s21 = ", s21); + addstr_LONG (name, ", s22 = ", s22); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S10 = s10; + state->S11 = s11; + state->S12 = s12; + state->S20 = s20; + state->S21 = s21; + state->S22 = s22; + + gen->param = NULL; + gen->state = state; + gen->Write = &WrMRG63k3; + gen->GetBits = &MRG63k3a_Bits; + gen->GetU01 = &MRG63k3a_U01; + return gen; +} + +unif01_Gen *ulec_CreateMRG63k3b (longlong s10, longlong s11, longlong s12, + longlong s20, longlong s21, longlong s22) +{ + unif01_Gen *gen; + MRG63k3_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG63k3_state)); + + strcpy (name, "ulec_CreateMRG63k3b:"); + addstr_LONG (name, " s10 = ", s10); + addstr_LONG (name, ", s11 = ", s11); + addstr_LONG (name, ", s12 = ", s12); + addstr_LONG (name, ", s20 = ", s20); + addstr_LONG (name, ", s21 = ", s21); + addstr_LONG (name, ", s22 = ", s22); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S10 = s10; + state->S11 = s11; + state->S12 = s12; + state->S20 = s20; + state->S21 = s21; + state->S22 = s22; + + gen->param = NULL; + gen->state = state; + gen->Write = &WrMRG63k3; + gen->GetBits = &MRG63k3b_Bits; + gen->GetU01 = &MRG63k3b_U01; + return gen; +} + + +#endif /* USE_LONGLONG */ + +/**************************************************************************/ +/* LFSR Generators. */ + +/* d_j = k_j - s_j. */ + +#define q1 13 +#define q2 2 +#define q3 3 +#define d1 19 +#define d2 25 +#define d3 11 +#define s1 12 +#define s2 4 +#define s3 17 +#define msk1 4294967294U /* (2^32) - 2 */ +#define msk2 4294967288U /* (2^32) - 8 */ +#define msk3 4294967280U /* (2^32) - 16 */ + + +static unsigned long lfsr88_Bits (void *junk, void *vsta) +{ + lfsr88_state *state = vsta; + unsigned int b; + + b = ((state->z1 << q1) ^ state->z1) >> d1; + state->z1 = ((state->z1 & msk1) << s1) ^ b; + b = ((state->z2 << q2) ^ state->z2) >> d2; + state->z2 = ((state->z2 & msk2) << s2) ^ b; + b = ((state->z3 << q3) ^ state->z3) >> d3; + state->z3 = ((state->z3 & msk3) << s3) ^ b; + return state->z1 ^ state->z2 ^ state->z3; +} + +/*-------------------------------------------------------------------------*/ + +static double lfsr88_U01 (void *junk, void *vsta) +{ + return lfsr88_Bits (junk, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void Wrlfsr88 (void *vsta) +{ + lfsr88_state *state = vsta; + printf (" z1 = %1u", state->z1); + printf (", z2 = %1u", state->z2); + printf (", z3 = %1u\n\n", state->z3); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_Createlfsr88 (unsigned int us1, unsigned int us2, + unsigned int us3) +{ + unif01_Gen *gen; + lfsr88_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (us1 >= 2, "ulec_Createlfsr88: s1 < 2"); + util_Assert (us2 >= 8, "ulec_Createlfsr88: s2 < 8"); + util_Assert (us3 >= 16, "ulec_Createlfsr88: s3 < 16"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (lfsr88_state)); + + strcpy (name, "ulec_Createlfsr88:"); + addstr_Uint (name, " s1 = ", us1); + addstr_Uint (name, ", s2 = ", us2); + addstr_Uint (name, ", s3 = ", us3); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->z1 = us1; + state->z2 = us2; + state->z3 = us3; + + gen->GetBits = &lfsr88_Bits; + gen->GetU01 = &lfsr88_U01; + gen->Write = &Wrlfsr88; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*======================================================================= */ + +#undef q1 +#undef q3 +#undef d1 +#undef d2 +#undef d3 +#undef s1 +#undef s2 +#undef s3 + +#define q1 6 +#define q2 2 +#define q3 13 +#define q4 3 +#define d1 13 +#define d2 27 +#define d3 21 +#define d4 12 +#define s1 18 +#define s2 2 +#define s3 7 +#define s4 13 +#define msk4 4294967168U /* 2^(32) - 128 */ + + +static unsigned long lfsr113_Bits (void *junk, void *vsta) +{ + lfsr113_state *state = vsta; + unsigned int b; + + b = ((state->z1 << q1) ^ state->z1) >> d1; + state->z1 = ((state->z1 & msk1) << s1) ^ b; + b = ((state->z2 << q2) ^ state->z2) >> d2; + state->z2 = ((state->z2 & msk2) << s2) ^ b; + b = ((state->z3 << q3) ^ state->z3) >> d3; + state->z3 = ((state->z3 & msk3) << s3) ^ b; + b = ((state->z4 << q4) ^ state->z4) >> d4; + state->z4 = ((state->z4 & msk4) << s4) ^ b; + return state->z1 ^ state->z2 ^ state->z3 ^ state->z4; +} + +/*-------------------------------------------------------------------------*/ + +static double lfsr113_U01 (void *junk, void *vsta) +{ + return lfsr113_Bits (junk, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void Wrlfsr113 (void *vsta) +{ + lfsr113_state *state = vsta; + printf (" z1 = %1u", state->z1); + printf (", z2 = %1u", state->z2); + printf (", z3 = %1u", state->z3); + printf (", z4 = %1u\n\n", state->z4); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_Createlfsr113 (unsigned int us1, unsigned int us2, + unsigned int us3, unsigned int us4) +{ + unif01_Gen *gen; + lfsr113_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (us1 >= 2, "ulec_Createlfsr113: s1 < 2"); + util_Assert (us2 >= 8, "ulec_Createlfsr113: s2 < 8"); + util_Assert (us3 >= 16, "ulec_Createlfsr113: s3 < 16"); + util_Assert (us4 >= 128, "ulec_Createlfsr113: s4 < 128"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (lfsr113_state)); + + strcpy (name, "ulec_Createlfsr113:"); + addstr_Uint (name, " s1 = ", us1); + addstr_Uint (name, ", s2 = ", us2); + addstr_Uint (name, ", s3 = ", us3); + addstr_Uint (name, ", s4 = ", us4); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->z1 = us1; + state->z2 = us2; + state->z3 = us3; + state->z4 = us4; + + gen->GetBits = &lfsr113_Bits; + gen->GetU01 = &lfsr113_U01; + gen->Write = &Wrlfsr113; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*======================================================================= */ +#ifdef USE_LONGLONG + +static unsigned long lfsr258_Bits (void *junk, void *vsta) +{ + lfsr258_state *state = vsta; + ulonglong b; + + b = ((state->y1 << 1) ^ state->y1) >> 53; + state->y1 = ((state->y1 & 18446744073709551614ULL) << 10) ^ b; + b = ((state->y2 << 24) ^ state->y2) >> 50; + state->y2 = ((state->y2 & 18446744073709551104ULL) << 5) ^ b; + b = ((state->y3 << 3) ^ state->y3) >> 23; + state->y3 = ((state->y3 & 18446744073709547520ULL) << 29) ^ b; + b = ((state->y4 << 5) ^ state->y4) >> 24; + state->y4 = ((state->y4 & 18446744073709420544ULL) << 23) ^ b; + b = ((state->y5 << 3) ^ state->y5) >> 33; + state->y5 = ((state->y5 & 18446744073701163008ULL) << 8) ^ b; + return (state->y1 ^ state->y2 ^ state->y3 ^ state->y4 ^ state->y5) >> 32; +} + +/*-------------------------------------------------------------------------*/ + +static double lfsr258_U01 (void *junk, void *vsta) +{ + return lfsr258_Bits (junk, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void Wrlfsr258 (void *vsta) +{ + lfsr258_state *state = vsta; + printf (" y1 = %21" PRIuLEAST64 "", state->y1); + printf (", y2 = %21" PRIuLEAST64 ",\n", state->y2); + printf (" y3 = %21" PRIuLEAST64 "", state->y3); + printf (", y4 = %21" PRIuLEAST64 ",\n", state->y4); + printf (" y5 = %21" PRIuLEAST64 "\n\n", state->y5); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *ulec_Createlfsr258 (ulonglong us1, ulonglong us2, + ulonglong us3, ulonglong us4, ulonglong us5) +{ + unif01_Gen *gen; + lfsr258_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (us1 >= 2, "ulec_Createlfsr258: s1 < 2"); + util_Assert (us2 >= 512, "ulec_Createlfsr258: s2 < 512"); + util_Assert (us3 >= 4096, "ulec_Createlfsr258: s3 < 4096"); + util_Assert (us4 >= 131072, "ulec_Createlfsr258: s4 < 131072"); + util_Assert (us5 >= 8388608, "ulec_Createlfsr258: s5 < 8388608"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (lfsr258_state)); + + strcpy (name, "ulec_Createlfsr258:"); + addstr_ULONG (name, " s1 = ", us1); + addstr_ULONG (name, ", s2 = ", us2); + addstr_ULONG (name, ", s3 = ", us3); + addstr_ULONG (name, ", s4 = ", us4); + addstr_ULONG (name, ", s5 = ", us5); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->y1 = us1; + state->y2 = us2; + state->y3 = us3; + state->y4 = us4; + state->y5 = us5; + + gen->GetBits = &lfsr258_Bits; + gen->GetU01 = &lfsr258_U01; + gen->Write = &Wrlfsr258; + gen->param = NULL; + gen->state = state; + return gen; +} + +#endif /* USE_LONGLONG */ + + +/***************************************************************************/ + +unif01_Gen *ulec_CreateCombTausLCG11 (unsigned int k, unsigned int q, + unsigned int s, unsigned int Y1, long m, long a, long c, long Y2) +{ + unif01_Gen *gen1, *gen2; + + gen1 = utaus_CreateTaus (k, q, s, Y1); + gen2 = ulcg_CreateLCG (m, a, c, Y2); + return unif01_CreateCombAdd2 (gen1, gen2, "ulec_CreateCombTausLCG11:"); +} + + +void ulec_DeleteCombTausLCG11 (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteGen (param->gen2); + utaus_DeleteGen (param->gen1); + unif01_DeleteCombGen (gen); +} + + +/***************************************************************************/ + +#undef q1 +#undef q2 +#undef s1 +#undef s2 + +unif01_Gen *ulec_CreateCombTausLCG21 (unsigned int k1, unsigned int q1, + unsigned int s1, unsigned int Y1, unsigned int k2, unsigned int q2, + unsigned int s2, unsigned int Y2, long m, long a, long c, long Y3) +{ + unif01_Gen *gen1, *gen2; + double x; + + gen1 = utaus_CreateCombTaus2 (k1, k2, q1, q2, s1, s2, Y1, Y2); + x = a * (double) m; + if (((x + c) >= num_TwoExp[53]) || ((-x) >= num_TwoExp[53])) + gen2 = ulcg_CreateLCG (m, a, c, Y3 % m); + else + gen2 = ulcg_CreateLCGFloat (m, a, c, Y3 % m); + return unif01_CreateCombAdd2 (gen1, gen2, "ulec_CreateCombTausLCG21:"); +} + + +void ulec_DeleteCombTausLCG21 (unif01_Gen *gen) +{ + unif01_Comb2_Param *param = gen->param; + + ulcg_DeleteGen (param->gen2); + utaus_DeleteGen (param->gen1); + unif01_DeleteCombGen (gen); +} + + +/***************************************************************************/ + +#undef M1 +#undef M2 +#undef NORM +#undef MASK12 +#undef MASK13 +#undef MASK21 +#define M1 2147483647 +#define M2 2147462579 +#define NORM 4.656612873077393e-10 +#define MASK12 511 +#define MASK13 16777215 +#define MASK21 65535 + +static double MRG31k3p_U01 (void *junk, void *vsta) +{ + MRG31k3p_state *state = vsta; + unsigned long t1, t2; + + /* First component */ + t1 = (((state->x11 & MASK12) << 22) + (state->x11 >> 9)) + + (((state->x12 & MASK13) << 7) + (state->x12 >> 24)); + if (t1 >= M1) + t1 -= M1; + t1 += state->x12; + if (t1 >= M1) + t1 -= M1; + state->x12 = state->x11; + state->x11 = state->x10; + state->x10 = t1; + + /* Second component */ + t1 = ((state->x20 & MASK21) << 15) + 21069 * (state->x20 >> 16); + if (t1 >= M2) + t1 -= M2; + t2 = ((state->x22 & MASK21) << 15) + 21069 * (state->x22 >> 16); + if (t2 >= M2) + t2 -= M2; + t2 += state->x22; + if (t2 >= M2) + t2 -= M2; + t2 += t1; + if (t2 >= M2) + t2 -= M2; + state->x22 = state->x21; + state->x21 = state->x20; + state->x20 = t2; + + /* Combination */ + if (state->x10 <= state->x20) + return ((state->x10 - state->x20 + M1) * NORM); + else + return ((state->x10 - state->x20) * NORM); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG31k3p_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG31k3p_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG31k3p (void *vsta) +{ + MRG31k3p_state *state = vsta; + printf ( + " x10 = %10lu, x11 = %10lu, x12 = %10lu,\n x20 = %10lu, x21 = %10lu, x22 = %10lu\n\n", + state->x10, state->x11, state->x12, state->x20, state->x21, state->x22); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * ulec_CreateMRG31k3p (long x10, long x11, + long x12, long x20, long x21, long x22) +{ + unif01_Gen *gen; + MRG31k3p_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (!((0 == x10) && (0 == x11) && (0 == x12)), + "ulec_CreateMRG31k3p: the first 3 seeds are all 0"); + util_Assert (!((0 == x20) && (0 == x21) && (0 == x22)), + "ulec_CreateMRG31k3p: the first 3 seeds are all 0"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG31k3p_state)); + + strncpy (name, "ulec_CreateMRG31k3p: (x10, x11, x12, x20, x21, x22) = ", + (size_t) LEN); + addstr_Long (name, "(", x10); + addstr_Long (name, ", ", x11); + addstr_Long (name, ", ", x12); + addstr_Long (name, ", ", x20); + addstr_Long (name, ", ", x21); + addstr_Long (name, ", ", x22); + strncat (name, ")", (size_t) 1); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x10 = x10 % M1; + state->x11 = x11 % M1; + state->x12 = x12 % M1; + state->x20 = x20 % M2; + state->x21 = x21 % M2; + state->x22 = x22 % M2; + + gen->GetBits = &MRG31k3p_Bits; + gen->GetU01 = &MRG31k3p_U01; + gen->Write = &WrMRG31k3p; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/***************************************************************************/ + +void ulec_DeleteGen (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); + +} diff --git a/TESTU01/TestU01-1.2.3/testu01/ulec.tex b/TESTU01/TestU01-1.2.3/testu01/ulec.tex new file mode 100644 index 0000000..5b1e16a --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/ulec.tex @@ -0,0 +1,348 @@ +\defmodule {ulec} + +This module collects several generators from the papers of +L'Ecuyer and his co-authors. + +%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* ulec.h for ANSI C */ + +#ifndef ULEC_H +#define ULEC_H +\endhide +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen * ulec_CreateCombLec88 (long S1, long S2); +\endcode + \tab Combined generator for 32-bit machines proposed by + L'Ecuyer \cite{rLEC88a}, in its original version. +\index{Generator!L'Ecuyer}\index{Generator!CombLec88}% + The integers $S_1$ and $S_2$ are the seed. + They must satisfy: $0 < S_1 < 2147483563$ and $0 < S_2 < 2147483399$. + \endtab +\code + + +unif01_Gen * ulec_CreateCombLec88Float (long S1, long S2); +\endcode + \tab Same generator as {\tt ulec\_CreateCombLec88}, + but implemented using floating-point arithmetic, as in + {\tt ulcg\_CreateLCGFloat}. + \endtab +\code + + +unif01_Gen * ulec_CreateCLCG4 (long S1, long S2, long S3, long S4); +\endcode + \tab This generator is a combined LCG with four components, +\index{Generator!L'Ecuyer-Andres}\index{Generator!CLCG4}% + with period length near $2^{121}$, + proposed by L'Ecuyer and Andres \cite{rLEC97d}. + \endtab +\code + + +unif01_Gen * ulec_CreateCLCG4Float (long S1, long S2, long S3, long S4); +\endcode + \tab Same generator as {\tt ulec\_CreateCLCG4}, + but implemented using floating-point arithmetic. + \endtab +\code + + +unif01_Gen * ulec_CreateMRG93 (long S1, long S2, long S3, long S4, long S5); +\endcode + \tab MRG of order 5, with modulus $m=2^{31}-1$, multipliers + $a_1 = 107374182$, $a_2 = a_3 = a_4 = 0$, $a_5 = 104480$, + and period length $m^5-1$, proposed by + L'Ecuyer, Blouin, and Couture \cite{rLEC93a}, page 97. +\index{Generator!L'Ecuyer-Blouin-Couture}\index{Generator!MRG93}% + The integers {\tt S1} to {\tt S5} are the seed. + They must be non-negative and not all zero. + \endtab +\code + + +unif01_Gen * ulec_CreateCombMRG96 (long S11, long S12, long S13, + long S21, long S22, long S23); +\endcode + \tab Combined MRG proposed by L'Ecuyer \cite{rLEC96b}, implemented + in integer arithmetic using the {\tt long} type. + This generator combines two MRGs of order 3 with distinct prime +\index{Generator!CombMRG96}% + moduli less than $2^{\,31}$. + The six parameters of the function make the seed. + They must all be non-negative, the first three not all zero, + and the last three not all zero. + \endtab +\code + + +unif01_Gen * ulec_CreateCombMRG96Float (long S11, long S12, long S13, + long S21, long S22, long S23); +\endcode + \tab Same as {\tt ulec\_CreateCombMRG96}, except that the implementation + is in floating-point arithmetic. + \endtab +\code + + +unif01_Gen * ulec_CreateCombMRG96D (long S11, long S12, long S13, + long S21, long S22, long S23); +\endcode + \tab Similar to {\tt ulec\_CreateCombMRG96}, except that the + generator has ``double'' precision. Two successive output values + $u_i$ of the {\tt ulec\_CreateCombMRG96} generator are used to build each + output value $U_i$ (uniform on [0, 1)) of this generator, as follows: + $$ + U_{i} = \left(u_{2i} + \frac{u_{2i+1}}{2^{\,24}}\right) \mod 1. + $$ + \endtab +\code + + +unif01_Gen * ulec_CreateCombMRG96FloatD (long S11, long S12, long S13, + long S21, long S22, long S23); +\endcode + \tab Similar to {\tt ulec\_CreateCombMRG96Float}, except that the + generator has ``double'' precision. Two successive output values + $u_i$ of the {\tt ulec\_CreateCombMRG96Float} generator are used + to build each + output value $U_i$ (uniform on [0, 1)) of this generator, as follows: + $$ + U_{i} = \left(u_{2i} + \frac{u_{2i+1}}{2^{\,24}}\right) \mod 1. + $$ + \endtab +\code + + +unif01_Gen * ulec_CreateMRG32k3a (double x10, double x11, double x12, + double x20, double x21, double x22); +\endcode + \tab Implements the combined MRG {\tt MRG32k3a} + proposed by L'Ecuyer \cite{rLEC99b}. +\index{Generator!MRG32k3a}% + Its period length is near $2^{\,191}$. + This is a floating-point implementation. + The six parameters represent the initial state and must be all + {\em integers\/} represented as {\tt double}'s. The first three must + be integers in [0, 4294967086] and not all 0. The last three must + be integers in [0, 4294944442] and not all 0. + \endtab +\code + + +unif01_Gen * ulec_CreateMRG32k3aL (long x10, long x11, long x12, + long x20, long x21, long x22); +\endcode + \tab Same as {\tt MRG32k3a} above, + but implemented assuming 64-bit {\tt long} integers. +\index{Generator!MRG32k3a}% + \endtab +\code + + +unif01_Gen * ulec_CreateMRG32k3b (double x10, double x11, double x12, + double x20, double x21, double x22); +\endcode + \tab Similar to {\tt ulec\_CreateMRG32k3a} but implements +\index{Generator!Wichmann-Hill}\index{Generator!MRG32k3b}% + the Wichmann-Hill variant. + \endtab +\code + + +unif01_Gen * ulec_CreateMRG32k5a (double x10, double x11, double x12, + double x13, double x14, double x20, + double x21, double x22, double x23, + double x24); +\endcode + \tab Implements the combined MRG {\tt MRG32k5a} + proposed by L'Ecuyer \cite{rLEC99b}. +\index{Generator!MRG32k5a}% + Its period length is near $2^{\,319}$. + This is a floating-point implementation. + \endtab +\code + + +unif01_Gen * ulec_CreateMRG32k5b (double x10, double x11, double x12, + double x13, double x14, double x20, + double x21, double x22, double x23, + double x24); +\endcode + \tab Similar to {\tt ulec\_CreateMRG32k5b} but implements +\index{Generator!MRG32k5b}\index{Generator!Wichmann-Hill}% + the Wichmann-Hill variant. + \endtab +\code + + +#ifdef USE_LONGLONG +unif01_Gen * ulec_CreateMRG63k3a (longlong s10, longlong s11, longlong s12, + longlong s20, longlong s21, longlong s22); +\endcode + \tab Implements the combined MRG {\tt MRG63k3a} + proposed by L'Ecuyer \cite{rLEC99b}. +\index{Generator!MRG63k3a}% + Uses 64-bit integers (see {\tt gdef.h}) + and works only if that type is fully supported by the compiler. + \endtab +\code + + +unif01_Gen * ulec_CreateMRG63k3b (longlong s10, longlong s11, longlong s12, + longlong s20, longlong s21, longlong s22); +\endcode + \tab Similar to {\tt ulec\_CreateMRG63k3a} +\index{Generator!Wichmann-Hill}% + but implements the Wichmann-Hill variant. + \endtab +\code +#endif + + +unif01_Gen * ulec_Createlfsr88 (unsigned int s1, unsigned int s2, + unsigned int s3); +\endcode + \tab Combined Tausworthe generator proposed by L'Ecuyer \cite{rLEC96a}, + with period length near $2^{\,88}$. The initial seeds \texttt{s1, s2, s3} + must be greater or equal than 2, 8, and 16 respectively. +\index{Generator!lfsr88}% + \endtab +\code + + +unif01_Gen * ulec_Createlfsr113 (unsigned int s1, unsigned int s2, + unsigned int s3, unsigned int s4); +\endcode + \tab Combined Tausworthe generator proposed by L'Ecuyer \cite{rLEC99a}, + with period length near $2^{113}$. Restrictions: the initial seeds +\index{Generator!lfsr113}% + \texttt{s1, s2, s3, s4} + must be greater or equal than 2, 8, 16, and 128 respectively. + \endtab +\code + + +#ifdef USE_LONGLONG +unif01_Gen * ulec_Createlfsr258 (ulonglong s1, ulonglong s2, ulonglong s3, + ulonglong s4, ulonglong s5); +#endif +\endcode + \tab Combined Tausworthe generator proposed by L'Ecuyer \cite{rLEC99a}, +\index{Generator!lfsr258}% + with period length near $2^{258}$. + This implementation uses 64-bits integers (see {\tt gdef.h}), + and works only with machines and compilers that support them. + Restrictions: the initial seeds \texttt{s1, s2, s3, s4, s5} + must be greater or equal than 2, 512, 4096, 131072 and 8388608 respectively. + \endtab +\code + + +unif01_Gen * ulec_CreateCombTausLCG11 (unsigned int k, unsigned int q, + unsigned int s, unsigned S1, + long m, long a, long c, long S2); +\endcode + \tab Combines a Tausworthe generator of parameters + $(k, q, s)$ and initial state {\tt S1} with an LCG + of parameters $(m, a, c)$ and initial state {\tt S2}. + The combination is made via addition modulo 1 of the outputs + of the two generators. + \endtab +\code + + +unif01_Gen * ulec_CreateCombTausLCG21 (unsigned int k1, unsigned int q1, + unsigned int s1, unsigned int Y1, + unsigned int k2, unsigned int q2, + unsigned int s2, unsigned int Y2, + long m, long a, long c, long Y3); +\endcode + \tab Combines a combined Tausworthe generator with two components + of parameters + $(k_1, q_1, s_1)$, $(k_2, q_2, s_2)$ and initial states + {\tt Y1, Y2}, with a LCG of parameters + $(m, a, c)$ and initial state {\tt Y3}. + The combination is made by addition modulo 1 of the outputs + of the two generators. + \endtab +\code + + +unif01_Gen * ulec_CreateMRG31k3p (long x10, long x11, long x12, + long x20, long x21, long x22); +\endcode + \tab Implements the combined MRG with two components of order 3 + named {\tt MRG31k3p} by L'Ecuyer and Touzin \cite{rLEC00b}. +\index{Generator!MRG31k3p}% + The two components have parameters $(m$, $a_1$, $a_2$, $a_3)$ equal to + $(2^{31} - 1$, $0$, $2^{22}$, $2^7 +1)$ and + $(2^{31} - 21069$, $2^{15}$, $0$, $2^{15} +1)$. + Its period length is close to $2^{\,185}$ and the six parameters + represent the initial state. Restrictions: + $0 \le {}$ {\tt x10}, {\tt x11}, {\tt x12} ${} < 2147483647$ and not all 0, + and $0 \le {}$ {\tt x20}, {\tt x21}, {\tt x22} ${} < 2147462579$ + and not all 0. + \endtab + +\guisec{Clean-up functions} + + +\code +void ulec_DeleteCombTausLCG11 (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory allocated by + {\tt ulec\_CreateCombTausLCG11}. + \endtab +\code + + +void ulec_DeleteCombTausLCG21 (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory allocated by + {\tt ulec\_CreateCombTausLCG21}. + \endtab +\code + + +void ulec_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called when a generator + is no longer in use. + \endtab +\code +\hide +#endif +\endhide +\endcode + + +\iffalse %%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\bigskip + +{ +See also +\bigskip + +\setlength{\partopsep}{0pt} +\setlength{\parskip}{0pt} +\setlength{\topsep}{0pt} +\setlength{\itemsep}{0pt} + +\begin{itemize} +\item {\tt utezu\_CreateTezLec91} +\end{itemize} +} +\fi %%%%%%%%%% diff --git a/TESTU01/TestU01-1.2.3/testu01/umarsa.c b/TESTU01/TestU01-1.2.3/testu01/umarsa.c new file mode 100644 index 0000000..db8fc51 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/umarsa.c @@ -0,0 +1,1593 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: umarsa.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" + +#include "umarsa.h" +#include "unif01.h" + +#include +#include +#include +#include + + + + + +/*============================== Constants ==============================*/ + +#define LEN 200 /* Max length of strings */ + +#define MASK8 0xff /* Mask of 8 bits */ +#define MASK16 0xffff /* Mask of 16 bits */ +#define MASK31 0x7fffffffU /* Mask of 31 bits */ +#define MASK32 0xffffffffUL /* Mask of 32 bits */ +#define MA 4294967291UL /* 2^32 - 5 */ + +#define INV32L 2.32830643653869628906250E-10L /* 1 / 2^32 */ +#define INV32 2.3283064365386963E-10 /* 1 / 2^32 */ +#define INV32m1 2.3283064370807973E-10 /* 1 / (2^32 - 1) */ + + + +/*================================ Types ================================*/ + +typedef struct { + unsigned int S1, S2, S3, S4, carry; +} KISS_state; + + +typedef struct { + unsigned int r, s; /* Lags */ + unsigned int C; /* Carry */ + unsigned int X[43]; + unsigned int W; /* State of the Weyl generator */ +} Marsa90a_state; + + +typedef struct { + double SeqD, SeqM; +} RANMAR_param; + + +typedef struct { + double X[98]; + unsigned int r, s; + double Seq; +} RANMAR_state; + + +#ifdef USE_LONGLONG +typedef struct { + ulonglong S1, S2, S3, S4; /* State */ + ulonglong C; /* Carry */ +} Mother0_state; +#endif + +typedef struct { + unsigned long X1, X2, Y1; +} Combo_state; + + +typedef struct { + double X1, X2, X3; +} ECG_state; + +typedef struct { + double Norm; +} ECG_param; + + +typedef struct{ + unsigned int I1, I2; +} MWC97R_state; + + +typedef struct{ + unsigned int X[256]; + unsigned int r; + unsigned int b; +} LFIB4_99_state; + +#define ULTRA_R 99 + +typedef struct { + unsigned long X[1 + ULTRA_R]; + int r, s; + unsigned long I; +} ULTRA_state; + + +#ifdef USE_LONGLONG +typedef struct{ + ulonglong x, y; +} SupDup64_state; + +typedef struct{ + ulonglong a, c; + unsigned int s1, s2, s3; +} SupDup64_param; +#endif + + +typedef MWC97R_state FIB_99_state; +typedef MWC97R_state SupDup73_state; +typedef MWC97R_state SupDup96_state; +typedef LFIB4_99_state SWB_99_state; + + + + + +/*============================== Functions ==============================*/ + + + +static unsigned long KISS93_Bits (void *junk, void *vsta) +{ + KISS_state *state = vsta; + unsigned int b; + + state->S1 = 69069 * state->S1 + 23606797; + b = state->S2 ^ (state->S2 << 17); + state->S2 = (b >> 15) ^ b; + b = ((state->S3 << 18) ^ state->S3) & MASK31; + state->S3 = (b >> 13) ^ b; + return state->S1 + state->S2 + state->S3; +} + +/*-----------------------------------------------------------------------*/ + +static double KISS93_U01 (void *vpar, void *vsta) +{ + return KISS93_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrKISS93 (void *vsta) +{ + KISS_state *state = vsta; + printf (" x0 = %1u, y0 = %1u, z0 = %1u\n\n", + state->S1, state->S2, state->S3); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateKISS93 (unsigned int s1, unsigned int s2, + unsigned int s3) +{ + unif01_Gen *gen; + KISS_state *state; + size_t leng; + char name[LEN + 1]; + + if (s3 > 2147483647) + util_Error ("umarsa_CreateKISS93: s3 >= 2^31"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (KISS_state)); + + strcpy (name, "umarsa_CreateKISS93:"); + addstr_Uint (name, " x0 = ", s1); + addstr_Uint (name, ", y0 = ", s2); + addstr_Uint (name, ", z0 = ", s3); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = s1; + state->S2 = s2; + state->S3 = s3; + + gen->GetBits = &KISS93_Bits; + gen->GetU01 = &KISS93_U01; + gen->Write = &WrKISS93; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static unsigned long KISS96_Bits (void *junk, void *vsta) +{ + KISS_state *state = vsta; + unsigned int y, k; + + state->S1 = 69069 * state->S1 + 1; + y = state->S2 ^ (state->S2 << 13); + y ^= y >> 17; + state->S2 = y ^ (y << 5); + k = (state->S3 >> 2) + (state->S4 >> 3) + (state->carry >> 2); + y = state->S4 + state->S4 + state->S3 + state->carry; + state->S3 = state->S4; + state->S4 = y; + state->carry = k >> 30; + return state->S1 + state->S2 + state->S4; +} + +/*-----------------------------------------------------------------------*/ + +static double KISS96_U01 (void *vpar, void *vsta) +{ + return KISS96_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrKISS96 (void *vsta) +{ + KISS_state *state = vsta; + printf (" x = %u, y = %u, z1 = %u, z2 = %u\n\n", + state->S1, state->S2, state->S3, state->S4); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateKISS96 (unsigned int x, unsigned int y, + unsigned int z1, unsigned int z2) +{ + unif01_Gen *gen; + KISS_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (KISS_state)); + + strcpy (name, "umarsa_CreateKISS96:"); + addstr_Uint (name, " x = ", x); + addstr_Uint (name, ", y = ", y); + addstr_Uint (name, ", z1 = ", z1); + addstr_Uint (name, ", z2 = ", z2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = x; + state->S2 = y; + state->S3 = z1; + state->S4 = z2; + state->carry = 0; + + gen->GetBits = &KISS96_Bits; + gen->GetU01 = &KISS96_U01; + gen->Write = &WrKISS96; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static unsigned long KISS99_Bits (void *junk, void *vsta) +{ + KISS_state *state = vsta; + unsigned int b; + + state->S1 = 69069 * state->S1 + 1234567; + b = state->S2 ^ (state->S2 << 17); + b ^= (b >> 13); + state->S2 = b ^ (b << 5); + state->S3 = 36969 * (state->S3 & MASK16) + (state->S3 >> 16); + state->S4 = 18000 * (state->S4 & MASK16) + (state->S4 >> 16); + b = (state->S3 << 16) + state->S4; + return state->S2 + (state->S1 ^ b); +} + +/*-----------------------------------------------------------------------*/ + +static double KISS99_U01 (void *vpar, void *vsta) +{ + return KISS99_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrKISS99 (void *vsta) +{ + KISS_state *state = vsta; + printf (" x = %1u, y = %1u, I1 = %1u, I2 = %1u\n\n", + state->S1, state->S2, state->S3, state->S4); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateKISS99 (unsigned int x, unsigned int y, + unsigned int I1, unsigned int I2) +{ + unif01_Gen *gen; + KISS_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (KISS_state)); + + strcpy (name, "umarsa_CreateKISS99:"); + addstr_Uint (name, " x0 = ", x); + addstr_Uint (name, ", y0 = ", y); + addstr_Uint (name, ", I1 = ", I1); + addstr_Uint (name, ", I2 = ", I2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = x; + state->S2 = y; + state->S3 = I1; + state->S4 = I2; + + gen->GetBits = &KISS99_Bits; + gen->GetU01 = &KISS99_U01; + gen->Write = &WrKISS99; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static unsigned long ULTRA_Bits (void *junk, void *vsta) +{ + ULTRA_state *state = vsta; + unsigned long t; + + state->X[state->r] = state->X[state->r] * state->X[state->s]; + t = state->X[state->r] &= MASK32; + if (--state->r < 0) + state->r = 96; + if (--state->s < 0) + state->s = 96; + + state->I = (state->I & MASK16) * 30903 + (state->I >> 16); + return (t + state->I) & MASK32; +} + +/*-----------------------------------------------------------------------*/ + +static double ULTRA_U01 (void *vpar, void *vsta) +{ + return ULTRA_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrULTRA (void *junk) +{ + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ +/* + * I believe there are errors in that gen, but I have chosen to make it + * output the same numbers as those from the ULTRA in Diehard. The + * Lag Fib is supposed to be of order 99, but the programmed version in + * Diehard uses only 97 elements of the array. + */ +unif01_Gen *umarsa_CreateULTRA (unsigned int x, unsigned int y, + unsigned int z, unsigned int w) +{ + unif01_Gen *gen; + ULTRA_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int js; + int i; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (ULTRA_state)); + + strcpy (name, "umarsa_CreateULTRA:"); + addstr_Uint (name, " s1 = ", x); + addstr_Uint (name, ", s2 = ", y); + addstr_Uint (name, ", s3 = ", z); + addstr_Uint (name, ", s4 = ", w); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->I = x + y + z + w; + for (i = 0; i < 99; ++i) { + x = (x & 65535) * 18273 + (x >> 16); + y = (y & 65535) * 23163 + (y >> 16); + z = (z & 65535) * 24984 + (z >> 16); + w = (w & 65535) * 28854 + (w >> 16); + js = (x << 16) + (y & 65535) + (z << 16) + (w & 65535); + state->X[i] = js | 1; + } + state->r = 98; + state->s = 32; + gen->GetBits = &ULTRA_Bits; + gen->GetU01 = &ULTRA_U01; + gen->Write = &WrULTRA; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static unsigned long SupDup73_Bits (void *junk, void *vsta) +{ + SupDup73_state *state = vsta; + unsigned int b; + + state->I1 = 69069 * state->I1; + b = state->I2 ^ (state->I2 >> 15); + state->I2 = b ^ (b << 17); + return state->I2 ^ state->I1; +} + +/*-----------------------------------------------------------------------*/ + +static double SupDup73_U01 (void *vpar, void *vsta) +{ + return SupDup73_Bits (vpar, vsta) * INV32m1; +} + +/*-----------------------------------------------------------------------*/ + +static void WrSupDup73 (void *vsta) +{ + SupDup73_state *state = vsta; + printf (" x = %1u, y = %1u\n\n", state->I1, state->I2); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateSupDup73 (unsigned int x, unsigned int y) +{ + unif01_Gen *gen; + SupDup73_state *state; + size_t leng; + char name[LEN + 1]; + + + util_Warning (!(x & 1), "umarsa_CreateSupDup73: x reset to odd"); + x |= 1; + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (SupDup73_state)); + state->I1 = x; + state->I2 = y; + + strcpy (name, "umarsa_CreateSupDup73:"); + addstr_Uint (name, " x0 = ", x); + addstr_Uint (name, ", y0 = ", y); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &SupDup73_Bits; + gen->GetU01 = &SupDup73_U01; + gen->Write = &WrSupDup73; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static unsigned long SupDup96ADD_Bits (void *vpar, void *vsta) +{ + SupDup96_state *state = vsta; + unsigned int *pc = vpar; + unsigned int b; + + state->I1 = 69069U * state->I1 + *pc; + b = state->I2 ^ (state->I2 << 13); + b ^= (b >> 17); + state->I2 = b ^ (b << 5); + return state->I2 + state->I1; +} + +/*-----------------------------------------------------------------------*/ + +static double SupDup96ADD_U01 (void *vpar, void *vsta) +{ + return SupDup96ADD_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long SupDup96XOR_Bits (void *vpar, void *vsta) +{ + SupDup96_state *state = vsta; + unsigned int *pc = vpar; + unsigned int b; + + state->I1 = 69069U * state->I1 + *pc; + b = state->I2 ^ (state->I2 << 13); + b ^= (b >> 17); + state->I2 = b ^ (b << 5); + return state->I2 ^ state->I1; +} + +/*-----------------------------------------------------------------------*/ + +static double SupDup96XOR_U01 (void *vpar, void *vsta) +{ + return SupDup96XOR_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrSupDup96 (void *vsta) +{ + SupDup96_state *state = vsta; + printf (" x = %1u, y = %1u\n\n", state->I1, state->I2); +} + +/*-----------------------------------------------------------------------*/ + +static unif01_Gen *CreateSupDup96 (unsigned int x, unsigned int y, + unsigned int c, char op) +{ + unif01_Gen *gen; + SupDup96_state *state; + unsigned int *p; + size_t leng; + char name[LEN + 1]; + + util_Assert (op == '+' || op == 'x', + "umarsa_CreateSupDup96: op must be '+' or 'x'"); + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (SupDup96_state)); + p = util_Malloc (sizeof (unsigned int)); + state->I1 = x; + state->I2 = y; + *p = c | 1; + + if (op == '+') + strcpy (name, "umarsa_CreateSupDup96Add:"); + else + strcpy (name, "umarsa_CreateSupDup96Xor:"); + addstr_Uint (name, " x0 = ", x); + addstr_Uint (name, ", y0 = ", y); + addstr_Uint (name, ", c = ", *p); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (op == 'x') { + gen->GetBits = &SupDup96XOR_Bits; + gen->GetU01 = &SupDup96XOR_U01; + } else { + gen->GetBits = &SupDup96ADD_Bits; + gen->GetU01 = &SupDup96ADD_U01; + } + gen->Write = &WrSupDup96; + gen->param = p; + gen->state = state; + return gen; +} + +unif01_Gen * umarsa_CreateSupDup96Add (unsigned int x0, unsigned int y0, + unsigned int c) +{ + return CreateSupDup96 (x0, y0, c, '+'); +} + +unif01_Gen * umarsa_CreateSupDup96Xor (unsigned int x0, unsigned int y0, + unsigned int c) +{ + return CreateSupDup96 (x0, y0, c, 'x'); +} + +/**************************************************************************/ +#ifdef USE_LONGLONG + +static unsigned long SupDup64ADD_Bits (void *vpar, void *vsta) +{ + SupDup64_state *state = vsta; + SupDup64_param *param = vpar; + ulonglong b; + + state->x = param->a * state->x + param->c; + b = state->y ^ (state->y << param->s1); + b ^= (b >> param->s2); + state->y = b ^ (b << param->s3); + return (state->y + state->x) >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double SupDup64ADD_U01 (void *vpar, void *vsta) +{ + return SupDup64ADD_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long SupDup64XOR_Bits (void *vpar, void *vsta) +{ + SupDup64_state *state = vsta; + SupDup64_param *param = vpar; + ulonglong b; + + state->x = param->a * state->x + param->c; + b = state->y ^ (state->y << param->s1); + b ^= b >> param->s2; + state->y = b ^ (b << param->s3); + return (state->y ^ state->x) >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double SupDup64XOR_U01 (void *vpar, void *vsta) +{ + return SupDup64XOR_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrSupDup64 (void *vsta) +{ + SupDup64_state *state = vsta; + printf (" x = %1" PRIuLEAST64 ", y = %1" PRIuLEAST64 "\n\n", + state->x, state->y); +} + +/*-----------------------------------------------------------------------*/ + +static unif01_Gen *CreateSupDup64 (ulonglong x, ulonglong y, ulonglong a, + ulonglong c, int s1, int s2, int s3, char op) +{ + unif01_Gen *gen; + SupDup64_state *state; + SupDup64_param *param; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (SupDup64_state)); + param = util_Malloc (sizeof (SupDup64_param)); + state->x = x; + state->y = y; + param->a = a; + param->c = c; + param->s1 = s1; + param->s2 = s2; + param->s3 = s3; + + util_Assert ((a % 8 == 3) || (a % 8 == 5), + "umarsa_CreateSupDup64: a must be 3 mod 8 or 5 mod 8"); + if (op == '+') + strcpy (name, "umarsa_CreateSupDup64Add:"); + else + strcpy (name, "umarsa_CreateSupDup64Xor:"); + addstr_ULONG (name, " x0 = ", x); + addstr_ULONG (name, ", y0 = ", y); + addstr_ULONG (name, ", a = ", a); + addstr_ULONG (name, ", c = ", c); + addstr_Uint (name, ", s1 = ", (unsigned int) s1); + addstr_Uint (name, ", s2 = ", (unsigned int) s2); + addstr_Uint (name, ", s3 = ", (unsigned int) s3); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (op == 'x') { + gen->GetBits = &SupDup64XOR_Bits; + gen->GetU01 = &SupDup64XOR_U01; + } else { + gen->GetBits = &SupDup64ADD_Bits; + gen->GetU01 = &SupDup64ADD_U01; + } + gen->Write = &WrSupDup64; + gen->param = param; + gen->state = state; + return gen; +} + +unif01_Gen * umarsa_CreateSupDup64Add (ulonglong x, ulonglong y, ulonglong a, + ulonglong c, int s1, int s2, int s3) +{ + return CreateSupDup64 (x, y, a, c, s1, s2, s3, '+'); +} + +unif01_Gen * umarsa_CreateSupDup64Xor (ulonglong x, ulonglong y, ulonglong a, + ulonglong c, int s1, int s2, int s3) +{ + return CreateSupDup64 (x, y, a, c, s1, s2, s3, 'x'); +} + +#endif +/**************************************************************************/ + +static unsigned long Marsa90a_Bits (void *junk, void *vsta) +{ + Marsa90a_state *state = vsta; + unsigned int x, y; + + x = state->X[state->s]; + y = state->X[state->r] + state->C; + if (x < y) { + x += (MA - y); + state->C = 1; + } else { + x -= y; + state->C = 0; + } + state->X[state->r] = x; + state->r = (state->r + 1) % 43; + state->s = (state->s + 1) % 43; + + state->W -= 362436069; + return x - state->W; +} + +/*-----------------------------------------------------------------------*/ + +static double Marsa90a_U01 (void *vpar, void *vsta) +{ + return Marsa90a_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrMarsa90a (void *vsta) +{ + Marsa90a_state *state = vsta; + int j; + + if (unif01_WrLongStateFlag) { + printf (" X = {\n"); + for (j = 0; j < 43; j++) { + printf (" %10u\n", state->X[j]); + } + printf (" }\n\n Weyl: W = %10u\n", state->W); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateMarsa90a (int s1, int s2, int s3, int s4, + unsigned int s5) +{ + unif01_Gen *gen; + Marsa90a_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int s; + unsigned int t, M, j; + + /* For the generation of the 43 first values of the SWB generator, */ + /* ACARRYPC uses a combination of a 3-Lag Fibonacci generator */ + /* with a LCG generator LCG. */ + + if ((s1 >= 179) || (s2 >= 179) || (s3 >= 179) || + (s1 <= 0) || (s2 <= 0) || (s3 <= 0) || (s4 >= 169)) + util_Error ("umarsa_CreateMarsa90a: Invalid parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (Marsa90a_state)); + + strcpy (name, "umarsa_CreateMarsa90a:"); + addstr_Uint (name, " y1 = ", (unsigned) s1); + addstr_Uint (name, ", y2 = ", (unsigned) s2); + addstr_Uint (name, ", y3 = ", (unsigned) s3); + addstr_Uint (name, ", z0 = ", (unsigned) s4); + addstr_Uint (name, ", Y0 = ", s5); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->r = 0; + state->s = 21; + for (j = 0; j < 43; j++) { + s = 0; + for (t = 0; t < 32; t++) { + M = (((s1 * s2) % 179) * s3) % 179; + s1 = s2; + s2 = s3; + s3 = M; + s4 = ((53 * s4) + 1) % 169; + if (((s4 * M) % 64) >= 32) + s |= 1 << t; + } + state->X[j] = s % MA; + } + M = (((s1 * s2) % 179) * s3) % 179; + s1 = s2; + s2 = s3; + s3 = M; + s4 = ((53 * s4) + 1) % 169; + if (((s4 * M) % 64) >= 32) + state->C = 1; + else + state->C = 0; + state->W = s5; + + gen->GetBits = &Marsa90a_Bits; + gen->GetU01 = &Marsa90a_U01; + gen->Write = &WrMarsa90a; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static double RANMAR_U01 (void *vpar, void *vsta) +/* + * Generator proposed by G. Marsaglia. Combines a lag-Fibonacci generator + * F(97,33,-) with the following arithmetic sequence modulo (2^24 - 3): I + * - k, I - 2k, I - 3k,... (for an initial integer I). + */ +{ + RANMAR_state *state = vsta; + RANMAR_param *param = vpar; + double temp; + + temp = state->X[state->r] - state->X[state->s]; + if (temp < 0.0) + temp += 1.0; + state->X[state->r] = temp; + + state->r--; + if (state->r == 0) + state->r = 97; + + state->s--; + if (state->s == 0) + state->s = 97; + + state->Seq -= param->SeqD; + if (state->Seq < 0.0) + state->Seq += param->SeqM; + temp -= state->Seq; + if (temp < 0.0) + return temp + 1.0; + return temp; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long RANMAR_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (RANMAR_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrRANMAR (void *vsta) +{ + RANMAR_state *state = vsta; + int j; + + if (unif01_WrLongStateFlag) { + printf (" X = {\n"); + for (j = 1; j <= 97; j++) { + printf (" %12.9f\n", state->X[j]); + } + printf (" }\n\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateRANMAR (int s1, int s2, int s3, int s4) +/* + * For the generation of its 97 first values, Marsa90 uses + * a combination of a 3-Lag Fib. gen. with a LCG gen. + */ +{ + unif01_Gen *gen; + RANMAR_state *state; + RANMAR_param *param; + size_t leng; + char name[LEN + 1]; + double s, t; + unsigned int M, k, j; + + + if ((s1 >= 179) || (s2 >= 179) || (s3 >= 179) || + (s1 <= 0) || (s2 <= 0) || (s3 <= 0) || (s4 >= 169)) { + util_Error ("umarsa_CreateRANMAR: Invalid parameter"); + } + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (RANMAR_state)); + param = util_Malloc (sizeof (RANMAR_param)); + + strcpy (name, "umarsa_CreateRANMAR:"); + addstr_Uint (name, " y1 = ", (unsigned) s1); + addstr_Uint (name, ", y2 = ", (unsigned) s2); + addstr_Uint (name, ", y3 = ", (unsigned) s3); + addstr_Uint (name, ", z0 = ", (unsigned) s4); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->r = 97; + state->s = 33; + state->Seq = 362436.0 / 16777216.0; + param->SeqD = 7654321.0 / 16777216.0; + param->SeqM = 16777213.0 / 16777216.0; + + for (j = 1; j <= 97; j++) { + s = 0.0; + t = 0.5; + for (k = 1; k <= 24; k++) { + M = (((s1 * s2) % 179) * s3) % 179; + s1 = s2; + s2 = s3; + s3 = M; + s4 = ((53 * s4) + 1) % 169; + if (((s4 * M) % 64) >= 32) + s += t; + t *= 0.5; + } + state->X[j] = s; + } + + gen->GetBits = &RANMAR_Bits; + gen->GetU01 = &RANMAR_U01; + gen->Write = &WrRANMAR; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ +#ifdef USE_LONGLONG + +static unsigned long Mother0_Bits (void *junk, void *vsta) +{ + Mother0_state *state = vsta; + ulonglong V; + + V = 2111111111ULL * state->S1 + 1492ULL * state->S2 + 1776ULL * state->S3 + + 5115ULL * state->S4 + state->C; + state->S1 = state->S2; + state->S2 = state->S3; + state->S3 = state->S4; + state->S4 = V & MASK32; + state->C = V >> 32; + return state->S4; +} + +/*-----------------------------------------------------------------------*/ + +static double Mother0_U01 (void *vpar, void *vsta) +{ + return Mother0_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrMother0 (void *vsta) +{ + Mother0_state *state = vsta; + printf + (" (S1, S2, S3, S4, C) = ( %1" PRIuLEAST64 ", %1" PRIuLEAST64 ", %1" + PRIuLEAST64 ",\n" " %1" PRIuLEAST64 + ", %1" PRIuLEAST64 " )\n", + state->S1, state->S2, state->S3, state->S4, state->C); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateMother0 (unsigned long s1, unsigned long s2, + unsigned long s3, unsigned long s4, unsigned long c) +{ + unif01_Gen *gen; + Mother0_state *state; + size_t leng; + char name[LEN + 1]; + + if (c > 2111119494) { + util_Error ("umarsa_CreateMother0: Invalid parameter"); + } + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (Mother0_state)); + + strcpy (name, "umarsa_CreateMother0:"); + addstr_Ulong (name, " x1 = ", s1); + addstr_Ulong (name, ", x2 = ", s2); + addstr_Ulong (name, ", x3 = ", s3); + addstr_Ulong (name, ", x4 = ", s4); + addstr_Ulong (name, ", c = ", c); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = s1; + state->S2 = s2; + state->S3 = s3; + state->S4 = s4; + state->C = c; + + gen->GetBits = &Mother0_Bits; + gen->GetU01 = &Mother0_U01; + gen->Write = &WrMother0; + gen->param = NULL; + gen->state = state; + return gen; +} + + +#endif +/*****************************************************************************/ + +static unsigned long Combo_Bits (void *junk, void *vsta) +{ + Combo_state *state = vsta; + unsigned long V, Z; + + V = (state->X1 * state->X2) & MASK32; + state->X1 = state->X2; + state->X2 = V; + Z = state->Y1; + state->Y1 = 30903 * (MASK16 & Z); + state->Y1 = (state->Y1 + (Z >> 16)) & MASK32; + return (state->X2 + state->Y1) & MASK32; +} + +/*-----------------------------------------------------------------------*/ + +static double Combo_U01 (void *vpar, void *vsta) +{ + return Combo_Bits (vpar, vsta) * INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrCombo (void *vsta) +{ + Combo_state *state = vsta; + printf (" (x1, x2, y1, c) = ( %1lu, %1lu, %1lu, %1lu )\n\n", + state->X1, state->X2, state->Y1 % 65536, state->Y1 / 65536); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateCombo (unsigned int x1, unsigned int x2, + unsigned int y1, unsigned int c) +{ + unif01_Gen *gen; + Combo_state *state; + size_t leng; + char name[LEN + 1]; + + if ((y1 >= 65536) || (c > 30903)) { + util_Error ("umarsa_CreateCombo: Invalid parameter"); + } + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (Combo_state)); + + strcpy (name, "umarsa_CreateCombo:"); + addstr_Uint (name, " x1 = ", x1); + addstr_Uint (name, ", x2 = ", x2); + addstr_Uint (name, ", y1 = ", y1); + addstr_Uint (name, ", c = ", c); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->X1 = 2 * x1 + 1; + state->X1 = 3 * state->X1 * state->X1; + state->X2 = 2 * x2 + 1; + state->Y1 = y1 + c; + + gen->GetBits = &Combo_Bits; + gen->GetU01 = &Combo_U01; + gen->Write = &WrCombo; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/***************************************************************************/ + +static double ECG1_U01 (void *vpar, void *vsta) +{ + ECG_state *state = vsta; + ECG_param *param = vpar; + double y; + + y = 65065.0 * state->X1 + 67067.0 * state->X2 + 69069.0 * state->X3; + y = fmod (y, param->Norm); + state->X1 = state->X2; + state->X2 = state->X3; + state->X3 = y; + return (y / param->Norm); +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long ECG1_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (ECG1_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static double ECG2_U01 (void *vpar, void *vsta) +{ + ECG_param *param = vpar; + ECG_state *state = vsta; + double y; + + y = 1024.0 * (state->X1 + state->X2 + state->X3); + y = fmod (y, param->Norm); + state->X1 = state->X2; + state->X2 = state->X3; + state->X3 = y; + return (y / param->Norm); +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long ECG2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (ECG2_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static double ECG3_U01 (void *vpar, void *vsta) +{ + ECG_param *param = vpar; + ECG_state *state = vsta; + double y; + + y = 2000.0 * state->X1 + 1950.0 * state->X2 + 1900.0 * state->X3; + y = fmod (y, param->Norm); + state->X1 = state->X2; + state->X2 = state->X3; + state->X3 = y; + return (y / param->Norm); +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long ECG3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (ECG3_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static double ECG4_U01 (void *vpar, void *vsta) +{ + ECG_param *param = vpar; + ECG_state *state = vsta; + double y; + + y = 1048576.0 * (state->X1 + state->X2 + state->X3); + y = fmod (y, param->Norm); + state->X1 = state->X2; + state->X2 = state->X3; + state->X3 = y; + return (y / param->Norm); +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long ECG4_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (ECG4_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrECG (void *vsta) +{ + ECG_state *state = vsta; + printf (" X1 = %12.0f, X2 = %12.0f, X3 = %12.0f\n\n", + state->X1, state->X2, state->X3); +} + +/*-----------------------------------------------------------------------*/ + +static unif01_Gen *CreateECG (char *nom, unsigned int x1, unsigned int x2, + unsigned int x3) +{ + unif01_Gen *gen; + ECG_param *param; + ECG_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (ECG_state)); + param = util_Malloc (sizeof (ECG_param)); + + strcpy (name, nom); + addstr_Uint (name, " x1 = ", x1); + addstr_Uint (name, ", x2 = ", x2); + addstr_Uint (name, ", x3 = ", x3); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->X1 = x1; + state->X2 = x2; + state->X3 = x3; + + gen->Write = &WrECG; + gen->param = param; + gen->state = state; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateECG1 (unsigned int x1, unsigned int x2, + unsigned int x3) +{ + unif01_Gen *gen; + ECG_param *param; + + gen = CreateECG ("umarsa_CreateECG1:", x1, x2, x3); + param = gen->param; + param->Norm = 4294967291.0; + gen->GetBits = &ECG1_Bits; + gen->GetU01 = &ECG1_U01; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateECG2 (unsigned int x1, unsigned int x2, + unsigned int x3) +{ + unif01_Gen *gen; + ECG_param *param; + + gen = CreateECG ("umarsa_CreateECG2:", x1, x2, x3); + param = gen->param; + param->Norm = 4294967291.0; + gen->GetBits = &ECG2_Bits; + gen->GetU01 = &ECG2_U01; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateECG3 (unsigned int x1, unsigned int x2, + unsigned int x3) +{ + unif01_Gen *gen; + ECG_param *param; + + gen = CreateECG ("umarsa_CreateECG3:", x1, x2, x3); + param = gen->param; + param->Norm = 4294967087.0; + gen->GetBits = &ECG3_Bits; + gen->GetU01 = &ECG3_U01; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateECG4 (unsigned int x1, unsigned int x2, + unsigned int x3) +{ + unif01_Gen *gen; + ECG_param *param; + + gen = CreateECG ("umarsa_CreateECG4:", x1, x2, x3); + param = gen->param; + param->Norm = 4294967087.0; + gen->GetBits = &ECG4_Bits; + gen->GetU01 = &ECG4_U01; + return gen; +} + + +/*****************************************************************************/ + +static unsigned long MWC97R_Bits (void *junk, void *sta) +{ + MWC97R_state *state = sta; + state->I1 = 36969 * (state->I1 & MASK16) + (state->I1 >> 16); + state->I2 = 18000 * (state->I2 & MASK16) + (state->I2 >> 16); + return (state->I1 << 16) + (state->I2 & MASK16); +} + +/*-----------------------------------------------------------------------*/ + +static double MWC97R_U01 (void *par, void *sta) +{ + return MWC97R_Bits (par, sta) * 2.328306437080797e-10; +} + +/*-----------------------------------------------------------------------*/ + +static void WrMWC97R (void *sta) +{ + MWC97R_state *state = sta; + printf (" I1 = %u, I2 = %u\n", state->I1, state->I2); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateMWC97R (unsigned int I1, unsigned int I2) +{ + unif01_Gen *gen; + MWC97R_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + gen->state = state = util_Malloc (sizeof (MWC97R_state)); + state->I1 = I1; + state->I2 = I2; + gen->param = NULL; + gen->Write = WrMWC97R; + gen->GetU01 = MWC97R_U01; + gen->GetBits = MWC97R_Bits; + + strcpy (name, "umarsa_CreateMWC97R:"); + addstr_Uint (name, " x0 = ", I1); + addstr_Uint (name, ", y0 = ", I2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + return gen; +} + + +/***************************************************************************/ + +static unsigned long LFIB4_99_Bits (void *junk, void *vsta) +{ + LFIB4_99_state *state = vsta; + + ++state->r; + state->r &= MASK8; + state->X[state->r] += state->X[(state->r + 58) & MASK8] + + state->X[(state->r + 119) & MASK8] + state->X[(state->r + 178) & MASK8]; + return state->X[state->r]; +} + +/*-------------------------------------------------------------------------*/ + +static double LFIB4_99_U01 (void *vpar, void *vsta) +{ + return LFIB4_99_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrLFIB4_99 (void *vsta) +{ + LFIB4_99_state *state = vsta; + unsigned int j; + + if (unif01_WrLongStateFlag) { + printf ("T = {\n"); + for (j = 0; j < 256; j++) { + printf (" %12u", state->X[(state->r + j) & MASK8]); + if (j < 255) + printf (","); + if (((j + 1) % 5) == 0) + printf ("\n"); + }; + printf ("\n};\n"); + } else + unif01_WrLongStateDef (); +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *umarsa_Create4LFIB99 (unsigned int T[256]) +{ + unif01_Gen *gen; + LFIB4_99_state *state; + size_t leng; + char name[LEN + 1]; + int j; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (LFIB4_99_state)); + + strcpy (name, "umarsa_Create4LFIB99:"); + addstr_ArrayUint (name, " T = ", 256, T); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->r = 0; + gen->GetBits = &LFIB4_99_Bits; + gen->GetU01 = &LFIB4_99_U01; + + for (j = 0; j < 256; j++) { + state->X[j] = T[j]; + } + gen->param = NULL; + gen->state = state; + gen->Write = &WrLFIB4_99; + + return gen; +} + + +/***************************************************************************/ + +static unsigned long SHR3_99_Bits (void *junk, void *sta) +{ + unsigned long *I1 = sta; + unsigned long t = *I1; + + t ^= t << 17; +#ifndef IS_ULONG32 + t &= MASK32; +#endif + t ^= t >> 13; + t ^= t << 5; + *I1 = t & MASK32; + return *I1; +} + +/*-----------------------------------------------------------------------*/ + +static double SHR3_99_U01 (void *par, void *sta) +{ + return SHR3_99_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrSHR3_99 (void *sta) +{ + unsigned long *I1 = sta; + printf (" x = %lu\n", *I1); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *umarsa_Create3SHR99 (unsigned int I1) +{ + unif01_Gen *gen; + unsigned long *p1; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + p1 = gen->state = util_Malloc (sizeof (unsigned long)); + *p1 = I1; + gen->param = NULL; + gen->Write = WrSHR3_99; + gen->GetU01 = SHR3_99_U01; + gen->GetBits = SHR3_99_Bits; + + strcpy (name, "umarsa_Create3SHR99:"); + addstr_Uint (name, " x0 = ", I1); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + return gen; +} + + +/***************************************************************************/ + +static unsigned long SWB_99_Bits (void *junk, void *vsta) +{ + SWB_99_state *state = vsta; + + ++state->r; + state->r &= MASK8; + state->b = (state->X[(state->r + 33) & MASK8] < + state->X[(state->r + 18) & MASK8] + state->b) ? 1 : 0; + state->X[state->r] = state->X[(state->r + 34) & MASK8] + - state->X[(state->r + 19) & MASK8] - state->b; + return state->X[state->r]; +} + +/*-------------------------------------------------------------------------*/ + +static double SWB_99_U01 (void *vpar, void *vsta) +{ + return SWB_99_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrSWB_99 (void *vsta) +{ + SWB_99_state *state = vsta; + unsigned int j; + + if (unif01_WrLongStateFlag) { + printf ("b = %u\n", state->b); + printf ("T = {\n"); + for (j = 0; j < 256; j++) { + printf (" %12u", state->X[(state->r + j) & MASK8]); + if (j < 255) + printf (","); + if (((j + 1) % 5) == 0) + printf ("\n"); + }; + printf ("\n};\n"); + } else + unif01_WrLongStateDef (); +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *umarsa_CreateSWB99 (unsigned int T[256], int b) +{ + unif01_Gen *gen; + SWB_99_state *state; + size_t leng; + char name[LEN + 1]; + int j; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (SWB_99_state)); + + strcpy (name, "umarsa_CreateSWB99:"); + addstr_Uint (name, " b = ", (unsigned) b); + addstr_ArrayUint (name, ", T = ", 256, T); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->r = 0; + state->b = b; + gen->GetBits = &SWB_99_Bits; + gen->GetU01 = &SWB_99_U01; + + for (j = 0; j < 256; j++) { + state->X[j] = T[j]; + } + gen->param = NULL; + gen->state = state; + gen->Write = &WrSWB_99; + + return gen; +} + + +void umarsa_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/umarsa.tex b/TESTU01/TestU01-1.2.3/testu01/umarsa.tex new file mode 100644 index 0000000..8b843b2 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/umarsa.tex @@ -0,0 +1,441 @@ +\defmodule {umarsa} + +This module implements several generators proposed in different places +by George Marsaglia and his co-workers. +See also the URL site \url{http://stat.fsu.edu/~geo/}. +In the description of the generators, the symbols $\ll$ stands for + the left shift operator, $\gg$ for the right shift operator, + and $\oplus$ for the bitwise exclusive-or operator. In the +implementations of the generators, multiplications and divisions by powers +of 2 are implemented with left and right bit shifts. +\index{Generator!Marsaglia} + +\def\OP{\mathop {S}\nolimits} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* umarsa.h for ANSI C */ +#ifndef UMARSA_H +#define UMARSA_H +\endhide +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen * umarsa_CreateMarsa90a (int y1, int y2, int y3, int z0, + unsigned int Y0); +\endcode + \tab Implements the combination proposed by Marsaglia, Narasimhan and + Zaman \cite{rMAR90a}. Its components are the subtract-with-borrow +\index{Generator!Marsa90a}% + generator (SWB) (see {\tt CreateSWB} in module {\tt ucarry}) + $X_n = (X_{n-22} - X_{n-43} - C) \mod (2^{32}-5)$ + where $C$ is the borrow, and the Weyl generator + $Y_n = (Y_{n-1} - 362436069) \mod 2^{32}$. + The combination is done by subtraction modulo $2^{32}$, i.e., + $Z_n = (X_n - Y_n) \mod 2^{32}$ and the value returned is + $u_n = Z_n/2^{32}$. + The first 43 values of the generator SWB are initialized by the + combination of a 3-lag Fibonacci generator whose recurrence is + $y_n = (y_{n-1}y_{n-2}y_{n-3}) \mod 179$, with a LCG with recurrence + $z_n = (53z_{n-1} + 1) \mod 169$, as + follows: the sixth bit of $y_i z_i \mod 64$ is used to fill the seed + numbers of the main generator, bit by bit. + The parameters {\tt y1}, {\tt y2}, and {\tt y3} are the seeds of the + 3-lag Fibonacci sequence, while {\tt z0} is the seed of the + sequence $z_{n} = (53 z_{n-1} + 1)\mod 169$. Finally {\tt Y0} + is the seed of the Weyl generator. Restrictions: $0 < {\tt y1}, + {\tt y2}, {\tt y3} < 179$ and $0 \le {\tt z0} < 169$. + \endtab +\code + + +unif01_Gen * umarsa_CreateRANMAR (int y1, int y2, int y3, int z0); +\endcode + \tab Implements {\it RANMAR}, a combination proposed by Marsaglia, + Zaman and Tsang +\index{Generator!RANMAR}% + in \cite{rMAR90b}. Its components are the lagged-Fibonacci generator + $X_n = (X_{n - 97} - X_{n - 33}) \mod 1$, implemented using 24-bit + floating-point numbers, and the arithmetic sequence + $S_n = (S_{n-1}-k) \mod (2^{24}-3)$. The first 97 values of the + lagged-Fibonacci generator are initialized in exactly the same way + as the main generator in {\tt umarsa\_CreateMarsa90a}. +% by the combination of a +% 3-lag Fibonacci generator $y_n = y_{n-1}y_{n-2}y_{n-3} \mod 179$ with a +% LCG $z_n = 53z_{n-1} + 1 \mod 169$ as +% follows: the sixth bit of $y_iz_i \mod 64$ is used to fill the seed +% numbers of the main generator, bit by bit. + The parameters + {\tt y1}, {\tt y2}, and {\tt y3} are the seeds of the + 3-lag Fibonacci sequence, while {\tt z0} is the seed of the LCG. + This generator has 24 bits of resolution. + Restrictions: $0 < {\tt y1}, {\tt y2}, {\tt y3} < 179$ and + $0 \le {\tt z0} < 169$. + \endtab +\code + +#ifdef USE_LONGLONG + unif01_Gen * umarsa_CreateMother0 (unsigned long x1, unsigned long x2, + unsigned long x3, unsigned long x4, unsigned long c); +#endif +\endcode + \tab Marsaglia \cite{rMAR96a} named this generator + {\it ``The Mother of all RNG's''}. It is a ``multiply-with-carry'' +\index{Generator!The Mother of all RNG's}% + generator (MWC) whose recurrence is + \begin {eqnarray*} + Y &=& 5115\, x_{n-1} + 1776\, x_{n-2} + 1492\, x_{n-3} + + 2111111111\, x_{n-4} + C, \\ + x_n &=& Y \mod 2^{32}, \\ + C &=& Y \, /\, 2^{32}, + \end {eqnarray*} + where $C$ is the carry. + The returned value is $x_n / 2^{32}$. + The four seeds {\tt x1}, {\tt x2}, {\tt x3} and {\tt x4} are the initial + values of the $x_i$ and {\tt c} is the initial carry. + Marsaglia uses ${\tt c} = 0$ as initial value of the carry. + Restrictions: $ 0 \le {\tt c} \le 2111119494$ + (= the sum of the coefficients of the $x_{n}$). + \endtab +\code + + +unif01_Gen * umarsa_CreateCombo (unsigned int x1, unsigned int x2, + unsigned int y1, unsigned int c); +\endcode + \tab Generator {\em Combo\/} proposed by Marsaglia \cite{rMAR96a}: +\index{Generator!Combo}% + \begin {eqnarray*} + x_n &=& (x_{n-1} \, x_{n-2}) \mod 2^{32}, \\ + y_n &=& 30903 \left(y_{n-1} \mod 2^{16}\right) + y_{n-1}\div 2^{16}. + \end {eqnarray*} + The output is $u_n = z_n/2^{32}$ with the + combination $z_n = (x_n + y_n) \mod 2^{32}$. + Marsaglia uses $c = 0$ as initial value of the carry. + Restrictions: $y_1 < 2^{16}$ and $0 \le c \le 30903$. + \endtab +\code + + +unif01_Gen * umarsa_CreateECG1 (unsigned int x1, unsigned int x2, + unsigned int x3); +\endcode + \tab Marsaglia \cite{rMAR96a} named these + ``{\em extended congruential\/}'' generators. This one is based on + \begin {eqnarray*} + x_n &=& (65065 x_{n-1} + 67067 x_{n-2} + 69069 x_{n-3}) \mod (2^{32}-5) + \end {eqnarray*} + and $u_n = x_n / (2^{32}-5)$. +\index{Generator!ECG1}% + Restrictions: $0 \le x1, x2, x3 < 4294967291$. + \endtab +\code + + +unif01_Gen * umarsa_CreateECG2 (unsigned int x1, unsigned int x2, + unsigned int x3); +\endcode + \tab Generator based on the recurrence +\index{Generator!ECG2}% + \begin {eqnarray*} + x_n &=& 2^{10} (x_{n-1} + x_{n-2} + x_{n-3}) \mod (2^{32}-5) + \end {eqnarray*} + and $u_n = x_n / (2^{32}-5)$. + Restrictions: $0 \le x1, x2, x3 < 4294967291$. + \endtab +\code + + +unif01_Gen * umarsa_CreateECG3 (unsigned int x1, unsigned int x2, + unsigned int x3); +\endcode + \tab Generator based on the recurrence +\index{Generator!ECG3}% + \begin {eqnarray*} + x_n &=& (2000 x_{n-1} + 1950 x_{n-2} + 1900 x_{n-3}) \mod (2^{32}-209) + \end {eqnarray*} + and $u_n = x_n / (2^{32}-209)$. + Restrictions: $0 \le x1, x2, x3 < 4294967087$. + \endtab +\code + + +unif01_Gen * umarsa_CreateECG4 (unsigned int x1, unsigned int x2, + unsigned int x3); +\endcode +\index{Generator!ECG4}% + \tab Generator based on the recurrence + \begin{eqnarray*} + x_n &=& 2^{20} (x_{n-1} + x_{n-2} + x_{n-3}) \mod (2^{32}-209) + \end{eqnarray*} + and $u_n = x_n / (2^{32}-209)$. + Restrictions: $0 \le x1, x2, x3 < 4294967087$. + \endtab +\code + + +unif01_Gen * umarsa_CreateMWC97R (unsigned int x0, unsigned int y0); +\endcode + \tab This generator proposed by Marsaglia in \cite{rMAR97a} concatenates two + 16-bit multiply-with-carry generators based on the recurrences + \begin{eqnarray*} + x_{n} &=& 36969 \left(x_{n-1} \mod 2^{16}\right) + x_{n-1}\div 2^{16}, \\ + y_{n} &=& 18000 \left(y_{n-1} \mod 2^{16}\right) + y_{n-1}\div 2^{16}, \\ + Z_n &=& \left( 2^{16} x_{n} + y_{n} \mod 2^{16}\right) \mod 2^{32}. + \end{eqnarray*} + The 16 upper bits of $x_n$ and $y_n$ are the carries of the respective + equation. The generator returns $Z_n/(2^{32} - 1)$. + It has been included as the default generator in the GNU package {\it R} +\index{Generator!MultiCarry}% + under the name {\it Marsaglia-MultiCarry} \cite{tGNU03a}. + \endtab +\code + + +unif01_Gen * umarsa_CreateULTRA (unsigned int s1, unsigned int s2, + unsigned int s3, unsigned int s4); +\endcode + \tab Implements the {\it ULTRA} generator \cite{rMAR96a}, a combination of a + lagged Fibonacci generator (see {\tt CreateLagFib} in module {\tt umrg}) +\index{Generator!ULTRA}% + with a multiply-with-carry generator + (see {\tt CreateMWC} in module {\tt ucarry}), + proposed by Marsaglia with his test suite DIEHARD: + \begin {eqnarray*} + x_n &=& (x_{n-97}\,x_{n-33}) \mod 2^{32}, \\ + y_{n} &=& 30903\, \left(y_{n-1} \mod 2^{16}\right) + y_{n-1}\div 2^{16}, \\ + z_n &=& (x_n + y_{n}) \mod 2^{32}. + \end {eqnarray*} + The generator returns $z_n/2^{32}$. This agrees with the effective + implementation in DIEHARD which does not agree with its documentation. + The four seeds {\tt s1}, {\tt s2}, {\tt s3} and {\tt s4} are used in + a complicated way to initialize the component generators. + \endtab +\code + + +unif01_Gen * umarsa_CreateSupDup73 (unsigned int x0, unsigned int y0); +\endcode + \tab Implements the original {\it SuperDuper} generator \cite{rMAR73a}, a +\index{Generator!SuperDuper}\label{gen:SupDup73}% + combination of a congruential generator with a shift-register generator: + \begin {eqnarray*} + x_n &=& 69069\, x_{n-1} \mod 2^{32}, \\ + t &=& y_{n-1}\oplus \left(y_{n-1} \div 2^{15}\right), \\ + y_{n} &=& t \oplus \left(2^{17} t \mod 2^{32}\right), \\ + z_n &=& x_n \oplus y_{n} + \end {eqnarray*} + The generator returns $z_n / (2^{32} - 1)$. The seeds {\tt x0} and + {\tt y0} initializes the $x_n$ and $y_n$. + Restriction: {\tt x0} must be odd. + \endtab +\code + + +unif01_Gen * umarsa_CreateSupDup96Add (unsigned int x0, unsigned int y0, + unsigned int c); +\endcode + \tab Implements the {\it SuperDuper} generator, an additive combination of a + congruential generator with a shift-register generator, proposed by + Marsaglia with his test suite DIEHARD \cite{rMAR96a}: +\index{Generator!SuperDuper96}\label{gen:SupDup96}% + \begin {eqnarray*} + x_n &=& (69069\, x_{n-1} + c) \mod 2^{32}, \\ + t &=& y_{n-1}\oplus (2^{13}y_{n-1}), \\ + t &=& t \oplus (t \div 2^{17}), \\ + y_{n} &=& (t \oplus (2^{5}t)) \mod 2^{32}, \\ + z_n &=& (x_n + y_n) \mod 2^{32} + \end {eqnarray*} + The generator returns $z_n/2^{32}$. + This is the uniform generator (called {\tt randuni}) + included in {\sc Matlab} that is used to \index{Generator!Matlab-5}% + generate normal random variables. + Restriction: {\tt c} odd. + \endtab +\code + + +unif01_Gen * umarsa_CreateSupDup96Xor (unsigned int x0, unsigned int y0, + unsigned int c); +\endcode + \tab Similar to {\tt umarsa\_CreateSupDup96Add} above, except that + the combination of the two generators is with a bitwise exclusive-or: + $$ + z_n \ = \ x_n \oplus y_{n} + $$ + \endtab +\code + + +#ifdef USE_LONGLONG +unif01_Gen * umarsa_CreateSupDup64Add (ulonglong x0, ulonglong y0, + ulonglong a, ulonglong c, + int s1, int s2, int s3); +#endif +\endcode + \tab Implements the 64-bit generator {\it supdup64}, an additive + combination of +\index{Generator!supdup64}% + a congruential generator with a shift-register generator, proposed by + Marsaglia in \cite{rMAR02a}: + \begin {eqnarray*} + x_n &=& (a\, x_{n-1} + c) \mod 2^{64}, \\ + t &=& y_{n-1}\oplus \left(2^{s_1}y_{n-1}\right), \\ + t &=& t \oplus \left(t\div 2^{s_2}\right), \\ + y_{n} &=& \left(t \oplus \left(2^{s_3} t\right)\right) \mod 2^{64}, \\ + z_n &=& (x_n + y_{n}) \mod 2^{64} + \end {eqnarray*} + The generator returns $z_n/2^{64}$ using only the 32 most significant + bits of $z_n$ and setting the others to 0. + In his post, Marsaglia suggests the values $a = 6906969069$, + $c=1234567$, $s_1 = 13$, $s_2 = 17$ and $s_3 = 43$. + Restrictions: $a = 3 \mod 8$ or $a = 5 \mod 8$. + \endtab +\code + + +#ifdef USE_LONGLONG +unif01_Gen * umarsa_CreateSupDup64Xor (ulonglong x0, ulonglong y0, + ulonglong a, ulonglong c, + int s1, int s2, int s3); +#endif +\endcode + \tab Similar to {\tt umarsa\_CreateSupDup64Add} above, except that + the combination of the two generators is with a bitwise exclusive-or: + $$ + z_n \ = \ x_n \oplus y_{n} + $$ + \endtab +\code + + +unif01_Gen * umarsa_CreateKISS93 (unsigned int x0, unsigned int y0, + unsigned int z0); +\endcode + \tab Implements the generator {\it KISS} + proposed by Marsaglia in \cite{rMAR93c}, +\index{Generator!KISS}% + which is a combination of a LCG sequence with two 2-shifts register + sequences: + \begin {eqnarray*} + x_n &=& (69069\, x_{n-1} + 23606797) \mod 2^{32}, \\ + t &=& y_{n-1}\oplus \left(2^{17} y_{n-1}\right), \\ + y_{n} &=& t \oplus \left(t\div 2^{15}\right) \mod 2^{32}, \\ + t &=& \left(z_{n-1}\oplus \left(2^{18} z_{n-1}\right)\right) \mod 2^{31},\\ + z_n &=& t \oplus \left(t \div 2^{13}\right) + \end {eqnarray*} + The generator returns + $\left((x_n + y_n + z_n) \mod 2^{32}\right) / 2^{32}$. + Restrictions: {\tt $0 \le$ z0 $< 2^{31}$}. + \endtab +\code + + +unif01_Gen * umarsa_CreateKISS96 (unsigned int x0, unsigned int y0, + unsigned int z1, unsigned int z2); +\endcode + \tab Implements the generator {\it KISS} + proposed by Marsaglia in his test suite + DIEHARD \cite{rMAR96a}: + \begin {eqnarray*} + x_n &=& \left(69069\,x_{n-1} + 1\right) \mod 2^{32}, \\ + t &=& y_{n-1}\oplus \left(2^{13} y_{n-1}\right), \\ + t &=& t\oplus \left(t \div 2^{17}\right), \\ + y_n &=& \left(t\oplus \left(2^{5} t\right)\right) \mod 2^{32}, \\ + z_n &=& \left(2z_{n-1}+ z_{n-2} + c_{n-1}\right) \mod 2^{32}, \\ + c_n &=& (2z_{n-1} + z_{n-2} + c_{n-1}) \div 2^{32}, + \end {eqnarray*} + where the $x_n$ are a LCG sequence, the $y_n$ are a 3-shifts register + sequence, and the $z_n$ are a simple multiply-with-carry sequence + with $c_n$ as the carry (see {\tt CreateMWC} in module {\tt ucarry}). + The variable $x_0$ is the seed of the LCG component, $y_0$ is the seed + of the shift register component, and $z_1, z_2$ are the seeds of + the multiply-with-carry sequence. The generator returns + $\left((x_n + y_n + z_n) \mod 2^{32}\right) / 2^{32}$. + \endtab +\code + + +unif01_Gen * umarsa_CreateKISS99 (unsigned int x0, unsigned int y0, + unsigned int z1, unsigned int z2); +\endcode + \tab Implements the generator {\it KISS} proposed by Marsaglia in + \cite{rMAR99a}. It is a combination of a LCG, a 3-shifts register generator, +\index{Generator!KISS}% + and two multiply-with-carry generators: + \begin {eqnarray*} + x_n &=& (69069\,x_{n-1} + 1234567) \mod 2^{32}, \\ + t &=& y_{n-1}\oplus \left(2^{17} y_{n-1} \right), \\ + t &=& t\oplus \left(t \div 2^{13}\right), \\ + y_n &=& \left( t\oplus \left(2^{5} t \right)\right) \mod 2^{32}, \\ + Z_n &=& \mbox{as in {\tt umarsa\_CreateMWC97R} above} + \end {eqnarray*} + where $x_0$ is the seed of the LCG component, $y_0$ the seed of the + 3-shifts register component, and $z_1, z_2$ the seeds of the + multiply-with-carry generators. The generator returns + $\left( ((Z_n \oplus x_n) + y_n) \mod 2^{32}\right)/2^{32}$. + \endtab +\code + + +unif01_Gen * umarsa_Create4LFIB99 (unsigned int T[256]); +\endcode + \tab Implements the 4-lag lagged Fibonacci generator {\it LFIB4} proposed by +\index{Generator!LFIB4}% + Marsaglia in \cite{rMAR99a}. It uses addition in the form + (see also {\tt CreateLagFib} in module {\tt umrg}) + $$ + T_{n} = (T_{n-55} + T_{n-119} + T_{n-179} + T_{n-256}) \mod 2^{32}. + $$ + The generator returns $T_{n}/2^{32}$. Its period is close to + $2^{287}$. + \endtab +\code + + +unif01_Gen * umarsa_Create3SHR99 (unsigned int y0); +\endcode + \tab Implements the 3-shift random number generator {\it SHR3} proposed by +\index{Generator!SHR3}% + Marsaglia in \cite{rMAR99a}: + \begin {eqnarray*} + t &=& y_{n-1}\oplus \left(2^{17} y_{n-1}\right), \\ + t &=& t\oplus \left(t \div 2^{13}\right), \\ + y_{n} &=& \left(t \oplus \left(2^{5} t\right)\right) \bmod 2^{32}. + \end {eqnarray*} + The generator returns $y_n/2^{32}$ and its period is $2^{32} -1$. + \endtab +\code + + +unif01_Gen * umarsa_CreateSWB99 (unsigned int T[256], int b); +\endcode + \tab Implements the subtract-with-borrow generator {\it SWB} +\index{Generator!SWB}% + proposed by Marsaglia in \cite{rMAR99a}: + \begin {eqnarray*} + b_n &=& I[T_{n-222} < T_{n-237} + b_{n-1}], \\ + T_{n} &=& \left(T_{n-222} - T_{n-237} - b_{n-1}\right) \bmod 2^{32}, + \end {eqnarray*} + where $b_n$ is the borrow and $I$ is the indicator function + (see {\tt CreateSWB} in module {\tt ucarry}). + The generator returns $T_{n}/2^{32}$ and its period is close to $2^{7578}$. + \endtab + + + +\guisec{Clean-up functions} +\code + +void umarsa_DeleteGen (unif01_Gen *gen); +\endcode + \tab \DelGen + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/umrg.c b/TESTU01/TestU01-1.2.3/testu01/umrg.c new file mode 100644 index 0000000..e7099d5 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/umrg.c @@ -0,0 +1,2225 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: umrg.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "umrg.h" +#include "unif01.h" + +#include +#include +#include +#include + + +#ifdef USE_GMP +#include +#endif + + + +#define LEN 300 /* Max length of strings */ +#define MASK32 0xffffffffUL /* 2^32 - 1 */ + + + + + +/*================================= Types =================================*/ + +typedef struct { + int kind; + long a1, q1, r1, a2, q2, r2; + long M; + double Norm; +} MRG2_param; + +typedef struct { + long x1, x2; +} MRG2_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + int kind; + long a1, q1, r1, a3, q3, r3; + long M; + double Norm; +} MRG3_param; + +typedef struct { + long x1, x2, x3; +} MRG3_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + int kind; + long a1, q1, r1, a5, q5, r5; + long M; + double Norm; +} MRG5_param; + +typedef struct { + long x1, x2, x3, x4, x5; +} MRG5_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + int kind; + long a1, q1, r1, a7, q7, r7; + long M; + double Norm; +} MRG7_param; + +typedef struct { + long x1, x2, x3, x4, x5, x6, x7; +} MRG7_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + int kind; + long *A, *Q, *R; + long M; + double Norm; +} MRG_param; + +typedef struct { + long *S; + int k; +} MRG_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + double *A; + double M; + double Norm; +} MRGFloat_param; + +typedef struct { + double *S; + int k; +} MRGFloat_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long a12, a13, a21, a23; /* Multipliers */ + long q12, q13, q21, q23; /* qij = mi DIV aj */ + long r12, r13, r21, r23; /* rij = mi MOD aj */ + long M1, M2; /* Modules */ + double Norm; +} CombMRG3_param; + +typedef struct { + long x10, x11, x12, x20, x21, x22; /* State */ +} CombMRG3_state; + +/*-------------------------------------------------------------------------*/ +#ifdef USE_GMP + +typedef struct { + mpz_t M, *A, W, T; + mpf_t F, Norm; + lebool *AnonZero; +} BigMRG_param; + +typedef struct { + mpz_t *S; + int k; +} BigMRG_state; + +typedef struct { + mpz_t M1, M2, *A1, *A2, W, T1, T2; + mpf_t F1, F2, Norm1, Norm2; + lebool *A1nonZero, *A2nonZero; +} BigC2MRG_param; + +typedef struct { + mpz_t *S1, *S2; + int k; +} BigC2MRG_state; + +#endif +/*-------------------------------------------------------------------------*/ + +typedef struct { + lebool Flag; /* TRUE if k > r, FALSE if k < r */ + int Skip; +} LagFibFloat_param; + +typedef struct { + double *X; + int r, s, RR; + int Lag; +} LagFibFloat_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long Mask; /* 2^t - 1 */ + int b; /* shift |t - 32| bits, right or left */ + lebool LeftShift; /* TRUE for left shift, FALSE for right shift */ + lebool Flag; /* TRUE if k > r, FALSE if k < r */ + int Skip; +} LagFib_param; + +typedef struct { + unsigned long *X; + int r, s, RR; + int Lag; +} LagFib_state; + +/*-------------------------------------------------------------------------*/ + + + + + + +/*============================ functions ==================================*/ + + +static void AddArrayString (char *name, const char *add, int high, char *A[]) +/* + * Add the string array A of size = high to name + */ +{ + int j; + strcat (name, add); + strcat (name, "("); + strcat (name, A[0]); + for (j = 1; (j < high) && (j < 7); j++) { + strcat (name, ", "); + if (A[j]) + strcat (name, A[j]); + else + strcat (name, "0"); + } + if (high > 7) + strcat (name, ", ... )"); + else + strcat (name, ")"); +} + + +/**************************************************************************/ + +static double MRG2_U01 (void *vpar, void *vsta) +/* + * Implementation used for k = 2, a1 > 0, a2 > 0 + */ +{ + MRG2_param *param = vpar; + MRG2_state *state = vsta; + long h; + long p; + + h = state->x2 / param->q2; + p = param->a2 * (state->x2 - h * param->q2) - h * param->r2; + if (p < 0) + p += param->M; + state->x2 = state->x1; + + h = state->x1 / param->q1; + state->x1 = param->a1 * (state->x1 - h * param->q1) - h * param->r1; + if (state->x1 <= 0) + state->x1 += p; + else + state->x1 = (state->x1 - param->M) + p; + if (state->x1 < 0) + state->x1 += param->M; + return state->x1 * param->Norm; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG2_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG2 (void *vsta) +{ + MRG2_state *state = vsta; + printf (" S[1] = %10ld, S[2] = %10ld\n\n", state->x1, state->x2); +} + + +/**************************************************************************/ + +static double MRG3_U01 (void *vpar, void *vsta) +/* + * Implementation used for k = 3, a1 > 0, a3 > 0 and a2 = 0 + */ +{ + MRG3_param *param = vpar; + MRG3_state *state = vsta; + long h; + long p; + + h = state->x3 / param->q3; + p = param->a3 * (state->x3 - h * param->q3) - h * param->r3; + if (p < 0) + p += param->M; + state->x3 = state->x2; + state->x2 = state->x1; + h = state->x1 / param->q1; + state->x1 = param->a1 * (state->x1 - h * param->q1) - h * param->r1; + if (state->x1 <= 0) + state->x1 += p; + else + state->x1 = (state->x1 - param->M) + p; + if (state->x1 < 0) + state->x1 += param->M; + return state->x1 * param->Norm; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG3_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG3 (void *vsta) +{ + MRG3_state *state = vsta; + printf (" S[1] = %10ld, S[2] = %10ld, S[3] = %10ld\n\n", + state->x1, state->x2, state->x3); +} + + +/**************************************************************************/ + +static double MRG5_U01 (void *vpar, void *vsta) +/* + * Implementation used for k = 5, a1 > 0, a5 > 0 and a2 = a3 = a4 = 0 + */ +{ + MRG5_param *param = vpar; + MRG5_state *state = vsta; + long h; + long p; + + h = state->x5 / param->q5; + p = param->a5 * (state->x5 - h * param->q5) - h * param->r5; + if (p < 0) + p += param->M; + state->x5 = state->x4; + state->x4 = state->x3; + state->x3 = state->x2; + state->x2 = state->x1; + h = state->x1 / param->q1; + state->x1 = param->a1 * (state->x1 - h * param->q1) - h * param->r1; + if (state->x1 <= 0) + state->x1 += p; + else + state->x1 = (state->x1 - param->M) + p; + if (state->x1 < 0) + state->x1 += param->M; + return state->x1 * param->Norm; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG5_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG5_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG5 (void *vsta) +{ + MRG5_state *state = vsta; + printf (" S[1] = %10ld, S[2] = %10ld, S[3] = %10ld,\n", + state->x1, state->x2, state->x3); + printf (" S[4] = %10ld, S[5] = %10ld\n\n", state->x4, state->x5); +} + + +/**************************************************************************/ + +static double MRG7_U01 (void *vpar, void *vsta) +/* + * Implementation used for k = 7, a1 > 0, a7 > 0, a2 = a3 = a4 = a5 = a6 = 0 + */ +{ + MRG7_param *param = vpar; + MRG7_state *state = vsta; + long h; + long p; + + h = state->x7 / param->q7; + p = param->a7 * (state->x7 - h * param->q7) - h * param->r7; + if (p < 0) + p += param->M; + state->x7 = state->x6; + state->x6 = state->x5; + state->x5 = state->x4; + state->x4 = state->x3; + state->x3 = state->x2; + state->x2 = state->x1; + h = state->x1 / param->q1; + state->x1 = param->a1 * (state->x1 - h * param->q1) - h * param->r1; + if (state->x1 <= 0) + state->x1 += p; + else + state->x1 = (state->x1 - param->M) + p; + if (state->x1 < 0) + state->x1 += param->M; + return state->x1 * param->Norm; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG7_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG7_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG7 (void *vsta) +{ + MRG7_state *state = vsta; + printf (" S[1] = %10ld, S[2] = %10ld, S[3] = %10ld,\n", + state->x1, state->x2, state->x3); + printf (" S[4] = %10ld, S[5] = %10ld, S[6] = %10ld,\n", + state->x4, state->x5, state->x6); + printf (" S[7] = %10ld\n\n", state->x7); +} + + +/**************************************************************************/ + +static double MRG_U01 (void *vpar, void *vsta) +/* + * Generator MRG of order k when R[i] < Q[i] for all i. The values returned + * by the generator MRG are in the set { 0, 1/m, 2/m, ..., (m-1)/m } + */ +{ + MRG_param *param = vpar; + MRG_state *state = vsta; + long i, p, h, t; + + p = 0; + for (i = state->k; i > 0; i--) { + if (param->A[i] != 0) { + h = state->S[i] / param->Q[i]; + t = labs (param->A[i]) * (state->S[i] - h * param->Q[i]) - + h * param->R[i]; + if (t < 0) + t += param->M; + if (param->A[i] < 0) + p -= t; + else + p += (t - param->M); + if (p < 0) + p += param->M; + } + if (i > 1) + state->S[i] = state->S[i - 1]; + else + state->S[i] = p; + } + return (p * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG (void *vsta) +{ + MRG_state *state = vsta; + int i; + if (unif01_WrLongStateFlag || (state->k < 8)) { + printf (" S = {\n "); + for (i = 1; i <= state->k; i++) { + printf (" %12ld", state->S[i]); + if (i < state->k) + printf (","); + if ((i % 4) == 0) + printf ("\n "); + } + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-------------------------------------------------------------------------*/ + +enum {MRG_ALL = 987654321}; + +static unif01_Gen * CreateMRG_all (long m, int k, long AA[], long SS[]) +{ + unif01_Gen *gen; + MRG_param *param; + MRG_state *state; + size_t leng; + char name[LEN + 1]; + int i; + long *A, *S, *Q, *R; + + if ((k < 2) || (m <= 1)) + util_Error ("umrg_CreateMRG: k < 2 or m < 2"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MRG_param)); + state = util_Malloc (sizeof (MRG_state)); + + strncpy (name, "umrg_CreateMRG:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", k = ", k); + addstr_ArrayLong (name, ", A = ", k, AA); + addstr_ArrayLong (name, ", S = ", k, SS); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + A = util_Calloc ((size_t) k + 1, sizeof (long)); + R = util_Calloc ((size_t) k + 1, sizeof (long)); + Q = util_Calloc ((size_t) k + 1, sizeof (long)); + S = util_Calloc ((size_t) k + 1, sizeof (long)); + + for (i = 1; i <= k; i++) { + A[i] = AA[i - 1]; + S[i] = SS[i - 1]; + if (A[i] != 0) { + R[i] = m % labs (A[i]); + Q[i] = m / labs (A[i]); + } + } + + param->kind = MRG_ALL; + param->M = m; + param->Norm = 1.0 / m; + param->A = A; + param->R = R; + param->Q = Q; + state->k = k; + state->S = S; + + gen->param = param; + gen->state = state; + gen->GetBits = &MRG_Bits; + gen->GetU01 = &MRG_U01; + gen->Write = &WrMRG; + + return gen; +} + +/*-------------------------------------------------------------------------*/ + +static void DeleteMRG_all (unif01_Gen * gen) +{ + MRG_param *param; + MRG_state *state; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + util_Free (state->S); + util_Free (param->A); + util_Free (param->Q); + util_Free (param->R); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +unif01_Gen * umrg_CreateMRG (long m, int k, long A[], long S[]) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + int i, n; + long r, q; + long R[8] = { 0 }; + long Q[8] = { 0 }; + + if ((k < 2) || (m <= 1)) + util_Error ("umrg_CreateMRG: k < 2 or m < 2"); + + n = 0; + for (i = 0; i < k; i++) { + util_Assert (labs (A[i]) < m, "umrg_CreateMRG: |A[i]| >= m"); + util_Assert (S[i] < m, "umrg_CreateMRG: S[i] >= m"); + util_Assert (S[i] >= 0, "umrg_CreateMRG: S[i] < 0"); + if (A[i] != 0) { + r = m % labs (A[i]); + q = m / labs (A[i]); + util_Assert (r <= q, "umrg_CreateMRG: r[i] > q[i]"); + if (i < 7) { + R[i] = r; + Q[i] = q; + } + } + if (S[i] != 0) + n++; + } + util_Assert (n > 0, "umrg_CreateMRG: all S[i] are 0"); + + + if ((k == 2) && (A[0] > 0) && (A[1] > 0)) { + MRG2_param *param; + MRG2_state *state; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MRG2_param)); + state = util_Malloc (sizeof (MRG2_state)); + param->kind = 2; + param->M = m; + param->Norm = 1.0 / m; + param->a1 = A[0]; + param->r1 = R[0]; + param->q1 = Q[0]; + param->a2 = A[1]; + param->r2 = R[1]; + param->q2 = Q[1]; + state->x1 = S[0]; + state->x2 = S[1]; + + gen->param = param; + gen->state = state; + gen->GetBits = &MRG2_Bits; + gen->GetU01 = &MRG2_U01; + gen->Write = &WrMRG2; + + } else if ((k == 3) && (A[0] > 0) && (A[1] == 0) && (A[2] > 0)) { + MRG3_param *param; + MRG3_state *state; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MRG3_param)); + state = util_Malloc (sizeof (MRG3_state)); + param->kind = 3; + param->M = m; + param->Norm = 1.0 / m; + param->a1 = A[0]; + param->r1 = R[0]; + param->q1 = Q[0]; + param->a3 = A[2]; + param->r3 = R[2]; + param->q3 = Q[2]; + state->x1 = S[0]; + state->x2 = S[1]; + state->x3 = S[2]; + + gen->param = param; + gen->state = state; + gen->GetBits = &MRG3_Bits; + gen->GetU01 = &MRG3_U01; + gen->Write = &WrMRG3; + + } else if ((k == 5) && (A[0] > 0) && (A[1] == 0) && (A[2] == 0) && + (A[3] == 0) && (A[4] > 0)) { + MRG5_param *param; + MRG5_state *state; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MRG5_param)); + state = util_Malloc (sizeof (MRG5_state)); + param->kind = 5; + param->M = m; + param->Norm = 1.0 / m; + param->a1 = A[0]; + param->r1 = R[0]; + param->q1 = Q[0]; + param->a5 = A[4]; + param->r5 = R[4]; + param->q5 = Q[4]; + state->x1 = S[0]; + state->x2 = S[1]; + state->x3 = S[2]; + state->x4 = S[3]; + state->x5 = S[4]; + + gen->param = param; + gen->state = state; + gen->GetBits = &MRG5_Bits; + gen->GetU01 = &MRG5_U01; + gen->Write = &WrMRG5; + + } else if ((k == 7) && (A[0] > 0) && (A[1] == 0) && (A[2] == 0) && + (A[3] == 0) && (A[4] == 0) && (A[5] == 0) && (A[6] > 0)) { + MRG7_param *param; + MRG7_state *state; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MRG7_param)); + state = util_Malloc (sizeof (MRG7_state)); + param->kind = 7; + param->M = m; + param->Norm = 1.0 / m; + param->a1 = A[0]; + param->r1 = R[0]; + param->q1 = Q[0]; + param->a7 = A[6]; + param->r7 = R[6]; + param->q7 = Q[6]; + state->x1 = S[0]; + state->x2 = S[1]; + state->x3 = S[2]; + state->x4 = S[3]; + state->x5 = S[4]; + state->x6 = S[5]; + state->x7 = S[6]; + + gen->param = param; + gen->state = state; + gen->GetBits = &MRG7_Bits; + gen->GetU01 = &MRG7_U01; + gen->Write = &WrMRG7; + + } else { + return CreateMRG_all (m, k, A, S); + } + + strncpy (name, "umrg_CreateMRG:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", k = ", k); + addstr_ArrayLong (name, ", A = ", k, A); + addstr_ArrayLong (name, ", S = ", k, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + return gen; +} + +/*-------------------------------------------------------------------------*/ + +void umrg_DeleteMRG (unif01_Gen * gen) +{ + MRG_param *param; + if (NULL == gen) + return; + param = (MRG_param *) gen->param; + if (param->kind == MRG_ALL) + DeleteMRG_all (gen); + else + unif01_DeleteGen (gen); +} + + +/**************************************************************************/ + +static double MRGFloat_U01 (void *vpar, void *vsta) +/* + * Generator MRG of order k. Implementation uses floating-point. + */ +{ + MRGFloat_param *param = vpar; + MRGFloat_state *state = vsta; + double p; + long j; + int i; + + p = 0.0; + for (i = state->k; i > 0; i--) { + if (param->A[i] != 0.0) + p += param->A[i] * state->S[i]; + if (i > 1) + state->S[i] = state->S[i - 1]; + } + j = p / param->M; + if (p >= 0.0) + p -= j * param->M; /* p = sum ... mod m */ + else { + p += (1 - j) * param->M; + /* When truncating, if p % M = 0, we will get p = M */ + if (p >= param->M) + p -= param->M; + } + state->S[1] = p; /* Must be in {0,..., m-1} */ + return (p * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRGFloat_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRGFloat_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRGFloat (void *vsta) +{ + MRGFloat_state *state = vsta; + int i; + if (unif01_WrLongStateFlag || (state->k < 8)) { + printf (" S = {\n "); + for (i = 1; i <= state->k; i++) { + printf (" %12.0f", state->S[i]); + if (i < state->k) + printf (","); + if ((i % 4) == 0) + printf ("\n "); + } + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * umrg_CreateMRGFloat (long m, int k, long AA[], long SS[]) +{ + unif01_Gen *gen; + MRGFloat_param *param; + MRGFloat_state *state; + size_t leng; + char name[LEN + 1]; + int i, n; + double *A, *S; + double pr1, pr2; + + if ((k < 2) || (m < 2)) + util_Error ("umrg_CreateMRGFloat: k < 2 or m < 2"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (MRGFloat_param)); + state = util_Malloc (sizeof (MRGFloat_state)); + + strncpy (name, "umrg_CreateMRGFloat:", (size_t) LEN); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", k = ", k); + addstr_ArrayLong (name, ", A = ", k, AA); + addstr_ArrayLong (name, ", S = ", k, SS); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + A = util_Calloc ((size_t) k + 1, sizeof (double)); + S = util_Calloc ((size_t) k + 1, sizeof (double)); + + n = 0; + pr1 = 0.0; + pr2 = 0.0; + for (i = 1; i <= k; i++) { + if ((AA[i - 1] >= m) || (-AA[i - 1] >= m)) + util_Error ("umrg_CreateMRGFloat: |A[i]| >= m"); + if ((SS[i - 1] >= m) || (-SS[i - 1] >= m)) + util_Error ("umrg_CreateMRGFloat: |S[i]| >= m"); + A[i] = AA[i - 1]; + S[i] = SS[i - 1]; + if (SS[i - 1] < 0) + S[i] += m; + if (AA[i - 1] < 0) + pr2 -= A[i]; + else + pr1 += A[i]; + if (SS[i - 1] != 0) + n++; + } + if (n == 0) + util_Error (" umrg_CreateMRGFloat: all S[i] are 0"); + if ((pr1 * m >= num_TwoExp[53]) || (pr2 * m >= num_TwoExp[53])) + util_Error ("umrg_CreateMRGFloat: Condition on a_i not valid"); + + param->M = m; + param->Norm = 1.0 / m; + param->A = A; + state->k = k; + state->S = S; + + gen->param = param; + gen->state = state; + gen->GetBits = &MRGFloat_Bits; + gen->GetU01 = &MRGFloat_U01; + gen->Write = &WrMRGFloat; + + return gen; +} + +/*-------------------------------------------------------------------------*/ + +void umrg_DeleteMRGFloat (unif01_Gen * gen) +{ + MRGFloat_param *param; + MRGFloat_state *state; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + util_Free (state->S); + util_Free (param->A); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +static double CombMRG3_U01 (void *vpar, void *vsta) +/* + * Implementation used for k = 3. It assumes that + * a11 = 0, a12 > 0, a13 < 0 and a21 > 0, a22 = 0, a23 < 0. + */ +{ + CombMRG3_param *param = vpar; + CombMRG3_state *state = vsta; + long h, p12, p13, p21, p23, Z; + + /* Component 1 */ + h = state->x10 / param->q13; + p13 = param->a13 * (state->x10 - h * param->q13) - h * param->r13; + if (p13 < 0) + p13 += param->M1; + util_Assert (p13 >= 0, + "umrg_CreateC2MRG: invalid parameters for a_{1,3}"); + h = state->x11 / param->q12; + p12 = param->a12 * (state->x11 - h * param->q12) - h * param->r12; + if (p12 < 0) + p12 += param->M1; + util_Assert (p12 >= 0, + "umrg_CreateC2MRG: invalid parameters for a_{1,2}"); + state->x10 = state->x11; + state->x11 = state->x12; + state->x12 = p12 - p13; + if (state->x12 < 0) + state->x12 += param->M1; + + /* Component 2 */ + h = state->x20 / param->q23; + p23 = param->a23 * (state->x20 - h * param->q23) - h * param->r23; + if (p23 < 0) + p23 += param->M2; + util_Assert (p23 >= 0, + "umrg_CreateC2MRG: invalid parameters for a_{2,3}"); + h = state->x22 / param->q21; + p21 = param->a21 * (state->x22 - h * param->q21) - h * param->r21; + if (p21 < 0) + p21 += param->M2; + util_Assert (p21 >= 0, + "umrg_CreateC2MRG: invalid parameters for a_{2,1}"); + state->x20 = state->x21; + state->x21 = state->x22; + state->x22 = p21 - p23; + if (state->x22 < 0) + state->x22 += param->M2; + + /* Combinaison */ + if (state->x12 < state->x22) + Z = state->x12 - state->x22 + param->M1; + else + Z = state->x12 - state->x22; + return (Z * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombMRG3_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * CombMRG3_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrCombMRG3 (void *vsta) +{ + CombMRG3_state *state = vsta; + printf (" S1[0] = %1ld S1[1] = %1ld S1[2] = %1ld\n", + state->x10, state->x11, state->x12); + printf (" S2[0] = %1ld S2[1] = %1ld S2[2] = %1ld\n\n", + state->x20, state->x21, state->x22); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * umrg_CreateC2MRG (long m1, long m2, int k, long A1[], long A2[], + long S1[], long S2[]) +{ + unif01_Gen *gen; + CombMRG3_param *param; + CombMRG3_state *state; + size_t leng; + char name[LEN + 1]; + int i; + long cs1[4], cs2[4], cq1[4] = {0}, cq2[4] = {0}, cr1[4] = {0}, + cr2[4] = {0}, ca1[4], ca2[4]; + + if (k != 3) + util_Error ("umrg_CreateC2MRG: k != 3"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (CombMRG3_param)); + state = util_Malloc (sizeof (CombMRG3_state)); + + strncpy (name, "umrg_CreateC2MRG:", (size_t) LEN); + addstr_Long (name, " m1 = ", m1); + addstr_Long (name, ", m2 = ", m2); + addstr_Long (name, ", k = ", k); + addstr_ArrayLong (name, ", A1 = ", k, A1); + addstr_ArrayLong (name, ", S1 = ", k, S1); + addstr_ArrayLong (name, ", A2 = ", k, A2); + addstr_ArrayLong (name, ", S2 = ", k, S2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + for (i = 1; i <= k; i++) { + ca1[i] = A1[i - 1]; + ca2[i] = A2[i - 1]; + cs1[i] = S1[i - 1]; + cs2[i] = S2[i - 1]; + if (ca1[i] != 0) { + cr1[i] = m1 % labs (ca1[i]); + cq1[i] = m1 / labs (ca1[i]); + util_Assert ((double) cr1[i] * labs(ca1[i]) < m1, + "umrg_CreateC2MRG: |A1[i]| * (m1 mod |A1[i]|) >= m1"); + } + if (ca2[i] != 0) { + cr2[i] = m2 % labs (ca2[i]); + cq2[i] = m2 / labs (ca2[i]); + util_Assert ((double) cr2[i] * labs(ca2[i]) < m2, + "umrg_CreateC2MRG:pp |A2[i]| * (m2 mod |A2[i]|) >= m2"); + } + } + param->M1 = m1; + param->M2 = m2; + param->Norm = 1.0 / m1; + if (k == 3) { + param->a12 = ca1[2]; + param->a13 = ca1[3]; + param->a21 = ca2[1]; + param->a23 = ca2[3]; + param->q12 = cq1[2]; + param->q13 = cq1[3]; + param->q21 = cq2[1]; + param->q23 = cq2[3]; + param->r12 = cr1[2]; + param->r13 = cr1[3]; + param->r21 = cr2[1]; + param->r23 = cr2[3]; + state->x10 = cs1[1]; + state->x11 = cs1[2]; + state->x12 = cs1[3]; + state->x20 = cs2[1]; + state->x21 = cs2[2]; + state->x22 = cs2[3]; + + gen->GetBits = &CombMRG3_Bits; + gen->GetU01 = &CombMRG3_U01; + gen->Write = &WrCombMRG3; + } + gen->param = param; + gen->state = state; + return gen; +} + +/*-------------------------------------------------------------------------*/ + +void umrg_DeleteC2MRG (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} + + +/***************************************************************************/ + +#ifdef USE_GMP + +static void WrBigMRG (void *vsta) +{ + BigMRG_state *state = vsta; + int i; + + printf (" S = {\n "); + for (i = 1; i <= state->k; i++) { + mpz_out_str (NULL, 10, state->S[i]); + if (i < state->k) + printf (",\n "); + } + printf ("\n }\n"); +} + +/*-------------------------------------------------------------------------*/ + +static double BigMRG_U01 (void *vpar, void *vsta) +{ + BigMRG_param *param = vpar; + BigMRG_state *state = vsta; + int i; + + mpz_set_ui (param->T, 0); /* T = 0 */ + + for (i = state->k; i >= 1; i--) { + if (param->AnonZero[i]) { + mpz_mul (param->W, param->A[i], state->S[i]); /* W = A[i]*S[i] */ + mpz_mod (param->W, param->W, param->M); /* W = W % M */ + mpz_add (param->T, param->W, param->T); /* T = W + T */ + } + if (i > 1) { + mpz_set (state->S[i], state->S[i - 1]); /* S[i] = S[i - 1] */ + } else { + mpz_mod (state->S[i], param->T, param->M); /* S[i] = T % M */ + } + } + mpf_set_z (param->F, state->S[1]); /* F = S[1] */ + mpf_mul (param->F, param->F, param->Norm); /* F = F * Norm */ + return mpf_get_d (param->F); /* U = F */ +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long BigMRG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * BigMRG_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *umrg_CreateBigMRG (char *m, int k, char *A[], char *S[]) +{ + unif01_Gen *gen; + BigMRG_param *param; + BigMRG_state *state; + size_t len1, len2; + char name[LEN + 1]; + int i, flag; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (BigMRG_param)); + state = util_Malloc (sizeof (BigMRG_state)); + + /* These flags are set to 0 if the corresponding element is 0 */ + param->AnonZero = util_Calloc ((size_t) k + 1, sizeof (lebool)); + + strncpy (name, "umrg_CreateBigMRG:", (size_t) LEN); + strcat (name, " m = "); + strcat (name, m); + addstr_Long (name, ", k = ", k); + len1 = strlen (name); + len2 = len1 + 4 * strlen (", A = "); + + for (i = 0; i < k; i++) { + if (A[i]) { + len2 += strlen (A[i]); + param->AnonZero[i + 1] = TRUE; + } else + /* If NULL pointer, set corresponding element to 0 */ + param->AnonZero[i + 1] = FALSE; + + if (S[i]) + len2 += strlen (S[i]); + } + + gen->name = util_Calloc (len2 + LEN, sizeof (char)); + strncpy (gen->name, name, len2); + AddArrayString (gen->name, ", A = ", k, A); + AddArrayString (gen->name, ", S = ", k, S); + len1 = strlen (gen->name); + gen->name = util_Realloc (gen->name, (len1 + 1) * sizeof (char)); + + state->k = k; + mpz_init (param->M); + mpz_init (param->T); + mpz_init (param->W); + mpz_set_str (param->M, m, 0); + + param->A = util_Calloc ((size_t) k + 1, sizeof (mpz_t)); + state->S = util_Calloc ((size_t) k + 1, sizeof (mpz_t)); + + for (i = 1; i <= k; i++) { + if (param->AnonZero[i]) { + mpz_init (param->A[i]); + mpz_set_str (param->A[i], A[i - 1], 0); + mpz_abs (param->T, param->A[i]); + flag = mpz_cmp (param->T, param->M); + util_Assert (flag < 0, "umrg_CreateBigMRG: one A >= m"); + /* Check if element is 0 */ + if (mpz_sgn (param->A[i]) == 0) { + param->AnonZero[i] = FALSE; + mpz_clear (param->A[i]); + } + } + mpz_init (state->S[i]); + if (S[i - 1]) { + mpz_set_str (state->S[i], S[i - 1], 0); + mpz_abs (param->T, state->S[i]); + flag = mpz_cmp (param->T, param->M); + util_Assert (flag < 0, "umrg_CreateBigMRG: one S >= m"); + } + } + + mpf_set_default_prec (DBL_MANT_DIG); /* Set precision to 53 bits */ + mpf_init (param->F); + mpf_init (param->Norm); + mpf_set_z (param->Norm, param->M); + mpf_ui_div (param->Norm, 1, param->Norm); /* Norm = 1 / m */ + + gen->param = param; + gen->state = state; + gen->GetBits = &BigMRG_Bits; + gen->GetU01 = &BigMRG_U01; + gen->Write = &WrBigMRG; + + return gen; +} + +/*-------------------------------------------------------------------------*/ + +void umrg_DeleteBigMRG (unif01_Gen * gen) +{ + BigMRG_param *param; + BigMRG_state *state; + int i; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + mpf_clear (param->F); + mpf_clear (param->Norm); + + for (i = 1; i <= state->k; i++) { + if (param->AnonZero[i]) + mpz_clear (param->A[i]); + mpz_clear (state->S[i]); + } + + mpz_clear (param->M); + mpz_clear (param->T); + mpz_clear (param->W); + + util_Free (param->AnonZero); + util_Free (state->S); + util_Free (param->A); + + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/***************************************************************************/ + +static void WrBigC2MRG (void *vsta) +{ + BigC2MRG_state *state = vsta; + int i; + + printf (" S1 = {\n "); + for (i = 1; i <= state->k; i++) { + mpz_out_str (NULL, 10, state->S1[i]); + if (i < state->k) + printf (",\n "); + } + printf ("\n }\n\n S2 = {\n "); + for (i = 1; i <= state->k; i++) { + mpz_out_str (NULL, 10, state->S2[i]); + if (i < state->k) + printf (",\n "); + else + printf ("\n }\n"); + } +} + +/*-------------------------------------------------------------------------*/ + +static double BigC2MRG_U01 (void *vpar, void *vsta) +{ + BigC2MRG_param *param = vpar; + BigC2MRG_state *state = vsta; + int i; + double U, U2; + + mpz_set_ui (param->T1, 0); /* T1 = 0 */ + mpz_set_ui (param->T2, 0); /* T2 = 0 */ + + for (i = state->k; i >= 1; i--) { + if (param->A1nonZero[i]) { + mpz_mul (param->W, param->A1[i], state->S1[i]); /* W = A1[i]*S1[i] */ + mpz_mod (param->W, param->W, param->M1); /* W = W % M1 */ + mpz_add (param->T1, param->W, param->T1); /* T1 = W + T1 */ + } + if (param->A2nonZero[i]) { + mpz_mul (param->W, param->A2[i], state->S2[i]); /* W = A2[i]*S2[i] */ + mpz_mod (param->W, param->W, param->M2); /* W = W % M2 */ + mpz_add (param->T2, param->W, param->T2); /* T2 = W + T2 */ + } + if (i > 1) { + mpz_set (state->S1[i], state->S1[i - 1]); /* S1[i] = S1[i - 1] */ + mpz_set (state->S2[i], state->S2[i - 1]); /* S2[i] = S2[i - 1] */ + } else { + mpz_mod (state->S1[i], param->T1, param->M1); /* S1[i] = T1 % M1 */ + mpz_mod (state->S2[i], param->T2, param->M2); /* S2[i] = T2 % M2 */ + } + } + mpf_set_z (param->F1, state->S1[1]); /* F1 = S1[1] */ + mpf_set_z (param->F2, state->S2[1]); /* F2 = S2[1] */ + mpf_mul (param->F1, param->F1, param->Norm1); /* F1 = F1 * Norm1 */ + mpf_mul (param->F2, param->F2, param->Norm2); /* F2 = F2 * Norm2 */ + U = mpf_get_d (param->F1); /* U = F1 */ + U2 = mpf_get_d (param->F2); /* U2 = F2 */ + + U = U - U2; + if (U < 0.0) + return U + 1.0; + if (U < 1.0) + return U; + return U - 1.0; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long BigC2MRG_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * BigC2MRG_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *umrg_CreateBigC2MRG (char *m1, char *m2, int k, + char *A1[], char *A2[], char *S1[], char *S2[]) +{ + unif01_Gen *gen; + BigC2MRG_param *param; + BigC2MRG_state *state; + size_t len1, len2; + char name[LEN + 1]; + int i, flag; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (BigC2MRG_param)); + state = util_Malloc (sizeof (BigC2MRG_state)); + + /* These flags are set to 0 if the corresponding element is 0 */ + param->A1nonZero = util_Calloc ((size_t) k + 1, sizeof (lebool)); + param->A2nonZero = util_Calloc ((size_t) k + 1, sizeof (lebool)); + + strncpy (name, "umrg_CreateBigC2MRG:", (size_t) LEN); + strcat (name, " m1 = "); + strcat (name, m1); + strcat (name, ", m2 = "); + strcat (name, m2); + addstr_Long (name, ", k = ", k); + len1 = strlen (name); + len2 = len1 + 4 * strlen (", A1 = "); + + for (i = 0; i < k; i++) { + if (A1[i]) { + len2 += strlen (A1[i]); + param->A1nonZero[i + 1] = TRUE; + } else + /* If NULL pointer, set corresponding element to 0 */ + param->A1nonZero[i + 1] = FALSE; + + if (A2[i]) { + len2 += strlen (A2[i]); + param->A2nonZero[i + 1] = TRUE; + } else + param->A2nonZero[i + 1] = FALSE; + + if (S1[i]) + len2 += strlen (S1[i]); + + if (S2[i]) + len2 += strlen (S1[i]); + } + + gen->name = util_Calloc (len2 + LEN, sizeof (char)); + strncpy (gen->name, name, len2); + AddArrayString (gen->name, ", A1 = ", k, A1); + AddArrayString (gen->name, ", A2 = ", k, A2); + AddArrayString (gen->name, ", S1 = ", k, S1); + AddArrayString (gen->name, ", S2 = ", k, S2); + len1 = strlen (gen->name); + gen->name = util_Realloc (gen->name, (len1 + 1) * sizeof (char)); + + state->k = k; + mpz_init (param->M1); + mpz_init (param->M2); + mpz_init (param->T1); + mpz_init (param->T2); + mpz_init (param->W); + mpz_set_str (param->M1, m1, 0); + mpz_set_str (param->M2, m2, 0); + + param->A1 = util_Calloc ((size_t) k + 1, sizeof (mpz_t)); + param->A2 = util_Calloc ((size_t) k + 1, sizeof (mpz_t)); + state->S1 = util_Calloc ((size_t) k + 1, sizeof (mpz_t)); + state->S2 = util_Calloc ((size_t) k + 1, sizeof (mpz_t)); + + for (i = 1; i <= k; i++) { + if (param->A1nonZero[i]) { + mpz_init (param->A1[i]); + mpz_set_str (param->A1[i], A1[i - 1], 0); + mpz_abs (param->T1, param->A1[i]); + flag = mpz_cmp (param->T1, param->M1); + util_Assert (flag < 0, "umrg_CreateBigC2MRG: one A1 >= m1"); + /* Check if element is 0 */ + if (mpz_sgn (param->A1[i]) == 0) { + param->A1nonZero[i] = FALSE; + mpz_clear (param->A1[i]); + } + } + if (param->A2nonZero[i]) { + mpz_init (param->A2[i]); + mpz_set_str (param->A2[i], A2[i - 1], 0); + mpz_abs (param->T1, param->A2[i]); + flag = mpz_cmp (param->T1, param->M2); + util_Assert (flag < 0, "umrg_CreateBigC2MRG: one A2 >= m2"); + if (mpz_sgn (param->A2[i]) == 0) { + param->A2nonZero[i] = FALSE; + mpz_clear (param->A2[i]); + } + } + mpz_init (state->S1[i]); + if (S1[i - 1]) { + mpz_set_str (state->S1[i], S1[i - 1], 0); + mpz_abs (param->T1, state->S1[i]); + flag = mpz_cmp (param->T1, param->M1); + util_Assert (flag < 0, "umrg_CreateBigC2MRG: one S1 >= m1"); + } + + mpz_init (state->S2[i]); + if (S2[i - 1]) { + mpz_set_str (state->S2[i], S2[i - 1], 0); + mpz_abs (param->T1, state->S2[i]); + flag = mpz_cmp (param->T1, param->M2); + util_Assert (flag < 0, "umrg_CreateBigC2MRG: one S2 >= m2"); + } + } + + mpf_set_default_prec (DBL_MANT_DIG); /* Set precision to 53 bits */ + mpf_init (param->F1); + mpf_init (param->F2); + mpf_init (param->Norm1); + mpf_init (param->Norm2); + mpf_set_z (param->Norm1, param->M1); + mpf_set_z (param->Norm2, param->M2); + mpf_ui_div (param->Norm1, 1, param->Norm1); /* Norm1 = 1 / m1 */ + mpf_ui_div (param->Norm2, 1, param->Norm2); /* Norm2 = 1 / m2 */ + + gen->param = param; + gen->state = state; + gen->GetBits = &BigC2MRG_Bits; + gen->GetU01 = &BigC2MRG_U01; + gen->Write = &WrBigC2MRG; + + return gen; +} + +/*-------------------------------------------------------------------------*/ + +void umrg_DeleteBigC2MRG (unif01_Gen * gen) +{ + BigC2MRG_param *param; + BigC2MRG_state *state; + int i; + + if (NULL == gen) + return; + param = gen->param; + state = gen->state; + mpf_clear (param->F1); + mpf_clear (param->F2); + mpf_clear (param->Norm1); + mpf_clear (param->Norm2); + + for (i = 1; i <= state->k; i++) { + if (param->A1nonZero[i]) + mpz_clear (param->A1[i]); + if (param->A2nonZero[i]) + mpz_clear (param->A2[i]); + mpz_clear (state->S1[i]); + mpz_clear (state->S2[i]); + } + + mpz_clear (param->M1); + mpz_clear (param->M2); + mpz_clear (param->T1); + mpz_clear (param->T2); + mpz_clear (param->W); + + util_Free (param->A1nonZero); + util_Free (param->A2nonZero); + + util_Free (state->S1); + util_Free (state->S2); + util_Free (param->A1); + util_Free (param->A2); + + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + +#endif + +/***************************************************************************/ + +static double LagFibAddFloat_U01 (void *junk, void *vsta) +{ + LagFibFloat_state *state = vsta; + double temp; + + temp = state->X[state->r] + state->X[state->s]; + if (temp >= 1.0) + temp -= 1.0; + state->X[state->r] = temp; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibSousFloat_U01 (void *vpar, void *vsta) +{ + LagFibFloat_param *param = vpar; + LagFibFloat_state *state = vsta; + double temp; + + if (param->Flag) + temp = state->X[state->r] - state->X[state->s]; + else + temp = state->X[state->s] - state->X[state->r]; + if (temp < 0.0) + temp += 1.0; + state->X[state->r] = temp; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibAddFloatLux_U01 (void *vpar, void *vsta) +{ + LagFibFloat_param *param = vpar; + LagFibFloat_state *state = vsta; + double temp; + int j; + + if (--state->RR == 0) { + state->RR = state->Lag; + for (j = 0; j < param->Skip; j++) { + temp = state->X[state->r] + state->X[state->s]; + state->X[state->r] = (temp >= 1.0) ? temp - 1.0 : temp; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + } + } + temp = state->X[state->r] + state->X[state->s]; + if (temp >= 1.0) + temp -= 1.0; + state->X[state->r] = temp; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibSousFloatLux_U01 (void *vpar, void *vsta) +{ + LagFibFloat_param *param = vpar; + LagFibFloat_state *state = vsta; + double temp; + int j; + + if (--state->RR == 0) { + state->RR = state->Lag; + for (j = 0; j < param->Skip; j++) { + if (param->Flag) + temp = state->X[state->r] - state->X[state->s]; + else + temp = state->X[state->s] - state->X[state->r]; + state->X[state->r] = (temp < 0.0) ? temp + 1.0 : temp; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + } + } + if (param->Flag) + temp = state->X[state->r] - state->X[state->s]; + else + temp = state->X[state->s] - state->X[state->r]; + if (temp < 0.0) + temp += 1.0; + state->X[state->r] = temp; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibAddFloat_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LagFibAddFloat_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibSousFloat_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LagFibSousFloat_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibAddFloatLux_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LagFibAddFloatLux_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibSousFloatLux_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LagFibSousFloatLux_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrLagFibFloat (void *vsta) +{ + LagFibFloat_state *state = vsta; + int j; + unsigned long Z; + + if (unif01_WrLongStateFlag) { + printf ("S = {\n"); + for (j = 0; j < state->Lag; j++) { + Z = unif01_NORM32 * state->X[state->r]; + printf (" %12lu", Z); + if (--state->r == 0) + state->r = state->Lag; + if (j < state->Lag - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n"); + } + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * umrg_CreateLagFibFloat (int k, int r, char Op, int Lux, + unsigned long S[]) +{ + unif01_Gen *gen; + LagFibFloat_param *param; + LagFibFloat_state *state; + size_t leng; + char name[LEN + 1]; + char chaine[2]; + int j; + double *X; + +/* util_Assert (k > r, "umrg_CreateLagFibFloat: k <= r"); */ + util_Assert ((Op == '-') || (Op == '+'), + "umrg_CreateLagFibFloat: only + and - are implemented"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LagFibFloat_param)); + state = util_Malloc (sizeof (LagFibFloat_state)); + + strncpy (name, "umrg_CreateLagFibFloat:", (size_t) LEN); + addstr_Long (name, " k = ", k); + addstr_Long (name, ", r = ", r); + strcat (name, ", Op = "); + sprintf (chaine, "%c", Op); + strcat (name, chaine); + addstr_Long (name, ", Lux = ", Lux); + if (k >= r) + addstr_ArrayUlong (name, ", S = ", k, S); + else + addstr_ArrayUlong (name, ", S = ", r, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (k >= r) { + state->Lag = k; + state->r = k; + state->s = r; + param->Flag = TRUE; + } else { + state->Lag = r; + state->r = r; + state->s = k; + param->Flag = FALSE; + } + param->Skip = Lux - state->Lag; + + if (param->Skip > 0) { + X = util_Calloc ((size_t) Lux + 1, sizeof (double)); + state->RR = state->Lag; + switch (Op) { + case '+': + gen->GetBits = &LagFibAddFloatLux_Bits; + gen->GetU01 = &LagFibAddFloatLux_U01; + break; + case '-': + gen->GetBits = &LagFibSousFloatLux_Bits; + gen->GetU01 = &LagFibSousFloatLux_U01; + break; + } + } else { + X = util_Calloc ((size_t) state->Lag + 1, sizeof (double)); + switch (Op) { + case '+': + gen->GetBits = &LagFibAddFloat_Bits; + gen->GetU01 = &LagFibAddFloat_U01; + break; + case '-': + gen->GetBits = &LagFibSousFloat_Bits; + gen->GetU01 = &LagFibSousFloat_U01; + break; + } + } + + for (j = 0; j < state->Lag; j++) + X[state->Lag - j] = (S[j] & MASK32) / unif01_NORM32; + + state->X = X; + gen->param = param; + gen->state = state; + gen->Write = &WrLagFibFloat; + + return gen; +} + +/*-------------------------------------------------------------------------*/ + +void umrg_DeleteLagFibFloat (unif01_Gen * gen) +{ + LagFibFloat_state *state; + + if (NULL == gen) + return; + state = gen->state; + util_Free (state->X); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +static unsigned long LagFibAdd_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + state->X[state->r] = (state->X[state->r] + state->X[state->s]) & param->Mask; + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibAddLux_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + if (--state->RR == 0) { + int j; + state->RR = state->Lag; + for (j = 0; j < param->Skip; j++) { + state->X[state->r] = (state->X[state->r] + state->X[state->s]) & param->Mask; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + } + } + state->X[state->r] = (state->X[state->r] + state->X[state->s]) & param->Mask; + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibAdd_U01 (void *vpar, void *vsta) +{ + return LagFibAdd_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibAddLux_U01 (void *vpar, void *vsta) +{ + return LagFibAddLux_Bits (vpar, vsta) * unif01_INV32; +} + + +/**************************************************************************/ + +static unsigned long LagFibSub_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + if (param->Flag) + state->X[state->r] = (state->X[state->r] - state->X[state->s]) & param->Mask; + else + state->X[state->r] = (state->X[state->s] - state->X[state->r]) & param->Mask; + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibSubLux_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + if (--state->RR == 0) { + int j; + state->RR = state->Lag; + for (j = 0; j < param->Skip; j++) { + if (param->Flag) + state->X[state->r] = (state->X[state->r] - state->X[state->s]) & + param->Mask; + else + state->X[state->r] = (state->X[state->s] - state->X[state->r]) & + param->Mask; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + } + } + if (param->Flag) + state->X[state->r] = (state->X[state->r] - state->X[state->s]) & param->Mask; + else + state->X[state->r] = (state->X[state->s] - state->X[state->r]) & param->Mask; + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibSub_U01 (void *vpar, void *vsta) +{ + return LagFibSub_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibSubLux_U01 (void *vpar, void *vsta) +{ + return LagFibSubLux_Bits (vpar, vsta) * unif01_INV32; +} + + +/**************************************************************************/ + +static unsigned long LagFibXor_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + state->X[state->r] = state->X[state->s] ^ state->X[state->r]; + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibXorLux_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + if (--state->RR == 0) { + int j; + state->RR = state->Lag; + for (j = 0; j < param->Skip; j++) { + state->X[state->r] = (state->X[state->r] ^ state->X[state->s]); + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + } + } + state->X[state->r] = (state->X[state->r] ^ state->X[state->s]); + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibXor_U01 (void *vpar, void *vsta) +{ + return LagFibXor_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibXorLux_U01 (void *vpar, void *vsta) +{ + return LagFibXorLux_Bits (vpar, vsta) * unif01_INV32; +} + + +/**************************************************************************/ + +static unsigned long LagFibMult_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + state->X[state->r] = (state->X[state->r] * state->X[state->s]) & param->Mask; + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LagFibMultLux_Bits (void *vpar, void *vsta) +{ + LagFib_param *param = vpar; + LagFib_state *state = vsta; + unsigned long temp; + + if (--state->RR == 0) { + int j; + state->RR = state->Lag; + for (j = 0; j < param->Skip; j++) { + state->X[state->r] = (state->X[state->r] * state->X[state->s]) & param->Mask; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + } + } + state->X[state->r] = (state->X[state->r] * state->X[state->s]) & param->Mask; + if (param->LeftShift) + temp = state->X[state->r] << param->b; + else + temp = state->X[state->r] >> param->b; + if (--state->r == 0) + state->r = state->Lag; + if (--state->s == 0) + state->s = state->Lag; + return temp; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibMult_U01 (void *vpar, void *vsta) +{ + return LagFibMult_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static double LagFibMultLux_U01 (void *vpar, void *vsta) +{ + return LagFibMultLux_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrLagFib (void *vsta) +{ + LagFib_state *state = vsta; + int j; + + if (unif01_WrLongStateFlag) { + printf ("S = {\n"); + for (j = 0; j < state->Lag; j++) { + printf (" %12lu", state->X[state->r]); + if (--state->r == 0) + state->r = state->Lag; + if (j < state->Lag - 1) + printf (","); + if ((j % 5) == 4) + printf ("\n"); + } + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * umrg_CreateLagFib (int t, int k, int r, char Op, int Lux, + unsigned long S[]) +{ + unif01_Gen *gen; + LagFib_param *param; + LagFib_state *state; + size_t leng; + char name[LEN + 1]; + char chaine[2]; + int j; + unsigned long *X; + + util_Assert (t > 0, "umrg_CreateLagFib: t <= 0"); +#ifdef IS_ULONG32 + util_Assert (t <= 32, "umrg_CreateLagFib: t > 32"); +#else + util_Assert (t <= 64, "umrg_CreateLagFib: t > 64"); +#endif + /* util_Assert (k > r, "umrg_CreateLagFib: k <= r"); */ + util_Assert ((Op == '*') || (Op == '+') || (Op == '-') || (Op == 'x'), + "umrg_CreateLagFib: Op must be one of { +, -, *, x }"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LagFib_param)); + state = util_Malloc (sizeof (LagFib_state)); + + strcpy (name, "umrg_CreateLagFib:"); + addstr_Long (name, " t = ", t); + addstr_Long (name, ", k = ", k); + addstr_Long (name, ", r = ", r); + strcat (name, ", Op = "); + sprintf (chaine, "%c", Op); + strcat (name, chaine); + addstr_Long (name, ", Lux = ", Lux); + + if (k >= r) { + state->Lag = k; + state->r = k; + state->s = r; + param->Flag = TRUE; + } else { + state->Lag = r; + state->r = r; + state->s = k; + param->Flag = FALSE; + } + param->Skip = Lux - state->Lag; + + addstr_ArrayUlong (name, ", S = ", state->Lag, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->b = t - 32; + if (param->b <= 0) { + param->b = -param->b; + param->LeftShift = TRUE; + } else { + param->LeftShift = FALSE; + } + param->Mask = (1UL << t) - 1; +#ifndef IS_ULONG32 + if (64 == t) + param->Mask = 0xffffffffffffffffUL; +#endif + if (32 == t) + param->Mask = 0xffffffffUL; + + if (param->Skip > 0) { + X = util_Calloc ((size_t) Lux + 1, sizeof (unsigned long)); + state->RR = state->Lag; + + switch (Op) { + case '*': + gen->GetBits = &LagFibMultLux_Bits; + gen->GetU01 = &LagFibMultLux_U01; + break; + case '-': + gen->GetBits = &LagFibSubLux_Bits; + gen->GetU01 = &LagFibSubLux_U01; + break; + case '+': + gen->GetBits = &LagFibAddLux_Bits; + gen->GetU01 = &LagFibAddLux_U01; + break; + case 'x': + gen->GetBits = &LagFibXorLux_Bits; + gen->GetU01 = &LagFibXorLux_U01; + break; + } + + } else { + X = util_Calloc ((size_t) state->Lag + 1, sizeof (unsigned long)); + switch (Op) { + case '*': + gen->GetBits = &LagFibMult_Bits; + gen->GetU01 = &LagFibMult_U01; + break; + case '-': + gen->GetBits = &LagFibSub_Bits; + gen->GetU01 = &LagFibSub_U01; + break; + case '+': + gen->GetBits = &LagFibAdd_Bits; + gen->GetU01 = &LagFibAdd_U01; + break; + case 'x': + gen->GetBits = &LagFibXor_Bits; + gen->GetU01 = &LagFibXor_U01; + break; + } + } + + if (Op == '*') { + int flag = 0; + for (j = 0; j < state->Lag; j++) { + X[state->Lag - j] = (S[j] & param->Mask) | 1; + if (X[state->Lag - j] % 4 != 1) + flag = 1; + } + /* Make sure that not all seeds are = 1 mod 4 */ + if (!flag) + X[1] = (X[1] + 2) & param->Mask; + } else { + for (j = 0; j < state->Lag; j++) + X[state->Lag - j] = S[j] & param->Mask; + } + + state->X = X; + gen->param = param; + gen->state = state; + gen->Write = &WrLagFib; + return gen; +} + + +/*-------------------------------------------------------------------------*/ + +void umrg_DeleteLagFib (unif01_Gen * gen) +{ + LagFib_state *state; + + if (NULL == gen) + return; + state = gen->state; + util_Free (state->X); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + +/**************************************************************************/ diff --git a/TESTU01/TestU01-1.2.3/testu01/umrg.tex b/TESTU01/TestU01-1.2.3/testu01/umrg.tex new file mode 100644 index 0000000..06b0cb8 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/umrg.tex @@ -0,0 +1,257 @@ +\defmodule{umrg} + +This module implements {\em multiple recursive generators\/} (MRGs), +based on a linear recurrence of order $k$, modulo $m$: +\eq + x_n = (a_1 x_{n-1} + \cdots + a_k x_{n-k}) \mod m. \eqlabel {mrg} +\endeq +and whose output is normally $u_n = x_n / m$. +It implements combined MRGs as well. +For more details about these generators, see for example +\cite {rLEC93a,rLEC94a,rLEC96b,rLEC99b,rLEC00b,rNIE92b}. + +{\em Lagged-Fibonacci\/} generators are also implemented here. +These generators are actually MRGs only when the selected operation +is addition or subtraction. +Multiplicative lagged-Fibonacci generators, for example, are {\em not\/} +MRGs, but are implemented here nonetheless. + +Some of the generators in this module use the GNU multiprecision package GMP. +%% (see the web site at \url{http://www.gnu.org/software/gmp/gmp.html}). +The macro {\tt USE\_GMP} is defined in module {\tt gdef} in directory +{\tt mylib}. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* umrg.h for ANSI C */ +#ifndef UMRG_H +#define UMRG_H +\endhide +#include "gdef.h" +#include "unif01.h" +\endcode + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Simple MRGs} + +\code +unif01_Gen * umrg_CreateMRG (long m, int k, long A[], long S[]); +\endcode + \tab Implements a MRG of the form (\ref{mrg}), with + $(a_1,\dots,a_k)$ in {\tt A[0..(k-1)]}, initial state + $(x_{-1},\dots,\?x_{-k})$ in {\tt S[0..(k-1)]}, and output + $u_n = x_n / m$. +\index{Generator!multiple recursive}% + Faster implementations are provided for the special cases + $k =2, 3, 5, 7$ when + $A[0] > 0, A[k-1] > 0$, and all other $A[i] = 0$. +% U_n = \cases { X_n/(m+1) & si $X_n\not=0$,\cr +% \rule{0pt}{16pt} m/(m+1) & si $X_n=0$.\cr } + Restrictions: $2 \le k$, $|a_i| (m \mod |a_i|) < m$, + $-m < a_i < m$, and $-m < x_{-i} < m$, for $i = 1,\dots,k$. + \endtab +\code + + +unif01_Gen * umrg_CreateMRGFloat (long m, int k, long A[], long S[]); +\endcode + \tab Similar to {\tt umrg\_CreateMRG} above, but uses a floating-point + implementation, as described in \cite{rLEC99b}. + Restrictions: $2 \le k$, + $-m < a_i < m$ and $-m < x_{-i} < m$ for $i = 1,\dots,k$, and + $m \max (Q^+, -Q^-) < 2^{53}$ + where $Q^+$ is the sum of the positive coefficients $a_i$ + and $Q^-$ is the sum of the negative coefficients $a_i$. + \endtab +\code + + +#ifdef USE_GMP + unif01_Gen * umrg_CreateBigMRG (char *m, int k, char *A[], char *S[]); +\endcode + \tab Similar to {\tt umrg\_CreateMRG} above, except that the modulus, + coefficients, and initial state are given as decimal character strings + in {\tt m}, {\tt A[0..(k-1)]} and {\tt S[0..(k-1)]}. + Restrictions: $-m < a_i < m$ and $-m < x_{-i} < m$ for $i = 1,\dots,k$. + \endtab +\code +#endif + + +unif01_Gen * umrg_CreateLagFibFloat (int k, int r, char Op, int Lux, + unsigned long S[]); +\endcode + \tab Implements a 2-lags Fibonacci generator \cite{rMAR85a,rKNU98a}, + using a floating-point implementation, +\index{Generator!lag-Fibonacci}% + with recurrence + $$ + u_n = (u_{n-k} \mbox{ \tt Op } u_{n-r}) \bmod 1, + $$ + where the binary operator {\tt Op} can take the values + {\tt '+'} or {\tt '-'}, which stand for addition and subtraction. + The seed vector {\tt S[0..(k-1)]} must contain the first {\tt k} values + $u_{-1},\dots,u_{-k}$. +% It must have been initialized before calling {\tt umrg\_CreateLagFibFloat}. + The parameter {\tt Lux} gives the {\em luxury level} defined as + follows: if {\tt Lux} is larger than $k$, + then for each block of {\tt Lux} successive output values, + the first $k$ are used and the next ${\tt Lux} - k$ are skipped. + If {\tt Lux} $\le k$, no value is skipped. {\em Note:} for {\tt Op = '-'}, + one may choose either $k < r$ or $k > r$. For example, the case + $k=55$, $r=24$ corresponds to $X_n = (X_{n-55} - X_{n-24}) \bmod 1$, + while the case $k=24$, $r=55$ corresponds to $X_n = (X_{n-24} - X_{n-55}) + \bmod 1$. + {\em Restrictions:} ${\tt S[i]} < 2^{32}$ and {\tt Op} $\in$ \{{\tt '+', '-'}\}. + \endtab +\code + + +unif01_Gen * umrg_CreateLagFib (int t, int k, int r, char Op, int Lux, + unsigned long S[]); +\endcode + \tab + Similar to {\tt umrg\_CreateLagFibFloat}, except that the implementation + uses $t$-bit integers + $$ + X_n = (X_{n-k} \mbox{ \tt Op } X_{n-r}) \bmod 2^t. + $$ +\index{Generator!lag-Fibonacci}% + The parameter {\tt Op} may take one of + the values \{{\tt '*', '+', '-', 'x'}\}, which stands for multiplication, + addition, subtraction, and exclusive-or respectively. + Note that the resulting multiplicative lagged-Fibonacci generator + is not an MRG. Assume that $k>r$. + If $M$ is a power of 2, say $M = 2^t$, then the maximal period length + is $(2^k-1) 2^{t-1}$ for the additive and subtractive cases, + and $(2^k-1) 2^{t-3}$ for the multiplicative case. + This maximal period is reached if and only if the characteristic + polynomial $f(x) = x^k - x^{k-r} - 1$ is a primitive polynomial + modulo 2 (i.e., over the finite field $\mathbb{F}_2$) + \cite{rKNU81a,rBRE94a,rCOD94a}. + Pairs of lags $(k,r)$ that give a maximal period can be found in + \cite{rMAR85b,rKNU98a,rBRE94a}. {\em Note:} for {\tt Op = '-'}, + one may choose $k < r$ or $k > r$. For example, the case + $k=55$, $r=24$ corresponds to $X_n = (X_{n-55} - X_{n-24}) \bmod 2^t$, + while $k=24$, $r=55$ corresponds to $X_n = (X_{n-24} - X_{n-55}) \bmod 2^t$. + \hrichard {Une r\'ef\'erence int\'eressante est: + \url{http://nhse.cs.rice.edu/NHSEreview/RNG/node11.html}.} +\iffalse %%%%%%%% +\begin{center} +\begin{tabular}{|@{\qquad}c@{\qquad}@{\qquad}c@{\qquad}|}\hline + $k$ & $r$ \\ \hline + 9689 & 4187 \\ + 4423 & 2098 \\ + 2281 & 1029 \\ + 1279 & 418 \\ + 607 & 273 \\ + 521 & 168 \\ + 250 & 103 \\ + 127 & 63 \\ + 97 & 33 \\ + 55 & 24 \\ + 43 & 22 \\ + 31 & 13 \\ + 24 & 10 \\ + 17 & 5 \\ + 7 & 3 \\[2pt] + \hline +\end{tabular} +\end{center} +\fi %%%%% + Restrictions: $0 < t \le 64$. In the case {\tt Op = '*'}, + all the $S[i]$ must be odd; if they are not, 1 will be added to the even + values. +\endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Combined MRGs} + +\code + +unif01_Gen * umrg_CreateC2MRG (long m1, long m2, int k, long A1[], + long A2[], long S1[], long S2[]); +\endcode + \tab Implements a generator that combines two MRGs of order $k$. + The combination method is by subtracting the states modulo $m_1$ + and the implementation is the same as in Figure~1 of \cite{rLEC96b}. + Restrictions: assumes that $a_{11} = 0$, $a_{12} > 0$, $a_{13} < 0$, + $a_{21} > 0$, $a_{22} = 0$ and $a_{23} < 0$, + $k=3$ and the coefficients must satisfy the conditions + $a_{1j} (m_1 \mod a_{1j}) < m_1$ and $a_{2j} (m_2 \mod a_{2j}) < m_2$. + \endtab +\code + + +#ifdef USE_GMP + unif01_Gen * umrg_CreateBigC2MRG (char *m1, char *m2, int k, char *A1[], + char *A2[], char *S1[], char *S2[]); +\endcode + \tab Implements a combined generator obtained from 2 MRGs + of order $k$, whose modulus are $m_1$ and $m_2$. + The coefficients of the 2 components are given as decimal strings in + {\tt A1[0..(k-1)], A2[0..(k-1)]}, and the initial values + are in {\tt S1[0..(k-1)], S2[0..(k-1)]}, also given as decimal strings. + Restrictions are as for {\tt umrg\_CreateMRG}. + + \endtab +\code +#endif +\endcode + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Clean-up functions} +\code + +void umrg_DeleteMRG (unif01_Gen * gen); +void umrg_DeleteMRGFloat (unif01_Gen * gen); +void umrg_DeleteLagFib (unif01_Gen * gen); +void umrg_DeleteLagFibFloat (unif01_Gen * gen); +void umrg_DeleteC2MRG (unif01_Gen * gen); + +#ifdef USE_GMP + void umrg_DeleteBigMRG (unif01_Gen * gen); + void umrg_DeleteBigC2MRG (unif01_Gen * gen); +#endif +\endcode + \tab Frees the dynamic memory used by the generators of this module, + and allocated by the corresponding {\tt Create} function. + \endtab +\code +\hide +#endif +\endhide +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Some related generators} +{ +\iffalse %%%%%%%%% +For other specific MRGs, see also + +\begin{itemize} +\item {\tt uwu\_CreateMRGWuG2} %% This is still confidential! +\end{itemize} + +\bigskip +\fi %%%%%%%% + +For some other specific lagged-Fibonacci generators, see also + +\begin{itemize} +\item {\tt uknuth\_CreateRan\_array1} +\item {\tt uknuth\_CreateRan\_array2} +\item {\tt uknuth\_CreateRanf\_array1} +\item {\tt uknuth\_CreateRanf\_array2} +\end{itemize} +} diff --git a/TESTU01/TestU01-1.2.3/testu01/unif01.c b/TESTU01/TestU01-1.2.3/testu01/unif01.c new file mode 100644 index 0000000..02bf620 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/unif01.c @@ -0,0 +1,1429 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: unif01.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "gdef.h" +#include "util.h" +#include "num.h" +#include "chrono.h" +#include "swrite.h" +#include "unif01.h" + +#include +#include +#include +#include + + +#define LEN0 500 /* Length of strings */ +#define LEN1 100 /* Length of strings */ + +#define MASK32 0xffffffffUL /* 2^32 - 1 */ + + + + +/*------------------------- extern variables ------------------------------*/ + +lebool unif01_WrLongStateFlag = FALSE; + + + + + +/* ========================== functions ================================== */ + +void unif01_WriteNameGen (unif01_Gen *gen) +{ + if (gen->name) + printf ("%s\n\n", gen->name); +} + +void unif01_WriteState (unif01_Gen *gen) +{ + printf ("\nGenerator state:\n"); + gen->Write (gen->state); + printf ("\n"); +} + +void unif01_WrLongStateDef (void) +{ + printf (" Not shown here ... takes too much space\n"); +} + + +/**************************************************************************/ + +double unif01_StripD (unif01_Gen *gen, int r) +{ + if (r == 0) { + return (gen->GetU01) (gen->param, gen->state); + } else { + double u = num_TwoExp[r] * (gen->GetU01) (gen->param, gen->state); + return (u - (long) u); + } +} + +long unif01_StripL (unif01_Gen *gen, int r, long d) +{ + if (r == 0) + return (long) (d * gen->GetU01 (gen->param, gen->state)); + else { + double u = num_TwoExp[r] * (gen->GetU01) (gen->param, gen->state); + return (long) (d * (u - (long) u)); + } +} + +unsigned long unif01_StripB (unif01_Gen *gen, int r, int s) +{ + if (r == 0) { + return gen->GetBits (gen->param, gen->state) >> (32 - s); + } else { + unsigned long u = gen->GetBits (gen->param, gen->state); + return ((u << r) & MASK32) >> (32 - s); + } +} + + +/*************************************************************************/ + +/* Dummy generator, always return 0. */ + +static double DummyGen_U01 (void *junk1, void *junk2) +{ + return 0.0; +} + +static unsigned long DummyGen_Bits (void *junk1, void *junk2) +{ + return 0; +} + +static void WrDummyGen (void *junk) +{ + printf (" Empty Generator (no state)\n"); +} + +unif01_Gen * unif01_CreateDummyGen (void) +{ + unif01_Gen *gen; + size_t len; + + gen = util_Malloc (sizeof (unif01_Gen)); + len = strlen ("Dummy generator that always returns 0"); + gen->name = util_Calloc (len + 1, sizeof (char)); + strncpy (gen->name, "Dummy generator that always returns 0", len); + gen->param = NULL; + gen->state = NULL; + gen->Write = &WrDummyGen; + gen->GetBits = &DummyGen_Bits; + gen->GetU01 = &DummyGen_U01; + return gen; +} + +void unif01_DeleteDummyGen (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->name = util_Free (gen->name); + util_Free (gen); +} + +void unif01_DeleteGen (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ +/* + * The original generator is gen0. The position of the bit at which the + * increased precision is applied is s, counting from the most significant + * bit; v = 1 / 2^s. + */ +typedef struct { + unif01_Gen *gen0; + double v; + int s; +} DoubleGen_param; + + +static double DoubleGen_U01 (void *vpar, void *junk) +{ + double U; + DoubleGen_param *paramD = vpar; + unif01_Gen *gen = paramD->gen0; + + U = gen->GetU01 (gen->param, gen->state); + U += paramD->v * gen->GetU01 (gen->param, gen->state); + if (U < 1.0) + return U; + else + return U - 1.0; +} + +static unsigned long DoubleGen_Bits (void *vpar, void *junk) +{ + return (unsigned long) (unif01_NORM32 * DoubleGen_U01 (vpar, junk)); +} + + +unif01_Gen * unif01_CreateDoubleGen2 (unif01_Gen *gen, double v) +{ + unif01_Gen *genD; + DoubleGen_param *paramD; + char *name; + char str[20]; + size_t len, len2, len3; + + util_Assert (v > 0.0, "unif01_CreateDoubleGen2: h <= 0"); + util_Assert (v < 1.0, "unif01_CreateDoubleGen2: h >= 1"); + genD = util_Malloc (sizeof (unif01_Gen)); + paramD = util_Malloc (sizeof (DoubleGen_param)); + paramD->s = -num_Log2(v); + paramD->v = v; + paramD->gen0 = gen; + + len = strlen (gen->name); + len2 = strlen ("\nunif01_CreateDoubleGen2 with h = "); + len += len2; + sprintf (str, "%-g", v); + len3 = strlen (str); + len += len3; + name = util_Calloc (len + 1, sizeof (char)); + strncpy (name, gen->name, len); + strncat (name, "\nunif01_CreateDoubleGen2 with h = ", len2); + strncat (name, str, len3); + + /* The state of the double generator is simply the state of the original + generator */ + genD->name = name; + genD->param = paramD; + genD->state = gen->state; + genD->Write = gen->Write; + genD->GetBits = &DoubleGen_Bits; + genD->GetU01 = &DoubleGen_U01; + return genD; +} + +unif01_Gen * unif01_CreateDoubleGen (unif01_Gen *gen, int s) +{ + unif01_Gen *genD; + DoubleGen_param *paramD; + char *name; + char str[8]; + size_t len, len2, len3; + + util_Assert (s > 0, "unif01_CreateDoubleGen: s <= 0"); + genD = unif01_CreateDoubleGen2 (gen, 1.0 / num_TwoExp[s]); + paramD = genD->param; + paramD->s = s; + + len = strlen (gen->name); + len2 = strlen ("\nunif01_CreateDoubleGen with s = "); + len += len2; + sprintf (str, "%-d", paramD->s); + len3 = strlen (str); + len += len3; + name = util_Calloc (len + 1, sizeof (char)); + strncpy (name, gen->name, len); + strncat (name, "\nunif01_CreateDoubleGen with s = ", len2); + strncat (name, str, len3); + genD->name = name; + return genD; +} + +void unif01_DeleteDoubleGen (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +typedef struct { + unif01_Gen *gen0; /* Original generator */ + long *ILac; /* Table of lacunary indices */ + int k; /* Size of ILac */ + int cur; /* Current index in the table */ + long n; +} LacGen_param; + +static double LacGen_U01 (void *vpar, void *junk) +{ + LacGen_param *paramL = vpar; + unif01_Gen *gen = paramL->gen0; + int cur = paramL->cur; + long *ILac = paramL->ILac; + long j; +#if 1 + if (cur > 0) { + for (j = 2; j <= ILac[cur] - ILac[cur - 1]; j++) + gen->GetU01 (gen->param, gen->state); + } else { + for (j = 0; j < ILac[0]; j++) + gen->GetU01 (gen->param, gen->state); + } + cur++; + if (cur >= paramL->k) + cur = 0; + paramL->cur = cur; + +#else + /* For debugging: write the lacunary indices of the random numbers outputted */ + if (cur > 0) { + for (j = 2; j <= ILac[cur] - ILac[cur - 1]; j++) { + gen->GetU01 (gen->param, gen->state); + paramL->n++; + } + } else { + for (j = 0; j < ILac[0]; j++) { + gen->GetU01 (gen->param, gen->state); + paramL->n++; + } + } + cur++; + if (cur >= paramL->k) + cur = 0; + paramL->cur = cur; + printf ("Lac = %ld\n", paramL->n); + paramL->n++; +#endif + + return gen->GetU01 (gen->param, gen->state); +} + +static unsigned long LacGen_Bits (void *vpar, void *junk) +{ + LacGen_param *paramL = vpar; + unif01_Gen *gen = paramL->gen0; + int cur = paramL->cur; + long *ILac = paramL->ILac; + long j; + + if (cur > 0) { + for (j = 2; j <= ILac[cur] - ILac[cur - 1]; j++) + gen->GetBits (gen->param, gen->state); + } else { + for (j = 0; j < ILac[0]; j++) + gen->GetBits (gen->param, gen->state); + } + cur++; + if (cur >= paramL->k) + cur = 0; + paramL->cur = cur; + return gen->GetBits (gen->param, gen->state); +} + +unif01_Gen * unif01_CreateLacGen (unif01_Gen *gen, int k, long I[]) +{ + unif01_Gen *genL; + LacGen_param *paramL; + char name[LEN0 + 1] = ""; + char str[16]; + size_t len, len2; + int j; + + genL = util_Malloc (sizeof (unif01_Gen)); + paramL = util_Malloc (sizeof (LacGen_param)); + paramL->gen0 = gen; + paramL->k = k; + paramL->cur = 0; + paramL->n = 0; + paramL->ILac = util_Calloc ((size_t) k, sizeof (long)); + for (j = 0; j < k; j++) + paramL->ILac[j] = I[j]; + + len = strlen (gen->name); + strncpy (name, gen->name, len); + len2 = strlen ("\nunif01_CreateLacGen with k = "); + len += len2; + strncat (name, "\nunif01_CreateLacGen with k = ", len2); + sprintf (str, "%-d", k); + strncat (name, str, 16); + strncat (name, ", I = (", 8); + + for (j = 0; j < k; j++) { + sprintf (str, "%-ld", I[j]); + strncat (name, str, 16); + if (j < k - 1) + strncat (name, ", ", 2); + else + strncat (name, ")", 1); + } + + len = strlen (name); + genL->name = util_Calloc (1 + len, sizeof (char)); + strncpy (genL->name, name, len); + + /* The state of the lacunary generator is simply the state of the original + generator */ + genL->param = paramL; + genL->state = gen->state; + genL->Write = gen->Write; + genL->GetBits = &LacGen_Bits; + genL->GetU01 = &LacGen_U01; + return genL; +} + +void unif01_DeleteLacGen (unif01_Gen *gen) +{ + LacGen_param *param; + if (NULL == gen) return; + param = gen->param; + param->ILac = util_Free (param->ILac); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +typedef struct { + unif01_Gen *gen0; /* The original generator */ + double R; /* Total probability over [0, a) */ + double S; /* (R - a) / (1 - a) */ + double invp; /* Inverse of probability density over [0, a) */ + double invq; /* Inverse of probability density over [a, 1) */ +} BiasGen_param; + + +static double BiasGen_U01 (void *vpar, void *junk) +{ + double U; + BiasGen_param *paramB = vpar; + unif01_Gen *gen = paramB->gen0; + + U = gen->GetU01 (gen->param, gen->state); + if (U < paramB->R) + return (U * paramB->invp); + else + return (U - paramB->S) * paramB->invq; +} + + +static unsigned long BiasGen_Bits (void *vpar, void *junk) +{ + return (unsigned long) (unif01_NORM32 * BiasGen_U01 (vpar, junk)); +} + + +unif01_Gen * unif01_CreateBiasGen (unif01_Gen *gen, double a, double R) +{ + const double Epsilon = 2.0E-16; + unif01_Gen *genB; + BiasGen_param *paramB; + double p; /* probability density over [0, a) */ + double q; /* probability density over [a, 1) */ + char name[LEN0 + 1] = ""; + char str[16]; + size_t len; + + util_Assert (R >= 0.0 && R <= 1.0, + "unif01_CreateBiasGen: P must be in [0, 1]"); + util_Assert (a > 0.0 && a < 1.0, + "unif01_CreateBiasGen: a must be in (0, 1)"); + + genB = util_Malloc (sizeof (unif01_Gen)); + paramB = util_Malloc (sizeof (BiasGen_param)); + paramB->gen0 = gen; + + p = R / a; + q = (1.0 - R) / (1.0 - a); + if (p < Epsilon) + paramB->invp = 0.0; + else + paramB->invp = 1.0 / p; + if (q < Epsilon) + paramB->invq = 0.0; + else + paramB->invq = 1.0 / q; + paramB->R = R; + paramB->S = (p - q) * a; + + strncpy (name, gen->name, LEN0); + len = strlen ("\nunif01_CreateBiasGen with P = "); + strncat (name, "\nunif01_CreateBiasGen with P = ", len); + sprintf (str, "%.4f", R); + len = strlen (str); + strncat (name, str, len); + strncat (name, ", a = ", 8); + sprintf (str, "%.4f", a); + len = strlen (str); + strncat (name, str, len); + + len = strlen (name); + genB->name = util_Calloc (1 + len, sizeof (char)); + strncpy (genB->name, name, len); + + /* The state of the bias generator is simply the state of the original + generator */ + genB->param = paramB; + genB->state = gen->state; + genB->Write = gen->Write; + genB->GetBits = &BiasGen_Bits; + genB->GetU01 = &BiasGen_U01; + return genB; +} + +void unif01_DeleteBiasGen (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/*************************************************************************/ +typedef struct { + unif01_Gen *gen0; /* The original generator */ + int k; /* keep k numbers */ + int s; /* skip s numbers */ + int n; /* state */ +} LuxGen_param; + + +static unsigned long LuxGen_Bits (void *vpar, void *junk) +{ + LuxGen_param *paramL = vpar; + unif01_Gen *gen = paramL->gen0; + if (0 == paramL->n) { + int i; + for (i = paramL->s; i > 0; --i) + gen->GetBits (gen->param, gen->state); + paramL->n = paramL->k; + } + --paramL->n; + return gen->GetBits (gen->param, gen->state); +} + + +static double LuxGen_U01 (void *vpar, void *junk) +{ + LuxGen_param *paramL = vpar; + unif01_Gen *gen = paramL->gen0; + if (0 == paramL->n) { + int i; + for (i = paramL->s; i > 0; --i) + gen->GetU01 (gen->param, gen->state); + paramL->n = paramL->k; + } + --paramL->n; + return gen->GetU01 (gen->param, gen->state); +} + + +unif01_Gen * unif01_CreateLuxGen (unif01_Gen *gen, int k, int L) +{ + unif01_Gen *genL; + LuxGen_param *paramL; + char name[LEN0 + 1] = ""; + char str[26]; + size_t len; + const int s = L - k; + + util_Assert (k > 0, "unif01_CreateLuxGen: k <= 0"); + util_Assert (k <= L, "unif01_CreateLuxGen: L < k"); + + genL = util_Malloc (sizeof (unif01_Gen)); + paramL = util_Malloc (sizeof (LuxGen_param)); + paramL->gen0 = gen; + paramL->s = s; + paramL->k = k; + paramL->n = k; + + strncpy (name, gen->name, LEN0); + len = strlen ("\nunif01_CreateLuxGen: k = "); + strncat (name, "\nunif01_CreateLuxGen: k = ", len); + sprintf (str, "%-d, L = %-d", k, L); + len = strlen (str); + strncat (name, str, len); + len = strlen (name); + genL->name = util_Calloc (1 + len, sizeof (char)); + strncpy (genL->name, name, len); + + genL->param = paramL; + genL->state = gen->state; + genL->Write = gen->Write; + genL->GetBits = &LuxGen_Bits; + genL->GetU01 = &LuxGen_U01; + return genL; +} + + +void unif01_DeleteLuxGen (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/*************************************************************************/ +typedef struct { + unif01_Gen *gen0; /* The original generator */ + unsigned long mask; /* s most significant bits */ +} TruncGen_param; + + +static unsigned long TruncGen_Bits (void *vpar, void *junk) +{ + TruncGen_param *paramT = vpar; + unif01_Gen *gen = paramT->gen0; + + return paramT->mask & gen->GetBits (gen->param, gen->state); +} + +static double TruncGen_U01 (void *vpar, void *vsta) +{ + return TruncGen_Bits (vpar, vsta) * unif01_INV32; +} + +unif01_Gen * unif01_CreateTruncGen (unif01_Gen *gen, int b) +{ + unif01_Gen *genT; + TruncGen_param *paramT; + char name[LEN0 + 1] = ""; + char str[16]; + size_t len; + + if (b < 0) + util_Error ("unif01_CreateTruncGen: s < 0"); + if (b > 32) + util_Error ("unif01_CreateTruncGen: s > 32"); + + genT = util_Malloc (sizeof (unif01_Gen)); + paramT = util_Malloc (sizeof (TruncGen_param)); + paramT->gen0 = gen; + if (b >= 32) + paramT->mask = 0xffffffffU; + else + paramT->mask = (0xffffffffU >> (32 - b)) << (32 - b); + + strncpy (name, gen->name, LEN0); + len = strlen ("\nunif01_CreateTruncGen with b = "); + strncat (name, "\nunif01_CreateTruncGen with b = ", len); + sprintf (str, "%-d", b); + len = strlen (str); + strncat (name, str, len); + strncat (name, " bits:", 8); + + len = strlen (name); + genT->name = util_Calloc (1 + len, sizeof (char)); + strncpy (genT->name, name, len); + + /* The state of the trunc generator is simply the state of the original + generator */ + genT->param = paramT; + genT->state = gen->state; + genT->Write = gen->Write; + genT->GetBits = &TruncGen_Bits; + genT->GetU01 = &TruncGen_U01; + return genT; +} + +void unif01_DeleteTruncGen (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/************************************************************************/ +/* + * The original generator is gen0. The r most significant bits of each random + * number are dropped, and the s following bits are kept. + */ +typedef struct { + unif01_Gen *gen0; + int nrows; /* Number of integers used in making a new random number */ + int B; /* Number of blocks in 1 s-bits group */ + int w; /* Number of bits in a block */ + unsigned long maskw; /* Mask of w bits = 2^w - 1 */ + int r; + int s; +} BitBlock_param; + + +typedef struct { + unsigned long *Z; + int n; /* Build n random numbers at a time, n <= 32 */ + BitBlock_param *param; +} BitBlock_state; + + +static unsigned long BitBlock_Bits (void *vpar, void *vsta) +{ + BitBlock_state *state = vsta; + + if (state->n <= 0) { + BitBlock_param *param = vpar; + unsigned long X; + int i, j; + + /* Generate B random integers Z from the bits of nrows random integers + X from the original gen0 */ + for (j = 0; j < param->B; j++) + state->Z[j] = 0; + for (i = 0; i < param->nrows; i++) { + /* Get a random integer X of s bits */ + X = unif01_StripB (param->gen0, param->r, param->s); + /* Take w of the s bits of X to make bits of Z[j] */ + for (j = 0; j < param->B; j++) { + state->Z[j] <<= param->w; + state->Z[j] |= X & param->maskw; + X >>= param->w; + } + } + state->n = param->B; + } + return state->Z[--state->n]; +} + + +static double BitBlock_U01 (void *vpar, void *vsta) +{ + return BitBlock_Bits (vpar, vsta) * unif01_INV32; +} + + +static void WrBitBlock (void *vsta) +{ + BitBlock_state *state = vsta; + state->param->gen0->Write (state->param->gen0->state); +} + + +unif01_Gen * unif01_CreateBitBlockGen (unif01_Gen *gen, int r, int s, int w) +{ + unif01_Gen *genV; + BitBlock_param *paramV; + BitBlock_state *stateV; + char *name; + char str[64]; + size_t len, len2, len3; + + util_Assert (s > 0, "unif01_CreateBitBlockGen: s <= 0"); + util_Assert (r >= 0, "unif01_CreateBitBlockGen: r < 0"); + util_Assert (r + s <= 32, "unif01_CreateBitBlockGen: r + s > 32"); + util_Assert (w > 0, "unif01_CreateBitBlockGen: w < 1"); + util_Assert (32 % w == 0, "unif01_CreateBitBlockGen: w must divide 32"); + + genV = util_Malloc (sizeof (unif01_Gen)); + paramV = util_Malloc (sizeof (BitBlock_param)); + stateV = util_Malloc (sizeof (BitBlock_state)); + paramV->gen0 = gen; + paramV->s = s; + paramV->r = r; + paramV->w = w; + paramV->B = s / w; + paramV->maskw = num_TwoExp[paramV->w] - 1.0; + paramV->nrows = 32 / w; + stateV->param = paramV; + stateV->n = 0; + stateV->Z = util_Calloc ((size_t) paramV->B, sizeof (unsigned long)); + + len = strlen (gen->name); + len2 = strlen ("\nunif01_CreateBitBlockGen: "); + len += len2; + sprintf (str, "r = %1d, s = %1d, w = %1d", r, s, w); + len3 = strlen (str); + len += len3; + name = util_Calloc (len + 1, sizeof (char)); + strncpy (name, gen->name, len); + strncat (name, "\nunif01_CreateBitBlockGen: ", len2); + strncat (name, str, len3); + genV->name = name; + genV->param = paramV; + genV->state = stateV; + genV->Write = &WrBitBlock; + genV->GetBits = &BitBlock_Bits; + genV->GetU01 = &BitBlock_U01; + return genV; +} + + +void unif01_DeleteBitBlockGen (unif01_Gen *gen) +{ + BitBlock_state *state; + if (NULL == gen) return; + state = gen->state; + state->Z = util_Free (state->Z); + gen->param = util_Free (gen->param); + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/************************************************************************/ + +static double CombGen2_U01_Add (void *vpar, void *junk) +{ + unif01_Comb2_Param *g = vpar; + unif01_Gen *gen1 = g->gen1; + unif01_Gen *gen2 = g->gen2; + double U; + + U = gen1->GetU01 (gen1->param, gen1->state) + + gen2->GetU01 (gen2->param, gen2->state); + if (U >= 1.0) + return (U - 1.0); + else + return U; +} + + +static unsigned long CombGen2_Bits_Add (void *vpar, void *junk) +{ + return (unsigned long) (unif01_NORM32 * CombGen2_U01_Add (vpar, junk)); +} + + +static unsigned long CombGen2_Bits_Xor (void *vpar, void *junk) +{ + unif01_Comb2_Param *g = vpar; + unif01_Gen *gen1 = g->gen1; + unif01_Gen *gen2 = g->gen2; + + return gen1->GetBits (gen1->param, gen1->state) ^ + gen2->GetBits (gen2->param, gen2->state); +} + + +static double CombGen2_U01_Xor (void *vpar, void *junk) +{ + return CombGen2_Bits_Xor (vpar, junk) * unif01_INV32; +} + + +static void WrCombGen2 (void *vsta) +{ + unif01_Comb2_Param *g = vsta; + printf ("2 Combined Generators:\n"); + g->gen1->Write (g->gen1->state); + g->gen2->Write (g->gen2->state); +} + + +static unif01_Gen * CreateCombGen2 (unif01_Gen *g1, unif01_Gen *g2, + char *mess, char *name) +{ + unif01_Gen *gen; + unif01_Comb2_Param *paramC; + size_t len, L; + + gen = util_Malloc (sizeof (unif01_Gen)); + paramC = util_Malloc (sizeof (unif01_Comb2_Param)); + paramC->gen1 = g1; + paramC->gen2 = g2; + + len = strlen (g1->name) + strlen (g2->name) + strlen (name) + strlen (mess); + len += 5; + gen->name = util_Calloc (len + 1, sizeof (char)); + L = strlen (mess); + if (L > 0) { + strncpy (gen->name, mess, len); + if (mess[L - 1] != ':') + strncat (gen->name, ":", 3); + strncat (gen->name, "\n", 3); + } + strncat (gen->name, g1->name, len); + strncat (gen->name, "\n", 3); + strncat (gen->name, g2->name, len); + strncat (gen->name, name, len); + + gen->param = paramC; + gen->state = paramC; + gen->Write = &WrCombGen2; + return gen; +} + + +unif01_Gen * unif01_CreateCombAdd2 (unif01_Gen *g1, unif01_Gen *g2, char *Mess) +{ + unif01_Gen *gen; + gen = CreateCombGen2 (g1, g2, Mess, "\nunif01_CreateCombAdd2"); + gen->GetU01 = &CombGen2_U01_Add; + gen->GetBits = &CombGen2_Bits_Add; + return gen; +} + + +unif01_Gen * unif01_CreateCombXor2 (unif01_Gen *g1, unif01_Gen *g2, + char *Mess) +{ + unif01_Gen *gen; + gen = CreateCombGen2 (g1, g2, Mess, "\nunif01_CreateCombXor2"); + gen->GetU01 = &CombGen2_U01_Xor; + gen->GetBits = &CombGen2_Bits_Xor; + return gen; +} + +void unif01_DeleteCombGen (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/************************************************************************/ + +typedef struct { + unif01_Gen *gen1; + unif01_Gen *gen2; + unif01_Gen *gen3; +} Comb3_Param; + + +static double CombGen3_U01_Add (void *vpar, void *junk) +{ + Comb3_Param *g = vpar; + unif01_Gen *gen1 = g->gen1; + unif01_Gen *gen2 = g->gen2; + unif01_Gen *gen3 = g->gen3; + double U; + + /* + When the combined generator is used to generate random integers, in rare + cases, an integer may differ by 1 unit depending on the order of + addition of the 3 terms (one from each component). This is due + to the last bit (bit 53) of the value returned which may be affected by + floating-point numerical errors. Furthermore, the result + may be different if the addition is done without function calls + (as in the pre-programmed version of Wichmann-Hill for example in + {\tt ulcg\_CreateCombWH3}), in which case, the 2 extra guard bits + required by the IEEE-754 standard in floating-point arithmetic + operations may give a more precise result. + */ + U = gen1->GetU01 (gen1->param, gen1->state) + + gen2->GetU01 (gen2->param, gen2->state) + + gen3->GetU01 (gen3->param, gen3->state); + + if (U < 1.0) + return U; + if (U < 2.0) + return (U - 1.0); + return U - 2.0; +} + + +static unsigned long CombGen3_Bits_Add (void *vpar, void *junk) +{ + return (unsigned long) (CombGen3_U01_Add (vpar, junk) * unif01_NORM32); +} + + +static unsigned long CombGen3_Bits_Xor (void *vpar, void *junk) +{ + Comb3_Param *g = vpar; + unif01_Gen *gen1 = g->gen1; + unif01_Gen *gen2 = g->gen2; + unif01_Gen *gen3 = g->gen3; + + return gen1->GetBits (gen1->param, gen1->state) ^ + gen2->GetBits (gen2->param, gen2->state) ^ + gen3->GetBits (gen3->param, gen3->state); +} + + +static double CombGen3_U01_Xor (void *vpar, void *junk) +{ + return CombGen3_Bits_Xor (vpar, junk) * unif01_INV32; +} + + +static void WrCombGen3 (void *vsta ) +{ + Comb3_Param *g = vsta; + printf ("3 Combined Generators:\n"); + g->gen1->Write (g->gen1->state); + g->gen2->Write (g->gen2->state); + g->gen3->Write (g->gen3->state); +} + + +static unif01_Gen * CreateCombGen3 (unif01_Gen *g1, unif01_Gen *g2, + unif01_Gen *g3, const char *mess, const char *name) +{ + unif01_Gen *gen; + Comb3_Param *paramC; + size_t len, L; + + gen = util_Malloc (sizeof (unif01_Gen)); + paramC = util_Malloc (sizeof (Comb3_Param)); + paramC->gen1 = g1; + paramC->gen2 = g2; + paramC->gen3 = g3; + + len = strlen (g1->name) + strlen (g2->name) + strlen (g3->name) + + strlen (name) + strlen (mess); + len += 5; + gen->name = util_Calloc (len + 1, sizeof (char)); + L = strlen (mess); + if (L > 0) { + strncpy (gen->name, mess, len); + if (mess[L - 1] != ':') + strncat (gen->name, ":", 3); + strncat (gen->name, "\n", 3); + } + strncat (gen->name, g1->name, len); + strncat (gen->name, "\n", 3); + strncat (gen->name, g2->name, len); + strncat (gen->name, "\n", 3); + strncat (gen->name, g3->name, len); + strncat (gen->name, name, len); + + gen->param = paramC; + gen->state = paramC; + gen->Write = &WrCombGen3; + return gen; +} + + +unif01_Gen * unif01_CreateCombAdd3 (unif01_Gen *g1, unif01_Gen *g2, + unif01_Gen *g3, char *mess) +{ + unif01_Gen *gen; + gen = CreateCombGen3 (g1, g2, g3, mess, "\nunif01_CreateCombAdd3"); + gen->GetU01 = &CombGen3_U01_Add; + gen->GetBits = &CombGen3_Bits_Add; + return gen; +} + + +unif01_Gen * unif01_CreateCombXor3 (unif01_Gen *g1, unif01_Gen *g2, + unif01_Gen *g3, char *mess) +{ + unif01_Gen *gen; + gen = CreateCombGen3 (g1, g2, g3, mess, "\nunif01_CreateCombXor3"); + gen->GetU01 = &CombGen3_U01_Xor; + gen->GetBits = &CombGen3_Bits_Xor; + return gen; +} + + +/*=========================================================================*/ + +typedef struct { + int j; /* Which random number */ + int i; /* Which generator */ + int L; + int k; /* Number of parallel generators */ + unif01_Gen **agen; /* Parallel generators */ +} ParallelGen_state; + + +static double ParallelGen_U01 (void *junk, void *vsta) +{ + ParallelGen_state *stateP = vsta; + unif01_Gen *g; + + if (++stateP->j >= stateP->L) { + stateP->j = 0; + if (++stateP->i >= stateP->k) + stateP->i = 0; + } + g = stateP->agen[stateP->i]; + return g->GetU01 (g->param, g->state); +} + + +static unsigned long ParallelGen_Bits (void *junk, void *vsta) +{ + ParallelGen_state *stateP = vsta; + unif01_Gen *g; + + if (++stateP->j >= stateP->L) { + stateP->j = 0; + if (++stateP->i >= stateP->k) + stateP->i = 0; + } + g = stateP->agen[stateP->i]; + return g->GetBits (g->param, g->state); +} + + +static void WrParallelGen (void *vsta) +{ + int i; + ParallelGen_state *state = vsta; + printf (" i = %d, j = %d\n\nParallel Generators:\n", state->i, state->j); + for (i = 0; i < state->k; ++i) + unif01_WriteNameGen(state->agen[i]); +} + + +unif01_Gen * unif01_CreateParallelGen (int k, unif01_Gen *gen[], int L) +{ +#define NCAT 16 + unif01_Gen *genP; + ParallelGen_state *stateP; + char name[LEN0 + 1] = {0}; + char str[NCAT + 1]; + size_t len; + int j; + + genP = util_Malloc (sizeof (unif01_Gen)); + stateP = util_Malloc (sizeof (ParallelGen_state)); + stateP->k = k; + stateP->L = L; + stateP->i = k; + stateP->j = L; + stateP->agen = util_Calloc ((size_t) k, sizeof (unif01_Gen *)); + for (j = 0; j < k; j++) + stateP->agen[j] = gen[j]; + + len = strlen ("unif01_CreateParallelGen: k = "); + strncpy (name, "unif01_CreateParallelGen: k = ", len); + sprintf (str, "%-d", k); + strncat (name, str, NCAT); + strncat (name, ", L = ", NCAT); + sprintf (str, "%-d", L); + strncat (name, str, NCAT); + len = strlen (name); + genP->name = util_Calloc (1 + len, sizeof (char)); + strncpy (genP->name, name, len); + + genP->state = stateP; + genP->Write = &WrParallelGen; + genP->GetBits = &ParallelGen_Bits; + genP->GetU01 = &ParallelGen_U01; + return genP; +#undef NCAT +} + + +void unif01_DeleteParallelGen (unif01_Gen *gen) +{ + ParallelGen_state *state; + if (NULL == gen) return; + state = gen->state; + state->agen = util_Free (state->agen); + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/*=========================================================================*/ + +static double (*externGen_U01)(void); /* The external generator U01 */ +static int coGU = 0; /* Counter for GU_U01 */ + + +static double GU_U01 (void *junk1, void *junk2) +{ + return externGen_U01 (); +} + + +static unsigned long GU_Bits (void *junk1, void *junk2) +{ + return (unsigned long) (externGen_U01 () * unif01_NORM32); +} + + +static void WrExternGen (void *junk2) +{ +} + + +unif01_Gen *unif01_CreateExternGen01 (char *name, double (*f_U01)(void)) +{ + unif01_Gen *gen; + size_t leng; + + util_Assert (coGU == 0, + "unif01_CreateExternGen01: only 1 such generator can be in use"); + coGU++; + gen = util_Malloc (sizeof (unif01_Gen)); + gen->state = NULL; + gen->param = NULL; + gen->Write = WrExternGen; + externGen_U01 = f_U01; + gen->GetU01 = GU_U01; + gen->GetBits = GU_Bits; + + if (name) { + leng = strlen (name); + gen->name = util_Calloc (leng + 2, sizeof (char)); + strncpy (gen->name, name, leng); + } else { + gen->name = util_Calloc (1, sizeof (char)); + gen->name[0] = '\0'; + } + return gen; +} + + +void unif01_DeleteExternGen01 (unif01_Gen * gen) +{ + if (NULL == gen) + return; + gen->name = util_Free (gen->name); + util_Free (gen); + coGU--; +} + + +/*=========================================================================*/ + +static unsigned int (*externGen_Bits)(void); +static int coGB = 0; /* Counter for GB_U01 */ + +static double GB_U01 (void *junk1, void *junk2) +{ + return externGen_Bits () / unif01_NORM32; +} + + +static unsigned long GB_Bits (void *junk1, void *junk2) +{ + return externGen_Bits (); +} + + +unif01_Gen *unif01_CreateExternGenBits (char *name, + unsigned int (*f_Bits)(void)) +{ + unif01_Gen *gen; + size_t leng; + + util_Assert (coGB == 0, + "unif01_CreateExternGenBits: only 1 such generator can be in use"); + coGB++; + gen = util_Malloc (sizeof (unif01_Gen)); + gen->state = NULL; + gen->param = NULL; + gen->Write = WrExternGen; + externGen_Bits = f_Bits; + gen->GetU01 = GB_U01; + gen->GetBits = GB_Bits; + + if (name) { + leng = strlen (name); + gen->name = util_Calloc (leng + 2, sizeof (char)); + strncpy (gen->name, name, leng); + } else { + gen->name = util_Calloc (1, sizeof (char)); + gen->name[0] = '\0'; + } + return gen; +} + + +void unif01_DeleteExternGenBits (unif01_Gen * gen) +{ + if (NULL == gen) + return; + gen->name = util_Free (gen->name); + util_Free (gen); + coGB--; +} + + +/*=========================================================================*/ + +static unsigned long (*externGenLong_Bits)(void); +static int coGBL = 0; /* Counter for GBLong_U01 */ + +static double GBLong_U01 (void *junk1, void *junk2) +{ + return externGenLong_Bits () / unif01_NORM32; +} + + +static unsigned long GBLong_Bits (void *junk1, void *junk2) +{ + return externGenLong_Bits (); +} + + +unif01_Gen *unif01_CreateExternGenBitsL (char *name, + unsigned long (*f_Bits)(void)) +{ + unif01_Gen *gen; + size_t leng; + + util_Assert (coGBL == 0, + "unif01_CreateExternGenBitsL: only 1 such generator can be in use"); + coGBL++; + gen = util_Malloc (sizeof (unif01_Gen)); + gen->state = NULL; + gen->param = NULL; + gen->Write = WrExternGen; + externGenLong_Bits = f_Bits; + gen->GetU01 = GBLong_U01; + gen->GetBits = GBLong_Bits; + + if (name) { + leng = strlen (name); + gen->name = util_Calloc (leng + 2, sizeof (char)); + strncpy (gen->name, name, leng); + } else { + gen->name = util_Calloc (1, sizeof (char)); + gen->name[0] = '\0'; + } + return gen; +} + + +void unif01_DeleteExternGenBitsL (unif01_Gen * gen) +{ + if (NULL == gen) + return; + gen->name = util_Free (gen->name); + util_Free (gen); + coGBL--; +} + + +/**************************************************************************/ + +void unif01_TimerGen (unif01_Gen *gen, unif01_TimerRec * pt, long n, + lebool fU01) +{ + chrono_Chrono *C1; + double U; + unsigned long V; + long i; + + C1 = chrono_Create (); + if (fU01) + for (i = 0; i < n; i++) + U = gen->GetU01 (gen->param, gen->state); + else + for (i = 0; i < n; i++) + V = gen->GetBits (gen->param, gen->state); + pt->time = chrono_Val (C1, chrono_sec); + pt->mean = 0.0; + pt->n = n; + pt->fU01 = fU01; + pt->gen = gen; + chrono_Delete (C1); +} + +void unif01_TimerSumGen (unif01_Gen *gen, unif01_TimerRec * pt, long n, + lebool fU01) +{ + chrono_Chrono *C1; + double Sum = 0.0; + unsigned long Y = 0; + long i; + + C1 = chrono_Create (); + if (fU01) + for (i = 0; i < n; i++) + Sum += gen->GetU01 (gen->param, gen->state); + else + for (i = 0; i < n; i++) + Y += gen->GetBits (gen->param, gen->state); + pt->time = chrono_Val (C1, chrono_sec); + if (fU01) + pt->mean = Sum / n; + else + pt->mean = (double) Y / n; + pt->n = n; + pt->gen = gen; + pt->fU01 = fU01; + chrono_Delete (C1); +} + +void unif01_WriteTimerRec (unif01_TimerRec *R) +{ + unif01_Gen *gen = R->gen; + char stri [LEN1 + 1] = ""; + char *p; + size_t len; + + printf ("\n------------- Results of speed test ---------------"); + printf ("\n\n Host: "); + if (swrite_Host) + gdef_WriteHostName (); + else + printf ("\n"); + + /* Print only the generator name, without the parameters or seeds. */ + /* The parameters start after the first blank; name ends with ':' */ + printf (" Generator: "); + len = strcspn (gen->name, ":"); + strncpy (stri, gen->name, len); + stri [len] = '\0'; + printf ("%s", stri); + p = strstr (gen->name, "unif01"); + while (p != NULL) { + /* For Filters or Combined generators */ + len = strcspn (p, " \0"); + strncpy (stri, p, len); + stri [len] = '\0'; + printf (", %s", stri); + p += len; + p = strstr (p, "unif01"); + } + if (R->fU01) { + printf ("\n Method: GetU01"); + if (R->mean > 0.0) + printf ("\n Mean = %.15f", R->mean); + } else { + printf ("\n Method: GetBits"); + if (R->mean > 0.0) + printf ("\n Mean = %.16g", R->mean); + } + printf ("\n Number of calls: %ld", R->n); + printf ("\n Total CPU time: "); + printf ("%6.2f sec\n\n", R->time); +} + +void unif01_TimerGenWr (unif01_Gen *gen, long n, lebool fU01) +{ + unif01_TimerRec timer; + unif01_TimerGen (gen, &timer, n, fU01); + unif01_WriteTimerRec (&timer); +} + +void unif01_TimerSumGenWr (unif01_Gen *gen, long n, lebool fU01) +{ + unif01_TimerRec timer; + unif01_TimerSumGen (gen, &timer, n, fU01); + unif01_WriteTimerRec (&timer); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/unif01.tex b/TESTU01/TestU01-1.2.3/testu01/unif01.tex new file mode 100644 index 0000000..b0aafaf --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/unif01.tex @@ -0,0 +1,883 @@ +\defmodule {unif01} + +This module offers basic tools for defining, manipulating, and +transforming uniform random number generators to which tests are +to be applied or which could be used for other purposes. +Each generator is implemented as a +structure of type {\tt unif01\_Gen}. +Several predefined generators are available in the {\tt u} modules. +Each such generator must be created by the appropriate +{\tt \ldots Create\ldots} function before being used, and should +be deleted by the corresponding {\tt \ldots Delete\ldots} function +to free the memory used by the generator when it is no longer needed. +One can create and use simultaneously any number of generators. +These generators are usually passed to functions as pointers to +objects of type {\tt unif01\_Gen}. + +One may call an external generator for testing using the functions in +this module. See Figure~\ref{prog:ex7} for an example. +One may also implement one's own generator, by creating a structure of +type {\tt unif01\_Gen} and defining all its fields properly. +See Figure~\ref{fig:my16807} for an illustration. + +Each implemented generator returns either a floating-point +number in $[0, 1)$ (via its function {\tt GetU01}) +or a block of 32 bits (via its function {\tt GetBits}). +Ideally, these should follow the uniform distribution $(0,1)$ +and $\{0,\dots,2^{32}-1\}$, respectively. +Most of the tests in the {\tt s} modules actually call the generator +to be tested only indirectly through the use of one of the interface +functions {\tt unif01\_StripD}, + {\tt unif01\_StripL} and {\tt unif01\_StripB}. +These functions drop the $r$ most significant bits of each random number +and return a number built out of the remaining bits. + +Functions are also provided for adding one or many output {\em filters\/} +to a given generator. These functions create another generator +object which implements a mechanism that automatically +transforms the output values of the original generator in a specified way. +One can also combine the outputs of several generators in different ways. +By using the output of several generators or several substreams of the +same generator in a round-robin way, one can test the quality of these as +examples of parallel generators. +Finally, tools are provided for measuring the speed of generators +and adding their output values (for testing purposes). + + + +%%%%%%%%%%%%% +\bigskip\hrule +\code\hide +/* unif01.h for ANSI C */ +#ifndef UNIF01_H +#define UNIF01_H +\endhide +#include "gdef.h" +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Basic types} +\code + +typedef struct { + void *state; + void *param; + char *name; + double (*GetU01) (void *param, void *state); + unsigned long (*GetBits) (void *param, void *state); + void (*Write) (void *state); +} unif01_Gen; +\endcode + \tab Generic random number generator. The function {\tt GetU01} + returns a floating-point number in $[0,1)$ while {\tt GetBits} + returns a block of 32 bits. If the generator delivers less than 32 + bits, these bits are left shifted so that the most + significant bits are the relevant ones. +% If the generator returns less than 32 bits of precision, then one must make +% sure that these bits are the most significant bits of the returned block. + The variable {\tt state} keeps the + current state of the generator and {\tt param} is the set of + specific parameters used in computing the next random number. + The function {\tt Write} will write the current state of the + generator. The string {\tt name} describes the current generator, + its parameters, and its initial state. + In the description of the generators in the u modules, one + indicates how the {\tt GetU01} function gets its value from the + generator's recurrence; + it is always understood that the {\tt GetBits} function is + equivalent to $2^{32}\,${\tt GetU01}. + \endtab + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Environment variables} + +\ifdetailed +\code + +#define unif01_MASK32 0xffffffffUL +\endcode + \tab 32-bit mask. + \endtab +\code + + +#define unif01_NORM32 4294967296.0 +#define unif01_INV32 2.328306436538696289e-10 +\endcode + \tab The constants $2^{32}$ and $1/2^{32}$ respectively: + normalization factors used in many generators to transform + a floating-point ``random'' number into a 32-bit integer, or vice-versa. + \endtab +\fi + +\code + + +extern lebool unif01_WrLongStateFlag; +\endcode + \tab For generators whose state is a large array, determines whether + the state will be written out in full ({\tt TRUE}) or not ({\tt FALSE}) + in the printouts. The default value is {\tt FALSE}. +\hrichard{C'est la seule variable globale qui reste. On pourrait + l'\'eliminer en ajoutant un argument \`a unif01\_Gen.Write, qui + deviendrait {\tt Write (void *state, lebool flag).}} + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Basic functions} + +\code + + +double unif01_StripD (unif01_Gen *gen, int r); +\endcode +\tab Makes one call to the generator {\tt gen}, drops the $r$ most + significant bits, left-shift the others by $r$ positions, and + returns the result, which is a floating-point number in $[0,1)$. + More specifically, returns $2^r u \mod 1$, + where $u$ is the output of {\tt gen}. + \endtab +\code + + +long unif01_StripL (unif01_Gen *gen, int r, long d); +\endcode +\tab + Similar to {\tt unif01\_StripD}, but generates an integer ``uniformly'' over + the set $\{0,\dots,d-1\}$, by using the most significant bits of the + output of {\tt gen} after having dropped the first $r$ bits. + More specifically, returns $\lfloor d (2^r u \mod 1)\rfloor$, + where $u$ is the output of {\tt gen}. +\endtab +\code + + +unsigned long unif01_StripB (unif01_Gen *gen, int r, int s); +\endcode +\tab + Calls the generator {\tt gen}, drops the $r$ most significant bits, + and returns the $s$ following bits as an integer in + the set $\{0,\dots,2^s-1\}$. +\endtab +\code + + +void unif01_WriteNameGen (unif01_Gen *gen); +\endcode + \tab Writes the character string {\tt gen->name} that describes the + generator. + \endtab +\code + + +void unif01_WriteState (unif01_Gen *gen); +\endcode + \tab Writes the current state of generator {\tt gen}. + \endtab +\code + + +void unif01_WrLongStateDef (void); +\endcode + \tab Dummy function used when the state of the current + generator is a large array and we do not want to write the full state. + Writes the message ``{\tt Not shown here ... takes too much space}''. + \endtab +\code + + +unif01_Gen * unif01_CreateDummyGen (void); +\endcode +\tab Creates a {\em dummy\/} generator, which does nothing and always +\index{Generator!dummy}% + returns zero. It can be used for instance to measure the overhead of + function calls when comparing generator's speeds + (see the timing tools below). +\endtab +\code + + +void unif01_DeleteDummyGen (unif01_Gen *gen); +\endcode +\tab Frees the dynamic memory used by the dummy generator above. +\endtab +\ifdetailed +\code + + +void unif01_DeleteGen (unif01_Gen *gen); +\endcode +\tab Frees the dynamic memory used by a typical generator, for which + the state does not contain dynamically allocated arrays. + In this case, the memory + is allocated by a {\tt u\ldots\_Create\ldots} function in some + {\tt u} module and the present function is called by the corresponding + {\tt u\ldots\_Delete\ldots} function in the same {\tt u} module. +\endtab +\fi + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Output filters} + +The following describes some filters that can be added to transform +the output of a given generator. In each case, a new generator object is +created that will effectively apply the filter to the original generator. +One may apply more than one filter at a time on a given generator +(for example, one may apply the {\tt Double}, the {\tt Bias}, the + {\tt Trunc} and the {\tt Lac} filters on top of one another). It suffices + to create the appropriate filters as described below. The resulting +filtered generator(s) will call the original generator behind the scenes. +Thus the state of the original generator will evolve as usual, even +though it is not called directly.\index{filters} + + +The different filters applied on an original generator are not independent +but are related as the elements of a stack. When they are no longer in use, +they must be deleted {\em in the reverse order of their creation}, +the original generator being the last one of this group to be deleted. +Figure~\ref{fig:prog-filter} illustrates how these facilities can be used. + +\code + + +unif01_Gen * unif01_CreateDoubleGen (unif01_Gen *gen, int s); +\endcode + \tab + Given a generator {\tt gen}, this function +\index{Generator!filter!increased precision}% + creates and returns a generator with increased precision, such that + every call to this new generator + corresponds to two successive calls to the original generator. + The method {\tt GetU01} of this doubled generator returns + $(U_1 + U_2/2^s)$ mod 1, where $U_1$ and $U_2$ are the results of + two successive calls to the method {\tt GetU01} of {\tt gen}. + If the current generator has 31 bits of precision, for example, + then one can obtain 53 bits of precision from {\tt GetU01} + by creating this new generator with {\tt s} between $22$ and $31$. +% Not true anymore: +% The function {\tt GetBits} of this new generator +% will return $(X_1 + X_2/2^s)$ mod $2^{32}$, +% where $X_1$ and $X_2$ are the results of two successive calls to the +% method {\tt GetBits} of the original {\tt gen}. +% So it may return more bits of precision, but never more than 32 bits. + \endtab +\code + + +unif01_Gen * unif01_CreateDoubleGen2 (unif01_Gen *gen, double h); +\endcode + \tab A more general version of {\tt unif01\_CreateDoubleGen} where + the method {\tt GetU01} of the double generator returns + $(U_1 + h U_2)$ mod 1. Restriction: $0 < h < 1$. + \endtab +\code + + +unif01_Gen * unif01_CreateLacGen (unif01_Gen *gen, int k, long I[]); +\endcode + \tab + Given an original generator {\tt gen}, this function +\index{Generator!filter!lacunary indices}% + creates and returns a generator involving lacunary indices, such that + successive calls to this new generator + will no longer provide successive values from the original + generator, but rather selected values as specified by + the table {\tt I[0..k-1]}, in a circular fashion. + More specifically, if $u_0, u_1, u_2, \dots$ is the sequence + produced by the original {\tt gen}, if the table {\tt I[0..k-1]} + contains the non-negative integers $i_0, \dots i_{k-1}$ (in increasing + order), and if we put $L = i_{k-1}+1$, + then the output sequence of the new generator will be: + $$ u_{i_0}, u_{i_1}, \dots, u_{i_{k-1}}, u_{L+i_0}, u_{L+i_1}, + \dots, u_{L+i_{k-1}}, u_{2L+i_0}, u_{2L+i_1}, \dots. $$ + For example, if $k=3$ and $I = \{0, 3, 5\}$, + the output sequence will be the numbers + $$ u_{0}, u_{3}, u_{5}, u_{6}, u_{9}, u_{11}, u_{12}, \dots $$ + of the original generator. + To obtain every $s$-th number produced by the original generator + for example (a {\em decimated sequence\/}), one should take + $k=1$ and $I = \{s-1\}$. +% (note that taking $I = \{0, s\}$ won't work; it would return +% $u_0, u_s, u_{s+1}, u_{2s+1}, \dots$). + \endtab +\code + + +unif01_Gen * unif01_CreateLuxGen (unif01_Gen *gen, int k, int L); +\endcode + \tab Given an original generator {\tt gen}, this function +\index{Generator!filter!luxury}% + creates and returns a new generator giving the output of the + original generator with luxury level $L$: out of every group of $L$ + random numbers, the first $k$ are kept and the next $L-k$ are skipped. + \endtab +\code + + +unif01_Gen * unif01_CreateBiasGen (unif01_Gen *gen, double a, double p); +\endcode + \tab Given an original generator {\tt gen}, this function + creates and returns a new generator giving a biased output of the + original generator. The output is biased +\index{Generator!filter!biased output}% + in such a way that the density becomes + constant with total probability $p$ over the interval $[0, a)$, and + constant with total probability $1 - p$ over $[a, 1)$ (the two constant + densities are different). For example, by choosing $p= 1$ and $a = 0.5$, + all the random numbers generated by {\tt GetU01} will fall + on the interval $[0,\; 0.5)$. This filter can be used, for example, + to study the power of certain statistical tests. + Restrictions: $0 < a < 1$ and $0 \le p \le 1$. + \endtab +\code + + +unif01_Gen * unif01_CreateTruncGen (unif01_Gen *gen, int s); +\endcode + \tab Given an original generator {\tt gen}, this function +\index{Generator!filter!bit truncated}% + creates and returns a new generator giving the output of the + original generator truncated to its $s$ most significant bits. + Restriction: $s \le 32$. +\endtab +\code + + +unif01_Gen * unif01_CreateBitBlockGen (unif01_Gen *gen, int r, int s, + int w); +\endcode + \tab Consider a group of $v \le 32$ successive 32-bit integers + outputted by generator {\tt gen}. For each of these, drop the $r$ most +\index{Generator!filter!blocks of bits}% + significant bits and keep the $s$ following bits numbered + $b_{i 1}, b_{i 2}, \ldots, b_{i s}$, starting with the + most significant, for $1 \le i \le v$. + Make with all these a $v\times s$ matrix of bits, say ${\cal B}$. + The generator returned by this function is a filter that builds new 32-bit + integers from $v\times w$ submatrices of ${\cal B}$. + The number of columns of the submatrix $w$ must be a power of 2 no larger + than 32 and it must be $\le s$. If $w$ does not divide $s$ exactly, + the last submatrix of ${\cal B}$ will have less than $w$ columns and + will be disregarded. + + If the stream of bits thus obtained from {\tt gen} is + $$ + b_{1 1}, b_{1 2}, \ldots, b_{1 s}, + b_{2 1}, b_{2 2}, \ldots, b_{2 s}, + \ldots, + b_{v 1}, b_{v 2}, \ldots, b_{v s}, \ldots +$$ + then the new integers returned by the filter will be 32-bit integers + taken from the rearranged stream of bits so that the first new + number is (its most significant bit being given first) + $$ + b_{1 1}, b_{1 2}, \ldots, b_{1 w}, + b_{2 1}, b_{2 2}, \ldots, b_{2 w}, + \ldots, + b_{v 1}, b_{v 2}, \ldots, b_{v w}, +$$ + the second new number is made of the bits (its most + significant bit first) + $$ + b_{1 (w+1)}, b_{1 (w+2)}, \ldots, b_{1 (2w)}, + b_{2 (w+1)}, b_{2 (w+2)}, \ldots, b_{2 (2w)}, + \ldots, + b_{v (w+1)}, b_{v (w+2)}, \ldots, b_{v (2w)}, + $$ + and so on. + + The following examples illustrates how the filter works. + If $r$ = 0 and $w = s = 32$, then the filter has no effect, + the new integers being the same as those outputted by {\tt gen}. + If $r$ = 0 and $w = s = 1$, then the filter will return integers + made only from the most significant bit of the original integers, all + other bits being dropped. + If $r$ = 0, $w = 1$ and $ s = 32$, then the filter will return integers + made from the columns of ${\cal B}$, i.e., since the rows of ${\cal B}$ + are made of the original integers, the filter will return the columns + of ${\cal B}$ as the new integers. + Restrictions: $r \ge 0$, $0 < s \le 32$ and + $w$ in $\{1, 2, 4, 8, 16, 32\}$. + \endtab +\code + + +void unif01_DeleteDoubleGen (unif01_Gen *gen); +void unif01_DeleteLacGen (unif01_Gen *gen); +void unif01_DeleteLuxGen (unif01_Gen *gen); +void unif01_DeleteBiasGen (unif01_Gen *gen); +void unif01_DeleteTruncGen (unif01_Gen *gen); +void unif01_DeleteBitBlockGen (unif01_Gen *gen); +\endcode + \tab Frees the memory used by the generator created by the corresponding + {\tt Create} functions above. + \endtab + + + +%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Combining generators} + +These functions permit one to define the combination of two, three +or more generators. The resulting generator calls +\index{Generator!combined}\index{combined generators}% +the component generators behind the scenes, so it changes their +state. \emph{The component generators must not be destroyed as long as the + combination generator is in use.} +One can obtain the combinations of more than three generators by combining +the generators obtained from combinations of two or three generators. +% +\hide +\code + +typedef struct { + unif01_Gen *gen1; + unif01_Gen *gen2; +} unif01_Comb2_Param; +\endcode + \tab This is used for combining two arbitrary generators. It is made + public because it would not be possible otherwise to free the dynamic + memory used by the two component generators when they are programmed + in another module. + \endtab +\endhide +\code + + +unif01_Gen * unif01_CreateCombAdd2 (unif01_Gen *gen1, unif01_Gen *gen2, + char *name); +\endcode + \tab This function creates and returns a generator whose output is the + addition of the outputs modulo 1 of the method {\tt GetU01} of the + two generators {\tt gen1} and {\tt gen2}. + The character string {\tt name} may be printed in reports to identify this + new combined generator. +\index{combined generators!addition} + \endtab +\code + + +unif01_Gen * unif01_CreateCombAdd3 (unif01_Gen *gen1, unif01_Gen *gen2, + unif01_Gen *gen3, char *name); +\endcode + \tab Same as {\tt unif01\_CreateCombAdd2}, except that the returned + generator is the combination (the addition of the outputs modulo 1 of the + method {\tt GetU01}) of the three generators {\tt gen1, gen2} and {\tt gen3}. +\hrichard{ + When the combined generator is used to generate random integers, in rare + cases, an integer may differ by 1 unit depending on the order of + addition of the 3 terms (one from each component). This is due + to the last bit (bit 53) of the value returned which may be affected by + floating-point numerical errors. Furthermore, the result + may be different if the addition is done without function calls + (as in the pre-programmed version of Wichmann-Hill for example in + {\tt ulcg\_CreateCombWH3}), in which + case, the 2 extra guard bits required by the IEEE-754 standard in + floating-point arithmetic operations may give a more exact result. +} + \endtab +\code + + +unif01_Gen * unif01_CreateCombXor2 (unif01_Gen *gen1, unif01_Gen *gen2, + char *name); +\endcode + \tab This function creates and returns a generator whose output is the + bitwise {\sl exclusive-or (XOR)\/} of the outputs of the two generators + {\tt gen1} and {\tt gen2}. The character string {\tt name} may be printed + in reports to identify this combined generator. + \index{combined generators!exclusive or} + \endtab +\code + + +unif01_Gen * unif01_CreateCombXor3 (unif01_Gen *gen1, unif01_Gen *gen2, + unif01_Gen *gen3, char *name); +\endcode + \tab Same as {\tt unif01\_CreateCombXor2}, except that the + returned generator is the combination of the three generators + {\tt gen1, gen2} and {\tt gen3}. + \endtab +\code + + +void unif01_DeleteCombGen (unif01_Gen *gen); +\endcode + \tab Frees the memory used by one of the combination generators returned + by the {\tt Create} functions above, but does not delete any of its + component generators. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Parallel generators} + + The following functions allow the joining of the output of several generators + or of different substreams of the same generator into a single stream of + random numbers. This can be used to test for apparent correlations between the + output of several generators or several substreams used in parallel. + For example, one may want to choose seeds + that are far separated for the same generator, while making sure that + such seed choice is statistically valid and does not introduce unwanted + correlation between the substreams thus defined. +\code + +unif01_Gen * unif01_CreateParallelGen (int k, unif01_Gen *gen[], int L); +\endcode + \tab Creates and returns a generator whose output is obtained in a round-robin + way $L$ numbers at a time from each of the $k$ generators \texttt{gen[i]} as + follows: the first $L$ numbers are generated from \texttt{gen[0]}, the next + $L$ numbers are generated from \texttt{gen[1]}, and so on until + $L$ numbers have been generated from \texttt{gen[k-1]}, after which, this whole + process is repeated. \emph{It is important that none of the generators} + \texttt{gen[i]} \emph{be destroyed as long as the parallel generator is in use.} + \endtab +\code + + +void unif01_DeleteParallelGen (unif01_Gen *gen); +\endcode + \tab Frees the memory allocated by the parallel generator returned + by the {\tt Create} function above, but \emph{does not} delete any of its + component generators, which is the responsibility of the program that + created them. + \endtab + + +%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{External generators} + +Although TestU01 implements many generators both in generic and in +specific forms, it is not possible to implement all those that are in +existence because there are just too many and new ones are proposed +regularly. The typical user would like to test his preferred generator +with as little complications as possible. The functions below allows one +to do just that. As long as the generator is programmed in C, +one has but to pass the function implementing the generator to one of the +functions below and call some of the tests available in TestU01. +It is the responsibility of the user to ensure that his generator does not +violate the conditions described in the functions below. For the +call in {\tt unif01\_CreateExternGen01}, his generator must return +floating-point numbers in $[0, 1)$. For the calls in + {\tt unif01\_CreateExternGenBitsL} and {\tt unif01\_CreateExternGenBits}, + his generator must return an integer in the interval $[0, 2^{32} - 1]$. +If these conditions are violated, the results of the tests in TestU01 are +unpredictable. % Similarly, a generator should not be so pathological so as to +% return the same value at every call. + \index{Generator!user defined} \index{Generator!external}% +\code + + +unif01_Gen *unif01_CreateExternGen01 (char *name, double (*gen01)(void)); +\endcode +\tab Implements a pre-existing external generator {\tt gen01} that is + not part of TestU01. \label{externgen} + It must be a C function taking no argument and returning a {\tt double} + in the interval $[0, 1)$. Parameter {\tt name} is the name of the generator. + No more than one generator of this type can be in use at a time. +\endtab +\code + + +unif01_Gen *unif01_CreateExternGenBits (char *name, + unsigned int (*genB)(void)); +\endcode +\tab Implements a pre-existing external generator {\tt genB} that is not part + of TestU01. It must be a C function taking no argument and returning + an integer in the interval $[0, 2^{32} - 1]$. + If the generator delivers less than 32 bits of resolution, then these + bits must be left shifted so that the most significant bit is bit 31 + (counting from 0). Parameter {\tt name} is the name of the generator. + No more than one generator of this type can be in use at a time. + \endtab +\code + + +unif01_Gen *unif01_CreateExternGenBitsL (char *name, + unsigned long (*genB)(void)); +\endcode +\tab Similar to {\tt unif01\_CreateExternGenBits}, but with +{\tt unsigned long} instead of {\tt unsigned int}. The generator +{\tt genB} must also return an integer in the interval $[0, 2^{32} - 1]$. + \endtab +\code + + +void unif01_DeleteExternGen01 (unif01_Gen * gen); +void unif01_DeleteExternGenBits (unif01_Gen * gen); +void unif01_DeleteExternGenBitsL (unif01_Gen * gen); +\endcode + \tab Frees the memory used by the generator created by the corresponding + {\tt Create} functions above. + \endtab + + +\bigskip +As an example, Figure~\ref{prog:ex7} shows how to apply + {\tt SmallCrush}, a small predefined battery of tests (described on page + \pageref{bat:SmallCrush}) to the generators {\tt MRG32k3a} and {\tt +xorshift}, whose code is shown in Figures~\ref{fig:MRG32k3a} and + \ref{fig:xorshift}. One must compile and link the two external +files with the main program and the TestU01 library. +The generator {\tt MRG32k3a} returns numbers in (0, 1) and was +proposed by L'Ecuyer in \cite{rLEC99b}. +The generator {\tt xorshift} returns 32-bit integers +and was proposed by Marsaglia in \cite[page 4]{rMAR03a}. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\setbox0=\vbox {\hsize = 6.2in +{\smallc +\verbatiminput{../examples/ex7.c}} +} + +\begin{figure} \centering \myboxit{\box0} +\caption {Example of a program to test two external generators} +\label {prog:ex7} +\end{figure} + + +\setbox1=\vbox {\hsize = 6.2in +{\smallc +\verbatiminput{../examples/mrg32k3a.c}} +} + +\begin{figure} \centering \myboxit{\box1} +\caption {External function for {\tt MRG32k3a}.} +\label {fig:MRG32k3a} +\end{figure} + + +\setbox1=\vbox {\hsize = 6.2in +{\smallc +\verbatiminput{../examples/xorshift.c}} +} + +\begin{figure} \centering \myboxit{\box1} +\caption {External function for {\tt xorshift}.} +\label {fig:xorshift} +\end{figure} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Timing devices} + +\code + +typedef struct { + unif01_Gen *gen; + long n; + double time; + double mean; + lebool fU01; + } unif01_TimerRec; +\endcode + \tab Structure to memorize the results of speed and sum tests on a given + generator. Here, {\tt gen} is the generator,\index{timer} + {\tt n} is the number of calls made to the generator, + {\tt time} is the total CPU time in seconds, and + {\tt mean} is the mean of the {\tt n} output values of the generator. + If {\tt fU01} is {\tt TRUE}, the function {\tt GetU01} of + {\tt gen} is called, otherwise the function {\tt GetBits} is called. + \endtab +\code + + +void unif01_TimerGen (unif01_Gen *gen, unif01_TimerRec *timer, long n, + lebool fU01); +\endcode + \tab + This function computes the CPU time needed to generate +\index{Generator!speed}\index{Generator!timing}% + {\tt n} random numbers with the generator {\tt gen}, + and returns the result in {\tt timer}. If {\tt fU01} is {\tt TRUE}, + the random numbers will be generated by the method {\tt GetU01} of + {\tt gen}, otherwise by the + method {\tt GetBits}. + \endtab +\code + + +void unif01_TimerSumGen (unif01_Gen *gen, unif01_TimerRec *timer, long n, + lebool fU01); +\endcode + \tab + Same as {\tt unif01\_TimerGen}, but also adds the {\tt n} random + numbers and saves their mean in {\tt timer->mean}. + \endtab +\code + + +void unif01_WriteTimerRec (unif01_TimerRec *timer); +\endcode + \tab + Prints the results contained in {\tt timer}, with some information + about the generator and the current machine. One should make sure that the + generator {\tt gen} in {\tt timer} has not been deleted when + calling this function. +\hrichard {Ceci m'inqui\`ete un peu, car si +l'utilisateur appelle cette fonction apr\`es que le g\'en\'erateur +ait \'et\'e d\'etruit, il y aura un {\tt segmentation fault}. L'alternative +serait de r\'eserver un tableau de 50 caract\`eres dans +{\tt unif01\_TimerRec} et d'y recopier le nom du g\'en\'erateur, au lieu +d'avoir le pointeur {\tt gen}.} + \endtab +\code + + +void unif01_TimerGenWr (unif01_Gen *gen, long n, lebool fU01); +\endcode + \tab + Equivalent to calling {\tt unif\_TimerGen} followed by + {\tt unif01\_WriteTimerRec}. + \endtab +\code + + +void unif01_TimerSumGenWr (unif01_Gen *gen, long n, lebool fU01); +\endcode + \tab + Equivalent to calling {\tt unif\_TimerSumGen} followed by + {\tt unif01\_WriteTimerRec}. + \endtab +\code +\hide +#endif +\endhide +\endcode + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\subsection*{Examples} + +We now provide some examples of how to use the facilities of {\tt unif01}. +Figure~\ref{fig:my16807} gives an example of how to implement one's own +generator, using all the paraphernalia of TestU01. This is specially +useful when one wants to implement a generator in generic form with +one or more parameters. + This is a simple LCG with hardcoded parameters $m=2^{31}-1$ +and $a = 16807$.\index{Generator!user defined} +The function {\tt My16807\_U01} will advance the generator's state +by one step and return a $U(0,1)$ random number $U$ each time it is +called, whereas {\tt My16807\_Bits} will return the 32 most significant +bits in the binary representation of $U$. +The function {\tt CreateMy16807} allocates the memory for the corresponding +{\tt unif01\_Gen} structure and initializes all its fields. + + +\setbox2=\vbox {\hsize = 6.2in +{\smallc +\verbatiminput{../examples/my16807.c}} +} + +\begin{figure} \centering \myboxit{\box2} +\caption {A user-defined generator, in file {\tt my16807.c}.} +\label {fig:my16807} +\end{figure} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +Figure~\ref{fig:unif-timing} shows how to use the timing facilities. +The {\tt main} program first sets the generator {\tt gen} to an LCG +with modulus $2^{31}-1$, multiplier $a = 16807$, and initial state 12345, +implemented in floating point. +\hrichard {Sur ma machine Linux, le + LCG (en entiers) est 12\% plus rapide que la version LCGFloat} +(This generator is well known, but certainly {\em not\/} to be recommended; +its period length of $2^{31}-2$ is much too small.) +The program calls {\tt unif01\_TimerSumGenWr} which generates 10 million +random numbers in $[0, 1)$, computes their mean, and prints the CPU time +needed to do that. +Next, the program deletes this {\tt unif01\_Gen} object and creates a +new one, which is actually a user-defined implementation of the same LCG, +taken from the home-made module {\tt my16807} whose code is shown in +Figure~\ref{fig:my16807}. +In this implementation, the parameters have been placed as constants +directly into the code. +Ten million random numbers are generated with this alternative +implementation, and the average and CPU time are printed. +The same procedure is repeated for two additional predefined +generators taken from modules {\tt ulec}. +% with period lengths near $2^{191}$ and near $2^{113}$, respectively. +Figure~\ref{fig:unif-timing-res} shows the results of this program, +run on a 2106 MHz computer running Linux, and compiled with {\tt gcc -O2}. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\setbox0=\vbox {\hsize = 6.2in +{\smallc +\verbatiminput{../examples/ex3.c}} +} + +\begin{figure} \centering \myboxit{\box0} +\caption {Example of a program creating and timing generators.} +\label {fig:unif-timing} +\end{figure} + + +\setbox1=\vbox {\hsize = 6.2in +{\smallc +\verbatiminput{../examples/ex3.res}} +} + +\begin{figure} \centering \myboxit{\box1} +\caption {Results of the program of Figure~\ref{fig:unif-timing}.} +\label {fig:unif-timing-res} +\end{figure} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +Figure~\ref{fig:prog-filter} shows how to apply filters to generators +and how to combine two or more generators by addition modulo 1 or bitwise +exclusive-or. +The program starts by creating a simple Tausworthe generator {\tt gen1} +and it generates 20 values from it. +It then deletes {\tt gen1}, creates a new copy of it with the same +parameters and initial state, and applies a ``lacunary indices'' +filter to create a second generator {\tt gen2}. +The output sequence of {\tt gen2} will be +(in terms of the original sequence numbering) +$u_3, u_7, u_9, u_{13}, u_{17}, u_{19}, u_{23}, \dots$. +Next, the program creates a generator {\tt gen3} for which each output value +is constructed from two successive output values of {\tt gen2}, +generates some values from {\tt gen3} and {\tt gen2}, and deletes them. +% +\hpierre{I would like to generate and print 20 numbers from {\tt gen1}, + then reset {\tt gen1} to its initial state, then + generate and print 20 numbers from {\tt gen2}. + But there is no public facility to reset a generator to a given state! + To implement such facilities, we would have to make public the + structure type that represents the state, for each type of generator. + Presently, these types are hidden in the .c} +\hrichard{Peut-\^etre qu'il ne serait pas n\'ecessaire de rendre le type + de l'\'etat public. Il faudrait toutefois une fonction {\tt Init} dans + la structure {\tt unif01\_Gen}.} + +After that, the program creates another Tausworthe generator {\tt gen2} +and a generator {\tt gen3} which is a combination of {\tt gen1} and +{\tt gen2} by bitwise exclusive-or. It generates a few values with +{\tt gen3} and deletes all the generators. + + + +\setbox10=\vbox {\hsize = 6.2in +{\smallc +\verbatiminput{../examples/ex4.c}} +} + +\begin{figure} \centering \myboxit{\box10} +\caption{Applying filters and combining generators.} +\label{fig:prog-filter} +\end{figure} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/TESTU01/TestU01-1.2.3/testu01/unumrec.c b/TESTU01/TestU01-1.2.3/testu01/unumrec.c new file mode 100644 index 0000000..3b9f698 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/unumrec.c @@ -0,0 +1,333 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: unumrec.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" + +#include "unumrec.h" +#include "unif01.h" + +#include +#include + + + +/*============================== Constants ===============================*/ + +#define LEN 100 /* Max length of strings */ + +#define N_TAB 32 +#define N_TAB8 40 /* N_TAB + 8 */ + +#define M1 2147483647 +#define A1 16807 +#define q1 127773 +#define r1 2836 +#define NDiv 67108864 /* = 1 + (M1 - 1) / N_TAB */ + + + +/*================================ Types ================================*/ + +typedef struct { + double Norm; +} Ran0_param; + +typedef struct { + long S1; +} Ran0_state; + +typedef struct { + long S1, z; + long Tab[N_TAB + 1]; +} Ran1_state; + +typedef struct { + long S1, S2, z; + long Tab[N_TAB + 1]; +} Ran2_state; + + +/**************************************************************************/ + +static double Ran0_U01 (void *vpar, void *vsta) +{ + Ran0_param *param = vpar; + Ran0_state *state = vsta; + long k; + + k = state->S1 / q1; + state->S1 = A1 * (state->S1 - k * q1) - k * r1; + if (state->S1 < 0) + state->S1 += M1; + return (state->S1 * param->Norm); +} + +static unsigned long Ran0_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Ran0_U01 (vpar, vsta)); +} + +static void WrRan0 (void *vsta) +{ + Ran0_state *state = vsta; + printf (" S = %1ld\n", state->S1); +} + +unif01_Gen * unumrec_CreateRan0 (long s) +{ + unif01_Gen *gen; + Ran0_param *param; + Ran0_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (s > 0, "unumrec_CreateRan0: s <= 0"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Ran0_param)); + state = util_Malloc (sizeof (Ran0_state)); + + strncpy (name, "unumrec_CreateRan0:", LEN); + addstr_Long (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = s; + param->Norm = 1.0 / M1; + + gen->GetBits = &Ran0_Bits; + gen->GetU01 = &Ran0_U01; + gen->Write = &WrRan0; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static double Ran1_U01 (void *vpar, void *vsta) +{ + Ran0_param *param = vpar; + Ran1_state *state = vsta; + long k; + int j; + + k = state->S1 / q1; + state->S1 = A1 * (state->S1 - k * q1) - k * r1; + if (state->S1 < 0) + state->S1 += M1; + + j = 1 + (int) (state->z / NDiv); + state->z = state->Tab[j]; + state->Tab[j] = state->S1; + + /* This is slightly different from Press and Teukolsky: they use RNMX. */ + return (state->z * param->Norm); +} + +static unsigned long Ran1_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Ran1_U01 (vpar, vsta)); +} + +static void WrRan1 (void *vsta) +{ + Ran1_state *state = vsta; + int i; + if (unif01_WrLongStateFlag) { + printf (" S = %1ld\n\n", state->S1); + for (i = 1; i <= N_TAB; i++) { + printf (" Tab [%2d] = %12ld\n", i, state->Tab[i]); + } + } else + unif01_WrLongStateDef (); +} + +unif01_Gen * unumrec_CreateRan1 (long s) +{ + unif01_Gen *gen; + Ran0_param *param; + Ran1_state *state; + size_t leng; + char name[LEN + 1]; + int i; + long k; + + util_Assert (s > 0, "unumrec_CreateRan1: s <= 0"); + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Ran0_param)); + state = util_Malloc (sizeof (Ran1_state)); + + strncpy (name, "unumrec_CreateRan1:", LEN); + addstr_Long (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Norm = 1.0 / M1; + state->S1 = s; + + for (i = N_TAB8; i >= 1; i--) { + k = state->S1 / q1; + state->S1 = A1 * (state->S1 - k * q1) - k * r1; + if (state->S1 < 0) + state->S1 += M1; + if (i <= N_TAB) + state->Tab[i] = state->S1; + } + state->z = state->Tab[1]; + + gen->GetBits = &Ran1_Bits; + gen->GetU01 = &Ran1_U01; + gen->Write = &WrRan1; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +#undef M1 +#undef A1 +#undef q1 +#undef r1 +#undef NDiv + +#define M1 2147483563 +#define M2 2147483399 +#define A1 40014 +#define A2 40692 +#define q1 53668 +#define q2 52774 +#define r1 12211 +#define r2 3791 +#define M1m1 2147483562 +#define NDiv 67108862 /* = 1 + M1m1 / N_TAB */ + + +static double Ran2_U01 (void *vpar, void *vsta) +{ + Ran0_param *param = vpar; + Ran2_state *state = vsta; + long k; + int j; + + k = state->S1 / q1; + state->S1 = A1 * (state->S1 - k * q1) - k * r1; + if (state->S1 < 0) + state->S1 += M1; + + k = state->S2 / q2; + state->S2 = A2 * (state->S2 - k * q2) - k * r2; + if (state->S2 < 0) + state->S2 += M2; + + j = 1 + (int) (state->z / NDiv); + state->z = state->Tab[j] - state->S2; + state->Tab[j] = state->S1; + if (state->z < 1) + state->z += M1m1; + + /* This is slightly different from Press and Teukolsky: they use RNMX. */ + return (state->z * param->Norm); +} + +static unsigned long Ran2_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Ran2_U01 (vpar, vsta)); +} + +static void WrRan2 (void *vsta) +{ + Ran2_state *state = vsta; + int i; + if (unif01_WrLongStateFlag) { + printf (" S1 = %1ld, S2 = %1ld\n\n", state->S1, state->S2); + for (i = 1; i <= N_TAB; i++) { + printf (" Tab [%2d] = %12ld\n", i, state->Tab[i]); + } + } else + unif01_WrLongStateDef (); +} + +unif01_Gen * unumrec_CreateRan2 (long s) +{ + unif01_Gen *gen; + Ran0_param *param; + Ran2_state *state; + size_t leng; + char name[LEN + 1]; + int i; + long k; + + util_Assert (s > 0, "unumrec_CreateRan2: s <= 0"); + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Ran0_param)); + state = util_Malloc (sizeof (Ran2_state)); + + strncpy (name, "unumrec_CreateRan2:", LEN); + addstr_Long (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->Norm = 1.0 / M1; + state->S1 = s; + state->S2 = s; + + for (i = N_TAB8; i >= 1; i--) { + k = state->S1 / q1; + state->S1 = A1 * (state->S1 - k * q1) - k * r1; + if (state->S1 < 0) + state->S1 += M1; + if (i <= N_TAB) + state->Tab[i] = state->S1; + } + state->z = state->Tab[1]; + + gen->GetBits = &Ran2_Bits; + gen->GetU01 = &Ran2_U01; + gen->Write = &WrRan2; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +void unumrec_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/unumrec.tex b/TESTU01/TestU01-1.2.3/testu01/unumrec.tex new file mode 100644 index 0000000..4383352 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/unumrec.tex @@ -0,0 +1,61 @@ +\defmodule {unumrec} + +Implements the generators proposed in +{\em Numerical Recipes: Portable Random Number Generators\/} + \cite{rPRE92a,rPRE92b}. +\index{Generator!Numerical Recipes} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* unumrec.h for ANSI C */ + +#ifndef UNUMREC_H +#define UNUMREC_H +\endhide +#include "unif01.h" + + +unif01_Gen * unumrec_CreateRan0 (long s); +\endcode + \tab Creates and initializes the generator {\tt Ran0} with the seed $s$. +\index{Generator!Ran0}% + Restriction: $0 < s < 2^{31}$. + \endtab +\code + + +unif01_Gen * unumrec_CreateRan1 (long s); +\endcode + \tab Creates and initializes the generator {\tt Ran1} with the seed $s$. +\index{Generator!Ran1}% + Restriction: $0 < s < 2^{31}$. + \endtab +\code + + +unif01_Gen * unumrec_CreateRan2 (long s); +\endcode + \tab Creates and initializes the generator {\tt Ran2} with the seed $s$. +\index{Generator!Ran2}% + Restriction: $0 < s < 2^{31}$. + \endtab + + + +\guisec{Clean-up functions} +\code + +void unumrec_DeleteGen (unif01_Gen *gen); +\endcode + \tab \DelGen + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/uquad.c b/TESTU01/TestU01-1.2.3/testu01/uquad.c new file mode 100644 index 0000000..aa748c8 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uquad.c @@ -0,0 +1,710 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uquad.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "uquad.h" +#include "unif01.h" + +#include +#include +#include +#include + + + + +/*============================= Constants =================================*/ + + +#if LONG_MAX <= 2147483647L +#define MASK64 0 +#define RacLONG_MAX 46340 /* Trunc (sqrt (LONG_MAX)) */ +#else +#define MASK64 0xffffffffffffffffUL /* Mask 64 bits */ +#define RacLONG_MAX 3037000499 +#endif + +#define MASK32 0xffffffffUL /* Mask 32 bits */ +#define LEN 200 /* Max length of strings */ + + + + +/*============================== Types ===================================*/ + +/* Different styles of generator of the same type: */ + +typedef enum { + XXQ, SSQ, SMQ, SLQ, MSQ, MMQ, + MLQ, LSQ, LMQ, LLQ +} GenStyle1; + +typedef enum { + Qu2, Qu2e32 +} GenStyle2; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + long C, /* Constant */ + A, B, /* Multipliers */ + Qa, Ra, /* Qa = M / A, Ra = M % A */ + Qb, Rb, /* Qb = M / B, Rb = M % B */ + M; /* Modulus */ + double Norm; +} Quad_param; + +typedef struct { + long S; + GenStyle1 style; +} Quad_state; + +/*-------------------------------------------------------------------------*/ + +typedef struct { + unsigned long A, B, C, Mask, Shift; + lebool Flag; +} Quad2_param; + +typedef struct { + unsigned long S; + GenStyle2 style; +} Quad2_state; + + + + + +/*============================= Functions ===============================*/ + +static double LLQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used in the general case. " Very slow " + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2; + + W1 = num_MultModL (state->S, state->S, 0L, param->M); + W1 = num_MultModL (param->A, W1, 0L, param->M); + W2 = num_MultModL (param->B, state->S, param->C, param->M); + state->S = (W1 - param->M) + W2; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LLQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LLQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double LMQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when b * (m % b) < m + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2, h; + + W1 = num_MultModL (state->S, state->S, 0L, param->M); + W1 = num_MultModL (param->A, W1, param->C, param->M); + h = state->S / param->Qb; + W2 = param->B * (state->S - h * param->Qb) - h * param->Rb; + if (W2 < 0) + state->S = W2 + W1; + else + state->S = (W2 - param->M) + W1; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LMQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LMQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double LSQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when b*(m-1) holds in a long int. + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2; + + W1 = num_MultModL (state->S, state->S, 0L, param->M); + W1 = num_MultModL (param->A, W1, param->C, param->M); + W2 = (param->B * state->S) % param->M; + state->S = (W1 - param->M) + W2; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long LSQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * LSQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double MLQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when a * (m % a) < m + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2, k; + + W1 = num_MultModL (param->B, state->S, param->C, param->M); + W2 = num_MultModL (state->S, state->S, 0L, param->M); + k = W2 / param->Qa; + W2 = param->A * (W2 - k * param->Qa) - k * param->Ra; + if (W2 < 0) + state->S = W2 + W1; + else + state->S = (W2 - param->M) + W1; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MLQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MLQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double MMQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when a * (m % a) < m and when b * (m % b) < m + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2, k, h; + + W1 = num_MultModL (state->S, state->S, 0L, param->M); + k = W1 / param->Qa; + W1 = param->A * (W1 - k * param->Qa) - k * param->Ra; + if (W1 < 0) + W1 += param->M; + h = state->S / param->Qb; + W2 = param->B * (state->S - h * param->Qb) - h * param->Rb; + if (W2 < 0) + state->S = W2 + W1; + else + state->S = (W2 - param->M) + W1; + if (state->S < 0) + state->S += param->C; + else + state->S = (state->S - param->M) + param->C; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MMQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MMQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double MSQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when a * (m % a) < m and when b*(m-1) holds in a + * long int + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2, k; + + W1 = (param->B * state->S) % param->M; + W2 = num_MultModL (state->S, state->S, 0L, param->M); + k = W2 / param->Qa; + W2 = param->A * (W2 - k * param->Qa) - k * param->Ra; + if (W2 < 0) + state->S = W2 + W1; + else + state->S = (W2 - param->M) + W1; + if (state->S < 0) + state->S += param->C; + else + state->S = (state->S - param->M) + param->C; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MSQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MSQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double SLQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when a*(m-1) holds in a long int + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2; + + W2 = num_MultModL (state->S, state->S, 0L, param->M); + W2 = (param->A * W2) % param->M; + W1 = num_MultModL (param->B, state->S, param->C, param->M); + state->S = (W2 - param->M) + W1; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long SLQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SLQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double SMQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when b * (m % b) < m and when a*(m-1) holds in + * a long int + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2, h; + + W1 = num_MultModL (state->S, state->S, 0L, param->M); + W1 = (param->A * W1) % param->M; + h = state->S / param->Qb; + W2 = param->B * (state->S - h * param->Qb) - h * param->Rb; + if (W2 < 0) + state->S = W2 + W1; + else + state->S = (W2 - param->M) + W1; + if (state->S < 0) + state->S += param->C; + else + state->S = (state->S - param->M) + param->C; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long SMQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SMQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double SSQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when a*(m-1) and b*(m-1) hold in a long int + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2; + + W1 = num_MultModL (state->S, state->S, 0L, param->M); + W1 = (param->A * W1) % param->M; + W2 = (param->B * state->S) % param->M; + state->S = (W1 - param->M) + W2; + if (state->S < 0) + state->S += param->C; + else + state->S = (state->S - param->M) + param->C; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long SSQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SSQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static double XXQuad_U01 (void *vpar, void *vsta) +/* + * Implementation used when all intermediary results hold in a long int. + * It is the case when M < Rac2MaxInt. + */ +{ + Quad_param *param = vpar; + Quad_state *state = vsta; + long W1, W2; + + W1 = (param->A * ((state->S * state->S) % param->M)) % param->M; + W2 = ((param->B * state->S) + param->C) % param->M; + state->S = (W1 - param->M) + W2; + if (state->S < 0) + state->S += param->M; + return (state->S * param->Norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long XXQuad_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * XXQuad_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrQuad (void *vsta) +{ + Quad_state *state = vsta; + + switch (state->style) { + case XXQ: + printf (" XXQuad"); + break; + case SSQ: + printf (" SSQuad"); + break; + case SMQ: + printf (" SMQuad"); + break; + case SLQ: + printf (" SLQuad"); + break; + case MSQ: + printf (" MSQuad"); + break; + case MMQ: + printf (" MMQuad"); + break; + case MLQ: + printf (" MLQuad"); + break; + case LSQ: + printf (" LSQuad"); + break; + case LMQ: + printf (" LMQuad"); + break; + case LLQ: + printf (" LLQuad"); + break; + default: + util_Error ("WrQuad: impossible case"); + } + printf (", S = %1ld\n", state->S); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * uquad_CreateQuadratic (long m, long a, long b, long c, long s) +{ + unif01_Gen *gen; + Quad_param *param; + Quad_state *state; + size_t leng; + char name[LEN + 1]; + GenStyle1 style; + + util_Assert ((a >= 0) && (b >= 0) && (c >= 0) && (s >= 0) && + (a < m) && (b < m) && (c < m) && (s < m) && (0 < m) && + ((a != 0) || (b != 0)) && ((c != 0) || (s != 0)), + "uquad_CreateQuadratic: Invalid Parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Quad_param)); + state = util_Malloc (sizeof (Quad_state)); + + strcpy (name, "uquad_CreateQuadratic:"); + addstr_Long (name, " m = ", m); + addstr_Long (name, ", a = ", a); + addstr_Long (name, ", b = ", b); + addstr_Long (name, ", c = ", c); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + param->A = a; + param->B = b; + param->C = c; + param->M = m; + param->Qa = m / a; + param->Ra = m % a; + param->Qb = m / b; + param->Rb = m % b; + param->Norm = 1.0 / m; + state->S = s; + + if (m - 1 <= LONG_MAX / a) + style = XXQ; + else if (param->Ra <= param->Qa) + style = SLQ; + else + style = MLQ; + + if (m - 1 <= LONG_MAX / b) + style += 1; + else if (param->Rb <= param->Qb) + style += 2; + else + style += 3; + + if (m - 1 <= RacLONG_MAX) + style = XXQ; + state->style = style; + + switch (style) { + case XXQ: + gen->GetBits = &XXQuad_Bits; + gen->GetU01 = &XXQuad_U01; + break; + case SSQ: + gen->GetBits = &SSQuad_Bits; + gen->GetU01 = &SSQuad_U01; + break; + case SMQ: + gen->GetBits = &SMQuad_Bits; + gen->GetU01 = &SMQuad_U01; + break; + case SLQ: + gen->GetBits = &SLQuad_Bits; + gen->GetU01 = &SLQuad_U01; + break; + case MSQ: + gen->GetBits = &MSQuad_Bits; + gen->GetU01 = &MSQuad_U01; + break; + case MMQ: + gen->GetBits = &MMQuad_Bits; + gen->GetU01 = &MMQuad_U01; + break; + case MLQ: + gen->GetBits = &MLQuad_Bits; + gen->GetU01 = &MLQuad_U01; + break; + case LSQ: + gen->GetBits = &LSQuad_Bits; + gen->GetU01 = &LSQuad_U01; + break; + case LMQ: + gen->GetBits = &LMQuad_Bits; + gen->GetU01 = &LMQuad_U01; + break; + case LLQ: + gen->GetBits = &LLQuad_Bits; + gen->GetU01 = &LLQuad_U01; + break; + default: + util_Error ("uquad_CreateQuadratic: impossible case"); + } + + gen->Write = &WrQuad; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static unsigned long Quad2_Bits (void *vpar, void *vsta) +{ + Quad2_param *param = vpar; + Quad2_state *state = vsta; + + state->S = (param->A * state->S * state->S + param->B * state->S + + param->C) & param->Mask; + if (param->Flag) + return state->S << param->Shift; + else + return state->S >> param->Shift; +} + +/*-------------------------------------------------------------------------*/ + +static double Quad2_U01 (void *vpar, void *vsta) +{ + return Quad2_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long Quad2e32_Bits (void *vpar, void *vsta) +/* + * Special case when M = 2^32 + */ +{ + Quad2_param *param = vpar; + Quad2_state *state = vsta; + + state->S = param->A * state->S * state->S + param->B * state->S + param->C; +#ifndef IS_ULONG32 + state->S &= MASK32; +#endif + return state->S; +} + +/*-------------------------------------------------------------------------*/ + +static double Quad2e32_U01 (void *vpar, void *vsta) +{ + return Quad2e32_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrQuad2 (void *vsta) +{ + Quad2_state *state = vsta; + + if (state->style == Qu2) + printf (" Quad2"); + else if (state->style == Qu2e32) + printf (" Quad2e32"); + printf (": S = %1lu\n", state->S); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uquad_CreateQuadratic2 (int e, unsigned long a, unsigned long b, + unsigned long c, unsigned long s) +{ + unif01_Gen *gen; + Quad2_param *param; + Quad2_state *state; + size_t leng; + char name[LEN + 1]; + double M; + + util_Assert (((a != 0) || (b != 0)) && ((s != 0) || (c != 0)) && + (e >= 2), "uquad_CreateQuadratic2: Invalid Parameter *"); +#if ULONG_MAX <= 4294967295UL + util_Assert (e <= 32, "uquad_CreateQuadratic2: e > 32"); +#else + util_Assert (e <= 64, "uquad_CreateQuadratic2: e > 64"); +#endif + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Quad2_param)); + state = util_Malloc (sizeof (Quad2_state)); + + strcpy (name, "uquad_CreateQuadratic2: "); + addstr_Uint (name, " e = ", (unsigned) e); + addstr_Ulong (name, ", a = ", a); + addstr_Ulong (name, ", b = ", b); + addstr_Ulong (name, ", c = ", c); + addstr_Ulong (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + M = num_TwoExp[e]; + util_Assert ((s < M) && (a < M) && (b < M) && (c < M), + "uquad_CreateQuadratic2: Invalid Parameter **"); + + param->A = a; + param->B = b; + param->C = c; + if (e == 64) + param->Mask = MASK64; + else if (32 == e) + param->Mask = MASK32; + else + param->Mask = M - 1; + if (e <= 32) { + param->Shift = 32 - e; + param->Flag = TRUE; + } else { + param->Shift = e - 32; + param->Flag = FALSE; + } + state->S = s; + + if (e == 32) { + state->style = Qu2e32; + gen->GetBits = &Quad2e32_Bits; + gen->GetU01 = &Quad2e32_U01; + + } else { + state->style = Qu2; + gen->GetBits = &Quad2_Bits; + gen->GetU01 = &Quad2_U01; + } + + gen->Write = &WrQuad2; + gen->param = param; + gen->state = state; + return gen; +} + +/**************************************************************************/ + +void uquad_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/uquad.tex b/TESTU01/TestU01-1.2.3/testu01/uquad.tex new file mode 100644 index 0000000..6f24886 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uquad.tex @@ -0,0 +1,59 @@ +\defmodule {uquad} + +This module implements generators based on quadratic recurrences +modulo $m$, of the form +\eq + x_{n+1} = (a x_n^2 + b x_n + c) \mod m, \eqlabel{quad} +\endeq +with output $u_n = x_n/m$ at step $n$. +See, e.g., \cite{rEIC87a,rEIC97d,rEMM97a,rKNU98a} +for analyses of such generators. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* uquad.h for ANSI C */ +#ifndef UQUAD_H +#define UQUAD_H +\endhide +#include "unif01.h" + + +unif01_Gen * uquad_CreateQuadratic (long m, long a, long b, long c, long s); +\endcode + \tab Initializes a generator based on recurrence (\ref{quad}), + with initial state $x_0 = s$. +\index{Generator!quadratic}% + Depending on the values of the parameters, various implementations + of different speeds are used. In general, this generator + is slow. Restrictions: $a$, $b$, $c$ and $s$ non + negative and less than $m$. + \endtab +\code + + +unif01_Gen * uquad_CreateQuadratic2 (int e, unsigned long a, + unsigned long b, unsigned long c, unsigned long s); +\endcode + \tab Similar to {\tt uquad\_CreateQuadratic}, but with $m=2^e$. + Restrictions: $a$, $b$, $c$ and $s$ non negative and + less than $2^e$; $e \le 32$ for 32-bit machines, + and $e \le 64$ for 64-bit machines. + \endtab + + +\guisec{Clean-up functions} +\code + +void uquad_DeleteGen (unif01_Gen *gen); +\endcode + \tab \DelGen + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/usoft.c b/TESTU01/TestU01-1.2.3/testu01/usoft.c new file mode 100644 index 0000000..a36858a --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/usoft.c @@ -0,0 +1,1005 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: usoft.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "usoft.h" +#include "ulcg.h" +#include "unif01.h" + +#include +#include +#include +#include + + + +#ifdef HAVE_MATHEMATICA +#include +#include "mathlink.h" +#endif + + + +/*============================= Constants ================================*/ + +#define DeuxExp31m1 2147483647 /* 2^31 - 1 */ +#define MASK52 4503599627370495ULL /* 2^52 - 1 */ +#define MASK48 281474976710655ULL /* 2^48 - 1 */ +#define MASK32 4294967295 /* 2^32 - 1 */ +#define MASK5 31 /* 2^5 - 1 */ + +#define LEN 200 /* Max length of strings */ + + + +/*================================ Types ================================*/ + + +typedef struct { + double Norm; +} SPlus_param; + +typedef struct { + unsigned long S1, S2; +} SPlus_state; + +/*------------------------------------*/ +#ifdef USE_LONGLONG + +typedef struct { + double Norm; + int Flag; +} Java48_param; + +typedef struct { + ulonglong S; +} Java48_state; + + +typedef struct { + double Z[32]; + double b; + unsigned int i, j; +} MATLAB5_state; + +#endif +/*------------------------------------*/ + +typedef struct { + double U; +} Excel97_state; + +/*------------------------------------*/ + +typedef struct { + unsigned long S; +} VisualBasic_state; + + + + + + +/*============================== Functions ==============================*/ + +static double SPlus_U01 (void *vpar, void *vsta) +{ + SPlus_state *state = vsta; + SPlus_param *param = vpar; + unsigned int z; + + do { + state->S1 *= 69069; + state->S2 ^= state->S2 >> 15; + state->S2 ^= state->S2 << 17; +#ifndef IS_ULONG32 + state->S1 &= unif01_MASK32; + state->S2 &= unif01_MASK32; +#endif + z = (state->S1 ^ state->S2) >> 1; + } while (0 == z); + return param->Norm * z; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long SPlus_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (SPlus_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrSPlus (void *vsta) +{ + SPlus_state *state = vsta; + printf (" S1 = %1lu, S2 = %1lu\n", state->S1, state->S2); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * usoft_CreateSPlus (long s1, long s2) +{ + unif01_Gen *gen; + SPlus_state *state; + SPlus_param *param; + size_t leng; + char name[LEN + 1]; + + util_Assert (s1 > 0, "usoft_CreateSPlus: must have s1 > 0"); + util_Assert (s1 < DeuxExp31m1, + "usoft_CreateSPlus: must have s1 < 2^31 - 1"); + util_Assert (s2 > 0, "usoft_CreateSPlus: must have s2 > 0"); + util_Assert (s2 < DeuxExp31m1, + "usoft_CreateSPlus: must have s2 < 2^31 - 1"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (SPlus_param)); + state = util_Malloc (sizeof (SPlus_state)); + + strcpy (name, "usoft_CreateSPlus:"); + addstr_Long (name, " s1 = ", s1); + addstr_Long (name, ", s2 = ", s2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S1 = s1; + state->S2 = s2; + param->Norm = 1.0 / num_TwoExp[31]; + + gen->GetBits = &SPlus_Bits; + gen->GetU01 = &SPlus_U01; + gen->Write = &WrSPlus; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ +/* The 5 generators random of Unix-Linux */ + +#ifdef HAVE_RANDOM + +static int coUnix = 0; /* Counter for Unix random RNG */ + +static unsigned long state1[] = { + 3UL, + 0x9a319039UL, 0x32d9c024UL, 0x9b663182UL, 0x5da1f342UL, + 0x7449e56bUL, 0xbeb1dbb0UL, 0xab5c5918UL, 0x946554fdUL, + 0x8c2e680fUL, 0xeb3d799fUL, 0xb11ee0b7UL, 0x2d436b86UL, + 0xda672e2aUL, 0x1588ca88UL, 0xe369735dUL, 0x904f35f7UL, + 0xd7158fd6UL, 0x6fa6f051UL, 0x616e6b96UL, 0xac94efdcUL, + 0xde3b81e0UL, 0xdf0a6fb5UL, 0xf103bc02UL, 0x48f340fbUL, + 0x36413f93UL, 0xc622c298UL, 0xf5a42ab8UL, 0x8a88d77bUL, + 0xf5ad9d0eUL, 0x8999220bUL, 0x27fb47b9UL, + 12345UL, + 0x9a319039UL, 0x32d9c024UL, 0x9b663182UL, 0x5da1f342UL, + 0x7449e56bUL, 0xbeb1dbb0UL, 0xab5c5918UL, 0x946554fdUL, + 0x8c2e680fUL, 0xeb3d799fUL, 0xb11ee0b7UL, 0x2d436b86UL, + 0xda672e2aUL, 0x1588ca88UL, 0xe369735dUL, 0x904f35f7UL, + 0xd7158fd6UL, 0x6fa6f051UL, 0x616e6b96UL, 0xac94efdcUL, + 0xde3b81e0UL, 0xdf0a6fb5UL, 0xf103bc02UL, 0x48f340fbUL, + 0x36413f93UL, 0xc622c298UL, 0xf5a42ab8UL, 0x8a88d77bUL, + 0xf5ad9d0eUL, 0x8999220bUL, 0x27fb47b9UL +}; + +/*------------------------------------------------------------------------*/ + +static void WrUnixRandom (void *junk) +{ +} + +/*------------------------------------------------------------------------*/ + +static double UnixRandom_U01 (void *junk1, void *junk2) +{ + return random () / (1.0 + RAND_MAX); +} + +/*------------------------------------------------------------------------*/ + +static unsigned long UnixRandom_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (UnixRandom_U01 (vpar, vsta) * unif01_NORM32); +} + +/*------------------------------------------------------------------------*/ + +unif01_Gen * usoft_CreateUnixRandom (unsigned int s) +{ + unif01_Gen *gen; + unsigned seed; + size_t leng; + char name[LEN + 1]; + + util_Assert (coUnix == 0, + "usoft_CreateUnixRandom: only 1 generator at a time can be in use"); + coUnix++; + + switch (s) { + case 8: + case 32: + case 64: + case 128: + case 256: + break; + default: + util_Error ("\nusoft_CreateUnixRandom: " + "s must be in {8, 32, 64, 128, 256}\n\n"); + } + gen = util_Malloc (sizeof (unif01_Gen)); + + seed = 12345; + initstate (seed, (char *) state1, (size_t) s); /* Defined in stdlib */ + setstate ((char *) state1); + + strcpy (name, "usoft_CreateUnixRandom:"); + addstr_Uint (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &UnixRandom_Bits; + gen->GetU01 = &UnixRandom_U01; + gen->Write = &WrUnixRandom; + gen->param = NULL; + gen->state = NULL; + return gen; +} + +/*-----------------------------------------------------------------------*/ + +void usoft_DeleteUnixRandom (unif01_Gen *gen) +{ + if (NULL == gen) return; + gen->name = util_Free (gen->name); + util_Free (gen); + coUnix--; +} + +#endif /* HAVE_RANDOM */ + + + +/*=========================================================================*/ +#ifdef USE_LONGLONG + +static double Java48_U01 (void *vpar, void *vsta) +{ + Java48_param *param = vpar; + Java48_state *state = vsta; + ulonglong temp; + + state->S = (25214903917ULL * state->S + 11) & MASK48; + /* Keep only the 26 most significant bits of S; shift 5. They will */ + /* make bits [27..52] of the next generated number, counting from 0. */ + temp = (state->S & 281474972516352ULL) << 5; + + state->S = (25214903917ULL * state->S + 11) & MASK48; + /* Keep only the 27 most significant bits of S; shift 21. They will */ + /* make bits [0..26] of the next generated number */ + return (temp + (state->S >> 21)) * param->Norm; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long Java48_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (Java48_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrJava48 (void *vsta) +{ + Java48_state *state = vsta; + printf (" S = %" PRIuLEAST64 "\n", state->S); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * usoft_CreateJava48 (ulonglong s, int jflag) +{ + unif01_Gen *gen; + Java48_param *param; + Java48_state *state; + size_t leng; + char name[LEN + 1]; + + if (s > MASK48) + util_Error ("usoft_CreateJava48: s >= 281474976710656"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Java48_param)); + state = util_Malloc (sizeof (Java48_state)); + + strcpy (name, "usoft_CreateJava48:"); + addstr_ULONG (name, " s = ", s); + addstr_Long (name, ", jflag = ", (long) jflag); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + /* This bit XOR is used to get the same numbers as those generated by the + SUN Random.nextDouble */ + if (jflag) + state->S = s ^ 0x5DEECE66DULL; + else + state->S = s; + + param->Norm = 1.0 / num_TwoExp[53]; + gen->GetBits = &Java48_Bits; + gen->GetU01 = &Java48_U01; + gen->Write = &WrJava48; + gen->param = param; + gen->state = state; + return gen; +} + +#endif /* USE_LONGLONG */ + + +/*=========================================================================*/ + +static double Excel97_U01 (void *junk, void *vsta) +{ + Excel97_state *state = vsta; + state->U = 9821.0 * state->U + 0.211327; + state->U -= (int) state->U; + return state->U; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long Excel97_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (Excel97_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrExcel97 (void *vsta) +{ + Excel97_state *state = vsta; + printf (" R = %20.16f\n", state->U); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * usoft_CreateExcel97 (double r) +{ + unif01_Gen *gen; + Excel97_state *state; + size_t leng; + char name[LEN + 1]; + + if (r < 0.0 || r >= 1.0) + util_Error ("usoft_CreateExcel97: r must be in [0, 1)"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (Excel97_state)); + + strcpy (name, "usoft_CreateExcel97:"); + addstr_Double (name, " r = ", r); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->U = r; + gen->GetBits = &Excel97_Bits; + gen->GetU01 = &Excel97_U01; + gen->Write = &WrExcel97; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*=========================================================================*/ + +unif01_Gen * usoft_CreateExcel2003 (int x0, int y0, int z0) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + gen = ulcg_CreateCombWH3 (30323, 30307, 30269, 170, 172, 171, + 0, 0, 0, x0, y0, z0); + strcpy (name, "usoft_CreateExcel2003:"); + addstr_Uint (name, " x0 = ", x0); + addstr_Uint (name, ", y0 = ", y0); + addstr_Uint (name, ", z0 = ", z0); + leng = strlen (name); + gen->name = util_Free (gen->name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + return gen; +} + + +/*=========================================================================*/ + +static unsigned long VisualBasic_Bits (void *junk, void *vsta) +{ + VisualBasic_state *state = vsta; + state->S = (16598013 * state->S + 12820163) & 0xffffff; + return (state->S << 8); +} + +/*-----------------------------------------------------------------------*/ + +static double VisualBasic_U01 (void *vpar, void *vsta) +{ + return VisualBasic_Bits (vpar, vsta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrVisualBasic (void *vsta) +{ + VisualBasic_state *state = vsta; + printf (" S = %1lu\n", state->S); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * usoft_CreateVisualBasic (unsigned long s) +{ + unif01_Gen *gen; + VisualBasic_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (VisualBasic_state)); + + strcpy (name, "usoft_CreateVisualBasic:"); + addstr_Ulong (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S = s; + gen->GetBits = &VisualBasic_Bits; + gen->GetU01 = &VisualBasic_U01; + gen->Write = &WrVisualBasic; + gen->param = NULL; + gen->state = state; + return gen; +} + + + +/*=========================================================================*/ +#if defined(USE_GMP) && defined(USE_LONGLONG) + +unif01_Gen * usoft_CreateMaple_9 (longlong s) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + char str[20]; + + sprintf (str, "%1" PRIdLEAST64, s); + gen = ulcg_CreateBigLCG ("999999999989", "427419669081", "0", str); + gen->name = util_Free (gen->name); + strcpy (name, "usoft_CreateMaple_9:"); + addstr_LONG (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + return gen; +} + + +void usoft_DeleteMaple_9 (unif01_Gen *gen) +{ + ulcg_DeleteBigLCG (gen); +} + +#endif + + +/*=========================================================================*/ +#ifdef USE_LONGLONG +#define IMAX 32 + +static double MATLAB5_U01 (void *junk, void *vsta) +{ + static const double ULP = 1.0 / 9007199254740992.0; /* 1 / 2^53 */ + MATLAB5_state *state = vsta; + ulonglong t, mask = state->j; + int n; + double x; + + x = state->Z[(state->i + 20) & MASK5] - state->Z[(state->i + 5) & MASK5] + - state->b; + if (x < 0.0) { + x += 1.0; + state->b = ULP; + } else + state->b = 0.0; + state->Z[state->i] = x; + state->i = (state->i + 1) & MASK5; + + state->j ^= (state->j<<13); + state->j ^= (state->j>>17); + state->j ^= (state->j<<5); + mask ^= ((((ulonglong) state->j) << 32) & MASK52); + x = frexp (x, &n); + t = ldexp (x, 53); + t ^= mask; + x = ldexp ((double) t, n - 53); + return x; +} + + +/*-----------------------------------------------------------------------*/ + +static unsigned long MATLAB5_Bits (void *vpar, void *vsta) +{ + return unif01_NORM32 * MATLAB5_U01 (vpar, vsta); +} + +/*-----------------------------------------------------------------------*/ + +static void WrMATLAB5 (void *vsta) +{ + unsigned int j; + MATLAB5_state *state = vsta; + printf (" i = %1u,", state->i); + printf (" j = %1u,", state->j); + printf (" b = %d,\n Z = ", state->b > 0.0 ? 1 : 0); + if (unif01_WrLongStateFlag) { + printf (" {\n "); + for (j = 0; j < IMAX; j++) { + printf (" %.16f", state->Z[j]); + if (j < IMAX - 1) + printf (","); + if ((j % 3) == 2) + printf ("\n "); + }; + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * usoft_CreateMATLAB (int i, unsigned int j0, int b, double Z[]) +{ + unif01_Gen *gen; + MATLAB5_state *state; + size_t leng; + char name[LEN + 1]; + int r; + + strcpy (name, "usoft_CreateMATLAB:"); + addstr_Int (name, " i = ", i); + if (i >= 0) { + addstr_Uint (name, ", j = ", j0); + addstr_Int (name, ", b = ", b); + util_Assert (Z != NULL, "usoft_CreateMATLAB: Z is NULL"); + addstr_ArrayDouble (name, ", Z = ", IMAX, Z); + } + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MATLAB5_state)); + + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (i < 0) { + unsigned int s, j; + double x; + state->b = 0; + state->i = 0; + j = state->j = 1U << 31; + /* RANDSETUP in randtx: Generate n reals in [0,1] bit by bit. */ + for (r = 0; r < IMAX; r++) { + x = 0; + for (s = 0; s < 53; s++) { + j ^= (j<<13); j ^= (j>>17); j ^= (j<<5); + x = 2*x + ((j >> 19) & 1); + } + state->Z[r] = ldexp (x, -53); + } + + } else { + double junk; + for (r = 0; r < IMAX; r++) { + util_Assert (state->Z[r] >= 0.0, + "usoft_CreateMATLAB: negative Z[r]"); + state->Z[r] = modf (Z[r], &junk); + } + state->b = b > 0 ? 1.0/num_TwoExp[53] : 0.0; + state->i = i & MASK5; + state->j = j0 > 0 ? j0 : (1U << 31); + } + + gen->param = NULL; + gen->state = state; + gen->GetBits = &MATLAB5_Bits; + gen->GetU01 = &MATLAB5_U01; + gen->Write = &WrMATLAB5; + return gen; +} + + +/*-----------------------------------------------------------------------*/ + +void usoft_DeleteMATLAB (unif01_Gen *gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} +#undef IMAX +#endif + + +/*=========================================================================*/ +#ifdef HAVE_MATHEMATICA + +/* The Mathematica RNG for the Real */ +static int coMath = 0; /* Counter */ +static double *Math_A; +static long Math_n = 262144; +static MLINK lp; +static MLEnvironment env; + +#if 0 +static double Mathematica00 (void) +/* + * Very slow function: generate 1 number at a time + */ +{ + double x; + MLPutFunction (lp, "Random", 0); + MLEndPacket (lp); + while (MLNextPacket (lp) != RETURNPKT) + MLNewPacket (lp); + MLGetDouble (lp, &x); + return x; +} +#endif + +static void GetArray (void) +{ + /* Ask Mathematica to generate Math_n random numbers at a time and put + them in array Math_A */ + static int flag = 0; + + /* free memory taken up by previous array Math_A */ + if (flag) + MLDisownRealList (lp, Math_A, Math_n); + flag = 1; + + /* send the command Table[Random[], {Math_n}] to the Mathematica kernel */ + MLPutFunction (lp, "Table", 2); + MLPutFunction (lp, "Random", 0); + MLPutFunction (lp, "List", 1); + MLPutInteger (lp, Math_n); + MLEndPacket (lp); + while (MLNextPacket (lp) != RETURNPKT) + MLNewPacket (lp); + + /* Get the Math_n numbers in Math_A */ + MLGetRealList (lp, &Math_A, &Math_n); +} + +/*------------------------------------------------------------------------*/ + +static double Mathematica_U01 (void *junk1, void *junk2) +{ + /* return one random number; when at top of array, get another bunch */ + static long i = 0; + if (i == Math_n) { + GetArray (); + i = 0; + } + return Math_A[i++]; +} + +/*------------------------------------------------------------------------*/ + +static unsigned long Mathematica_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Mathematica_U01 (vpar, vsta)); +} + +/*------------------------------------------------------------------------*/ + +static void WrMathematica (void *junk) +{ + /* The state is expressed as a very big integer (many decimal digits); + do not write it */ +} + +/*------------------------------------------------------------------------*/ + +unif01_Gen *usoft_CreateMathematicaReal (int argc, char *argv[], long s) +{ + long errno; + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + + if (argc == 1) { + util_Error ("usoft_CreateMathematicaReal:\n\n Usage: -linkname 'math -mathlink' -linklaunch"); + } + util_Assert (coMath == 0, + "usoft_CreateMathematicaReal: only 1 generator at a time can be used"); + coMath++; + + env = MLInitialize (NULL); + if (env == NULL) { + util_Assert (1, "usoft_CreateMathematicaReal: MathLink MLInitialize returns NULL"); + return NULL; + } + lp = MLOpenArgv (env, argv, argv + argc, &errno); + if (lp == NULL) { + util_Assert (1, "usoft_CreateMathematicaReal: MathLink MLOpenArgv returns NULL"); + return NULL; + } + + MLPutFunction (lp, "SeedRandom", 1); + MLPutInteger (lp, s); + MLEndPacket (lp); + while (MLNextPacket (lp) != RETURNPKT) + MLNewPacket (lp); + MLNewPacket (lp); + + gen = util_Malloc (sizeof (unif01_Gen)); + + strcpy (name, "usoft_CreateMathematicaReal:"); + addstr_Long (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + GetArray (); + gen->GetBits = &Mathematica_Bits; + gen->GetU01 = &Mathematica_U01; + gen->Write = &WrMathematica; + gen->param = NULL; + gen->state = NULL; + return gen; +} + +/*------------------------------------------------------------------------*/ + +void usoft_DeleteMathematicaReal (unif01_Gen *gen) +{ + MLDisownRealList (lp, Math_A, Math_n); + MLClose (lp); + MLDeinitialize (env); + if (NULL == gen) + return; + gen->name = util_Free (gen->name); + util_Free (gen); + coMath--; +} + + +/*=========================================================================*/ + +/* The Mathematica RNG for the Integer */ +static int coMathI = 0; /* Counter */ +static int *Math_AI; +static long Math_nI = 262144; +static MLINK lpI; +static MLEnvironment envI; + + +static void GetArrayI (void) +{ +/* Ask Mathematica to generate Math_nI random numbers at a time and put + them in array Math_AI */ + static int flag = 0; + + /* free memory taken up by previous array Math_AI */ + if (flag) + MLDisownIntegerList (lpI, Math_AI, Math_nI); + flag = 1; + + /* send the command Table[Random[Integer, {0, 2^30 - 1}], {Math_nI}] to + the Mathematica kernel */ + MLPutFunction (lpI, "Table", 2); + MLPutFunction (lpI, "Random", 2); + MLPutSymbol (lpI, "Integer"); + MLPutFunction (lpI, "List", 2); + MLPutInteger (lpI, 0); + MLPutInteger (lpI, 1073741823); /* 2^30 - 1; CA gives 30 bits max */ + MLPutFunction (lpI, "List", 1); + MLPutInteger (lpI, Math_nI); + MLEndPacket (lpI); + while (MLNextPacket (lpI) != RETURNPKT) + MLNewPacket (lpI); + + /* Get the Math_nI numbers in Math_AI */ + MLGetIntegerList (lpI, &Math_AI, &Math_nI); +} + + +/*------------------------------------------------------------------------*/ + +static unsigned long MathematicaI_Bits (void *junk1, void *junk2) +{ + /* return one random number; when at top of array, get another bunch */ + static long i = 0; + if (i == Math_nI) { + GetArrayI (); + i = 0; + } + /* Math_AI: Random numbers in [0, 2^30 - 1] */ + return ((unsigned int) Math_AI[i++] << 2); +} + + +/*------------------------------------------------------------------------*/ + +static double MathematicaI_U01 (void *vpar, void *vsta) +{ + return unif01_INV32 * MathematicaI_Bits (vpar, vsta); +} + + +/*------------------------------------------------------------------------*/ + +unif01_Gen *usoft_CreateMathematicaInteger (int argc, char *argv[], long s) +{ + long errno; + unif01_Gen *gen; + size_t leng; + char name[LEN + 1] = {0}; + + if (argc == 1) { + util_Error ("usoft_CreateMathematicaInteger:\n\n Usage: -linkname 'math -mathlink' -linklaunch"); + } + util_Assert (coMathI == 0, + "usoft_CreateMathematicaInteger: only 1 generator at a time can be used"); + coMathI++; + + envI = MLInitialize (NULL); + if (envI == NULL) { + util_Assert (1, "usoft_CreateMathematicaInteger: MathLink MLInitialize returns NULL"); + return NULL; + } + lpI = MLOpenArgv (envI, argv, argv + argc, &errno); + if (lpI == NULL) { + util_Assert (1, "usoft_CreateMathematicaInteger: MathLink MLOpenArgv returns NULL"); + return NULL; + } + + MLPutFunction (lpI, "SeedRandom", 1); + MLPutInteger (lpI, s); + MLEndPacket (lpI); + while (MLNextPacket (lpI) != RETURNPKT) + MLNewPacket (lpI); + MLNewPacket (lpI); + + gen = util_Malloc (sizeof (unif01_Gen)); + + strcpy (name, "usoft_CreateMathematicaInteger:"); + addstr_Long (name, " s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + GetArrayI (); + gen->GetBits = &MathematicaI_Bits; + gen->GetU01 = &MathematicaI_U01; + gen->Write = &WrMathematica; + gen->param = NULL; + gen->state = NULL; + return gen; +} + +/*------------------------------------------------------------------------*/ + +void usoft_DeleteMathematicaInteger (unif01_Gen *gen) +{ + MLDisownIntegerList (lpI, Math_AI, Math_nI); + MLClose (lpI); + MLDeinitialize (envI); + if (NULL == gen) + return; + gen->name = util_Free (gen->name); + util_Free (gen); + coMathI--; +} + +#endif + + +/*=========================================================================*/ +/* a simple example of using the Kernel of Mathematica: + request to Mathematica to compute the sum of 2 integers interactively + on the terminal from a C program. + + Compile with + gcc umath.c -I$MYMLPATH -L$MYMLPATH -lML -lm + Run with + a.out -linkname 'math -mathlink' -linkmode launch + +*/ + +#if 0 +int main (int argc, char *argv[]) +{ + + int i, j, sum; + MLINK lp; + int pkt; + MLEnvironment env; + + printf ("Enter two integers: \t\n"); + scanf ("%d %d", &i, &j); + env = MLInitialize (NULL); + if (env == NULL) + return 1; + + lp = MLOpen (argc, argv); + if (lp == NULL) + return 1; + + /* Send Plus[i, j] */ + MLPutFunction (lp, "Plus", 2); + MLPutInteger (lp, i); + MLPutInteger (lp, j); + + /* skip any packets before the first ReturnPacket */ + while (MLNextPacket (lp) != RETURNPKT) + MLNewPacket (lp); + + /* inside the ReturnPacket we expect an integer */ + MLGetInteger (lp, &sum); + printf ("sum = %d\n\n", sum); + + MLClose (lp); + MLDeinitialize (env); + return 0; +} +#endif + +/*=========================================================================*/ + +void usoft_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/usoft.tex b/TESTU01/TestU01-1.2.3/testu01/usoft.tex new file mode 100644 index 0000000..d882449 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/usoft.tex @@ -0,0 +1,352 @@ +\defmodule {usoft} + +This module implements (or, in some cases, provides an interface to) +some random number generators used in popular software products. +The macros of the form {\tt USE\_\ldots} are defined in module +{\tt gdef} in directory {\tt mylib}. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* usoft.h for ANSI C */ + +#ifndef USOFT_H +#define USOFT_H +\endhide +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen * usoft_CreateSPlus (long S1, long S2); +\endcode + \tab Generator used in the statistical software environment +\index{Generator!S-PLUS}% + {\em S-PLUS\/} \cite{tRIP94a,tSPL00a}. It is based on Marsaglia's Super-Duper + generator of 1973 (see the description of \texttt{SupDup73} on page + \pageref{gen:SupDup73} of this guide). See also the Web page at + \url{http://www.insightful.com/support/faqdetail.asp?FAQID=166&IsArchive=0}. + The generator never returns 0. + Restrictions: {\tt $0 <$ S1 $< 2^{31}-1$} and {\tt $0 <$ S2 $< 2^{31}-1$}. + \endtab +\code + + +#ifdef HAVE_RANDOM + unif01_Gen * usoft_CreateUnixRandom (unsigned int s); +#endif +\endcode + \tab + Provides an interface to the set of five additive feedback + \hpierre{C'est shift-register ou bien c'est lagged-Fibonacci? Clarifier. } + random number generators implemented in the function {\tt random()} + in the Unix or Linux {\tt C} library {\tt stdlib} +\index{Generator!Unix random}% + (see the documentation of {\tt random}). + It uses a default table of + long integers to return successive pseudo-random numbers. + The size of the state array determines the period of the + random number generator; increasing the state array size + increases the period. + The parameter {\tt s} determines the order of the recurrence. + % Remark: There are different versions of this family under + % Solaris and Linux; + This generator is not part of the standard ANSI C library. + Since it uses global variables, no more than one generator + of this type can be in use at any given time. + Restrictions: $s \in \{8, 32, 64, 128, 256\}$. + \endtab +\code + + +#ifdef USE_LONGLONG + unif01_Gen * usoft_CreateJava48 (ulonglong s, int jflag); +#endif +\endcode + \tab + Implements the same generator as the method {\tt nextDouble}, in +\index{Generator!Java}% + class {\tt java.util.Random} of the Java standard library + ({\tt {http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html}}). + It is based on a linear recurrence with period length $2^{48}$, + but each output value is constructed by taking + two successive values from the linear recurrence, as follows: +\begin{eqnarray*} + x_{i+1} &=& (25214903917\, x_i + 11) \mod 2^{48} \\[6pt] + u_i &=& \frac{2^{27}\lfloor x_{2i} / 2^{22} \rfloor + + \lfloor x_{2i+1} / 2^{21}\rfloor}{2^{53}}. +\end{eqnarray*} +\iffalse %%%%%%%%% +or equivalently +\begin{eqnarray*} + u_i &=& \left[(27 << (x_{2i} >> 22)) + (x_{2i+1} >> 21)\right] / 2^{53}. +\end{eqnarray*} +if $<< p$ and $>> p$ represent the left shift and right shift of the +binary representation by $p$ positions, respectively. +\fi %%%% +\iffalse %%%% The actual java code is: +static double Java48 (void) { + ulonglong temp; + SS = (25214903917ULL * SS + 11) \& m48; + /* Keep only the 26 most significant bits of SS; shift 5. They will */ + /* make bits [27..52] of the next generated number, counting from 0. */ + /* 281474972516352 = mask of the 26 most significant bits. */ + temp = (SS \& 281474972516352ULL) << 5; + + SS = (25214903917ULL * SS + 11) \& m48; + /* Keep only the 27 most significant bits of SS; shift 21. They will */ + /* make bits [0..26] of the next generated number */ + return (temp + (SS >> 21)) * norm; +\fi %%%% + Note that the generator {\tt rand48} in the Unix standard library + uses exactly the same recurrence, but produces its output simply + via $u_i = x_i / 2^{48}$. + If {\tt jflag > 0}, {\tt s} is transformed via + ``{\tt s = s\^{}0x5DEECE66D}'' at initialization, as is done in the + Java class {\tt Random}; one will then obtain the same numbers as + in Java {\tt Random} with the given seed. + If {\tt jflag = 0}, {\tt s} is used directly as initial seed. + Restriction: $s < 281474976710656$. + \endtab +\hide %%%%%%%%%%%%%%%%%%%%% +\code + +unif01_Gen * usoft_CreateExcel97 (double r); +\endcode + \tab + An ``approximation'' of the {RAND} generator included in +% \index{Generator!Excel}% + Microsoft Excel 1997, which uses the recurrence + (see \url{http://support.microsoft.com/directory}): +$$ + u_{i} = (9821.0\, u_{i-1} + 0.211327) \bmod 1, +$$ + where the $u_i$'s are represented in floating point. + Its period length depends on the numerical precision used for the + implementation. This is not stated in the documentation + and it is unclear what it is. + The earlier versions of Excel used the default seed $r = 0.5$. + More recent versions use a random seed determined from the + system clock by default. + Adding {\tt randomize=0} to the ``Microsoft Excel'' section of the + appropriate {\tt .INI} file causes the seed $r$ to be set to 0.5. + \endtab +\endhide %%%%%%%%%%%%%%% +\code + + +unif01_Gen * usoft_CreateExcel2003 (int x0, int y0, int z0); +\endcode + \tab + This is the generator implemented by the {RAND} function in +\index{Generator!Excel} \label{gen:Excel2003}% +\index{Generator!Wichmann-Hill}% + Microsoft Office Excel 2003 + (see \url{http://support.microsoft.com/default.aspx?scid=kb;en-us;828795}). + It uses the Wichmann-Hill generator \cite{rWIC82a,rWIC87a} +\begin{eqnarray*} + x_{i} &=& 170 \, x_{i-1} \bmod 30323 \\ + y_{i} &=& 172 \, y_{i-1} \bmod 30307 \\ + z_{i} &=& 171 \, z_{i-1} \bmod 30269 \\[6pt] + u_i &=& \left(\frac{x_i}{30323} + \frac{y_i}{30307} + + \frac{z_i}{30269}\right) \bmod 1. +\end{eqnarray*} + The Wichmann-Hill generators are described in this guide on page + \pageref{gen:Wichmann-Hill}. The Excel generator is equivalent to the call + \texttt{ulcg\_CreateCombWH3 (30323, 30307, 30269, 170, 172, 171, + 0, 0, 0, x0, y0, z0)}. The initial seeds are \texttt{x0}, + \texttt{y0} and \texttt{z0}. + Restrictions: $0 < \texttt{x0} < 30323$, + $0 < \texttt{y0} < 30307$ and $0 < \texttt{z0} < 30269$. + \endtab +\code + + +unif01_Gen * usoft_CreateVisualBasic (unsigned long s); +\endcode + \tab + The random number generator included in Microsoft VisualBasic. +\index{Generator!VisualBasic}% + It is an LCG defined as: +$$ + x_{i} = (1140671485\, x_{i-1} + 12820163) \mod 2^{24}; \qquad + u_i = x_i / 2^{24} +$$ +(see {\tt {http://support.microsoft.com/support/kb/articles/Q231/8/47.ASP}}). + The parameter {\tt s} gives the seed $x_0$. Note that the multiplier + 1140671485 in the equation above is equivalent to 16598013, since + $1140671485 \mod 2^{24} = 16598013$. + \endtab +\code + + +#if defined(USE_GMP) && defined(USE_LONGLONG) + unif01_Gen * usoft_CreateMaple_9 (longlong s); +#endif +\endcode + \tab Implements the generator included in {\sc Maple 9.5} and earlier versions. + It is a linear congruential generator (see the definition on page \pageref{lcg}) + with $m=999999999989$, $a=427419669081$ and $c = 0$. The seed is $s$. + Restriction: $0 < s < 999999999989$. {\em Note:} {\sc Maple 10} uses the + Mersenne twister MT19937 as its basic generator + (see page \pageref{rng:MT19937} of this guide). + \endtab +\code + + +#ifdef USE_LONGLONG + unif01_Gen * usoft_CreateMATLAB (int i, unsigned int j, int bf, + double Z[]); +#endif +\endcode + \tab Implements the basic generator (function {\tt rand}) included in + {\sc MATLAB} \cite{rMOL04a} to generate uniform random numbers. + It is \index{Generator!MATLAB}% + a combination of the subtract-with-borrow generator + (\ref{gen:matlab1}) proposed in \cite{rMAR91a}, where $z$ is an array of + 32 floating-point numbers in $[0, 1)$ and $b$ is a borrow flag, with the + Xorshift generator (\ref{gen:matlab2}) described in \cite{rMAR03a}: +\begin{equation} + z_i \ =\ z_{i+20} - z_{i+5} - b \label{gen:matlab1} +\end{equation} +\begin{equation} + \rule{0pt}{14pt} j \mbox{ \^{}= } (j\ll13);\quad j \mbox{ \^{}= } (j\gg17); + \quad j \mbox{ \^{}= } (j\ll5); \label{gen:matlab2} +\end{equation} +% $j$ \^{}$= (j\ll13);$ $j $ \^{}$= (j\gg17); j $ \^{}$= (j\ll5);$ +% \texttt{j \^{}= (j<<13); j \^{}= (j>>17); j \^{}= (j<<5);} + The combination is done by taking the bitwise \emph{exclusive-or} of + the bits of the mantissa of $z_i$ with a 52-bit shifted version + of $j$, and this gives the mantissa of the returned number in $[0, 1)$. + If \texttt{i}$\; <0$, then \texttt{j}, \texttt{bf} and \texttt{Z} + are unused, and the generator is initialized using the same + procedure as the one described in Cleve Moler's MATLAB + $M$-file \texttt{randtx.m} + (see \url{http://www.mathworks.com/moler/ncm/randtx.m}) + when $z$ is empty. If \texttt{i} $\ge 0$, then \texttt{j}, \texttt{bf} + and \texttt{Z} are used as initial values for the generator state. + If the flag \texttt{bf}$\;=0$, then the initial + borrow is set to $b=0$, while if \texttt{bf}$\ \ne 0$, then + it is set to $b=2^{-53}$. + Restrictions: \texttt{i}$\; < 32$, \texttt{bf} $\in \{0, 1\}$, + and $0 <$ \texttt{Z[i]} $ < 1$. + + Another uniform generator included in {\sc MATLAB} is used to + generate normal random variables. It is + Marsaglia's additive SuperDuper of 1996, with $c=1234567$, described on page + \pageref{gen:SupDup96} of this guide (see {\tt umarsa\_CreateSupDup96Add}). + {\sc MATLAB} includes also the Mersenne twister generator + of Matsumoto and Nishimura \cite{rMAT98a} (see {\tt ugfsr\_CreateMT19937} + on page \pageref{rng:MT19937} of this guide). + \endtab +\code + + +#ifdef HAVE_MATHEMATICA + unif01_Gen * usoft_CreateMathematicaReal (int argc, char * argv[], + long s); +#endif +\endcode + \tab This provides an interface to the random number generator +\index{Generator!Mathematica-Real}% + for real numbers in $[0, 1)$ implemented by function ``{\tt Random[ ]}'' of + {Mathematica 5} and earlier releases (see the web site of + Wolfram Research Inc. at \url{http://www.wolfram.com}). It is a + subtract-with-borrow generator (described on page \pageref{gen:SWB} + of this guide) of the type proposed by Marsaglia and Zaman + in \cite{rMAR91a}, apparently of the form $x_i = (x_{i-8} - x_{i-48} - c) + \bmod 2^{31}$, and each returned number in [0,1) uses two successive numbers + of the recurrence to get a double of 53 bits. + The parameters {\tt argc} and {\tt argv} are the usual + arguments of the ``{\tt main}'' function and the parameter + {\tt s} is the initial seed. The random numbers are + generated in batches of $2^{18} = 262144$ numbers, for greater + speed. + Since this generator uses file variables, no more than one generator + of this type can be in use at any given time. + See the documentation in module {\tt gdef} of MyLib concerning + the macro {\tt HAVE\_MATHEMATICA}. +% and on how to call {Mathematica} functions from a C program. + If the executable program is called, say \texttt{tulip}, then the program + is launched on a Unix/Linux platform by the command + \texttt{tulip -linkname 'math -mathlink' -linklaunch}. + \endtab +\code + + +#ifdef HAVE_MATHEMATICA + unif01_Gen * usoft_CreateMathematicaInteger (int argc, char * argv[], + long s); +#endif +\endcode + \tab Provides an interface to the random number generator +\index{Generator!Mathematica-Integer}% + for integers in $[0, 2^{30} - 1]$ implemented by function + ``{\tt Random[Integer, {$2^{30} - 1$}]}'' of + {Mathematica 5} and earlier releases. It is + based on a cellular automata with rule 30 proposed by Wolfram + \cite{rWOL86a}. See also the documentation of + \texttt{usoft\_CreateMathematicaReal} above. + \endtab + + +\guisec{Clean-up functions} +\code + +#ifdef USE_LONGLONG + void usoft_DeleteMATLAB (unif01_Gen *gen); +#endif +\endcode + \tab Frees the dynamic memory used by the {\sc MATLAB} + generator and allocated by the corresponding {\tt Create} function + above. + \endtab +\code + + +#ifdef HAVE_MATHEMATICA + void usoft_DeleteMathematicaReal (unif01_Gen *); + void usoft_DeleteMathematicaInteger (unif01_Gen *); +\endcode + \tab Frees the dynamic memory used by the {\sc Mathematica} + generators and allocated by the corresponding {\tt Create} function + above. + \endtab +\code +#endif + + +#ifdef HAVE_RANDOM + void usoft_DeleteUnixRandom (unif01_Gen *); +\endcode + \tab Frees the dynamic memory used by the {\tt UnixRandom} + generator and allocated by the corresponding {\tt Create} function + above. + \endtab +\code +#endif + + +#if defined(USE_GMP) && defined(USE_LONGLONG) + void usoft_DeleteMaple_9 (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by the {\sc Maple} generator and + allocated by the corresponding {\tt Create} function above. + \endtab +\code +#endif + + +void usoft_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called to clean up a generator object + when it is no longer in use. + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/utaus.c b/TESTU01/TestU01-1.2.3/testu01/utaus.c new file mode 100644 index 0000000..d22d719 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/utaus.c @@ -0,0 +1,636 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: utaus.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "mystr.h" +#include "addstr.h" + +#include "utaus.h" +#include "unif01.h" + +#include +#include + + + + +/*============================= constants ================================*/ + +#define LEN0 300 /* Max length of strings */ +#define LEN1 100 /* Max length of strings */ + + + + +/*================================ Types ================================*/ + +typedef struct { + unsigned int M1, S1, Q1, K1mS1; + unsigned int J; +} Taus_param; + +typedef struct { + unsigned int ST1; +} Taus_state; + +typedef struct { + unsigned int M1, S1, Q1, K1mS1; + unsigned int M2, S2, Q2, K2mS2; +} CombTaus2_param; + +typedef struct { + unsigned int ST1, ST2; +} CombTaus2_state; + +typedef struct { + unsigned int M1, S1, Q1, K1mS1; + unsigned int M2, S2, Q2, K2mS2; + unsigned int M3, S3, Q3, K3mS3; +} CombTaus3_param; + +typedef struct { + unsigned int ST1, ST2, ST3; +} CombTaus3_state; + + +#ifdef USE_LONGLONG +/* The 64 bits Tausworthe */ +typedef struct { + ulonglong M1, S1, Q1, K1mS1; +} LongTaus_param; + +typedef struct { + ulonglong ST1; +} LongTaus_state; +#endif + + +/*============================= Functions ===============================*/ + +static unsigned long Taus_Bits (void *vpar, void *vsta) +{ + Taus_param *param = vpar; + Taus_state *state = vsta; + unsigned int A, B; + + A = (state->ST1 & param->M1) << param->S1; + B = ((state->ST1 << param->Q1) ^ state->ST1) >> param->K1mS1; + state->ST1 = A ^ B; + return state->ST1; +} + +static double Taus_U01 (void *vpar, void *vsta) +{ + return Taus_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long TausJ_Bits (void *vpar, void *vsta) +/* + * Tausworthe generator that goes forward J steps for each value returned. + */ +{ + Taus_param *param = vpar; + Taus_state *state = vsta; + unsigned int A, B; + unsigned int i; + + for (i = 1; i <= param->J; i++) { + A = (state->ST1 & param->M1) << param->S1; + B = ((state->ST1 << param->Q1) ^ state->ST1) >> param->K1mS1; + state->ST1 = A ^ B; + } + return state->ST1; +} + +static double TausJ_U01 (void *vpar, void *vsta) +{ + return TausJ_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrTaus (void *vsta) +{ + Taus_state *state = vsta; + printf (" S = %1u\n", state->ST1); +} + +/*-------------------------------------------------------------------------*/ + +static unif01_Gen * CreateTaus_0 (char *na, unsigned int k, unsigned int q, + unsigned int s, unsigned int Y) +{ + unif01_Gen *gen; + Taus_param *param; + Taus_state *state; + size_t len; + char name[LEN0 + 1]; + char str[LEN1 + 1]; + unsigned int B; + + strncpy (str, na, (size_t) LEN1); + strncat (str, ": Invalid Parameter", (size_t) LEN1 - 30); + util_Assert ((k <= 32) && (k > 2 * q) && (s <= k - q) && + (s >= 1) && (q >= 1), str); + /* These restrictions implies, for 32 bits int, */ + /* 0 < k <= 32 ; 0 < q < 16 ; 0 < s < 32 ; 0 < k - s < 32 */ + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Taus_param)); + state = util_Malloc (sizeof (Taus_state)); + + strncpy (name, na, (size_t) LEN0); + addstr_Uint (name, ": k = ", k); + addstr_Uint (name, ", q = ", q); + addstr_Uint (name, ", s = ", s); + addstr_Uint (name, ", Y = ", Y); + len = strlen (name); + gen->name = util_Calloc (len + 1, sizeof (char)); + strncpy (gen->name, name, len); + + param->Q1 = q; + param->K1mS1 = k - s; + param->S1 = s; + + /* k most signif. bits at 1 */ + B = num_TwoExp[32 - k] - 1.0; + param->M1 = ~B; + + util_Assert (param->M1 > 0, "CreateTaus_0: M1 = 0"); + + strncpy (str, na, (size_t) LEN1); + strncat (str, ": Y = 0", (size_t) LEN1 - 30); + util_Assert (Y > 0, str); + state->ST1 = Y & param->M1; + + /* make sure that the initial state is not 0 */ + while (state->ST1 == 0) { + Y *= 2; + state->ST1 = Y & param->M1; + } + B = ((state->ST1 << param->Q1) ^ state->ST1) >> k; + if (k >= 8 * sizeof (int)) + B = 0; /* B = B >> 32 does not work */ + state->ST1 ^= B; + + gen->GetBits = &Taus_Bits; + gen->GetU01 = &Taus_U01; + gen->Write = &WrTaus; + gen->param = param; + gen->state = state; + return gen; +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *utaus_CreateTaus (unsigned int k, unsigned int q, unsigned int s, + unsigned int Y) +{ + return CreateTaus_0 ("utaus_CreateTaus", k, q, s, Y); +} + +unif01_Gen *utaus_CreateTausJ (unsigned int k, unsigned int q, + unsigned int s, unsigned int j, unsigned int Y) +{ + unif01_Gen *gen; + Taus_param *param; + unsigned int pos; + int found; + size_t len; + char str[LEN1 + 1] = ""; + + gen = CreateTaus_0 ("utaus_CreateTausJ", k, q, s, Y); + param = gen->param; + param->J = j; + gen->GetBits = &TausJ_Bits; + gen->GetU01 = &TausJ_U01; + + addstr_Uint (str, ", j = ", j); + len = strlen (gen->name) + strlen (str); + gen->name = util_Realloc (gen->name, (len + 1) * sizeof (char)); + mystr_Position (", Y =", gen->name, 0, &pos, &found); + mystr_Insert (gen->name, str, pos); + return gen; +} + + +/**************************************************************************/ +#ifdef USE_LONGLONG + +static unsigned long LongTaus_Bits (void *vpar, void *vsta) +/* + * Implementation of a Tausworthe generator for k <= 64. However, bits + * 33 to 64 will be right-shifted 32 bits before being returned in an + * unsigned int of 32 bits. This is to satisfy the return type + * of unif01_Gen.GetBits. + */ +{ + LongTaus_param *param = vpar; + LongTaus_state *state = vsta; + ulonglong A, B; + A = (state->ST1 & param->M1) << param->S1; + B = ((state->ST1 << param->Q1) ^ state->ST1) >> param->K1mS1; + state->ST1 = A ^ B; + return state->ST1 >> 32; +} + +static double LongTaus_U01 (void *vpar, void *vsta) +{ + return LongTaus_Bits (vpar, vsta) * unif01_INV32; +} + +/*-------------------------------------------------------------------------*/ + +static void WrLongTaus (void *vsta) +{ + LongTaus_state *state = vsta; + printf (" S = %1" PRIuLEAST64 "\n", state->ST1); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utaus_CreateLongTaus (unsigned int k, unsigned int q, + unsigned int s, ulonglong Y) +{ + unif01_Gen *gen; + LongTaus_param *param; + LongTaus_state *state; + size_t len; + char name[LEN0 + 1]; + ulonglong B; + + util_Assert ((k <= 64) && (k > 2 * q) && (s <= k - q) && (s >= 1) && + (q >= 1), "utaus_CreateLongTaus: Invalid Parameter"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (LongTaus_param)); + state = util_Malloc (sizeof (LongTaus_state)); + + strncpy (name, "utaus_CreateLongTaus", (size_t) LEN0); + addstr_Uint (name, ": k = ", k); + addstr_Uint (name, ", q = ", q); + addstr_Uint (name, ", s = ", s); + addstr_ULONG (name, ", Y = ", Y); + len = strlen (name); + gen->name = util_Calloc (len + 1, sizeof (char)); + strncpy (gen->name, name, len); + + param->Q1 = q; + param->K1mS1 = k - s; + param->S1 = s; + B = num_TwoExp[64 - k] - 1.0; /* k most signif. bits at 1 */ + param->M1 = ~B; + + util_Assert (Y > 0, "utaus_CreateLongTaus: Y = 0"); + state->ST1 = Y & param->M1; + + /* make sure that the initial state is not 0 */ + while (state->ST1 == 0) { + Y *= 2; + state->ST1 = Y & param->M1; + } + B = ((state->ST1 << param->Q1) ^ state->ST1) >> k; + state->ST1 ^= B; + + gen->GetBits = &LongTaus_Bits; + gen->GetU01 = &LongTaus_U01; + gen->Write = &WrLongTaus; + gen->param = param; + gen->state = state; + return gen; +} + +#endif + +/**************************************************************************/ + +static unsigned long CombTaus2_Bits (void *vpar, void *vsta) +{ + CombTaus2_param *param = vpar; + CombTaus2_state *state = vsta; + unsigned int A, B; + + A = (state->ST1 & param->M1) << param->S1; + B = ((state->ST1 << param->Q1) ^ state->ST1) >> param->K1mS1; + state->ST1 = A ^ B; + + A = (state->ST2 & param->M2) << param->S2; + B = ((state->ST2 << param->Q2) ^ state->ST2) >> param->K2mS2; + state->ST2 = A ^ B; + + return state->ST1 ^ state->ST2; +} + +static double CombTaus2_U01 (void *vpar, void *vsta) +{ + return CombTaus2_Bits (vpar, vsta) * unif01_INV32; +} + +static void WrCombTaus2 (void *vsta) +{ + CombTaus2_state *state = vsta; + printf (" S1 = %1u, S2 = %1u\n", state->ST1, state->ST2); +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utaus_CreateCombTaus2 (unsigned int k1, unsigned int k2, + unsigned int q1, unsigned int q2, unsigned int s1, unsigned int s2, + unsigned int Y1, unsigned int Y2) +{ + unif01_Gen *gen; + CombTaus2_param *param; + CombTaus2_state *state; + size_t len; + char name[LEN0 + 1]; + unsigned int B; + + util_Assert ( + (k1 <= 32) && (k1 > 2 * q1) && (s1 <= k1 - q1) && (s1 > 0) && + (k2 <= 32) && (k2 > 2 * q2) && (s2 <= k2 - q2) && (s2 > 0) && + (q1 > 0) && (q2 > 0) && (k1 >= k2), + "utaus_CreateCombTaus2: Invalid Parameter"); + + strncpy (name, "utaus_CreateCombTaus2:", (size_t) LEN0); + addstr_Uint (name, " (k1, k2) = ", k1); + addstr_Uint (name, ", ", k2); + addstr_Uint (name, ", (q1, q2) = ", q1); + addstr_Uint (name, ", ", q2); + addstr_Uint (name, ", (s1, s2) = ", s1); + addstr_Uint (name, ", ", s2); + addstr_Uint (name, ", (Y1, Y2) = ", Y1); + addstr_Uint (name, ", ", Y2); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = gen->param = util_Malloc (sizeof (CombTaus2_param)); + state = gen->state = util_Malloc (sizeof (CombTaus2_state)); + gen->GetU01 = &CombTaus2_U01; + gen->GetBits = &CombTaus2_Bits; + gen->Write = &WrCombTaus2; + + len = strlen (name); + gen->name = util_Calloc (len + 1, sizeof (char)); + strncpy (gen->name, name, len); + + param->Q1 = q1; + param->S1 = s1; + param->K1mS1 = k1 - s1; + param->M1 = num_TwoExp[32 - k1] - 1; /* k1 most sig. bits at 1 */ + param->M1 = ~param->M1; + + param->Q2 = q2; + param->S2 = s2; + param->K2mS2 = k2 - s2; + param->M2 = num_TwoExp[32 - k2] - 1; /* k2 most sig. bits at 1 */ + param->M2 = ~param->M2; + + /* Initialisation as in L'Ecuyer 1996. */ + util_Assert (Y1 > 0, "utaus_CreateCombTaus2: seed1 = 0"); + state->ST1 = Y1 & param->M1; + while (state->ST1 == 0) { /* Make sure the initial state is not 0 */ + Y1 = Y1 * 2; + state->ST1 = Y1 & param->M1; + } + B = ((state->ST1 << param->Q1) ^ state->ST1) >> k1; + if (k1 >= 8 * sizeof (int)) + B = 0; /* B = B >> 32 does not work */ + state->ST1 = state->ST1 ^ B; + + util_Assert (Y2 > 0, "utaus_CreateCombTaus2: seed2 = 0"); + state->ST2 = Y2 & param->M2; + while (state->ST2 == 0) { /* Make sure the initial state is not 0 */ + Y2 = Y2 * 2; + state->ST2 = Y2 & param->M2; + } + B = ((state->ST2 << param->Q2) ^ state->ST2) >> k2; + if (k2 >= 8 * sizeof (int)) + B = 0; /* B = B >> 32 does not work */ + state->ST2 = state->ST2 ^ B; + + return gen; +} + + +/****************************************************************************/ + +static unsigned long CombTaus3_Bits (void *vpar, void *vsta) +{ + CombTaus3_param *param = vpar; + CombTaus3_state *state = vsta; + unsigned int A, B; + + A = (state->ST1 & param->M1) << param->S1; + B = ((state->ST1 << param->Q1) ^ state->ST1) >> param->K1mS1; + state->ST1 = A ^ B; + + A = (state->ST2 & param->M2) << param->S2; + B = ((state->ST2 << param->Q2) ^ state->ST2) >> param->K2mS2; + state->ST2 = A ^ B; + + A = (state->ST3 & param->M3) << param->S3; + B = ((state->ST3 << param->Q3) ^ state->ST3) >> param->K3mS3; + state->ST3 = A ^ B; + + return state->ST1 ^ state->ST2 ^ state->ST3; +} + +static double CombTaus3_U01 (void *vpar, void *vsta) +{ + return CombTaus3_Bits (vpar, vsta) * unif01_INV32; +} + +static void WrCombTaus3 (void *vsta) +{ + CombTaus3_state *state = vsta; + printf (" S1 = %1u, S2 = %1u, S3 = %1u\n", + state->ST1, state->ST2, state->ST3); +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utaus_CreateCombTaus3 (unsigned int k1, unsigned int k2, + unsigned int k3, unsigned int q1, unsigned int q2, unsigned int q3, + unsigned int s1, unsigned int s2, unsigned int s3, unsigned int Y1, + unsigned int Y2, unsigned int Y3) +{ + unif01_Gen *gen; + CombTaus3_param *param; + CombTaus3_state *state; + size_t len; + char name[LEN0 + 1]; + unsigned int B; + + util_Assert ( + (k1 <= 32) && (k1 > 2 * q1) && (s1 <= k1 - q1) && (s1 > 0) && + (k2 <= 32) && (k2 > 2 * q2) && (s2 <= k2 - q2) && (s2 > 0) && + (k3 <= 32) && (k3 > 2 * q3) && (s3 <= k3 - q3) && (s3 > 0) && + (q1 > 0) && (q2 > 0) && (q3 > 0) && (k1 >= k2) && (k2 >= k3), + "utaus_CreateCombTaus3: Invalid Parameter"); + + strncpy (name, "utaus_CreateCombTaus3:", (size_t) LEN0); + addstr_Uint (name, " (k1, k2, k3) = ", k1); + addstr_Uint (name, ", ", k2); + addstr_Uint (name, ", ", k3); + addstr_Uint (name, ", (q1, q2, q3) = ", q1); + addstr_Uint (name, ", ", q2); + addstr_Uint (name, ", ", q3); + addstr_Uint (name, ", (s1, s2, s3) = ", s1); + addstr_Uint (name, ", ", s2); + addstr_Uint (name, ", ", s3); + addstr_Uint (name, ", (Y1, Y2, Y3) = ", Y1); + addstr_Uint (name, ", ", Y2); + addstr_Uint (name, ", ", Y3); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = gen->param = util_Malloc (sizeof (CombTaus3_param)); + state = gen->state = util_Malloc (sizeof (CombTaus3_state)); + gen->GetU01 = &CombTaus3_U01; + gen->GetBits = &CombTaus3_Bits; + gen->Write = &WrCombTaus3; + + len = strlen (name); + gen->name = util_Calloc (len + 1, sizeof (char)); + strncpy (gen->name, name, len); + + param->Q1 = q1; + param->S1 = s1; + param->K1mS1 = k1 - s1; + param->M1 = num_TwoExp[32 - k1] - 1; /* k1 most sig. bits at 1 */ + param->M1 = ~param->M1; + + param->Q2 = q2; + param->S2 = s2; + param->K2mS2 = k2 - s2; + param->M2 = num_TwoExp[32 - k2] - 1; /* k2 most sig. bits at 1 */ + param->M2 = ~param->M2; + + param->Q3 = q3; + param->S3 = s3; + param->K3mS3 = k3 - s3; + param->M3 = num_TwoExp[32 - k3] - 1; /* k3 most sig. bits at 1 */ + param->M3 = ~param->M3; + + /* Initialisation as in L'Ecuyer 1996. */ + util_Assert (Y1 > 0, "utaus_CreateCombTaus3: seed1 = 0"); + state->ST1 = Y1 & param->M1; + while (state->ST1 == 0) { /* Make sure the initial state is not 0 */ + Y1 = Y1 * 2; + state->ST1 = Y1 & param->M1; + } + B = ((state->ST1 << param->Q1) ^ state->ST1) >> k1; + if (k1 >= 8 * sizeof (int)) + B = 0; /* B = B >> 32 does not work */ + state->ST1 = state->ST1 ^ B; + + util_Assert (Y2 > 0, "utaus_CreateCombTaus3: seed2 = 0"); + state->ST2 = Y2 & param->M2; + while (state->ST2 == 0) { /* Make sure the initial state is not 0 */ + Y2 = Y2 * 2; + state->ST2 = Y2 & param->M2; + } + B = ((state->ST2 << param->Q2) ^ state->ST2) >> k2; + if (k2 >= 8 * sizeof (int)) + B = 0; /* B = B >> 32 does not work */ + state->ST2 = state->ST2 ^ B; + + util_Assert (Y3 > 0, "utaus_CreateCombTaus3: seed3 = 0"); + state->ST3 = Y3 & param->M3; + while (state->ST3 == 0) { /* Make sure the initial state is not 0 */ + Y3 = Y3 * 2; + state->ST3 = Y3 & param->M3; + } + B = ((state->ST3 << param->Q3) ^ state->ST3) >> k3; + if (k3 >= 8 * sizeof (int)) + B = 0; /* B = B >> 32 does not work */ + state->ST3 = state->ST3 ^ B; + + return gen; +} + + +/****************************************************************************/ + +#define FAC32 4294967296.0 /* 2^32 */ +#define FAC49 562949953421312.0 /* 2^49 */ +#define FAC66 73786976294838206464.0 /* 2^66 */ + +static double CombTaus3T_U01 (void *vpar, void *vsta) +{ + double U; + U = CombTaus3_Bits (vpar, vsta) / FAC32; + U += CombTaus3_Bits (vpar, vsta) / FAC49; + U += CombTaus3_Bits (vpar, vsta) / FAC66; + if (U < 1.0) + return U; + else + return U - 1.0; +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long CombTaus3T_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (CombTaus3T_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utaus_CreateCombTaus3T (unsigned int k1, unsigned int k2, + unsigned int k3, unsigned int q1, unsigned int q2, unsigned int q3, + unsigned int s1, unsigned int s2, unsigned int s3, unsigned int Y1, + unsigned int Y2, unsigned int Y3) +{ + unif01_Gen *gen; + size_t j; + + gen = utaus_CreateCombTaus3 ( + k1, k2, k3, q1, q2, q3, s1, s2, s3, Y1, Y2, Y3); + j = strlen (gen->name); + gen->name = util_Realloc (gen->name, (j + 2) * sizeof (char)); + j = strcspn (gen->name, ":"); + mystr_Insert (gen->name, "T", (unsigned int) j); + gen->GetU01 = &CombTaus3T_U01; + gen->GetBits = &CombTaus3T_Bits; + + return gen; +} + + +/****************************************************************************/ + +void utaus_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/utaus.tex b/TESTU01/TestU01-1.2.3/testu01/utaus.tex new file mode 100644 index 0000000..ba00d8c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/utaus.tex @@ -0,0 +1,165 @@ +\defmodule {utaus} + +Implements simple and combined Tausworthe generators using +the definitions, the initialization methods and the + algorithms given in \cite{rLEC94a,rLEC96a}. +The current implementation is restricted to components whose +characteristic polynomial is a {\em trinomial}. That is, +for a simple generator and for each component of a combined +generator, the basic recurrence has the form % (modulo 2) +\eq \eqlabel{taus1} + x_n = x_{n-r} \oplus x_{n-k} = x_{n-k+q} \oplus x_{n-k}, +\endeq +with characteristic polynomial $p(x) = x^p + x^q + 1$, +where $q = k-r$, each $x_n$ is 0 or 1, and $\oplus$ +means exclusive-or (i.e., addition modulo 2). +The output at step $n$ is +\eq \eqlabel{taus2} + u_n = \sum_{j=1}^w x_{ns+j-1} 2^{-j} +\endeq +with $w = 32$. +To obtain $w < 32$, it suffices to truncate the output. +The parameters must satisfy the following conditions: +$0 < 2q < k \le 32$ (except in the case of the {\tt LongTaus} generator +for which $k$ can take values as high as 64) and $0 < s \le r$. +In the functions defined below, the $k$ most significant +bits of the variable {\tt Y} contain +the initial values $x_0,\dots,x_{k-1}$ (this is the seed). +They must not be all zero. +\index{Generator!Tausworthe} \index{Generator!LFSR}% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* utaus.h for ANSI C */ + +#ifndef UTAUS_H +#define UTAUS_H +\endhide +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen * utaus_CreateTaus (unsigned int k, unsigned int q, + unsigned int s, unsigned int Y); +\endcode + \tab Implements a simple Tausworthe generator as described above. + Restrictions: $0 < 2q < k \le 32$ and $0 < s \le k-q$. + \endtab +\code + + +unif01_Gen * utaus_CreateTausJ (unsigned int k, unsigned int q, + unsigned int s, unsigned int j, + unsigned int Y); +\endcode + \tab Implements a Tausworthe generator as in {\tt utaus\_CreateTaus}, + except that it produces a $j$-decimated sequence. + That is, at each call, it skips $j-1$ values in the sequence + defined by (\ref{taus1}--\ref{taus2}) and outputs the next one. + The same restrictions as in {\tt utaus\_CreateTaus} apply. + \endtab +\code + + +#ifdef USE_LONGLONG + unif01_Gen * utaus_CreateLongTaus (unsigned int k, unsigned int q, + unsigned int s, ulonglong Y1); +\endcode + \tab Similar to {\tt utaus\_CreateTaus} but uses + 64 bits integers for the state of the generator. However, it returns + only the 32 most significant bits of each generated number, after + having shifted them 32 bits to the right. + Restrictions: $k \le 64$, $0 < 2q < k$ and $0 < s \le k-q$. + \endtab +\code +#endif + + +unif01_Gen * utaus_CreateCombTaus2 ( + unsigned int k1, unsigned int k2, unsigned int q1, unsigned int q2, + unsigned int s1, unsigned int s2, unsigned int Y1, unsigned int Y2); +\endcode + \tab Combines two Tausworthe generators defined as in + {\tt utaus\_CreateTaus}. The combination is via a bitwise exclusive-or, + as in \cite{rLEC96a,rTEZ89a,rTEZ91b}. + The same restrictions as in {\tt utaus\_CreateTaus} apply to each of the + two components. + Also assumes that $k_1\ge k_2$. + \endtab +\code + + +unif01_Gen * utaus_CreateCombTaus3 ( + unsigned int k1, unsigned int k2, unsigned int k3, + unsigned int q1, unsigned int q2, unsigned int q3, + unsigned int s1, unsigned int s2, unsigned int s3, + unsigned int Y1, unsigned int Y2, unsigned int Y3); +\endcode + \tab Similar to {\tt utaus\_CreateCombTaus2}, except that + three Tausworthe generators are combined instead of two. + Assumes that $k_1 \ge k_2 \ge k_3$. + \endtab +\code + + +unif01_Gen * utaus_CreateCombTaus3T ( + unsigned int k1, unsigned int k2, unsigned int k3, + unsigned int q1, unsigned int q2, unsigned int q3, + unsigned int s1, unsigned int s2, unsigned int s3, + unsigned int Y1, unsigned int Y2, unsigned int Y3); +\endcode + \tab Similar to {\tt utaus\_CreateCombTaus3}, except that the + generator has ``triple'' precision. Three successive output values + $u_i$ of the combined Tausworthe generator are used to build each + output value $U_i$ (uniform on [0, 1)) of this generator, as follows: + $$ + U_{i} = \left(u_{3i} + \frac{u_{3i+1}}{2^{17}} + + \frac{u_{3i+2}}{2^{34}}\right) \mod 1. + $$ + \endtab + + + +\guisec{Clean-up functions} +\code + +void utaus_DeleteGen (unif01_Gen *gen); +\endcode + \tab \DelGen + \endtab +\code +\hide +#endif +\endhide +\endcode + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\guisec{Related generators} + + +For specific Tausworthe generators, see also +{ +\setlength{\partopsep}{0pt} +\setlength{\parskip}{0pt} +\setlength{\topsep}{0pt} +\setlength{\itemsep}{0pt} + +\begin{itemize} +\item {\tt utezu\_CreateTezLec91} +\item {\tt utezu\_CreateTez95} +\end{itemize} + +\bigskip +\begin{itemize} +\item {\tt ulec\_Createlfsr88} +\item {\tt ulec\_Createlfsr88T} +\item {\tt ulec\_Createlfsr113} +\item {\tt ulec\_Createlfsr258} +%\item {\tt ulec\_CreateCombTausLCG11} % Not a Tausworthe generator. +%\item {\tt ulec\_CreateCombTausLCG21} +\end{itemize} +} diff --git a/TESTU01/TestU01-1.2.3/testu01/utezuka.c b/TESTU01/TestU01-1.2.3/testu01/utezuka.c new file mode 100644 index 0000000..7fc85a6 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/utezuka.c @@ -0,0 +1,360 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: utezuka.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" + +#include "utezuka.h" +#include "unif01.h" + +#include +#include + + + + +/*============================== constants ==============================*/ + +#define LEN 250 /* Max length of strings */ + +#define DeuxExp28 268435456 +#define DeuxExp29 536870912 +#define DeuxExp31 2147483648U +#define DeuxExp32 4294967296.0 + +/* For the TezLec91 generator */ +#define Q1 13 +#define Q2 2 +#define S1 12 +#define S2 17 +#define K1mS1 19 +#define K2mS2 12 +#define K1mK2 2 +#define M1 2147483647 /* (2^31) - 1 */ +#define M2 536870911 /* (2^29) - 1 */ + + + + + +/*================================ Types ================================*/ + +typedef struct { + double Norm; +} Tezuka_param; + +typedef Tezuka_param TezLec91_param; +typedef Tezuka_param Tez95_param; +typedef Tezuka_param TezMRG95_param; + +typedef struct { + unsigned int X1, X2; +} TezLec91_state; + +typedef struct { + unsigned int X1, X2, X3; +} Tez95_state; + +typedef struct { + int j1, k1, j2, k2; + unsigned int X1[5], X2[7]; +} TezMRG95_state; + + + + +/*============================== Functions ==============================*/ + +static void WrTezLec91 (void *vsta) +{ + TezLec91_state *state = vsta; + printf (" s1 = %1u, s2 = %1u\n", state->X1, state->X2); +} + +static unsigned long TezLec91_Bits (void *junk, void *vsta) +{ + TezLec91_state *state = vsta; + unsigned int A, B; + + B = (M1 & (state->X1 ^ (state->X1 << Q1))) >> K1mS1; + A = state->X1 << S1; + state->X1 = M1 & (A ^ B); + + B = (M2 & (state->X2 ^ (state->X2 << Q2))) >> K2mS2; + A = state->X2 << S2; + state->X2 = M2 & (A ^ B); + + return (state->X1 ^ (state->X2 << K1mK2)) << 1; +} + +static double TezLec91_U01 (void *vpar, void *vsta) +{ + TezLec91_param *param = vpar; + return param->Norm * TezLec91_Bits (vpar, vsta); +} + + +unif01_Gen * utezuka_CreateTezLec91 (unsigned int Y1, unsigned int Y2) +{ + unif01_Gen *gen; + TezLec91_param *param; + TezLec91_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (Y1 < DeuxExp31, "utezuka_CreateTezLec91: Y1 >= 2^31"); + util_Assert (Y2 < DeuxExp29, "utezuka_CreateTezLec91: Y2 >= 2^29"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (TezLec91_param)); + state = util_Malloc (sizeof (TezLec91_state)); + + strncpy (name, "utezuka_CreateTezLec91:", (size_t) LEN); + addstr_Uint (name, " Y1 = ", Y1); + addstr_Uint (name, ", Y2 = ", Y2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->X1 = Y1; + state->X2 = Y2; + param->Norm = 1.0 / DeuxExp32; + + gen->GetBits = &TezLec91_Bits; + gen->GetU01 = &TezLec91_U01; + gen->Write = &WrTezLec91; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static void WrTez95 (void *vsta) +{ + Tez95_state *state = vsta; + printf (" s1 = %1u, s2 = %1u, s3 = %1u\n", + state->X1, state->X2, state->X3); +} + +static unsigned long Tez95_Bits (void *junk, void *vsta) +{ + Tez95_state *state = vsta; + unsigned int B; + + B = ((state->X1 << 9) ^ state->X1) << 4; + state->X1 = (state->X1 << 13) ^ (B >> 19); + + B = ((state->X2 << 2) ^ state->X2) << 3; + state->X2 = (state->X2 << 20) ^ (B >> 12); + + B = ((state->X3 << 6) ^ state->X3) << 1; + state->X3 = (state->X3 << 17) ^ (B >> 15); + + return state->X1 ^ state->X2 ^ state->X3; +} + +static double Tez95_U01 (void *vpar, void *vsta) +{ + Tez95_param *param = vpar; + return param->Norm * Tez95_Bits (vpar, vsta); +} + + +unif01_Gen *utezuka_CreateTez95 (unsigned int Y1, unsigned int Y2, + unsigned int Y3) +{ + unif01_Gen *gen; + Tez95_param *param; + Tez95_state *state; + size_t leng; + char name[LEN + 1]; + unsigned int B; + + util_Assert (Y1 < DeuxExp28, "utezuka_CreateTez95: Y1 >= 2^28"); + util_Assert (Y2 < DeuxExp29, "utezuka_CreateTez95: Y2 >= 2^29"); + util_Assert (Y3 < DeuxExp31, "utezuka_CreateTez95: Y3 >= 2^31"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Tez95_param)); + state = util_Malloc (sizeof (Tez95_state)); + + strncpy (name, "utezuka_CreateTez95:", (size_t) LEN); + addstr_Uint (name, " Y1 = ", Y1); + addstr_Uint (name, ", Y2 = ", Y2); + addstr_Uint (name, ", Y3 = ", Y3); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + B = ((Y1 << 9) ^ Y1) << 4; + state->X1 = (Y1 << 4) ^ (B >> 28); + + B = ((Y2 << 2) ^ Y2) << 3; + state->X2 = (Y2 << 3) ^ (B >> 29); + + B = ((Y3 << 6) ^ Y3) << 1; + state->X3 = (Y3 << 1) ^ (B >> 31); + + param->Norm = 1.0 / DeuxExp32; + + gen->GetBits = &Tez95_Bits; + gen->GetU01 = &Tez95_U01; + gen->Write = &WrTez95; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static void WrTezMRG95 (void *vsta) +{ + TezMRG95_state *state = vsta; + int k; + if (unif01_WrLongStateFlag) { + printf (" S1 = ("); + for (k = 0; k < 5; k++) + printf ("%12u ", state->X1[k]); + printf (" )\n\nS2 = ("); + for (k = 0; k < 7; k++) { + printf ("%12u ", state->X2[k]); + if (k == 4) + printf ("\n "); + } + printf (" )\n\n"); + } else + unif01_WrLongStateDef (); +} + +static unsigned long TezMRG95_Bits (void *junk, void *vsta) +{ + TezMRG95_state *state = vsta; + unsigned int *X1 = state->X1; + unsigned int *X2 = state->X2; + unsigned int b1, b2; + + b1 = ((X1[state->k1] << 3) ^ X1[state->k1]) << 1; + b2 = ((X1[state->j1] << 3) ^ X1[state->j1]) << 1; + state->X1[state->k1] = (X1[state->k1] << 23) ^ (b1 >> 9) ^ + (X1[state->j1] << 5) ^ (b2 >> 27); + + b1 = ((X2[state->k2] << 2) ^ X2[state->k2]) << 3; + b2 = ((X2[state->j2] << 2) ^ X2[state->j2]) << 3; + state->X2[state->k2] = (X2[state->k2] << 19) ^ (b1 >> 13) ^ + (X2[state->j2] << 16) ^ (b2 >> 16); + + --state->j1; + if (state->j1 < 0) + state->j1 = 4; + + --state->k1; + if (state->k1 < 0) + state->k1 = 4; + + --state->j2; + if (state->j2 < 0) + state->j2 = 6; + + --state->k2; + if (state->k2 < 0) + state->k2 = 6; + + return state->X1[state->k1] ^ state->X2[state->k2]; +} + +static double TezMRG95_U01 (void *vpar, void *vsta) +{ + TezMRG95_param *param = vpar; + return param->Norm * TezMRG95_Bits (vpar, vsta); +} + + +unif01_Gen *utezuka_CreateTezMRG95 (unsigned int Y1[5], unsigned int Y2[7]) +{ + unif01_Gen *gen; + TezMRG95_param *param; + TezMRG95_state *state; + size_t leng; + char name[LEN + 1]; + int k; + unsigned int b; + + for (k = 0; k < 5; k++) + util_Assert (Y1[k] < DeuxExp31, + "utezuka_CreateTezMRG95: Y1[k] >= 2^31"); + for (k = 0; k < 7; k++) + util_Assert (Y2[k] < DeuxExp29, + "utezuka_CreateTezMRG95: Y2[k] >= 2^29"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (TezMRG95_param)); + state = util_Malloc (sizeof (TezMRG95_state)); + + strncpy (name, "utezuka_CreateTezMRG95:", (size_t) LEN); + addstr_ArrayUint (name, " Y1 = ", 5, Y1); + addstr_ArrayUint (name, ", Y2 = ", 7, Y2); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + for (k = 0; k < 5; k++) { + b = ((Y1[k] << 3) ^ Y1[k]) << 1; + state->X1[k] = (Y1[k] << 1) ^ (b >> 31); + } + + for (k = 0; k < 7; k++) { + b = ((Y2[k] << 2) ^ Y2[k]) << 3; + state->X2[k] = (Y2[k] << 3) ^ (b >> 29); + } + state->j1 = 1; + state->k1 = 4; + state->j2 = 4; + state->k2 = 6; + + param->Norm = 1.0 / DeuxExp32; + + gen->GetBits = &TezMRG95_Bits; + gen->GetU01 = &TezMRG95_U01; + gen->Write = &WrTezMRG95; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +void utezuka_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/utezuka.tex b/TESTU01/TestU01-1.2.3/testu01/utezuka.tex new file mode 100644 index 0000000..ec19a42 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/utezuka.tex @@ -0,0 +1,67 @@ +\defmodule {utezuka} + +This module collects some generators designed by S.~Tezuka. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* utezuka.h for ANSI C */ + +#ifndef UTEZUKA_H +#define UTEZUKA_H +\endhide +#include "unif01.h" + + +unif01_Gen * utezuka_CreateTezLec91 (unsigned int Y1, unsigned int Y2); +\endcode + \tab Implements a combined Tausworthe generator constructed + by Tezuka and L'Ecuyer \cite{rTEZ91b}, and whose implementation + is given in their paper. +\index{Generator!Tezuka}% + The initial values {\tt Y1} and {\tt Y2} must be positive and + less than $2^{31}$ and $2^{29}$ respectively. + \endtab +\code + + +unif01_Gen * utezuka_CreateTez95 (unsigned int Y1, unsigned int Y2, + unsigned int Y3); +\endcode + \tab Implements the combined generator proposed in + Figure A.1 of \cite{rTEZ95a}, page 194. + The initial values {\tt Y1, Y2, Y3} must be positive and + less than $2^{28}$, $2^{29}$ and $2^{31}$ + respectively. + \endtab +\code + + +unif01_Gen * utezuka_CreateTezMRG95 (unsigned int Y1[5], + unsigned int Y2[7]); +\endcode + \tab Implements the combined generator proposed in + Figure A.2 of \cite{rTEZ95a}, page 195. + The initial values of the array elements of {\tt Y1} and {\tt Y2} + must be positive and + less than $2^{31}$ and $2^{29}$ respectively. + \endtab + + + +\guisec{Clean-up functions} + +\code + +void utezuka_DeleteGen (unif01_Gen *gen); +\endcode + \tab \DelGen + \endtab +\code + +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/utouzin.c b/TESTU01/TestU01-1.2.3/testu01/utouzin.c new file mode 100644 index 0000000..c6e1505 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/utouzin.c @@ -0,0 +1,1116 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: utouzin.c + * Environment: ANSI C + * Programmer: R. Touzin + * Adapted to TestU01 by R. Simard + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" +#include "utouzin.h" +#include "unif01.h" + +#include +#include + + +typedef struct { + unsigned long x1, x2, x3, x4, x5, x6, x7, x8; +} MRG00a_state; + +typedef MRG00a_state MRG00b_state; +typedef MRG00a_state MRG00c_state; +typedef MRG00a_state MRG00d_state; + + +typedef struct { + unsigned long x10, x11, x12, x20, x21, x22, x13, x23; +} MRG00e_state; + +typedef MRG00e_state MRG00f_state; +typedef MRG00e_state MRG00h_state; + +typedef struct { + unsigned long x10, x11, x12, x20, x21, x22, x30, x31, x32; +} MRG00g_state; + +#define LEN 200 + + + + +/*=========================================================================*/ + +#define MASK1a 127 /* 2^(31 - 24) - 1 */ +#define MASK3a 8191 /* 2^(31 - 18) - 1 */ +#define MASK4a 134217727 /* 2^(31 - 4) - 1 */ +#define MASK5a 1048575 /* 2^(31 - 11) - 1 */ +#define m1 2147483647 /* 2^31 - 1 */ +#define norm 4.656612875245797e-10 /* 1/m1 */ + +static double MRG00a_U01 (void *junk, void *vsta) +{ + MRG00a_state *state = vsta; + unsigned long Resultat; + + /* Coefficient 1 */ + Resultat = m1 - (((state->x1 & MASK1a) << 24) + (state->x1 >> 7)); + Resultat += state->x1; + if (Resultat >= m1) + Resultat -= m1; + Resultat += state->x1; + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 3 */ + Resultat += (m1 - (((state->x3 & MASK3a) << 18) + (state->x3 >> 13))); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 4 */ + Resultat += (m1 - (((state->x4 & MASK4a) << 4) + (state->x4 >> 27))); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 5 */ + Resultat += (((state->x5 & MASK5a) << 11) + (state->x5 >> 20)); + if (Resultat >= m1) + Resultat -= m1; + Resultat = Resultat + (m1 - state->x5); + if (Resultat >= m1) + Resultat -= m1; + + state->x5 = state->x4; + state->x4 = state->x3; + state->x3 = state->x2; + state->x2 = state->x1; + + state->x1 = Resultat; + return (norm * state->x1); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00a_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00a_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00a (void *vsta) +{ + MRG00a_state *state = vsta; + printf + (" x1 = %10lu, x2 = %10lu, x3 = %10lu,\n x4 = %10lu, x5 = %10lu\n\n", + state->x1, state->x2, state->x3, state->x4, state->x5); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00a (long s1, long s2, long s3, long s4, + long s5) +{ + unif01_Gen *gen; + MRG00a_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00a_state)); + + strncpy (name, "utouzin_CreateMRG00a:", LEN); + addstr_Long (name, " s1 = ", s1); + addstr_Long (name, ", s2 = ", s2); + addstr_Long (name, ", s3 = ", s3); + addstr_Long (name, ", s4 = ", s4); + addstr_Long (name, ", s5 = ", s5); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x1 = s1 % m1; + state->x2 = s2 % m1; + state->x3 = s3 % m1; + state->x4 = s4 % m1; + state->x5 = s5 % m1; + + gen->GetBits = &MRG00a_Bits; + gen->GetU01 = &MRG00a_U01; + gen->Write = &WrMRG00a; + gen->param = NULL; + gen->state = state; + return gen; +} + +#undef MASK1a +#undef MASK3a +#undef MASK4a +#undef MASK5a +#undef m1 +#undef norm + + +/*=========================================================================*/ + +#define MASK1a 1023 /* 2^(31 - 21) -1 */ +#define MASK2a 524287 /* 2^(31 - 12) -1 */ +#define MASK3a 32767 /* 2^(31 - 16) -1 */ +#define MASK5a 16777215 /* 2^(31 - 7) -1 */ +#define MASK6a 15 /* 2^(31 - 27) -1 */ +#define m1 2147483647 /* 2^31 -1 */ +#define norm 4.656612875245797e-10 /* 1/m1 */ + +static double MRG00b_U01 (void *junk, void *vsta) +{ + MRG00b_state *state = vsta; + unsigned long Resultat; + + /* Coefficient 1 */ + Resultat = m1 - (((state->x1 & MASK1a) << 21) + (state->x1 >> 10)); + Resultat += (m1 - state->x1); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 2 */ + Resultat += (m1 - (((state->x2 & MASK2a) << 12) + (state->x2 >> 19))); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 3 */ + Resultat += (((state->x3 & MASK3a) << 16) + (state->x3 >> 15)); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 5 */ + Resultat += (((state->x5 & MASK5a) << 7) + (state->x5 >> 24)); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 6 */ + Resultat += (m1 - (((state->x6 & MASK6a) << 27) + (state->x6 >> 4))); + if (Resultat >= m1) + Resultat -= m1; + Resultat += state->x6; + if (Resultat >= m1) + Resultat -= m1; + + state->x6 = state->x5; + state->x5 = state->x4; + state->x4 = state->x3; + state->x3 = state->x2; + state->x2 = state->x1; + + state->x1 = Resultat; + return (norm * state->x1); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00b_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00b_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00b (void *vsta) +{ + MRG00b_state *state = vsta; + printf + (" x1 = %10lu, x2 = %10lu, x3 = %10lu,\n x4 = %10lu, x5 = %10lu, x6 = %10lu\n\n", + state->x1, state->x2, state->x3, state->x4, state->x5, state->x6); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00b (long s1, long s2, long s3, + long s4, long s5, long s6) +{ + unif01_Gen *gen; + MRG00b_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00b_state)); + + strncpy (name, "utouzin_CreateMRG00b:", LEN); + addstr_Long (name, " s1 = ", s1); + addstr_Long (name, ", s2 = ", s2); + addstr_Long (name, ", s3 = ", s3); + addstr_Long (name, ", s4 = ", s4); + addstr_Long (name, ", s5 = ", s5); + addstr_Long (name, ", s6 = ", s6); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x1 = s1 % m1; + state->x2 = s2 % m1; + state->x3 = s3 % m1; + state->x4 = s4 % m1; + state->x5 = s5 % m1; + state->x6 = s6 % m1; + + gen->GetBits = &MRG00b_Bits; + gen->GetU01 = &MRG00b_U01; + gen->Write = &WrMRG00b; + gen->param = NULL; + gen->state = state; + return gen; +} + +#undef MASK1a +#undef MASK2a +#undef MASK3a +#undef MASK5a +#undef MASK6a +#undef m1 +#undef norm + + +/*=========================================================================*/ + +#define MASK1a 524287 /* 2^(31 - 12) -1 */ +#define MASK2a 2047 /* 2^(31 - 20) -1 */ +#define MASK3a 131071 /* 2^(31 - 14) -1 */ +#define MASK5a 63 /* 2^(31 - 25) -1 */ +#define MASK6a 33554431 /* 2^(31 - 6) -1 */ +#define MASK7a 134217727 /* 2^(31-4)-1 */ +#define m1 2147483629 /* 2^31 -19 */ +#define norm 4.656612914277075e-10 /* 1/m1 */ + +static double MRG00c_U01 (void *junk, void *vsta) +{ + MRG00c_state *state = vsta; + unsigned long Resultat1, Resultat2; + + /* Coefficient 1 */ + Resultat1 = (((state->x1 & MASK1a) << 12) + 19 * (state->x1 >> 19)); + if (Resultat1 >= m1) + Resultat1 = m1 - (Resultat1 - m1); + else + Resultat1 = m1 - Resultat1; + + /* Coefficient 2 */ + Resultat2 = (((state->x2 & MASK2a) << 20) + 19 * (state->x2 >> 11)); + if (Resultat2 >= m1) + Resultat2 = m1 - (Resultat2 - m1); + else + Resultat2 = m1 - Resultat2; + + Resultat2 += Resultat1; + if (Resultat2 >= m1) + Resultat2 -= m1; + + /* Coefficient 3 */ + Resultat1 = (((state->x3 & MASK3a) << 14) + 19 * (state->x3 >> 17)); + if (Resultat1 >= m1) + Resultat1 -= m1; + + Resultat2 += Resultat1; + if (Resultat2 >= m1) + Resultat2 -= m1; + + /* Coefficient 5 */ + Resultat1 = (((state->x5 & MASK5a) << 25) + 19 * (state->x5 >> 6)); + if (Resultat1 >= m1) + Resultat1 -= m1; + + Resultat2 += Resultat1; + if (Resultat2 >= m1) + Resultat2 -= m1; + + /* Coefficient 6 */ + Resultat1 = (((state->x6 & MASK6a) << 6) + 19 * (state->x6 >> 25)); + if (Resultat1 >= m1) + Resultat1 = m1 - (Resultat1 - m1); + else + Resultat1 = m1 - Resultat1; + + Resultat2 += Resultat1; + if (Resultat2 >= m1) + Resultat2 -= m1; + + /* Coefficient 7 */ + Resultat1 = (((state->x7 & MASK7a) << 4) + 19 * (state->x7 >> 27)); + if (Resultat1 >= m1) + Resultat1 -= m1; + Resultat1 += state->x7; + if (Resultat1 >= m1) + Resultat1 -= m1; + + Resultat2 += Resultat1; + if (Resultat2 >= m1) + Resultat2 -= m1; + + state->x7 = state->x6; + state->x6 = state->x5; + state->x5 = state->x4; + state->x4 = state->x3; + state->x3 = state->x2; + state->x2 = state->x1; + + state->x1 = Resultat2; + return (norm * state->x1); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00c_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00c_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00c (void *vsta) +{ + MRG00c_state *state = vsta; + printf + (" x1 = %10lu, x2 = %10lu, x3 = %10lu, x4 = %10lu,\n x5 = %10lu, x6 = %10lu, x7 = %10lu\n\n", + state->x1, state->x2, state->x3, state->x4, state->x5, + state->x6, state->x7); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00c (long s1, long s2, long s3, + long s4, long s5, long s6, long s7) +{ + unif01_Gen *gen; + MRG00c_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00c_state)); + + strncpy (name, "utouzin_CreateMRG00c:", LEN); + addstr_Long (name, " s1 = ", s1); + addstr_Long (name, ", s2 = ", s2); + addstr_Long (name, ", s3 = ", s3); + addstr_Long (name, ", s4 = ", s4); + addstr_Long (name, ", s5 = ", s5); + addstr_Long (name, ", s6 = ", s6); + addstr_Long (name, ", s7 = ", s7); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x1 = s1 % m1; + state->x2 = s2 % m1; + state->x3 = s3 % m1; + state->x4 = s4 % m1; + state->x5 = s5 % m1; + state->x6 = s6 % m1; + state->x7 = s7 % m1; + + gen->GetBits = &MRG00c_Bits; + gen->GetU01 = &MRG00c_U01; + gen->Write = &WrMRG00c; + gen->param = NULL; + gen->state = state; + return gen; +} + +#undef MASK1a +#undef MASK2a +#undef MASK3a +#undef MASK5a +#undef MASK6a +#undef MASK7a +#undef m1 +#undef norm + + +/*=========================================================================*/ + +#define MASK1a 134217727 /* 2^(31 - 4) -1 */ +#define MASK3a 65535 /* 2^(31 - 15) -1 */ +#define MASK4a 524287 /* 2^(31 - 12) -1 */ +#define MASK5a 511 /* 2^(31 - 22) -1 */ +#define MASK6a 4194303 /* 2^(31 - 9) -1 */ +#define MASK7a 15 /* 2^(31 - 27) -1 */ +#define MASK8a 8191 /* 2^(31 - 18) -1 */ +#define MASK8b 1073741823 /* 2^(31 - 1) -1 */ +#define m1 2147483647 /* 2^31 -1 */ +#define norm 4.656612875245797e-10 /* 1/m1 */ + +static double MRG00d_U01 (void *junk, void *vsta) +{ + MRG00d_state *state = vsta; + unsigned long Resultat; + + /* Coefficient 1 */ + Resultat = m1 - (((state->x1 & MASK1a) << 4) + (state->x1 >> 27)); + + /* Coefficient 3 */ + Resultat += (((state->x3 & MASK3a) << 15) + (state->x3 >> 16)); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 4 */ + Resultat += (m1 - (((state->x4 & MASK4a) << 12) + (state->x4 >> 19))); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 5 */ + Resultat += (((state->x5 & MASK5a) << 22) + (state->x5 >> 9)); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 6 */ + Resultat += (((state->x6 & MASK6a) << 9) + (state->x6 >> 22)); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 7 */ + Resultat += (((state->x7 & MASK7a) << 27) + (state->x7 >> 4)); + if (Resultat >= m1) + Resultat -= m1; + + /* Coefficient 8 */ + Resultat += (((state->x8 & MASK8a) << 18) + (state->x8 >> 13)); + if (Resultat >= m1) + Resultat -= m1; + + Resultat += (m1 - state->x8); + if (Resultat >= m1) + Resultat -= m1; + Resultat += (m1 - state->x8); + if (Resultat >= m1) + Resultat -= m1; + + state->x8 = state->x7; + state->x7 = state->x6; + state->x6 = state->x5; + state->x5 = state->x4; + state->x4 = state->x3; + state->x3 = state->x2; + state->x2 = state->x1; + state->x1 = Resultat; + return (norm * state->x1); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00d_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00d_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00d (void *vsta) +{ + MRG00d_state *state = vsta; + printf + (" x1 = %10lu, x2 = %10lu, x3 = %10lu, x4 = %10lu,\n x5 = %10lu, x6 = %10lu, x7 = %10lu, x8 = %10lu\n\n", + state->x1, state->x2, state->x3, state->x4, state->x5, + state->x6, state->x7, state->x8); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00d (long s1, long s2, long s3, + long s4, long s5, long s6, long s7, long s8) +{ + unif01_Gen *gen; + MRG00d_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00d_state)); + + strncpy (name, "utouzin_CreateMRG00d:", LEN); + addstr_Long (name, " s1 = ", s1); + addstr_Long (name, ", s2 = ", s2); + addstr_Long (name, ", s3 = ", s3); + addstr_Long (name, ", s4 = ", s4); + addstr_Long (name, ", s5 = ", s5); + addstr_Long (name, ", s6 = ", s6); + addstr_Long (name, ", s7 = ", s7); + addstr_Long (name, ", s8 = ", s8); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x1 = s1 % m1; + state->x2 = s2 % m1; + state->x3 = s3 % m1; + state->x4 = s4 % m1; + state->x5 = s5 % m1; + state->x6 = s6 % m1; + state->x7 = s7 % m1; + state->x8 = s8 % m1; + + gen->GetBits = &MRG00d_Bits; + gen->GetU01 = &MRG00d_U01; + gen->Write = &WrMRG00d; + gen->param = NULL; + gen->state = state; + return gen; +} + +#undef MASK1a +#undef MASK3a +#undef MASK4a +#undef MASK5a +#undef MASK6a +#undef MASK7a +#undef MASK8a +#undef MASK8b +#undef m1 +#undef norm + + +/*=========================================================================*/ + +#define MASK11 511 /* 2^(31-22) - 1 */ +#define MASK12 16777215 /* 2^(31-7) - 1 */ +#define MASK20 65535 /* 2^(31-15) - 1 */ +#define MASK22 65535 /* 2^(31-15) - 1 */ +#define m1 2147483647 /* 2^31 -1 */ +#define m2 2147462579 /* 2^31 - 21069 */ +#define norm 4.656612873077393e-10 /* 1/(m1 + 1) */ + +static double MRG00e_U01 (void *junk, void *vsta) +{ + MRG00e_state *state = vsta; + unsigned long Resultat1; + unsigned long Resultat2; + + /* Component 1 x10 = ((2^22)* x11 + (2^7 + 1)*x12) mod 2^31 -1 */ + Resultat1 = (((state->x11 & MASK11) << 22) + (state->x11 >> 9)) + + (((state->x12 & MASK12) << 7) + (state->x12 >> 24)); + if (Resultat1 >= m1) + Resultat1 -= m1; + Resultat1 += state->x12; + if (Resultat1 >= m1) + Resultat1 -= m1; + state->x12 = state->x11; + state->x11 = state->x10; + state->x10 = Resultat1; + + /* Component 2 x20 = ((2^15)* x20 + (2^15+1) * x22) mod (2^31 - 21069) */ + Resultat1 = ((state->x20 & MASK20) << 15) + 21069 * (state->x20 >> 16); + if (Resultat1 >= m2) + Resultat1 -= m2; + Resultat2 = ((state->x22 & MASK22) << 15) + 21069 * (state->x22 >> 16); + if (Resultat2 >= m2) + Resultat2 -= m2; + Resultat1 += Resultat2; + if (Resultat1 >= m2) + Resultat1 -= m2; + Resultat1 += state->x22; + if (Resultat1 >= m2) + Resultat1 -= m2; + state->x22 = state->x21; + state->x21 = state->x20; + state->x20 = Resultat1; + + /* Combinaison */ + if (state->x10 <= state->x20) + return ((state->x10 - state->x20 + m1) * norm); + else + return ((state->x10 - state->x20) * norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00e_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00e_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00e (void *vsta) +{ + MRG00e_state *state = vsta; + printf + (" x10 = %10lu, x11 = %10lu, x12 = %10lu,\n x20 = %10lu, x21 = %10lu, x22 = %10lu \n\n", + state->x10, state->x11, state->x12, state->x20, state->x21, state->x22); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00e (long s10, long s11, long s12, + long s20, long s21, long s22) +{ + unif01_Gen *gen; + MRG00e_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00e_state)); + + strncpy (name, "utouzin_CreateMRG00e:", LEN); + addstr_Long (name, " s10 = ", s10); + addstr_Long (name, ", s11 = ", s11); + addstr_Long (name, ", s12 = ", s12); + addstr_Long (name, ", s20 = ", s20); + addstr_Long (name, ", s21 = ", s21); + addstr_Long (name, ", s22 = ", s22); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x10 = s10; + state->x11 = s11; + state->x12 = s12; + state->x20 = s20; + state->x21 = s21; + state->x22 = s22; + + gen->GetBits = &MRG00e_Bits; + gen->GetU01 = &MRG00e_U01; + gen->Write = &WrMRG00e; + gen->param = NULL; + gen->state = state; + return gen; +} + +#undef MASK11 +#undef MASK12 +#undef MASK20 +#undef MASK22 +#undef m1 +#undef m2 +#undef norm + + +/*=========================================================================*/ + +#define MASK11 131071 /* 2^(31-14) - 1 */ +#define MASK12 31 /* 2^(31-26) - 1 */ +#define MASK20 16383 /* 2^(31-17) - 1 */ +#define MASK22 1048575 /* 2^(31-11) - 1 */ +#define m1 2147483647 /* 2^31 -1 */ +#define m2 2147483629 /* 2^31 - 21069 */ +#define norm 4.656612873077393e-10 /* 1/(m1 + 1) */ + +static double MRG00f_U01 (void *junk, void *vsta) +{ + MRG00f_state *state = vsta; + unsigned long Resultat1; + unsigned long Resultat2; + + /* Component 1 x10 = ((2^14)* x11 + (-2^26 + 1)*x12) mod 2^31 -1 */ + Resultat1 = (((state->x11 & MASK11) << 14) + (state->x11 >> 17)) + + (m1 - (((state->x12 & MASK12) << 26) + (state->x12 >> 5))); + if (Resultat1 >= m1) + Resultat1 -= m1; + Resultat1 += state->x12; + if (Resultat1 >= m1) + Resultat1 -= m1; + state->x12 = state->x11; + state->x11 = state->x10; + state->x10 = Resultat1; + + /* Component 2 x20 = ((2^17)* x20 + (2^11) * x22) mod (2^31 - 19) */ + Resultat1 = ((state->x20 & MASK20) << 17) + (19 * (state->x20 >> 14)); + if (Resultat1 >= m2) + Resultat1 -= m2; + Resultat2 = ((state->x22 & MASK22) << 11) + (19 * (state->x22 >> 20)); + if (Resultat2 >= m2) + Resultat2 -= m2; + Resultat1 += Resultat2; + if (Resultat1 >= m2) + Resultat1 -= m2; + + state->x22 = state->x21; + state->x21 = state->x20; + state->x20 = Resultat1; + + /* Combinaison */ + if (state->x10 <= state->x20) + return ((state->x10 - state->x20 + m1) * norm); + else + return ((state->x10 - state->x20) * norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00f_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00f_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00f (void *vsta) +{ + MRG00f_state *state = vsta; + printf + (" x10 = %10lu, x11 = %10lu, x12 = %10lu,\n x20 = %10lu, x21 = %10lu, x22 = %10lu \n\n", + state->x10, state->x11, state->x12, state->x20, state->x21, state->x22); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00f (long s10, long s11, long s12, + long s20, long s21, long s22) +{ + unif01_Gen *gen; + MRG00f_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00f_state)); + + strncpy (name, "utouzin_CreateMRG00f:", LEN); + addstr_Long (name, " s10 = ", s10); + addstr_Long (name, ", s11 = ", s11); + addstr_Long (name, ", s12 = ", s12); + addstr_Long (name, ", s20 = ", s20); + addstr_Long (name, ", s21 = ", s21); + addstr_Long (name, ", s22 = ", s22); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x10 = s10; + state->x11 = s11; + state->x12 = s12; + state->x20 = s20; + state->x21 = s21; + state->x22 = s22; + + gen->GetBits = &MRG00f_Bits; + gen->GetU01 = &MRG00f_U01; + gen->Write = &WrMRG00f; + gen->param = NULL; + gen->state = state; + return gen; +} + +#undef MASK11 +#undef MASK12 +#undef MASK20 +#undef MASK22 +#undef m1 +#undef m2 +#undef norm + + +/*=========================================================================*/ + +#define MASK10 1 /* 2^(31-30) - 1 */ +#define MASK12 4095 /* 2^(31-19) - 1 */ +#define MASK21 255 /* 2^(31-23) - 1 */ +#define MASK22 4095 /* 2^(31-19) - 1 */ +#define MASK30 1048575 /* 2^(31-11) - 1 */ +#define MASK31 4194303 /* 2^(31-9 ) - 1 */ +#define m1 2147483647 /* 2^31 -1 */ +#define m2 2147483629 /* 2^31 -19 */ +#define m3 2147483587 /* 2^31 -61 */ +#define norm 4.656612873077393e-10 /* 1/(m1 + 1) */ + +static double MRG00g_U01 (void *junk, void *vsta) +{ + MRG00g_state *state = vsta; + unsigned long Resultat1; + unsigned long Resultat2; + + /* Component 1 x10 = ((2^14)* x11 + (-2^26 + 1)*x12) mod 2^31 -1 */ + Resultat1 = (((state->x10 & MASK10) << 30) + (state->x10 >> 1)) + + (((state->x12 & MASK12) << 19) + (state->x12 >> 12)); + if (Resultat1 >= m1) + Resultat1 -= m1; + Resultat1 += (m1 - state->x12); + if (Resultat1 >= m1) + Resultat1 -= m1; + state->x12 = state->x11; + state->x11 = state->x10; + state->x10 = Resultat1; + + /* Component 2 x20 = ((2^17)* x20 + (2^11) * x22) mod (2^31 - 19) */ + Resultat1 = ((state->x21 & MASK21) << 23) + (19 * (state->x21 >> 8)); + if (Resultat1 >= m2) + Resultat1 -= m2; + Resultat2 = ((state->x22 & MASK22) << 19) + (19 * (state->x22 >> 12)); + if (Resultat2 >= m2) + Resultat2 -= m2; + Resultat1 += Resultat2; + if (Resultat1 >= m2) + Resultat1 -= m2; + state->x22 = state->x21; + state->x21 = state->x20; + state->x20 = Resultat1; + + /* Component 3 x20 = ((2^17)* x20 + (2^11) * x22) mod (2^31 - 19) */ + Resultat1 = ((state->x30 & MASK30) << 11) + (61 * (state->x30 >> 20)); + if (Resultat1 >= m3) + Resultat1 -= m3; + Resultat2 = ((state->x31 & MASK31) << 9) + (61 * (state->x31 >> 22)); + if (Resultat2 >= m3) + Resultat2 -= m3; + Resultat1 += Resultat2; + if (Resultat1 >= m3) + Resultat1 -= m3; + Resultat1 += state->x32; + if (Resultat1 >= m3) + Resultat1 -= m3; + Resultat1 += state->x32; + if (Resultat1 >= m3) + Resultat1 -= m3; + state->x32 = state->x31; + state->x31 = state->x30; + state->x30 = Resultat1; + + /* Combinaison */ + if (state->x10 + state->x30 <= state->x20) + return ((state->x10 - state->x20 + state->x30 + m1) * norm); + else if (state->x10 - state->x20 + state->x30 > m1) + return ((state->x10 - state->x20 + state->x30 - m1) * norm); + else + return ((state->x10 - state->x20 + state->x30) * norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00g_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00g_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00g (void *vsta) +{ + MRG00g_state *state = vsta; + printf + (" x10 = %10lu, x11 = %10lu, x12 = %10lu,\n x20 = %10lu, x21 = %10lu, x22 = %10lu,\n x30 = %10lu, x31 = %10lu, x32 = %10lu\n\n", + state->x10, state->x11, state->x12, state->x20, state->x21, state->x22, + state->x30, state->x31, state->x32); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00g (long s10, long s11, long s12, + long s20, long s21, long s22, + long s30, long s31, long s32) +{ + unif01_Gen *gen; + MRG00g_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00g_state)); + + strncpy (name, "utouzin_CreateMRG00g:", LEN); + addstr_Long (name, " s10 = ", s10); + addstr_Long (name, ", s11 = ", s11); + addstr_Long (name, ", s12 = ", s12); + addstr_Long (name, ", s20 = ", s20); + addstr_Long (name, ", s21 = ", s21); + addstr_Long (name, ", s22 = ", s22); + addstr_Long (name, ", s30 = ", s30); + addstr_Long (name, ", s31 = ", s31); + addstr_Long (name, ", s32 = ", s32); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x10 = s10; + state->x11 = s11; + state->x12 = s12; + state->x20 = s20; + state->x21 = s21; + state->x22 = s22; + state->x30 = s30; + state->x31 = s31; + state->x32 = s32; + + gen->GetBits = &MRG00g_Bits; + gen->GetU01 = &MRG00g_U01; + gen->Write = &WrMRG00g; + gen->param = NULL; + gen->state = state; + return gen; +} + +#undef MASK10 +#undef MASK12 +#undef MASK21 +#undef MASK22 +#undef MASK30 +#undef MASK31 +#undef m1 +#undef m2 +#undef m3 +#undef norm + + +/*=========================================================================*/ + +#define MASK11 262143 /* 2^(31-13) - 1 */ +#define MASK13 255 /* 2^(31-23) - 1 */ +#define MASK20 2097151 /* 2^(31-10) - 1 */ +#define MASK22 2047 /* 2^(31-20) - 1 */ +#define MASK23 16777215 /* 2^(31 -7) - 1 */ +#define m1 2147483647 /* 2^31 -1 */ +#define m2 2147483629 /* 2^31 - 21069 */ +#define norm 4.656612873077393e-10 /* 1/(m1 + 1) */ + +static double MRG00h_U01 (void *junk, void *vsta) +{ + MRG00h_state *state = vsta; + unsigned long Resultat1; + unsigned long Resultat2; + + /* Component 1 x10 = ((2^14)* x11 + (-2^26 + 1)*x12) mod 2^31 -1 */ + Resultat1 = (m1 - state->x10) + (m1 - (((state->x11 & MASK11) << 13) + + (state->x11 >> 18))); + if (Resultat1 >= m1) + Resultat1 -= m1; + Resultat1 += ((state->x13 & MASK13) << 23) + (state->x13 >> 8); + if (Resultat1 >= m1) + Resultat1 -= m1; + Resultat1 += state->x13; + if (Resultat1 >= m1) + Resultat1 -= m1; + + state->x13 = state->x12; + state->x12 = state->x11; + state->x11 = state->x10; + state->x10 = Resultat1; + + /* Component 2 x20 = ((2^17)* x20 + (2^11) * x22) mod (2^31 - 19) */ + Resultat1 = ((state->x20 & MASK20) << 10) + (19 * (state->x20 >> 21)); + if (Resultat1 >= m2) + Resultat1 -= m2; + + Resultat2 = (((state->x22 & MASK22) << 20) + (19 * (state->x22 >> 11))); + if (Resultat2 >= m2) + Resultat2 = m2 - (Resultat2 - m2); + else + Resultat2 = m2 - Resultat2; + if (Resultat2 >= m2) + Resultat2 -= m2; + + Resultat1 += Resultat2; + if (Resultat1 >= m2) + Resultat1 -= m2; + Resultat2 = ((state->x23 & MASK23) << 7) + (19 * (state->x23 >> 24)); + if (Resultat2 >= m2) + Resultat2 -= m2; + Resultat1 += Resultat2; + if (Resultat1 >= m2) + Resultat1 -= m2; + + state->x23 = state->x22; + state->x22 = state->x21; + state->x21 = state->x20; + state->x20 = Resultat1; + + /* Combinaison */ + if (state->x10 <= state->x20) + return ((state->x10 - state->x20 + m1) * norm); + else + return ((state->x10 - state->x20) * norm); +} + +/*-------------------------------------------------------------------------*/ + +static unsigned long MRG00h_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * MRG00h_U01 (vpar, vsta)); +} + +/*-------------------------------------------------------------------------*/ + +static void WrMRG00h (void *vsta) +{ + MRG00h_state *state = vsta; + printf + (" x10 = %10lu, x11 = %10lu, x12 = %10lu, x13 = %10lu,\n x20 = %10lu, x21 = %10lu, x22 = %10lu, x23 = %10lu\n\n", + state->x10, state->x11, state->x12, state->x13, + state->x20, state->x21, state->x22, state->x23); +} + +/*-------------------------------------------------------------------------*/ + +unif01_Gen * utouzin_CreateMRG00h (long s10, long s11, long s12, + long s13, long s20, long s21, long s22, long s23) +{ + unif01_Gen *gen; + MRG00h_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (MRG00h_state)); + + strncpy (name, "utouzin_CreateMRG00h:", LEN); + addstr_Long (name, " s10 = ", s10); + addstr_Long (name, ", s11 = ", s11); + addstr_Long (name, ", s12 = ", s12); + addstr_Long (name, ", s13 = ", s13); + addstr_Long (name, ", s20 = ", s20); + addstr_Long (name, ", s21 = ", s21); + addstr_Long (name, ", s22 = ", s22); + addstr_Long (name, ", s23 = ", s23); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->x10 = s10; + state->x11 = s11; + state->x12 = s12; + state->x13 = s13; + state->x20 = s20; + state->x21 = s21; + state->x22 = s22; + state->x23 = s23; + gen->GetBits = &MRG00h_Bits; + gen->GetU01 = &MRG00h_U01; + gen->Write = &WrMRG00h; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*=========================================================================*/ + +void utouzin_DeleteGen (unif01_Gen * gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/utouzin.tex b/TESTU01/TestU01-1.2.3/testu01/utouzin.tex new file mode 100644 index 0000000..7fc6b09 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/utouzin.tex @@ -0,0 +1,157 @@ +\defmodule {utouzin} + +This module is an interface to random number generators proposed by +P. L'Ecuyer and R. Touzin \cite{rTOU01a}. +They are multiple recursive generators (MRG) or combinations of MRG's +with coefficients of the form $\pm2^p \pm 2^q$ +(see the description of MRG's in module {\tt umrg}). + + +\bigskip\hrule +\code\hide +/* utouzin.h for ANSI C */ +#ifndef UTOUZIN_H +#define UTOUZIN_H +\endhide +#include "unif01.h" + + +unif01_Gen * utouzin_CreateMRG00a (long s1, long s2, long s3, long s4, + long s5); +\endcode + \tab Creates a MRG of order 5 of the form\index{Generator!Touzin} +$$ +x_n = \left((2 -2^{24})x_{n-1} - 2^{18}x_{n-3} - 2^{4}x_{n-4} + + (2^{11} - 1)x_{n-5}\right) \mod m +$$ +where $ m = 2^{31} - 1$ and $u_n = x_n/m$. The parameters $s$ are the seeds. + \endtab +\code + + +unif01_Gen * utouzin_CreateMRG00b (long s1, long s2, long s3, long s4, + long s5, long s6); +\endcode + \tab Creates a MRG of order 6 of the form +$$ +x_n = \left((-2^{21} - 1)x_{n-1} - 2^{12}x_{n-2} + 2^{16}x_{n-3} + + 2^{7}x_{n-5} + (1 - 2^{27})x_{n-6}\right) \mod m +$$ +where $ m = 2^{31} - 1$ and $u_n = x_n/m$. The parameters $s$ are the seeds. + \endtab +\code + + +unif01_Gen * utouzin_CreateMRG00c (long s1, long s2, long s3, long s4, + long s5, long s6, long s7); +\endcode + \tab Creates a MRG of order 7 of the form +$$ +x_n = \left(-2^{12}x_{n-1} - 2^{20}x_{n-2} + 2^{14}x_{n-3} + + 2^{25}x_{n-5} - 2^{6}x_{n-6} + (2^4 + 1)x_{n-7}\right) \mod m +$$ +where $ m = 2^{31} - 19$ and $u_n = x_n/m$. The parameters $s$ are the seeds. + \endtab +\code + + +unif01_Gen * utouzin_CreateMRG00d (long s1, long s2, long s3, long s4, + long s5, long s6, long s7, long s8); + +\endcode + \tab Creates a MRG of order 8 of the form +$$ +x_n = \left(-2^{4}x_{n-1} + 2^{15}x_{n-3} - 2^{12}x_{n-4} + 2^{22}x_{n-5} + + 2^{9}x_{n-6} + 2^{27}x_{n-7} + (2^{18} - 2)x_{n-8}\right) \mod m +$$ +where $ m = 2^{31} - 1$ and $u_n = x_n/m$. The parameters $s$ are the seeds. + \endtab +\code + + +unif01_Gen * utouzin_CreateMRG00e (long s10, long s11, long s12, + long s20, long s21, long s22); + +\endcode + \tab Creates a combined MRG with two components of order 3 of the form +\begin{eqnarray*} +x_n &=& \left(2^{22}x_{n-2} + (2^{7} + 1)x_{n-3}\right) \mod m_1 \\ +y_n &=& \left(2^{15}y_{n-1} + (2^{15} + 1)y_{n-3}\right) \mod m_2 +\end{eqnarray*} +where $m_1 = 2^{31} - 1$, $m_2 = 2^{31} - 21069$, and $u_n = + \left((x_n - y_n)\mod m_1 \right)/(m_1+1)$ with the exception of the value +0 which is replaced by $u_n = m_1 /(m_1+1)$. Thus the generator cannot return +the values 0 or 1. + The parameters $s$ are the seeds. + \endtab +\code + + +unif01_Gen * utouzin_CreateMRG00f (long s10, long s11, long s12, + long s20, long s21, long s22); +\endcode + \tab Creates a combined MRG with two components of order 3 of the form +\begin{eqnarray*} +x_n &=& \left(2^{14}x_{n-2} + (-2^{26} + 1)x_{n-3}\right) \mod m_1 \\ +y_n &=& \left(2^{17}y_{n-1} + 2^{11}y_{n-3}\right) \mod m_2 +\end{eqnarray*} +where $m_1 = 2^{31} - 1$, $m_2 = 2^{31} - 19$, and $u_n = + \left((x_n - y_n)\mod m_1 \right)/(m_1+1)$ with the exception of the value +0 which is replaced by $u_n = m_1 /(m_1+1)$. Thus the generator cannot return +the values 0 or 1. + The parameters $s$ are the seeds. + \endtab +\code + + +unif01_Gen * utouzin_CreateMRG00g (long s10, long s11, long s12, + long s20, long s21, long s22, + long s30, long s31, long s32); +\endcode + \tab Creates a combined MRG with three components of order 3 of the form +\begin{eqnarray*} +x_n &=& \left(2^{30} x_{n-1} + (2^{19} - 1) x_{n-3}\right) \mod m_1 \\ +y_n &=& \left(2^{23} y_{n-2} + 2^{19} y_{n-3}\right) \mod m_2 \\ +z_n &=& \left(2^{11} z_{n-1} + 2^{9} z_{n-2} + 2 z_{n-3}\right) \mod m_3 +\end{eqnarray*} +where $m_1 = 2^{31} - 1$, $m_2 = 2^{31} - 19$, $m_3 = 2^{31} - 61$ + and $u_n = \left((x_n - y_n + z_n)\mod m_1 \right)/(m_1+1)$ with the + exception of the value 0 which is replaced by $u_n = m_1 /(m_1+1)$. +Thus the generator cannot return the values 0 or 1. + The parameters $s$ are the seeds. + \endtab +\code + + +unif01_Gen * utouzin_CreateMRG00h (long s10, long s11, long s12, long s13, + long s20, long s21, long s22, long s23); +\endcode + \tab Creates a combined MRG with two components of order 4 of the form +\begin{eqnarray*} +x_n &=& \left(-x_{n-1} - 2^{13}x_{n-2} + (2^{23} + 1)x_{n-4}\right) \mod m_1 \\ +y_n &=& \left(2^{10}y_{n-1} - 2^{20}y_{n-3} + 2^{7}y_{n-4}\right) \mod m_2 +\end{eqnarray*} +where $m_1 = 2^{31} - 1$, $m_2 = 2^{31} - 19$, and $u_n = + \left((x_n - y_n)\mod m_1 \right)/(m_1+1)$ with the exception of the value +0 which is replaced by $u_n = m_1 /(m_1+1)$. Thus the generator cannot return +the values 0 or 1.\index{Generator!Touzin}% + The parameters $s$ are the seeds. + \endtab + + +\guisec{Clean-up functions} + +\code + + +void utouzin_DeleteGen (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module. +% that does not have an explicit {\tt Delete} function. + This function should be called when a generator + is no longer in use. + \endtab +\code\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/uvaria.c b/TESTU01/TestU01-1.2.3/testu01/uvaria.c new file mode 100644 index 0000000..e068b39 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uvaria.c @@ -0,0 +1,635 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uvaria.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "num.h" +#include "addstr.h" + +#include "uvaria.h" +#include "unif01.h" + +#include +#include +#include +#include + + + + +static int co = 0; /* Counter for Ranrot */ + + + + +/*============================= Constants =================================*/ + +#define INV31 4.656612875245796E-10 /* 1 / (2^31 - 1) */ + +#define LEN 200 /* Max length of strings */ + + + + + +/*================================ Types ================================*/ + +typedef struct { + double *X; + int K; +} ACORN_state; + +/*------------------------------------*/ + +typedef struct { + long B, a0, a1; + double BK[33]; + int K; +} Tindo_param; + +typedef struct { + long C[33]; + int Current, L; +} Tindo_state; + +/*------------------------------------*/ + +typedef struct { + long S; + unsigned long V; +} CSD_state; + +/*------------------------------------*/ + +typedef struct { + double A1, B1, A2, B2; +} Rey97_param; + +typedef struct { + unsigned long n; +} Rey97_state; + + + + + + +/*============================== Functions ==============================*/ + +static double ACORN_U01 (void *junk, void *vsta) +{ + ACORN_state *state = vsta; + int j; + double temp; + + for (j = 0; j < state->K; j++) { + temp = state->X[j + 1] + state->X[j]; + if (temp >= 1.0) + state->X[j + 1] = temp - 1.0; + else + state->X[j + 1] = temp; + } + return state->X[state->K]; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long ACORN_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (ACORN_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrACORN (void *vsta) +{ + ACORN_state *state = vsta; + int j; + if (unif01_WrLongStateFlag) { + printf (" S = {\n"); + for (j = 0; j < state->K; j++) { + printf (" %22.16f", state->X[j]); + if (j < state->K) + printf (","); + if (((j + 1) % 3) == 0) + printf ("\n"); + }; + printf ("\n }\n"); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uvaria_CreateACORN (int k, double S[]) +{ + unif01_Gen *gen; + ACORN_state *state; + size_t leng; + char name[LEN + 1]; + int j; + + if (k < 1) { + util_Error ("uvaria_CreateACORN: k < 1"); + } + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (ACORN_state)); + + state->X = util_Calloc ((size_t) k + 1, sizeof (double)); + for (j = 0; j < k; j++) + state->X[j] = S[j]; + state->X[k] = 0.1234567; /* Arbitrary initial value */ + + strcpy (name, "uvaria_CreateACORN:"); + addstr_Int (name, " k = ", k); + addstr_ArrayDouble (name, ", S = ", k, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->K = k; + + gen->GetBits = &ACORN_Bits; + gen->GetU01 = &ACORN_U01; + gen->Write = &WrACORN; + gen->param = NULL; + gen->state = state; + return gen; +} + +/*------------------------------------------------------------------------*/ + +void uvaria_DeleteACORN (unif01_Gen * gen) +{ + ACORN_state *state; + + if (NULL == gen) + return; + state = gen->state; + util_Free (state->X); + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/**************************************************************************/ + +static double Tindo_U01 (void *vpar, void *vsta) +{ + Tindo_param *param = vpar; + Tindo_state *state = vsta; + long T[33]; + double Sum; + int j, i; + + Sum = 0.0; + for (j = 1; j <= param->K; j++) { + if (state->Current == 0) { + /* Refresh table C */ + T[1] = (param->a1 * state->C[state->L] + param->a0 * state->C[1] + 1) + % param->B; + for (i = 2; i <= state->L; i++) + T[i] = (param->a1 * state->C[i - 1] + param->a0 * state->C[i] + 1) + % param->B; + for (i = 1; i <= state->L; i++) + state->C[i] = T[i]; + } + Sum += param->BK[j] * state->C[state->Current + 1]; + state->Current = (state->Current + 1) % state->L; + } + while (Sum > 1.0) + Sum -= 1.0; + return Sum; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long Tindo_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (Tindo_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrTindo (void *vsta) +{ + Tindo_state *state = vsta; + int i; + if (unif01_WrLongStateFlag) { + printf (" C = {\n"); + for (i = 1; i <= state->L; i++) { + printf (" %10ld", state->C[i]); + if (i < state->L) + printf (","); + if ((i % 3) == 0) + printf ("\n"); + }; + printf ("\n }"); + printf ("\n Current = %1d\n", state->Current); + } else + unif01_WrLongStateDef (); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uvaria_CreateTindo (long b, long Delta, int l, int k) +/* + * Assumes that ( a0 < b ) , ( a1 < b ) and ( b < 2^15 = 32768 ) + */ +{ + unif01_Gen *gen; + Tindo_param *param; + Tindo_state *state; + size_t leng; + char name[LEN + 1]; + int i; + + util_Assert (k > 0, "uvaria_CreateTindo: must have k > 0"); + util_Assert (k <= 32, "uvaria_CreateTindo: must have k <= 32"); + util_Assert (l > 0, "uvaria_CreateTindo: must have l > 0"); + util_Assert (l <= 32, "uvaria_CreateTindo: must have l <= 32"); + util_Assert (b < 32768, "uvaria_CreateTindo: must have b < 2^15"); + util_Assert (Delta > 0, "uvaria_CreateTindo: must have Delta > 0"); + util_Assert (Delta < b - 1, + "uvaria_CreateTindo: must have Delta < b - 1"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Tindo_param)); + state = util_Malloc (sizeof (Tindo_state)); + + strcpy (name, "uvaria_CreateTindo:"); + addstr_Long (name, " b = ", b); + addstr_Long (name, ", Delta = ", Delta); + addstr_Int (name, ", s = ", l); + addstr_Int (name, ", k = ", k); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->Current = 0; + state->L = l; + for (i = 1; i <= l; i++) + state->C[i] = i % b; + param->B = b; + param->K = k; + param->a1 = Delta + 1; + param->a0 = b - Delta; + param->BK[1] = 1.0 / b; + for (i = 2; i <= k; i++) + param->BK[i] = param->BK[i - 1] * param->BK[1]; + + gen->GetBits = &Tindo_Bits; + gen->GetU01 = &Tindo_U01; + gen->Write = &WrTindo; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +static double CSD_U01 (void *junk, void *vsta) +{ + CSD_state *state = vsta; + double u; + unsigned long d1, d2, temp, c1, c4; + long v; + + v = state->S / 127773; + state->S = 16807 * (state->S - v * 127773) - v * 2836; + if (state->S < 0) + state->S += 2147483647; + u = state->S * INV31; + + d1 = 10.0 * u; + d2 = ((unsigned long) (100.0 * u)) - 10 * d1; + + state->V = (state->V + d1) % 10000; + temp = ((state->V * state->V) % 10000) * state->V; + c1 = temp % 10; + temp /= 1000; + c4 = temp % 10; + state->V = c1 * 1000 + d1 * 100 + c4 * 10 + d2; + return state->V * 0.0001; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long CSD_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (CSD_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrCSD (void *vsta) +{ + CSD_state *state = vsta; + printf (" V = %1lu, S = %1ld\n", state->V, state->S); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uvaria_CreateCSD (long v, long s) +{ + unif01_Gen *gen; + CSD_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert (v >= 0, "uvaria_CreateCSD: must have v >= 0"); + util_Assert (v <= 9999, "uvaria_CreateCSD: must have v <= 9999"); + util_Assert (s > 0, "uvaria_CreateCSD: must have s > 0"); + util_Assert (s < 2147483647, + "uvaria_CreateCSD: must have s < 2^31 - 1"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (CSD_state)); + + strcpy (name, "uvaria_CreateCSD:"); + addstr_Long (name, " v = ", v); + addstr_Long (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->V = v; + state->S = s; + + gen->GetBits = &CSD_Bits; + gen->GetU01 = &CSD_U01; + gen->Write = &WrCSD; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +/***********************************************************************/ +/* + This code is from Agner Fog: http://www.agner.org +*/ +/************************* RANROTB.C ******************** AgF 1999-03-03 * +* Random Number generator 'RANROT' type B * +* * +* This is a lagged-Fibonacci type of random number generator with * +* rotation of bits. The algorithm is: * +* X[n] = ((X[n-j] rotl r1) + (X[n-k] rotl r2)) modulo 2^b * +* * +* The last k values of X are stored in a circular buffer named * +* randbuffer. * +* * +* This version works with any integer size: 16, 32, 64 bits etc. * +* The integers must be unsigned. The resolution depends on the integer * +* size. * +* * +* Note that the function RanrotBInit must be called before the first * +* call to RanrotB or iRanrotB * +* * +* The theory of the RANROT type of generators is described at * +* www.agner.org/random/ranrot.htm * +* * +*************************************************************************/ + +/* names of header files may differ +#include +#include +#include +#include +#include +*/ + +/* define desired integer type */ +typedef unsigned int my_uint; + +/* If your system doesn't have a rotate function for the chosen integer type + then define it thus: */ +static my_uint rotl (my_uint x, my_uint r) { + return (x << r) | (x >> (sizeof(x)*8-r));} + +/* define parameters (R1 and R2 must be smaller than the integer size): */ +#define KK 17 +#define JJ 10 +#define R1 5 +#define R2 3 + +/* global variables */ +static my_uint randbuffer[KK]; /* history buffer */ +static int r_p1, r_p2; /* indexes into history buffer */ +static float scale; /* 2^(- integer size) */ + + +/* returns a random number between 0 and 1 */ +static double RanrotB(void) { + my_uint x; + /* generate next random number */ + x = randbuffer[r_p1] = rotl(randbuffer[r_p2], R1) + rotl(randbuffer[r_p1], R2); + /* rotate list pointers */ + if (--r_p1 < 0) r_p1 = KK - 1; + if (--r_p2 < 0) r_p2 = KK - 1; + /* conversion to float */ + return x * scale; +} + +/* get integer random number in interval from min to max */ +static int iRanrotB(int min, int max) { + int i, r; + i = max - min + 1; + r = i * RanrotB(); + if (r >= i) r = i-1; + return min + r; +} + +/* this function initializes the random number generator. */ +/* Must be called before the first call to RanrotB or iRanrotB */ +static void RanrotBInit (my_uint seed) { + int i; + + /* put semi-random numbers into the buffer */ + for (i=0; in); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uvaria_CreateRey97 (double a1, double a2, double b2, long n0) +{ + unif01_Gen *gen; + Rey97_state *state; + Rey97_param *param; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (Rey97_state)); + param = util_Malloc (sizeof (Rey97_param)); + + strcpy (name, "uvaria_CreateRey97:"); + addstr_Double (name, " a1 = ", a1); + addstr_Double (name, ", a2 = ", a2); + addstr_Double (name, ", b2 = ", b2); + addstr_Long (name, ", n0 = ", n0); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->n = n0; + param->A1 = a1; + param->A2 = a2; + param->B2 = b2; + param->B1 = (sqrt (5.0) - 1) * num_Pi / 2; + + gen->GetBits = &Rey97_Bits; + gen->GetU01 = &Rey97_U01; + gen->Write = &WrRey97; + gen->param = param; + gen->state = state; + return gen; +} + + +/**************************************************************************/ + +void uvaria_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/uvaria.tex b/TESTU01/TestU01-1.2.3/testu01/uvaria.tex new file mode 100644 index 0000000..cda6e60 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uvaria.tex @@ -0,0 +1,137 @@ +\defmodule {uvaria} + +Implements various special generators proposed in the litterature. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +/* uvaria.h for ANSI C */ + +#ifndef UVARIA_H +#define UVARIA_H +\endhide +#include "unif01.h" + + +unif01_Gen * uvaria_CreateACORN (int k, double S[]); +\endcode + \tab Initializes a generator ACORN (Additive COngruential Random Number) + \cite{rWIK89a} of order $k$ and +\index{Generator!ACORN}% + whose initial state is given by the vector {\tt S[0..(k-1)]}. + \endtab +\code + + +unif01_Gen * uvaria_CreateCSD (long v, long s); +\endcode + \tab Implements the generator proposed by Sherif and +\index{Generator!Sherif-Dear}% + Dear in \cite{rSHE90a}. The initial state of the generator is given + by {\tt v}. The generator uses a MLCG generator whose + initial state is given by {\tt s}. Restrictions: + {\tt $0 \le$ v $\le 9999$} and {\tt $0 <$ s $< 2^{31}-1$}. + \endtab +\code + + +unif01_Gen * uvaria_CreateRanrotB (unsigned int seed); +\endcode + \tab + This is a lagged-Fibonacci-type random number generator, but +\index{Generator!RANROT}% + with a rotation of bits, called RANROT, and proposed by + Fog \cite{rFOG01a}. The variant programmed here is RANROT of type B. + \hrichard {Voici ce que Agner Fog m'a r\'epondu: + The theoretical description is on my website. + The scientific journals will only publish code that is supported by + theoretical proof, and my point is that such proof may not be possible for + the best generators. } + The algorithm is: + $$ + X_n = \left((X_{n-j}\ \mbox{rotl}\ r_1) + + (X_{n-k}\ \mbox{rotl}\ r_2)\right) \mod 2^b + $$ + where rotl denotes a left rotation of the bits, + each $X_n$ is an {\tt unsigned int}, + and $b$ is the number of bits in an {\tt unsigned int}. + The output value is $u_n = X_n/2^b$. + The last $k$ values of $X$ are stored in a circular buffer + (here of size 17, with $r_1 = 5$ and $r_2 = 3$). + Information about RANROT generators can be found at + \url{http://www.agner.org/random/}. + +% Restrictions: {\tt type = 'B'}. + Since Fog's code is copied verbatim here, there are global + variables in the implementation. Thus no more than + one generator of that type can be in use at any given time. +% Using two or more simultaneously will give meaningless results. + \endtab +\code + + +unif01_Gen * uvaria_CreateRey97 (double a1, double a2, double b2, long n0); +\endcode + \tab Generator proposed by W.\ Rey \cite{rREY98a}. +% , of Philips Research +\index{Generator!Rey}% + It uses the recurrence: + \begin {eqnarray} + z_i &=& a_1 \sin (b_1 (i+n_0)) \mod 1;\\ + u_i &=& (a_2 + z_i) \sin (b_2 z) \mod 1, + \end {eqnarray} + where $b_1 = (\sqrt{5}-1) \pi/2$. + According to the author, $a_1$, $a_2$ and $b_2$ should be chosen + sufficiently large. + \endtab +\code + + +unif01_Gen * uvaria_CreateTindo (long b, long Delta, int s, int k); +\endcode + \tab Initializes the parameters of the generator proposed +\index{Generator!Tindo}% + by Tindo in \cite{rTIN90a}, with $a_0 = b - {\tt Delta}$ and + $a_1 = {\tt Delta} + 1$. Assumes that $0 < {\tt Delta} < b-1$ and + $b < 2^{15} = 32768$. + Restrictions: $1 \le k \le 32$, $1 \le s \le 32$. + \endtab + + +\guisec{Clean-up functions} +\code + +void uvaria_DeleteACORN (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by the {\tt ACORN} + generator and allocated by the corresponding {\tt Create} function + above. + \endtab +\code + + +void uvaria_DeleteRanrotB (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by the {\tt RanrotB} + generator and allocated by the corresponding {\tt Create} function + above. + \endtab +\code + + +void uvaria_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called to clean up a generator object + when it is no longer in use. + \endtab + +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/uweyl.c b/TESTU01/TestU01-1.2.3/testu01/uweyl.c new file mode 100644 index 0000000..5aad55e --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uweyl.c @@ -0,0 +1,234 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uweyl.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" +#include "uweyl.h" +#include "unif01.h" + +#include +#include + + +#define LEN 200 /* Max length of strings */ + + + +/*================================ Types ================================*/ + +typedef struct { + unsigned long n; +} Weyl_state; + +typedef struct { + double Alpha; +} Weyl_param; + +typedef struct { + double Alpha; + long M; +} SNWeyl_param; + + +/*========================= Common functions ============================*/ + +static void WrWeyl (void *vsta) +{ + Weyl_state *state = vsta; + printf (" n = %1lu\n", state->n); +} + +static unif01_Gen *CreateWeyl_0 (double Alpha, long n0, char name[]) +{ + unif01_Gen *gen; + Weyl_param *param; + Weyl_state *state; + size_t leng; + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (Weyl_param)); + state = util_Malloc (sizeof (Weyl_state)); + param->Alpha = Alpha; + state->n = n0; + + addstr_Double (name, " Alpha = ", Alpha); + addstr_Long (name, ", n0 = ", n0); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->Write = &WrWeyl; + gen->param = param; + gen->state = state; + return gen; +} + + +/*=======================================================================*/ + +static double Weyl_U01 (void *vpar, void *vsta) +{ + Weyl_param *param = vpar; + Weyl_state *state = vsta; + double X; + + state->n++; + X = state->n * param->Alpha; + return (X - (long) X); +} + +static unsigned long Weyl_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * Weyl_U01 (vpar, vsta)); +} + +unif01_Gen *uweyl_CreateWeyl (double Alpha, long n0) +{ + unif01_Gen *gen; + char name[LEN + 1]; + + util_Assert ((Alpha > 0.0), "uweyl_CreateWeyl: Alpha <= 0"); + util_Assert ((Alpha < 1.0), "uweyl_CreateWeyl: Alpha >= 1"); + + strncpy (name, "uweyl_CreateWeyl: ", (size_t) LEN); + gen = CreateWeyl_0 (Alpha, n0, name); + gen->GetU01 = &Weyl_U01; + gen->GetBits = &Weyl_Bits; + return gen; +} + + +/*=======================================================================*/ + +static double NWeyl_U01 (void *vpar, void *vsta) +{ + Weyl_param *param = vpar; + Weyl_state *state = vsta; + double X; + + state->n++; + X = state->n * param->Alpha; + X -= (long) X; + X *= state->n; + return (X - (long) X); +} + +static unsigned long NWeyl_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * NWeyl_U01 (vpar, vsta)); +} + +unif01_Gen *uweyl_CreateNWeyl (double Alpha, long n0) +{ + unif01_Gen *gen; + char name[LEN + 1]; + + util_Assert ((Alpha > 0.0), "uweyl_CreateNWeyl: Alpha <= 0"); + util_Assert ((Alpha < 1.0), "uweyl_CreateNWeyl: Alpha >= 1"); + + strncpy (name, "uweyl_CreateNWeyl (nested): ", (size_t) LEN); + gen = CreateWeyl_0 (Alpha, n0, name); + gen->GetU01 = &NWeyl_U01; + gen->GetBits = &NWeyl_Bits; + return gen; +} + + +/*=======================================================================*/ + +static double SNWeyl_U01 (void *vpar, void *vsta) +{ + /* This function gives very different results on the same machine + depending on the level of optimization in the compilation. */ + SNWeyl_param *param = vpar; + Weyl_state *state = vsta; + double X, Z; + + state->n++; + X = state->n * param->Alpha; + X -= (long) X; + X *= state->n; + X -= (long) X; + X = X * param->M + 0.5; + Z = X * param->Alpha; + Z -= (long) Z; + Z *= X; + Z -= (long) Z; + return Z; +} + +static unsigned long SNWeyl_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (unif01_NORM32 * SNWeyl_U01 (vpar, vsta)); +} + +unif01_Gen *uweyl_CreateSNWeyl (long M, double Alpha, long n0) +{ + unif01_Gen *gen; + SNWeyl_param *param; + Weyl_state *state; + size_t leng; + char name[LEN + 1]; + + util_Assert ((Alpha > 0.0), "uweyl_CreateSNWeyl: Alpha <= 0"); + util_Assert ((Alpha < 1.0), "uweyl_CreateSNWeyl: Alpha >= 1"); + + gen = util_Malloc (sizeof (unif01_Gen)); + param = util_Malloc (sizeof (SNWeyl_param)); + state = util_Malloc (sizeof (Weyl_state)); + param->Alpha = Alpha; + param->M = M; + if (n0 < 0) + n0 = -n0; + state->n = n0; + + strncpy (name, "uweyl_CreateSNWeyl (shuffled nested):", (size_t) LEN); + addstr_Long (name, " M = ", M); + addstr_Double (name, ", Alpha = ", Alpha); + addstr_Long (name, ", n0 = ", n0); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &SNWeyl_Bits; + gen->GetU01 = &SNWeyl_U01; + gen->Write = &WrWeyl; + gen->param = param; + gen->state = state; + return gen; +} + + +/*=======================================================================*/ + +void uweyl_DeleteGen (unif01_Gen *gen) +{ + unif01_DeleteGen (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/uweyl.tex b/TESTU01/TestU01-1.2.3/testu01/uweyl.tex new file mode 100644 index 0000000..0dbc31f --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uweyl.tex @@ -0,0 +1,86 @@ +\defmodule{uweyl} + +This module implements simple and combined generators based on +Weyl sequences, proposed by Holian et al.\ \cite{rHOL94a}. +\index{Generator!Weyl} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code +\hide +#ifndef UWEYL_H +#define UWEYL_H +/* uweyl.h for ANSI C */ +\endhide +#include "unif01.h" + + +unif01_Gen * uweyl_CreateWeyl (double alpha, long n0); +\endcode + \tab Implements a generator defined by the + Weyl sequence: + \eq + u_n = n \alpha \mod 1 = (u_{n-1} + \alpha) \mod 1, + \endeq + where $\alpha = $ {\tt alpha} is a real number in the interval $(0,1)$. + The initial value of $n$ is {\tt n0}. + In theory, if $\alpha$ is irrationnal, this sequence is asymptotically + equidistributed over (0,1) \cite {rWEY16a}. + However, this is not true for the present +%% \hrichard{remplacer par for any computer? Non} + implementation, because + $\alpha$ is represented only with finite precision. + The implementation is only a rough approximation, + valid when $n$ is not too large. + Some possible values for $\alpha$ are: + \begin {eqnarray*} + \sqrt{2} \mod 1 &=& 0.414213562373095 \\ + \sqrt{3} \mod 1 &=& 0.732050807568877 \\ + \pi \mod 1 &=& 0.141592653589793 \\ + e \mod 1 &=& 0.718281828459045 \\ + \gamma &=& 0.577215664901533 \\ + \end {eqnarray*} + \endtab +\code + +unif01_Gen * uweyl_CreateNWeyl (double alpha, long n0); +\endcode + \tab Implements a nested Weyl generator, as suggested in \cite{rHOL94a}, + defined by + \eq + u_n = (n\, (n\alpha \mod 1)) \mod 1, + \endeq + where {\tt alpha} $= \alpha \in (0,1)$. + The initial value of $n$ is {\tt n0}. + \endtab +\code + + +unif01_Gen * uweyl_CreateSNWeyl (long m, double alpha, long n0); +\endcode + \tab Implements a nested Weyl generator with + ``shuffling'', proposed in \cite{rHOL94a}, and defined by + \begin {eqnarray*} + \nu_n = m\, (n\, (n \alpha \mod 1) \mod 1) + 1/2, + \qquad u_n = (\nu_n\, (\nu_n \alpha \mod 1)) \mod 1, + \end {eqnarray*} + where $m$ is a large positive integer and {\tt alpha} $=\alpha \in (0,1)$. + The initial value of $n$ is {\tt n0}. + \endtab + + + +\guisec{Clean-up functions} +\code + +void uweyl_DeleteGen (unif01_Gen *gen); +\endcode + \tab \DelGen + \endtab +\code +\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/uwu.c b/TESTU01/TestU01-1.2.3/testu01/uwu.c new file mode 100644 index 0000000..5782108 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uwu.c @@ -0,0 +1,176 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uwu.c + * Environment: ANSI C + * Programmer: Richard Simard + +\********************************************************************/ + +#include "util.h" +#include "addstr.h" + +#include "uwu.h" +#include "unif01.h" + +#include +#include + + + +#define LEN 200 /* Max length of strings */ + + +#ifdef USE_LONGLONG + +typedef struct { + ulonglong S; +} LCGWu61_state; + +#endif + + + +/*=========================================================================*/ +#ifdef USE_LONGLONG + +#define LOG_W 64 +#define LOG_M 61 +#define M 0x1fffffffffffffffULL +#define K1 30 +#define K2 19 + +static double LCGWu61a_U01 (void *junk, void *vsta) +{ + LCGWu61_state *state = vsta; + ulonglong w1, w2; + longlong x1; + + w1 = (state->S >> (LOG_M - K1)) + + ((state->S << (K1 + LOG_W - LOG_M)) >> (LOG_W - LOG_M)); + w2 = (state->S >> (LOG_M - K2)) + + ((state->S << (K2 + LOG_W - LOG_M)) >> (LOG_W - LOG_M)); + x1 = w1 - w2; + if (x1 < 0) + state->S = x1 + M; + else + state->S = x1; + return state->S / (double) M; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long LCGWu61a_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (LCGWu61a_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +static void WrLCGWu61 (void *vsta) +{ + LCGWu61_state *state = vsta; + printf (" S = %1" PRIuLEAST64 " \n\n", state->S); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uwu_CreateLCGWu61a (longlong s) +{ + unif01_Gen *gen; + LCGWu61_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (LCGWu61_state)); + + strcpy (name, + "uwu_CreateLCGWu61a: m = 2^61 - 1, a = 2^30 - 2^19, c = 0"); + addstr_LONG (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S = s; + gen->GetBits = &LCGWu61a_Bits; + gen->GetU01 = &LCGWu61a_U01; + gen->Write = &WrLCGWu61; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*=========================================================================*/ + +#undef K1 +#undef K2 +#define K1 42 +#define K2 31 + +static double LCGWu61b_U01 (void *junk, void *vsta) +{ + LCGWu61_state *state = vsta; + ulonglong w1, w2; + longlong x1; + + w1 = (state->S >> (LOG_M - K1)) + + ((state->S << (K1 + LOG_W - LOG_M)) >> (LOG_W - LOG_M)); + w2 = (state->S >> (LOG_M - K2)) + + ((state->S << (K2 + LOG_W - LOG_M)) >> (LOG_W - LOG_M)); + x1 = w1 - w2; + if (x1 < 0) + state->S = x1 + M; + else + state->S = x1; + return state->S / (double) M; +} + +/*-----------------------------------------------------------------------*/ + +static unsigned long LCGWu61b_Bits (void *vpar, void *vsta) +{ + return (unsigned long) (LCGWu61b_U01 (vpar, vsta) * unif01_NORM32); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen * uwu_CreateLCGWu61b (longlong s) +{ + unif01_Gen *gen; + LCGWu61_state *state; + size_t leng; + char name[LEN + 1]; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (LCGWu61_state)); + strcpy (name, + "uwu_CreateLCGWu61b: m = 2^61 - 1, a = 2^42 - 2^31, c = 0"); + addstr_LONG (name, ", s = ", s); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->S = s; + gen->GetBits = &LCGWu61b_Bits; + gen->GetU01 = &LCGWu61b_U01; + gen->Write = &WrLCGWu61; + gen->param = NULL; + gen->state = state; + return gen; +} + +#endif /* USE_LONGLONG */ + + +/*=========================================================================*/ + +void uwu_DeleteGen (unif01_Gen * gen) +{ + if (NULL == gen) + return; + gen->name = util_Free (gen->name); + gen->state = util_Free (gen->state); + util_Free (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/uwu.tex b/TESTU01/TestU01-1.2.3/testu01/uwu.tex new file mode 100644 index 0000000..18c08ba --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uwu.tex @@ -0,0 +1,79 @@ +\defmodule {uwu} + +This module collects some generators from Pei-Chi Wu. +\index{Generator!Wu} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\bigskip +\hrule +\code\hide +/* uwu.h for ANSI C */ + +#ifndef UWU_H +#define UWU_H +\endhide +#include "gdef.h" +#include "unif01.h" + + +#ifdef USE_LONGLONG + unif01_Gen * uwu_CreateLCGWu61a (longlong s); +\endcode + \tab Implements a LCG proposed by Wu \cite{rWU97a}, + with $m= 2^{61}-1$, $a = 2^{30} - 2^{19}$, $c=0$. + Uses a fast implementation with shifts rather than + multiplications. + It uses 64-bits integers. % which must be available. + \endtab +\code + + + unif01_Gen * uwu_CreateLCGWu61b (longlong s); +\endcode + \tab Similar to {\tt uwu\_CreateLCGWu61a}, + but with $a = 2^{42} - 2^{31}$. + \endtab +\code +#endif +\endcode + + + +\guisec{Clean-up functions} + +\code + + +void uwu_DeleteGen (unif01_Gen *gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module + that does not have an explicit {\tt Delete} function. + This function should be called to clean up a generator object + when it is no longer in use. + \endtab +\code + +\hide +#endif +\endhide +\endcode + + +\bigskip +\hrule +\bigskip + +{ +See also +\bigskip + +\setlength{\partopsep}{0pt} +\setlength{\parskip}{0pt} +\setlength{\topsep}{0pt} +\setlength{\itemsep}{0pt} + +\begin{itemize} +\item {\tt ulcg\_CreateLCGWu2} +\end{itemize} +} diff --git a/TESTU01/TestU01-1.2.3/testu01/uxorshift.c b/TESTU01/TestU01-1.2.3/testu01/uxorshift.c new file mode 100644 index 0000000..7bdbabe --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uxorshift.c @@ -0,0 +1,930 @@ +/*************************************************************************\ + * + * Package: TestU01 + * File: uxorshift.c + * Environment: ANSI C + * + * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. + * e-mail: lecuyer@iro.umontreal.ca + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted without a fee for private, research, + * academic, or other non-commercial purposes. + * Any use of this software in a commercial environment requires a + * written licence from the copyright owner. + * + * Any changes made to this package must be clearly identified as such. + * + * In scientific publications which used this software, a reference to it + * would be appreciated. + * + * Redistributions of source code must retain this copyright notice + * and the following disclaimer. + * + * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * +\*************************************************************************/ + +#include "util.h" +#include "addstr.h" +#include "uxorshift.h" +#include "unif01.h" + +#include +#include + +#define LEN 200 + +#define MASK32 0xffffffffUL /* Mask of 32 bits */ + + +typedef struct { + unsigned long *Z; + int N; +} XorshiftC_state; + +typedef struct { + int a, b, c; +} XorshiftC_param; + +typedef XorshiftC_state XorshiftD_state; + + +typedef struct { + unsigned int a, b, c; +} Shift3_param; + + +typedef struct { + int *a; +} XorshiftD_param; + +typedef struct { + unsigned int X[8]; + unsigned int k; +} Xorshift7_state; + +typedef Xorshift7_state Xorshift13_state; + + + +/***************************************************************************/ + +static unsigned long Shift32RLL_Bits (void *vpar, void *vsta) +{ + unsigned long *p = vsta; + unsigned long t = *p; + Shift3_param *param = vpar; + + t ^= t >> param->a; + t ^= t << param->b; + t ^= t << param->c; + *p = t & MASK32; + return *p; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift32RLL_U01 (void *par, void *sta) +{ + return Shift32RLL_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* LRL */ +static unsigned long Shift32LRL_Bits (void *vpar, void *vsta) +{ + unsigned long *p = vsta; + unsigned long t = *p; + Shift3_param *param = vpar; + + t ^= t << param->a; +#ifndef IS_ULONG32 + t &= MASK32; +#endif + t ^= t >> param->b; + t ^= t << param->c; + *p = t & MASK32; + return *p; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift32LRL_U01 (void *par, void *sta) +{ + return Shift32LRL_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* LLR */ +static unsigned long Shift32LLR_Bits (void *vpar, void *vsta) +{ + unsigned long *p = vsta; + unsigned long t = *p; + Shift3_param *param = vpar; + + t ^= t << param->a; + t ^= t << param->b; +#ifndef IS_ULONG32 + t &= MASK32; +#endif + t ^= t >> param->c; + *p = t; + return *p; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift32LLR_U01 (void *par, void *sta) +{ + return Shift32LLR_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* RRL */ +static unsigned long Shift32RRL_Bits (void *vpar, void *vsta) +{ + unsigned long *p = vsta; + unsigned long t = *p; + Shift3_param *param = vpar; + + t ^= t >> param->a; + t ^= t >> param->b; + t ^= t << param->c; + *p = t & MASK32; + return *p; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift32RRL_U01 (void *par, void *sta) +{ + return Shift32RRL_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* RLR */ +static unsigned long Shift32RLR_Bits (void *vpar, void *vsta) +{ + unsigned long *p = vsta; + unsigned long t = *p; + Shift3_param *param = vpar; + + t ^= t >> param->a; + t ^= t << param->b; +#ifndef IS_ULONG32 + t &= MASK32; +#endif + t ^= t >> param->c; + *p = t; + return *p; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift32RLR_U01 (void *par, void *sta) +{ + return Shift32RLR_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* LRR */ +static unsigned long Shift32LRR_Bits (void *vpar, void *vsta) +{ + unsigned long *p = vsta; + unsigned long t = *p; + Shift3_param *param = vpar; + + t ^= t << param->a; +#ifndef IS_ULONG32 + t &= MASK32; +#endif + t ^= t >> param->b; + t ^= t >> param->c; + *p = t; + return *p; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift32LRR_U01 (void *par, void *sta) +{ + return Shift32LRR_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrShift32 (void *sta) +{ + unsigned long *p = sta; + printf (" y = %lu\n", *p); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *uxorshift_CreateXorshift32 (int a, int b, int c, unsigned int y) +{ + unif01_Gen *gen; + unsigned long *p1; + size_t leng; + char name[LEN + 1]; + Shift3_param *param; + + util_Assert ((a < 32) && (a > -32), + "uxorshift_CreateXorshift32: a must be in [-32..32]"); + util_Assert ((b < 32) && (b > -32), + "uxorshift_CreateXorshift32: b must be in [-32..32]"); + util_Assert ((c < 32) && (c > -32), + "uxorshift_CreateXorshift32: c must be in [-32..32]"); + + gen = util_Malloc (sizeof (unif01_Gen)); + p1 = gen->state = util_Malloc (sizeof (unsigned long)); + param = util_Malloc (sizeof (Shift3_param)); + + *p1 = y; + param->a = a > 0 ? a : -a; + param->b = b > 0 ? b : -b; + param->c = c > 0 ? c : -c; + gen->param = param; + gen->Write = &WrShift32; + + strcpy (name, "uxorshift_CreateXorshift32:"); + addstr_Int (name, " a = ", a); + addstr_Int (name, ", b = ", b); + addstr_Int (name, ", c = ", c); + addstr_Uint (name, ", y = ", y); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (a > 0) { + if (b > 0) { + if (c > 0) { + util_Error ( + "uxorshift_CreateXorshift32: case { <<, <<, << } not programmed"); + } else { + gen->GetBits = &Shift32LLR_Bits; + gen->GetU01 = &Shift32LLR_U01; + } + } else { + if (c > 0) { + gen->GetBits = &Shift32LRL_Bits; + gen->GetU01 = &Shift32LRL_U01; + } else { + gen->GetBits = &Shift32LRR_Bits; + gen->GetU01 = &Shift32LRR_U01; + } + } + } else { + if (b > 0) { + if (c > 0) { + gen->GetBits = &Shift32RLL_Bits; + gen->GetU01 = &Shift32RLL_U01; + } else { + gen->GetBits = &Shift32RLR_Bits; + gen->GetU01 = &Shift32RLR_U01; + } + } else { + if (c > 0) { + gen->GetBits = &Shift32RRL_Bits; + gen->GetU01 = &Shift32RRL_U01; + } else { + util_Error ( + "uxorshift_CreateXorshift32: case { >>, >>, >> } not programmed"); + } + } + } + return gen; +} + + +/***************************************************************************/ +#ifdef USE_LONGLONG + +static unsigned long Shift64RLL_Bits (void *vpar, void *vsta) +{ + ulonglong *state = vsta; + ulonglong t = *state; + Shift3_param *param = vpar; + + t ^= t >> param->a; + t ^= t << param->b; + *state = t ^ (t << param->c); + return *state >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift64RLL_U01 (void *par, void *sta) +{ + return Shift64RLL_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* LRL */ +static unsigned long Shift64LRL_Bits (void *vpar, void *vsta) +{ + ulonglong *state = vsta; + ulonglong t = *state; + Shift3_param *param = vpar; + + t ^= t << param->a; + t ^= t >> param->b; + *state = t ^ (t << param->c); + return *state >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift64LRL_U01 (void *par, void *sta) +{ + return Shift64LRL_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* LLR */ +static unsigned long Shift64LLR_Bits (void *vpar, void *vsta) +{ + ulonglong *state = vsta; + ulonglong t = *state; + Shift3_param *param = vpar; + + t ^= t << param->a; + t ^= t << param->b; + *state = t ^ (t >> param->c); + return *state >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift64LLR_U01 (void *par, void *sta) +{ + return Shift64LLR_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* RRL */ +static unsigned long Shift64RRL_Bits (void *vpar, void *vsta) +{ + ulonglong *state = vsta; + ulonglong t = *state; + Shift3_param *param = vpar; + + t ^= t >> param->a; + t ^= t >> param->b; + *state = t ^ (t << param->c); + return *state >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift64RRL_U01 (void *par, void *sta) +{ + return Shift64RRL_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* RLR */ +static unsigned long Shift64RLR_Bits (void *vpar, void *vsta) +{ + ulonglong *state = vsta; + ulonglong t = *state; + Shift3_param *param = vpar; + + t ^= t >> param->a; + t ^= t << param->b; + *state = t ^ (t >> param->c); + return *state >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift64RLR_U01 (void *par, void *sta) +{ + return Shift64RLR_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ +/* LRR */ +static unsigned long Shift64LRR_Bits (void *vpar, void *vsta) +{ + ulonglong *state = vsta; + ulonglong t = *state; + Shift3_param *param = vpar; + + t ^= t << param->a; + t ^= t >> param->b; + *state = t ^ (t >> param->c); + return *state >> 32; +} + +/*-----------------------------------------------------------------------*/ + +static double Shift64LRR_U01 (void *par, void *sta) +{ + return Shift64LRR_Bits (par, sta) * unif01_INV32; +} + +/*-----------------------------------------------------------------------*/ + +static void WrShift64 (void *sta) +{ + ulonglong *state = sta; + printf (" S = %" PRIuLEAST64 "\n", *state); +} + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *uxorshift_CreateXorshift64 (int a, int b, int c, ulonglong y) +{ + unif01_Gen *gen; + size_t leng; + char name[LEN + 1]; + Shift3_param *param; + ulonglong *state; + + util_Assert ((a < 64) && (a > -64), + "uxorshift_CreateXorshift64: a must be in [-64..64]"); + util_Assert ((b < 64) && (b > -64), + "uxorshift_CreateXorshift64: b must be in [-64..64]"); + util_Assert ((c < 64) && (c > -64), + "uxorshift_CreateXorshift64: c must be in [-64..64]"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (ulonglong)); + param = util_Malloc (sizeof (Shift3_param)); + + *state = y; + param->a = a > 0 ? a : -a; + param->b = b > 0 ? b : -b; + param->c = c > 0 ? c : -c; + gen->param = param; + gen->state = state; + gen->Write = &WrShift64; + + strcpy (name, "uxorshift_CreateXorshift64:"); + addstr_Int (name, " a = ", a); + addstr_Int (name, ", b = ", b); + addstr_Int (name, ", c = ", c); + addstr_ULONG (name, ", y = ", y); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + if (a > 0) { + if (b > 0) { + if (c > 0) { + util_Error ( + "uxorshift_CreateXorshift64: case { <<, <<, << } not programmed"); + } else { + gen->GetBits = &Shift64LLR_Bits; + gen->GetU01 = &Shift64LLR_U01; + } + } else { + if (c > 0) { + gen->GetBits = &Shift64LRL_Bits; + gen->GetU01 = &Shift64LRL_U01; + } else { + gen->GetBits = &Shift64LRR_Bits; + gen->GetU01 = &Shift64LRR_U01; + } + } + } else { + if (b > 0) { + if (c > 0) { + gen->GetBits = &Shift64RLL_Bits; + gen->GetU01 = &Shift64RLL_U01; + } else { + gen->GetBits = &Shift64RLR_Bits; + gen->GetU01 = &Shift64RLR_U01; + } + } else { + if (c > 0) { + gen->GetBits = &Shift64RRL_Bits; + gen->GetU01 = &Shift64RRL_U01; + } else { + util_Error ( + "uxorshift_CreateXorshift64: case { >>, >>, >> } not programmed"); + } + } + } + return gen; +} + + +#endif +/***************************************************************************/ + + +static unsigned long XorshiftC_Bits (void *vpar, void *vsta) +/* + * Only elements Z[j], j = 1, 2, ..., N are used for the state. + * Elements Z[0] is unused. + */ +{ + XorshiftC_state *state = vsta; + XorshiftC_param *param = vpar; + unsigned long t; + int j; + + if (param->a > 0) + t = state->Z[1] ^ (state->Z[1] << param->a); + else + t = state->Z[1] ^ (state->Z[1] >> -param->a); + + for (j = 1; j < state->N; j++) + state->Z[j] = state->Z[j + 1]; + + if (param->b > 0) + t = t ^ (t << param->b); + else { +#ifndef IS_ULONG32 + t &= MASK32; +#endif + t = t ^ (t >> -param->b); + } + + if (param->c > 0) + state->Z[state->N] = state->Z[state->N] ^ + (state->Z[state->N] << param->c) ^ t; + else + state->Z[state->N] = state->Z[state->N] ^ + (state->Z[state->N] >> -param->c) ^ t; + +#ifndef IS_ULONG32 + state->Z[state->N] &= MASK32; +#endif + + return state->Z[state->N]; +} + + +/*-----------------------------------------------------------------------*/ + +static double XorshiftC_U01 (void *par, void *sta) +{ + return XorshiftC_Bits (par, sta) * unif01_INV32; +} + + +/*-----------------------------------------------------------------------*/ + +static void WrXorshiftC (void *vsta) +{ + XorshiftC_state *state = vsta; + int i; + if (unif01_WrLongStateFlag || (state->N < 8)) { + printf (" S = {\n "); + for (i = 1; i <= state->N; i++) { + printf (" %12lu", state->Z[i]); + if (i < state->N) + printf (","); + if ((i % 4) == 0) + printf ("\n "); + } + printf (" }\n"); + } else + unif01_WrLongStateDef (); +} + + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *uxorshift_CreateXorshiftC (int a, int b, int c, int N, + unsigned int S[]) +{ + unif01_Gen *gen; + int i; + size_t leng; + char name[LEN + 1]; + XorshiftC_param *param; + XorshiftC_state *state; + + util_Assert ((a < 32) && (a > -32), + "uxorshift_CreateXorshiftC: a must be in [-31..31]"); + util_Assert ((b < 32) && (b > -32), + "uxorshift_CreateXorshiftC: b must be in [-31..31]"); + util_Assert ((c < 32) && (c > -32), + "uxorshift_CreateXorshiftC: c must be in [-31..31]"); + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (XorshiftC_state)); + param = util_Malloc (sizeof (XorshiftC_param)); + + param->a = a; + param->b = b; + param->c = c; + + strcpy (name, "uxorshift_CreateXorshiftC:"); + addstr_Int (name, " a = ", a); + addstr_Int (name, ", b = ", b); + addstr_Int (name, ", c = ", c); + addstr_Int (name, ", N = ", N); + addstr_ArrayUint (name, ", S = ", N, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->N = N; + state->Z = util_Calloc ((size_t) N + 1, sizeof (unsigned long)); + for (i = 0; i < N; i++) + state->Z[i + 1] = S[i]; + + gen->GetBits = &XorshiftC_Bits; + gen->GetU01 = &XorshiftC_U01; + gen->state = state; + gen->param = param; + gen->Write = &WrXorshiftC; + + return gen; +} + + +/*-------------------------------------------------------------------------*/ + +void uxorshift_DeleteXorshiftC (unif01_Gen * gen) +{ + XorshiftC_state *state; + if (NULL == gen) + return; + state = gen->state; + util_Free (state->Z); + gen->state = util_Free (gen->state); + gen->param = util_Free (gen->param); + gen->name = util_Free (gen->name); + util_Free (gen); +} + + +/***************************************************************************/ + +static unsigned long XorshiftD_Bits (void *vpar, void *vsta) +/* + * Only elements Z[j], j = 1, 2, ..., N are used for the state. + * Elements Z[0] is unused. + */ +{ + XorshiftD_state *state = vsta; + XorshiftD_param *param = vpar; + unsigned long t = 0; + int j; + + for (j = 1; j <= state->N; j++) { + if (param->a[j] > 0) + t ^= state->Z[j] ^ (state->Z[j] << param->a[j]); + else + t ^= state->Z[j] ^ (state->Z[j] >> -param->a[j]); + } + + for (j = 1; j < state->N; j++) + state->Z[j] = state->Z[j + 1]; + +#ifndef IS_ULONG32 + t &= MASK32; +#endif + state->Z[state->N] = t; + return t; +} + + +/*-----------------------------------------------------------------------*/ + +static double XorshiftD_U01 (void *par, void *sta) +{ + return XorshiftD_Bits (par, sta) * unif01_INV32; +} + + +/*-----------------------------------------------------------------------*/ + +static void WrXorshiftD (void *vsta) +{ + WrXorshiftC (vsta); +} + + +/*-----------------------------------------------------------------------*/ + +unif01_Gen *uxorshift_CreateXorshiftD (int N, int b[], unsigned int S[]) +{ + unif01_Gen *gen; + int i; + size_t leng; + char name[LEN + 1]; + XorshiftD_param *param; + XorshiftD_state *state; + + + for (i = 0; i < N; i++) { + util_Assert ((b[i] < 32) && (b[i] > -32), + "uxorshift_CreateXorshiftD: all b[i] must be in [-31..31]"); + } + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (XorshiftD_state)); + param = util_Malloc (sizeof (XorshiftD_param)); + + strcpy (name, "uxorshift_CreateXorshiftD:"); + addstr_Int (name, " r = ", N); + addstr_ArrayInt(name, ", b = ", N, b); + addstr_ArrayUint (name, ", S = ", N, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + state->N = N; + state->Z = util_Calloc ((size_t) N + 1, sizeof (unsigned long)); + param->a = util_Calloc ((size_t) N + 1, sizeof (int)); + for (i = 0; i < N; i++) { + state->Z[i + 1] = S[i]; + param->a[i + 1] = b[i]; + } + + gen->GetBits = &XorshiftD_Bits; + gen->GetU01 = &XorshiftD_U01; + gen->state = state; + gen->param = param; + gen->Write = &WrXorshiftD; + + return gen; +} + + +/*-------------------------------------------------------------------------*/ + +void uxorshift_DeleteXorshiftD (unif01_Gen * gen) +{ + uxorshift_DeleteXorshiftC (gen); +} + + +/***************************************************************************/ + +static unsigned long Xorshift7_Bits (void *junk, void *vsta) +{ + Xorshift7_state *state = vsta; + unsigned int y, t; + t = state->X[(state->k + 7) & 0x7U]; + t = t ^ (t << 13); + y = t ^ (t << 9); + t = state->X[(state->k + 4) & 0x7U]; + y ^= t ^ (t << 7); + t = state->X[(state->k + 3) & 0x7U]; + y ^= t ^ (t >> 3); + t = state->X[(state->k + 1) & 0x7U]; + y ^= t ^ (t >> 10); + t = state->X[state->k]; + t = t ^ (t >> 7); + y ^= t ^ (t << 24); + state->X[state->k] = y; + state->k = (state->k + 1) & 0x7U; + return y; +} + + +/*-------------------------------------------------------------------------*/ + +static double Xorshift7_U01 (void *vpar, void *vsta) +{ + return (unif01_INV32 * Xorshift7_Bits (vpar, vsta)); +} + + +/*-------------------------------------------------------------------------*/ + +static void WrXorshift7 (void *vsta) +{ + Xorshift7_state *state = vsta; + int j; + printf (" k = %1u\n", state->k); + printf (" X = {"); + for (j = 0; j < 8; j++) { + printf (" %10u", state->X[j]); + if (j < 7) + printf (","); + if (j == 3) + printf ("\n "); + } + printf (" }\n\n"); +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uxorshift_CreateXorshift7 (unsigned int S[]) +{ + unif01_Gen *gen; + Xorshift7_state *state; + size_t leng; + char name[LEN + 1]; + int j; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (Xorshift7_state)); + for (j = 0; j < 8; j++) + state->X[j] = S[j]; + state->k = 0; + + strncpy (name, "uxorshift_CreateXorshift7:", LEN); + addstr_ArrayUint (name, " S = ", 8, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &Xorshift7_Bits; + gen->GetU01 = &Xorshift7_U01; + gen->Write = &WrXorshift7; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*=========================================================================*/ + +static unsigned long Xorshift13_Bits (void *junk, void *vsta) +{ + Xorshift13_state *state = vsta; + unsigned int y, t; + + t = state->X[(state->k + 7) & 0x7U]; + y = t ^ (t << 17); + t = state->X[(state->k + 6) & 0x7U]; + y ^= t ^ (t << 10); + t = state->X[(state->k + 4) & 0x7U]; + t = t ^ (t << 17); + y ^= t ^ (t >> 9); + t = state->X[(state->k + 4) & 0x7U]; + y ^= t ^ (t >> 3); + t = state->X[(state->k + 3) & 0x7U]; + y ^= t ^ (t >> 12); + t = state->X[(state->k + 3) & 0x7U]; + y ^= t ^ (t >> 25); + t = state->X[(state->k + 2) & 0x7U]; + t = t ^ (t >> 2); + y ^= t ^ (t >> 3); + t = state->X[(state->k + 1) & 0x7U]; + y ^= t ^ (t >> 27); + t = state->X[(state->k + 1) & 0x7U]; + y ^= t ^ (t >> 22); + t = state->X[state->k]; + t = t ^ (t >> 3); + y ^= t ^ (t << 24); + state->X[state->k] = y; + state->k = (state->k + 1) & 0x7U; + return y; +} + + +/*-------------------------------------------------------------------------*/ + +static double Xorshift13_U01 (void *vpar, void *vsta) +{ + return (unif01_INV32 * Xorshift13_Bits (vpar, vsta)); +} + + +/*-------------------------------------------------------------------------*/ + +unif01_Gen *uxorshift_CreateXorshift13 (unsigned int S[]) +{ + unif01_Gen *gen; + Xorshift13_state *state; + size_t leng; + char name[LEN + 1]; + int j; + + gen = util_Malloc (sizeof (unif01_Gen)); + state = util_Malloc (sizeof (Xorshift13_state)); + for (j = 0; j < 8; j++) + state->X[j] = S[j]; + state->k = 0; + + strncpy (name, "uxorshift_CreateXorshift13:", LEN); + addstr_ArrayUint (name, " S = ", 8, S); + leng = strlen (name); + gen->name = util_Calloc (leng + 1, sizeof (char)); + strncpy (gen->name, name, leng); + + gen->GetBits = &Xorshift13_Bits; + gen->GetU01 = &Xorshift13_U01; + gen->Write = &WrXorshift7; + gen->param = NULL; + gen->state = state; + return gen; +} + + +/*=========================================================================*/ + +void uxorshift_DeleteGen (unif01_Gen * gen) +{ + if (NULL == gen) + return; + gen->state = util_Free (gen->state); + gen->name = util_Free (gen->name); + util_Free (gen); +} diff --git a/TESTU01/TestU01-1.2.3/testu01/uxorshift.h b/TESTU01/TestU01-1.2.3/testu01/uxorshift.h new file mode 100644 index 0000000..a97126c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uxorshift.h @@ -0,0 +1,49 @@ + + +/* uxorshift.h for ANSI C */ +#ifndef UXORSHIFT_H +#define UXORSHIFT_H + +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen* uxorshift_CreateXorshift32 (int a, int b, int c, unsigned int x); + + + +#ifdef USE_LONGLONG + unif01_Gen* uxorshift_CreateXorshift64 (int a, int b, int c, ulonglong x); +#endif + + + +unif01_Gen * uxorshift_CreateXorshiftC (int a, int b, int c, int r, + unsigned int X[]); + + + +unif01_Gen * uxorshift_CreateXorshiftD (int r, int a[], unsigned int X[]); + + + +unif01_Gen* uxorshift_CreateXorshift7 (unsigned int S[8]); + + + +unif01_Gen* uxorshift_CreateXorshift13 (unsigned int S[8]); + + +void uxorshift_DeleteXorshiftC (unif01_Gen * gen); + + + +void uxorshift_DeleteXorshiftD (unif01_Gen * gen); + + + +void uxorshift_DeleteGen (unif01_Gen * gen); + +#endif + + diff --git a/TESTU01/TestU01-1.2.3/testu01/uxorshift.tex b/TESTU01/TestU01-1.2.3/testu01/uxorshift.tex new file mode 100644 index 0000000..9344353 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/uxorshift.tex @@ -0,0 +1,213 @@ +\defmodule {uxorshift} + +\def\OP{\mathop {H}\nolimits} + +This module implements \emph{xorshift} generators, a class of very fast + generators proposed by Marsaglia in \cite{rMAR03a}, and studied +in depth by Panneton and L'\'Ecuyer in \cite{rPAN04c}. +The state of a xorshift generator is a vector of bits. At each +step, the next state is obtained by applying a given number of +xorshift operations to $w$-bit blocks in the current state, where +$w=32$ or 64. A \emph{xorshift operation} is defined as +follows: replace the $w$-bit block by a bitwise \emph{xor} (exclusive or) +of the original block with a shifted copy of itself by $a$ positions +either to the right or to the left, where $0 < a < w$. + +Xorshifts are linear operations. +% on $w$-bit vectors and they can be represented by matrices. +The left shift of a $w$-bit vector $\bx$ by one bit, $\bx \ll 1$, +can also be written as $\bL\bx$ where $\bL$ is the $w\times w$ matrix +with 1's on its main subdiagonal and 0's elsewhere. +Similarly, the right shift $\bx \gg 1$ can be written as $\bR\bx$ +where $\bR$ has 1's on its main superdiagonal and 0's elsewhere. +Matrices of the forms $(\bI+\bL^{a})$ and $(\bI+\bR^{a})$, +where $a \in \{1,\dots,w-1\}$, are called +\emph{left} and \emph{right xorshift matrices}, respectively. +They represent \emph{left} and \emph{right $a$-bit xorshift operations}. + + +A \emph{xorshift generator} is defined by a recurrence of the form +\begin{equation} +\label{eq:MRMMprime} + \bv_i = \sum_{j=1}^p \tilde{\bA}_j \bv_{i-m_j} \bmod 2 +\end{equation} +where $p$ is a positive integer, the $\bv_i$'s are $w$-bit vectors, +the $m_j$'s are integers, +and $\tilde{\bA}_j$ is either the identity or the product of +$\nu_j$ xorshift matrices for some $\nu_j\ge 0$, +for each $j$ ($\tilde{\bA}_j$ is the zero matrix if $\nu_j = 0$). +The generator's state at step $i$ is +$\bx_i = (\bv_i\tpose,\ldots,\bv_{i-r+1}\tpose)\tpose$ and +the output is $u_i = \sum_{\ell=1}^w v_{i,\ell-1} 2^{-\ell}$ +where $\bv_i = (v_{i,0},\dots,v_{i,w-1})\tpose$. + +\bigskip +\hrule +\code +\hide +/* uxorshift.h for ANSI C */ +#ifndef UXORSHIFT_H +#define UXORSHIFT_H +\endhide +#include "gdef.h" +#include "unif01.h" + + +unif01_Gen* uxorshift_CreateXorshift32 (int a, int b, int c, unsigned int x); +\endcode + \tab Implements the 32-bit {\it Xorshift} generators + proposed by Marsaglia in \cite[page 3]{rMAR03a}: \label{marsa-xorshift} + \begin {eqnarray*} + y &=& y_{n-1} \oplus (y_{n-1} \OP_1 a), \\ + y &=& y \oplus (y \OP_2 b), \\ + y_{n} &=& y \oplus (y \OP_3 c) \bmod 2^{32} + \end {eqnarray*} +\index{Generator!Xorshift}% + where the operators $\OP_1$, $\OP_2$ and $\OP_3$ may be either + the left bit-shift operator $\ll$ or the right bit-shift operator $\gg$, + depending on whether the corresponding parameter ($a$, $b$ or $c$) + is positive (left shift) or negative (right shift). + The initial seed is {\tt x} and the generator returns $y_{n}/2^{32}$. + Restrictions: $-32 < a, b, c < 32$. + \endtab +\code + + +#ifdef USE_LONGLONG + unif01_Gen* uxorshift_CreateXorshift64 (int a, int b, int c, ulonglong x); +#endif +\endcode + \tab Similar to {\tt uxorshift\_CreateXorshift32} but using 64-bit integers + (see \cite[page 3]{rMAR03a}). + Only the 32 most significant bits of each + generated number are returned, though the generator does + all its calculations with 64 bits. Restrictions: $-64 < a, b, c < 64$. + \endtab +\code + + +unif01_Gen * uxorshift_CreateXorshiftC (int a, int b, int c, int r, + unsigned int X[]); +\endcode + \tab Generalizes the {\it Xorshift} generators + proposed by Marsaglia in \cite[page 4]{rMAR03a} to generators + with maximal period $2^{32r} - 1$. + Given integers $x_i$,\ $i = 1,2,\ldots, r$, + representing the state of the generator, the next + state is obtained through: + \begin {eqnarray*} + t &= & x_1 \oplus (x_1 \OP_1 a) \\ + x_i &=& x_{i+1}, \qquad i = 1,2,\ldots, r-1 \\ + x_r &=& x_r \oplus (x_r \OP_3 c) \oplus t \oplus (t \OP_2 b) + \end {eqnarray*} + where the operators $\OP_1$, $\OP_2$ and $\OP_3$ may be either + the left bit-shift operator $\ll$ or the right bit-shift operator $\gg$, + depending on whether the corresponding parameter ($a$, $b$ or $c$) + is positive (left shift) or negative (right shift). + The initial state $x_i$ is obtained from the seed {\tt X} as + $x_i = {\tt X} [i - 1], i = 1,2,\ldots, r$ and + the generator returns $x_{r}/2^{32}$. + Restrictions: $-32 < a, b, c < 32$. + \endtab +\code + + +unif01_Gen * uxorshift_CreateXorshiftD (int r, int a[], unsigned int X[]); +\endcode + \tab Generalizes the {\it Xorshift} generators + proposed by Marsaglia in \cite[page 5]{rMAR03a} to generators + with maximal period $2^{32r} - 1$. + Given integers $x_i$,\ $i = 1,2,\ldots, r$, + representing the state of the generator, and shift parameters + $a_i$,\ $i = 1,2,\ldots, r$, the next + state is obtained through: + \begin {eqnarray*} + t &= & x_1 \oplus (x_1 \OP_1 a_1) \oplus x_2 \oplus (x_2 \OP_2 a_2) + \oplus \cdots \oplus x_r \oplus (x_r \OP_r a_r) \\ + x_i &=& x_{i+1}, \qquad i = 1,2,\ldots, r-1 \\ + x_r &=& t + \end {eqnarray*} + where the operators $\OP_i$ may be either + the left bit-shift operator $\ll$ or the right bit-shift operator $\gg$, + depending on whether the corresponding parameter $a_i$ + is positive (left shift) or negative (right shift). + The initial state $x_i$ is obtained from the seed {\tt X} as + $x_i = {\tt X} [i - 1], i = 1,2,\ldots, r$ and the shift parameters are + given by $a_i = {\tt a}[i - 1], i = 1,2,\ldots, r$. + The generator returns $x_{r}/2^{32}$. + Restrictions: $-32 < {\tt a}[i] < 32, \quad i = 0, 1,2,\ldots, r-1 $. + \endtab +\code + + +unif01_Gen* uxorshift_CreateXorshift7 (unsigned int S[8]); +\endcode + \tab Creates a full-period \texttt{Xorshift} generator% + \index{Generator!Xorshift7} + of order $8$ with $7$ xorshifts, proposed in \cite{rPAN04c}. + It has a period length of + $2^{256}-1$, its state $\bv$ is made up of eight 32-bit integers, and it + satisfies the recurrence +\begin{eqnarray*} +\bv_{n} &=& (\bI + \bL^9)(\bI + \bL^{13})\bv_{n-1} ++ (\bI+\bL^{7})\bv_{n-4} + (\bI+\bR^{3})\bv_{n-5} + \\[6pt] + && (\bI+\bR^{10})\bv_{n-7} + +(\bI+\bL^{24})(\bI+\bR^{7})\bv_{n-8} +\end{eqnarray*} + where $\bL^j$ stands for a $j$-bits left shift, $\bR^j$ stands for + a $j$-bits right shift, and $\bI$ is the identity operator. All additions +are done modulo 2. + The \texttt{S} are the 8 seeds. + \endtab +\code + + +unif01_Gen* uxorshift_CreateXorshift13 (unsigned int S[8]); +\endcode + \tab Similar to the \texttt{uxorshift\_CreateXorshift7} generator + \cite{rPAN04c}% + \index{Generator!Xorshift13} + but with $13$ xorshifts and satisfying the recurrence +\begin{eqnarray*} +\bv_{n} &=& (\bI+\bL^{17})\bv_{n-1} ++(\bI+\bL^{10})\bv_{n-2} ++(\bI+\bR^{9})(\bI+\bL^{17})\bv_{n-4} ++ (\bI+\bR^{3})\bv_{n-4} + \\[6pt] + && (\bI+\bR^{12})\bv_{n-5} ++ (\bI+\bR^{25})\bv_{n-5} ++ (\bI+\bR^{3})(\bI+\bR^{2})\bv_{n-6} ++(\bI+\bR^{22})\bv_{n-7} + \\[6pt] + && (\bI+\bL^{24})(\bI+\bR^{3})\bv_{n-8}. +\end{eqnarray*} + \endtab + + +\guisec{Clean-up functions} + +\code + +void uxorshift_DeleteXorshiftC (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory allocated by {\tt uxorshift\_CreateXorshiftC}. + \endtab +\code + + +void uxorshift_DeleteXorshiftD (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory allocated by {\tt uxorshift\_CreateXorshiftD}. + \endtab +\code + + +void uxorshift_DeleteGen (unif01_Gen * gen); +\endcode + \tab Frees the dynamic memory used by any generator of this module. +% that does not have an explicit {\tt Delete} function. + This function should be called when a generator + is no longer in use. + \endtab +\code\hide +#endif +\endhide +\endcode diff --git a/TESTU01/TestU01-1.2.3/testu01/vectorsF2.c b/TESTU01/TestU01-1.2.3/testu01/vectorsF2.c new file mode 100644 index 0000000..be08023 --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/vectorsF2.c @@ -0,0 +1,1089 @@ +#include "vectorsF2.h" +#include +#include + +#define WL vectorsF2_WL + +#define MC 0x80000000UL /* permet de diagonaliser la matrice dans Diag() */ + +unsigned long MMC[WL] = + { MC, MC >> 1, MC >> 2, MC >> 3, MC >> 4, MC >> 5, MC >> 6, MC >> 7, + MC >> 8, MC >> 9, MC >> 10, + MC >> 11, MC >> 12, MC >> 13, MC >> 14, MC >> 15, MC >> 16, MC >> 17, + MC >> 18, MC >> 19, MC >> 20, + MC >> 21, MC >> 22, MC >> 23, MC >> 24, MC >> 25, MC >> 26, MC >> 27, + MC >> 28, MC >> 29, MC >> 30, MC >> 31 +}; + +lebool InverseMatrix (Matrix * InvM, Matrix * M) +{ + + Matrix Temp; + int j, rang; + if (M->nblignes != M->l) { + printf ("Matrix M is not square!\n"); + exit (1); + } + AllocMat (&Temp, M->nblignes, M->l, 2); + for (j = 0; j < M->l; j++) + CopyBV (&(Temp.lignes[j][0]), &(M->lignes[j][0])); + for (j = 0; j < M->l; j++) { + BVCanonic (&(Temp.lignes[j][1]), j); + } + /* DispMat(&Temp,2,M->l,M->nblignes,0); */ + rang = CompleteElimination (&Temp, M->nblignes, M->l, 2); + /* DispMat(&Temp,2,M->l,M->nblignes,0); */ + /* printf("rang=%d",rang); */ + for (j = 0; j < M->l; j++) + CopyBV (&(InvM->lignes[j][0]), &(Temp.lignes[j][1])); + return (rang == M->l); + FreeMat (&Temp); +} + + +/* ********************************************************************** */ +/* lebool Diag( Matrix m, int kg, */ +/* int t, int l, int *gr ) */ +/* Evalue si la matrice de travail m sur kg lignes est de plein rang en */ +/* la diagonalisant. On procede sur t BitVect en considerant les l */ +/* premiers bits de chacun. La fonction retourne TRUE si la matrice m */ +/* est de plein rang t*l et *gr est inchange. La fonction retourne */ +/* FALSE sinon et *gr prend pour valeur le numero du BitVect ou il y a */ +/* eu echec moins un ( = dimension pour laquelle on a resolution l ). */ +/* ********************************************************************** */ +lebool Diag (Matrix * m, int kg, int t, int l, int *gr) +{ + int i, j, cl, rang; + + rang = 0; + + /* On diagonalise la matrice des entrees (i,j) sur l bits */ + /* avec 0 <= i < kg et 0 <= j < t . */ + + for (j = 0; j < t; j++) { + cl = 1; + while (cl <= l) { + /* On cherche dans la j-eme colonne, commencant a la */ + /* rang-eme ligne, la premiere entree dont le bit le plus */ + /* significatif est non nul. Bref, on cherche un pivot. */ + i = rang; + + while ((i < kg) + && (m->lignes[i][j].vect[(cl - 1) / WL] < MMC[(cl - 1) % WL])) + i++; + if (i < kg) { /* pivot trouve ... */ + ExchangeVect (m, rang, i); + for (i = rang + 1; i < kg; i++) { + if (m->lignes[i][j].vect[(cl - 1) / WL] & MMC[(cl - 1) % WL]) + XorVect (m, i, rang, j, m->t); + } + rang++; + } else { /* pas de pivot trouve ... ==> pas de plein + rang ... */ + + *gr = j; /* no de groupe ou il y a echec moins un */ + return FALSE; /* c'est j car on indexe a partir de 0 . */ + } + cl++; + } + } + return TRUE; /* on a trouve tous les pivots ==> plein + rang ! */ +} + + +int CompleteElimination (Matrix * m, int nblignes, int l, int t) +{ + int i, j, cl, rang; + + rang = 0; + + j = 0; + while (j < t) { + cl = 0; + while (cl < l) { + /* On cherche dans la j-eme colonne, commencant a la */ + /* rang-eme ligne, la premiere entree dont le bit le plus */ + /* significatif est non nul. Bref, on cherche un pivot. */ + i = rang; + while ((i < nblignes) + && ((((m->lignes)[i])[j]).vect[(cl) / WL] < MMC[(cl) % WL])) + i++; + if (i < nblignes) { /* pivot trouve ... */ + ExchangeVect (m, rang, i); + for (i = 0; i < nblignes; i++) + if (i != rang) + if ((((m->lignes)[i])[j]).vect[(cl) / WL] & MMC[(cl) % WL]) + XorVect (m, i, rang, 0, m->t); + + rang++; + if (rang == nblignes) + return rang; + } else + return rang; + cl++; + } + j++; + } + return rang; +} + + +int GaussianElimination (Matrix * m, int nblignes, int l, int t) +{ + int i, j, cl, rang; + + rang = 0; + + j = 0; + while (j < t) { + cl = 0; + while (cl < l) { + /* On cherche dans la j-eme colonne, commencant a la */ + /* rang-eme ligne, la premiere entree dont le bit le plus */ + /* significatif est non nul. Bref, on cherche un pivot. */ + i = rang; + while ((i < nblignes) + && ((((m->lignes)[i])[j]).vect[(cl) / WL] < MMC[(cl) % WL])) + i++; + if (i < nblignes) { /* pivot trouve ... */ + ExchangeVect (m, rang, i); + for (i = rang + 1; i < nblignes; i++) + if ((((m->lignes)[i])[j]).vect[(cl) / WL] & MMC[(cl) % WL]) + XorVect (m, i, rang, 0, m->t); + + rang++; + if (rang == nblignes) + return rang; + } + cl++; + } + j++; + } + return rang; +} + + +int SpecialGaussianElimination (Matrix * m, int nblignes, int l, int t, + int *indices) +{ + int i, j, cl, rang; + + rang = 0; + + j = 0; + while (j < t) { + cl = 0; + while (cl < l) { + /* On cherche dans la j-eme colonne, commencant a la */ + /* rang-eme ligne, la premiere entree dont le bit le plus */ + /* significatif est non nul. Bref, on cherche un pivot. */ + i = rang; + while ((i < nblignes) + && ((((m->lignes)[i])[indices[j]]).vect[(cl) / WL] < + MMC[(cl) % WL])) + i++; + if (i < nblignes) { /* pivot trouve ... */ + ExchangeVect (m, rang, i); + for (i = rang + 1; i < nblignes; i++) + if ((((m->lignes)[i])[indices[j]]).vect[(cl) / + WL] & MMC[(cl) % WL]) + XorVect (m, i, rang, 0, m->t); + + rang++; + if (rang == nblignes) + return rang; + } + cl++; + } + j++; + } + return rang; +} + + +void MultMatrixByBV (BitVect * A, Matrix * M, BitVect * B) +{ + int i, j, res; + if (M->l < B->n * WL) { + printf ("Error in MultMatrixByBV(): sizes do not match\n"); + exit (1); + } + if (A->n * WL < M->nblignes) { + printf ("Error in MultMatrixByBV(): sizes do not match\n"); + exit (1); + } + if (M->t != 1) { + printf ("Error in MultMatrixByBV(): Not implemented for M->t > 1\n"); + exit (1); + } + PutBVToZero (A); + for (i = 0; i < M->nblignes; i++) { + res = 0; + for (j = 0; j < M->l; j++) + res += ValBitBV (&(M->lignes[i][0]), j) * ValBitBV (B, j); + res %= 2; + PutBitBV (A, i, res); + } +} + + +/* ********************************************************************** */ +/* int GetBitBV (BitVect A, int noBit) */ +/* Fonction qui permet de prendre la valeur du noBit-ieme bit */ +/* (l'indexation commence au bit 0) */ +/* ********************************************************************** */ +int ValBitBV (BitVect * A, int noBit) +{ + int k; + unsigned long mask; + k = noBit / WL; + mask = 0x80000000UL >> (noBit - k * WL); + if (A->vect[k] & mask) + return 1; + else + return 0; +} + + +/* ********************************************************************** */ +/* void SetBitBV (BitVect A, int noBit, int valBit) */ +/* Fonction qui permet de rendre la valeur du noBit-ieme bit `a valBit */ +/* (l'indexation commence au bit 0) (valBit=1 ou valBit=0) */ +/* ********************************************************************** */ +void PutBitBV (BitVect * A, int noBit, int valBit) +{ + int k; + unsigned long mask; + + k = noBit / WL; + if (valBit == 1) { + mask = 0x80000000UL >> (noBit - k * WL); + A->vect[k] |= mask; + } else { + mask = 0xffffffffUL ^ (0x80000000UL >> (noBit - k * WL)); + A->vect[k] &= mask; + } +} + + +/* ********************************************************************** */ +/* SetBVToZero( BitVect A) */ +/* Initialise le vecteur de bit a zero */ +/* ********************************************************************** */ +void PutBVToZero (BitVect * A) +{ + int i; + for (i = 0; i < A->n; i++) + A->vect[i] = 0UL; +} + + +/* ********************************************************************** */ +/* void CopyBV(BitVect A, BitVect B) */ +/* Copie le contenu de B dans A (A=B) */ +/* ********************************************************************** */ +void CopyBV (BitVect * A, BitVect * B) +{ + int i; + + if (A->n != B->n) { + printf + ("Error in CopyBV(): vectors of different dimensions! (%d and %d bits)\n", + A->n * WL, B->n * WL); + exit (1); + } + + if (B->n == 0) { + printf ("Nothing to copy!\n"); + exit (1); + } + for (i = 0; i < B->n; i++) + A->vect[i] = B->vect[i]; +} +void CopyBVPart (BitVect * A, BitVect * B, int l) +{ + + int i, n; + + n = (l - 1) / WL + 1; + + if (A->n < n) { + printf ("Error in CopyBVPart() : The vector A is not large enough!\n"); + exit (1); + } + if (B->n == 0) { + printf ("Nothing to copy!\n"); + exit (1); + } + + for (i = 0; i < n; i++) + A->vect[i] = B->vect[i]; + + if (l % WL) { + BitVect m; + AllocBV (&m, A->n * WL); + Mask (&m, l); + ANDBVSelf (A, &m); + FreeBV (&m); + } +} + + +/* ********************************************************************** */ +/* void EgalBV(BitVect A, BitVect B) */ +/* Compare le contenu de B avec celui de A. Retourne TRUE si les deux */ +/* contiennent la meme information. */ +/* ********************************************************************** */ +lebool CompareBV (BitVect * A, BitVect * B) +{ + + int i; + + if (A->n != B->n) { + printf ("Error in EgalBV(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < A->n; i++) + if (A->vect[i] != B->vect[i]) + return FALSE; + return TRUE; +} + + +lebool BVisZero (BitVect * A) +{ + int j = 0; + while (j < A->n) + if (A->vect[j++] != 0UL) + return FALSE; + return TRUE; +} + + +/* ********************************************************************** */ +/* void XORBV(BitVect A, BitVect B, BitVect C) */ +/* Cette fonction effectue A = B ^ C */ +/* ********************************************************************** */ +void XORBV (BitVect * A, BitVect * B, BitVect * C) +{ + + int i; + + if ((A->n != B->n) || (B->n != C->n)) { + printf ("Error in XORBV(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < B->n; i++) + A->vect[i] = B->vect[i] ^ C->vect[i]; +} + + +/* ********************************************************************** */ +/* void XOR2BV(BitVect A, BitVect B, BitVect C, BitVect D) */ +/* Cette fonction effectue A = B ^ C ^ D */ +/* ********************************************************************** */ +void XOR2BV (BitVect * A, BitVect * B, BitVect * C, BitVect * D) +{ + + int i; + + if ((A->n != B->n) || (B->n != C->n) || (C->n != D->n)) { + printf ("Error in XOR2BV(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < B->n; i++) + A->vect[i] = B->vect[i] ^ C->vect[i] ^ D->vect[i]; +} + + +/* ********************************************************************** */ +/* void ANDBV(BitVect A, BitVect B, BitVect C) */ +/* Cette fonction effectue A = B & C */ +/* ********************************************************************** */ +void ANDBV (BitVect * A, BitVect * B, BitVect * C) +{ + + int i; + + if ((A->n != B->n) || (B->n != C->n)) { + printf ("Error in ANDBV(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < B->n; i++) + A->vect[i] = B->vect[i] & C->vect[i]; +} + + +void ANDBVMask (BitVect * A, BitVect * B, int t) +{ + int n, m, j; + if (A->n != B->n) { + printf ("Error in ANDBVMask(): Vectors of different sizes\n"); + exit (1); + } + + if (t > B->n * WL) + CopyBV (A, B); + else if (t == 0) + PutBVToZero (A); + else { + n = t / WL; + m = t - n * WL; + for (j = 0; j < n; j++) { + A->vect[j] = B->vect[j]; + + } + if (m != 0) { + A->vect[j] = B->vect[j] & (0xffffffffUL << (WL - m)); + j++; + } + /* printf("n=%d j=%d %d m=%d ",n,j,A->n,m); */ + for (; j < A->n; j++) { + A->vect[j] = 0UL; + } + } +} + + +void ANDBVInvMask (BitVect * A, BitVect * B, int t) +{ + int n, m, j; + if (A->n != B->n) { + printf ("Error in ANDBV(): Vectors of different sizes\n"); + exit (1); + } + if (t > B->n * WL) + PutBVToZero (A); + else if (t == 0) + CopyBV (A, B); + else { + n = t / WL; + m = t - n * WL; + for (j = 0; j < n; j++) + A->vect[j] = 0UL; + if (m == 0) + A->vect[j] = B->vect[j]; + else { + A->vect[j] = B->vect[j] & (0xffffffffUL >> m); + + } + j++; + for (; j < A->n; j++) + A->vect[j] = B->vect[j]; + } +} + + + + +/* ********************************************************************** */ +/* void ANDBVSelf(BitVect A, BitVect B) */ +/* Cette fonction effectue A &=B */ +/* ********************************************************************** */ +void ANDBVSelf (BitVect * A, BitVect * B) +{ + int i; + + if ((A->n != B->n)) { + printf ("Error in ANDBVSelf(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < B->n; i++) + A->vect[i] &= B->vect[i]; +} + + +/* ********************************************************************** */ +/* void XORBVSelf(BitVect A, BitVect B) */ +/* Cette fonction effectue A ^=B */ +/* ********************************************************************** */ +void XORBVSelf (BitVect * A, BitVect * B) +{ + int i; + + if ((A->n != B->n)) { + printf ("Error in XORBVSelf(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < B->n; i++) + A->vect[i] ^= B->vect[i]; +} + + +/* ********************************************************************** */ +/* void BVLShift( BitVect R, BitVect A, int n ) */ +/* Effectue : R = A << n ; */ +/* ********************************************************************** */ +void BVLShift (BitVect * R, BitVect * A, int n) +{ + int i; + int WLmn; + unsigned long temp; + + if ((R->n != A->n)) { + printf ("Error in BVLShift(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < A->n; i++) + R->vect[i] = A->vect[i]; + while (n >= 32) { + for (i = 1; i < A->n; i++) + R->vect[i - 1] = R->vect[i]; + R->vect[A->n - 1] = 0UL; + n -= 32; + } + if (n > 0) { + WLmn = WL - n; + R->vect[0] <<= n; + for (i = 1; i < A->n; i++) { + temp = R->vect[i] >> WLmn; + R->vect[i - 1] |= temp; + R->vect[i] <<= n; + } + } + +} + + +/* ********************************************************************** */ +/* void BVRShift( BitVect R, BitVect A, int n ) */ +/* Effectue : R = A >> n ; */ +/* ********************************************************************** */ +void BVRShift (BitVect * R, BitVect * A, int n) +{ + int i; + int WLmn; + unsigned long temp; + if ((R->n != A->n)) { + printf ("Error in BVRShift(): Vectors of different sizes\n"); + exit (1); + } + + for (i = 0; i < A->n; i++) + R->vect[i] = A->vect[i]; + while (n >= 32) { + for (i = A->n; i > 1; i--) + R->vect[i - 1] = R->vect[i - 2]; + R->vect[0] = 0UL; + n -= 32; + } + if (n > 0) { + WLmn = WL - n; + R->vect[A->n - 1] >>= n; + for (i = A->n - 2; i >= 0; i--) { + temp = R->vect[i] << WLmn; + R->vect[i + 1] |= temp; + R->vect[i] >>= n; + } + } +} + + +/* ********************************************************************** */ +/* void BVLShiftSelf( BitVect R, int n ) */ +/* Effectue : R <<= n ; */ +/* ********************************************************************** */ +void BVLShiftSelf (BitVect * R, int n) +{ + int i; + int WLmn; + unsigned long temp; + + while (n >= 32) { + for (i = 1; i < R->n; i++) + R->vect[i - 1] = R->vect[i]; + R->vect[R->n - 1] = 0UL; + n -= 32; + } + if (n > 0) { + WLmn = WL - n; + R->vect[0] <<= n; + for (i = 1; i < R->n; i++) { + temp = R->vect[i] >> WLmn; + R->vect[i - 1] |= temp; + R->vect[i] <<= n; + } + } +} + + +/* ********************************************************************** */ +/* void BVLS1Self( BitVect R ) */ +/* Effectue : R <<= 1 ; */ +/* Version specialisee de BVLShiftSelf pour utilisation frequente. */ +/* ********************************************************************** */ +void BVLS1Self (BitVect * R) +{ + int i; + R->vect[0] <<= 1; + for (i = 1; i < R->n; i++) { + if (R->vect[i] & MC) + R->vect[i - 1] |= 0x1UL; + R->vect[i] <<= 1; + } +} + + +/* ********************************************************************** */ +/* void BVRShiftSelf( BitVect R, int n ) */ +/* Effectue : R >>= n ; */ +/* ********************************************************************** */ +void BVRShiftSelf (BitVect * R, int n) +{ + int i; + int WLmn; + unsigned long temp; + + while (n >= 32) { + for (i = R->n - 1; i > 0; i--) + R->vect[i] = R->vect[i - 1]; + R->vect[0] = 0UL; + n -= 32; + } + if (n > 0) { + WLmn = WL - n; + R->vect[R->n - 1] >>= n; + for (i = R->n - 2; i >= 0; i--) { + temp = R->vect[i] << WLmn; + R->vect[i + 1] |= temp; + R->vect[i] >>= n; + } + } +} + + +/* ********************************************************************** */ +/* void invertBV(Bitvect A) */ +/* fait A ~=A */ +/* ********************************************************************** */ +void InverseBV (BitVect * A) +{ + int i; + for (i = 0; i < A->n; i++) + A->vect[i] = ~A->vect[i]; +} + + +/* ********************************************************************** */ +/* lebool CheckCD( BitVect ds1, BitVect ds2 ) */ +/* Verifie si les ensembles ds1 et ds2 ont des bits communs. */ +/* ********************************************************************** */ +lebool VerifBitsCommuns (BitVect * ds1, BitVect * ds2) +{ + int i; + unsigned long temp = 0UL; + if ((ds1->n != ds2->n)) { + printf ("Error in VerifBitsCommuns(): Vectors of different sizes\n"); + exit (1); + } + for (i = 0; i < ds1->n; i++) + temp |= (ds1->vect[i] & ds2->vect[i]); + if (temp) + return TRUE; + else + return FALSE; +} + + +/* -------------------------------------------- */ +/* Fonctions pour la manipulation des matrices. */ +/* -------------------------------------------- */ +void BVCanonic (BitVect * A, int l) +{ + int n; + PutBVToZero (A); + n = l / WL; + if (n > A->n) { + printf + ("Error in BVCanonic(): vector A is not long enough to store BVCanonic[%d].\n", + l); + exit (1); + } + A->vect[n] = 0x80000000UL >> (l - n * WL); +} + +void Mask (BitVect * A, int l) +{ + + InvMask (A, l); + InverseBV (A); +} + +void InvMask (BitVect * A, int l) +{ + AllOnes (A); + BVRShiftSelf (A, l); +} + +void AllOnes (BitVect * A) +{ + int i; + for (i = 0; i < A->n; i++) + A->vect[i] = 0xffffffffUL; +} + +void AllocBV (BitVect * A, int l) +{ + int n; + n = (l - 1) / WL + 1; + A->vect = (unsigned long *) calloc ((size_t) n, sizeof (unsigned long)); + A->n = n; +} + +void FreeBV (BitVect * A) +{ + if (A->vect != NULL) { + free (A->vect); + } + A->n = 0; +} + +void AllocMat (Matrix * m, int nblines, int l, int t) +{ + int i, j; + m->lignes = (BitVect **) calloc ((size_t) nblines, sizeof (BitVect *)); + for (i = 0; i < nblines; i++) { + if (!(m->lignes[i] = (BitVect *) calloc ((size_t) t, sizeof (BitVect)))) { + printf ("\n*** Memoire insuffisante pour AllocMat() ! nl=%d***\n", + nblines); + exit (1); + } + for (j = 0; j < t; j++) + AllocBV (&(m->lignes[i][j]), l); + + } + m->nblignes = nblines; + m->t = t; + m->l = l; + +} + + +/* ********************************************************************** */ +/* void FreeSpace( Matrix m, int nl ) */ +/* Libere l'espace des nl vecteurs de la matrice m. */ +/* ********************************************************************** */ +void FreeMat (Matrix * m) +{ + int i, j; + for (i = 0; i < m->nblignes; i++) { + for (j = 0; j < m->t; j++) + FreeBV (&(m->lignes[i][j])); + free (m->lignes[i]); + } + free (m->lignes); + m->nblignes = 0; + m->l = 0; + m->t = 0; + +} + + +/* ********************************************************************** */ +/* void CopyMat( Matrix m, Matrix ms, int nl, int t ) */ +/* Cette procedure sert a copier les t premiers BitVect des nl premieres */ +/* lignes de la matrice ms dans la matrice de travail m. */ +/* ********************************************************************** */ +void CopyMat (Matrix * m, Matrix * ms, int nl, int t) +{ + int i, j; + if (m == NULL) { + AllocMat (m, ms->nblignes, ms->l, ms->t); + } else if ((ms->nblignes < nl) || (ms->t < t)) { + printf ("Error in CopyMat(): source matrix too small %d\n", + ms->nblignes / ms->t); + exit (1); + } else if ((m->nblignes < nl) || (m->t < t)) { + printf ("Error in CopyMat(): destination matrix too small\n"); + exit (1); + } + for (i = 0; i < nl; i++) + for (j = 0; j < t; j++) { + CopyBV (&(m->lignes[i][j]), &(ms->lignes[i][j])); + } +} + + +/* ********************************************************************** */ +/* void CopyNTupleMat( Matrix m, Matrix ms, int nl, */ +/* int *colonnes, int t ) */ +/* Cette procedure sert a copier les t-1 BitVect indiqu'es par le vecteur */ +/* *colonnes plus la colonne 0 des nl premieres lignes de la matrice ms */ +/* dans la matrice de travail m. */ +/* ********************************************************************** */ +void CopyNTupleMat (Matrix * m, Matrix * ms, int nl, int *colonnes, int t) +{ + + int i, j, k, n; + + if (m == NULL) + AllocMat (m, ms->nblignes, ms->l, t); + else { + if ((ms->nblignes != m->nblignes) || (ms->l != m->l)) + printf ("Error in CopieNTupleMat(): matrices of different sizes\n"); + } + n = (ms->l - 1) / WL; + for (i = 0; i < nl; i++) { + for (k = 0; k <= n; k++) + (m->lignes[i])[0].vect[k] = (ms->lignes[i])[0].vect[k]; + for (j = 1; j < t; j++) + for (k = 0; k <= n; k++) + (m->lignes[i])[j].vect[k] = + (ms->lignes[i])[colonnes[j - 1]].vect[k]; + + } +} + + +/* ********************************************************************** */ +/* void SwapVect( Matrix m, int i, int j ) */ +/* Pour interchanger les lignes i et j de la matrice de travail m. */ +/* ********************************************************************** */ +void ExchangeVect (Matrix * m, int i, int j) +{ + BitVect *p; + if (i != j) { + p = m->lignes[i]; + m->lignes[i] = m->lignes[j]; + m->lignes[j] = p; + } +} + + +void TransposeMatrices (Matrix * T, Matrix * M, int mmax, int smax, int L) +{ + + int s, l, m; + + for (s = 0; s < smax; s++) + for (l = 0; l < L; l++) { + PutBVToZero (&T->lignes[l][s]); + for (m = 0; m < mmax; m++) { + /* printf("m=%d l=%d s=%d\n",m,l,s);fflush(stdout); */ + if (M->lignes[m][s].vect[0] & (0x80000000UL >> l)) { + T->lignes[l][s].vect[0] |= (0x80000000UL >> m); + } + } + } +} + + +/* ********************************************************************** */ +/* void XorVect( Matrix m, */ +/* int r, int s, int min, int max ) */ +/* Effectue un Xor entre la s-eme et la r-eme ligne de la matrice de */ +/* travail m pour les colonnes (BitVect) min a max-1 seulement. */ +/* Le resultat est mis dans la r-eme ligne. ( m[r] ^= m[s] ) */ +/* ********************************************************************** */ +void XorVect (Matrix * m, int r, int s, int min, int max) +{ + int j; + for (j = min; j < max; j++) + XORBVSelf (&(m->lignes[r][j]), &(m->lignes[s][j])); +} + + +/* ********************************************************************** */ +/* void displaymat(Matrix m, int t, int l, int kg) */ +/* Affiche la matrice m sur kg lignes par t x l colonnes */ +/* ********************************************************************** */ +void DispMat (Matrix * m, int t, int l, int kg, lebool mathematica) +{ + int i, j; + + i = kg; + + printf ("\n"); + if (mathematica) + printf ("{"); + for (i = 0; i < kg; i++) { + if (!mathematica) + printf ("["); + for (j = 0; j < t; j++) { + DispBitVect (&(m->lignes[i][j]), l, mathematica); + } + if (mathematica) { + if (i != kg - 1) + printf (",\n"); + else + printf ("}\n"); + } else + printf ("]\n"); + } + printf ("\n\n"); + +} + + +/* ********************************************************************** */ +/* void displaybitvect(BitVect A, int l) */ +/* Affiche le BitVect A sur l bits seulement */ +/* ********************************************************************** */ +void DispBitVect (BitVect * A, int l, int mathematica) +{ + int j; + unsigned Un; + Un = 1UL; + j = 0; + if (mathematica) { + printf ("{"); + while (j < l - 1) { + printf ("%ld,", + (A->vect[j / WL] >> (((WL * A->n) - j - 1) % WL)) & Un); + j++; + } + printf ("%ld}", (A->vect[j / WL] >> (((WL * A->n) - j - 1) % WL)) & Un); + } else + while (j < l) { + printf ("%ld", + (A->vect[j / WL] >> (((WL * A->n) - j - 1) % WL)) & Un); + j++; + } +} + + +/* ********************************************************************** */ +/* MultMatrixByMatrix ( Matrix *A, Matrix *B, Matrix *C) */ +/* Fait la multiplication matricielle A = B x C */ +/* ********************************************************************** */ + +void MultMatrixByMatrix (Matrix * A, Matrix * B, Matrix * C) +{ + int i, j; + if (B->l != C->nblignes) { + printf ("Tailles de matrices non-compatibles, kaput.\n"); + exit (1); + } + + if (A->nblignes != B->nblignes || A->l != C->l) { + printf ("Matrice preallouee de mauvaise taille.\n"); + exit (1); + } + + for (i = 0; i < A->nblignes; i++) + PutBVToZero (A->lignes[i]); + + for (i = 0; i < B->nblignes; i++) + for (j = 0; j < B->l; j++) { + if (ValBitBV (B->lignes[i], j)) + XORBVSelf (A->lignes[i], C->lignes[j]); + } +} + + +/* ********************************************************************** */ +/* MatrixTwoPow ( Matrix *A, Matrix *B, unsigned int e) */ +/* Fait l'exponentiation : A = B^(2^e) */ +/* ********************************************************************** */ + +void MatrixTwoPow (Matrix * A, Matrix * B, unsigned int e) +{ + unsigned int i; + Matrix tempMatrix; + Matrix *AA = &tempMatrix; + + if (B->nblignes != B->l) { + printf ("Matrice non carree.\n"); + exit (1); + } + if (A->nblignes != B->nblignes || A->l != B->l) { + printf ("Matrice preallouee de mauvaise taille.\n"); + exit (1); + } + + AllocMat (AA, B->nblignes, B->l, 1); + + if (e == 0) { + CopyMat (A, B, B->nblignes, 1); + return; + } + /* A = B^(2^1) */ + MultMatrixByMatrix (A, B, B); + + for (i = 1; i < e - 1; i += 2) { + /* AA = A * A */ + MultMatrixByMatrix (AA, A, A); + + /* A = AA * AA */ + MultMatrixByMatrix (A, AA, AA); + } + + if (i == e - 1) { + /* AA = A * A */ + MultMatrixByMatrix (AA, A, A); + CopyMat (A, AA, AA->nblignes, 1); + } + + FreeMat (AA); +} + +/* ********************************************************************** */ +/* MatrixPow ( Matrix *A, Matrix *B, unsigned int e) */ +/* Fait l'exponentiation : A = B^e */ +/* ********************************************************************** */ + +#ifdef USE_LONGLONG +void MatrixPow (Matrix * A, Matrix * B, longlong e) +#else +void MatrixPow (Matrix * A, Matrix * B, long e) +#endif +{ + int i; + Matrix C; + Matrix D; + + if (B->nblignes != B->l) { + printf ("Matrice non carree.\n"); + exit (1); + } + + if (A->nblignes != B->nblignes || A->l != B->l) { + printf ("Matrice preallouee de mauvaise taille.\n"); + exit (1); + } + + AllocMat (&C, B->nblignes, B->l, 1); + + if (e < 0) { + InverseMatrix (&C, B); + MatrixPow (A, &C, -e); + FreeMat (&C); + return; + } + AllocMat (&D, B->nblignes, B->l, 1); + + /* A = I */ + for (i = 0; i < A->nblignes; i++) + BVCanonic (A->lignes[i], i); + + /* C = B^1 */ + CopyMat (&C, B, B->nblignes, 1); + + while (e) { + if (e & 1) { + CopyMat (&D, A, B->nblignes, 1); + MultMatrixByMatrix (A, &D, &C); + } + + e >>= 1; + + if (e) { + CopyMat (&D, &C, B->nblignes, 1); + MultMatrixByMatrix (&C, &D, &D); + } + } + + FreeMat (&C); + FreeMat (&D); +} + + +/* FIN vectorsF2.c */ diff --git a/TESTU01/TestU01-1.2.3/testu01/vectorsF2.tex b/TESTU01/TestU01-1.2.3/testu01/vectorsF2.tex new file mode 100644 index 0000000..7d8b09c --- /dev/null +++ b/TESTU01/TestU01-1.2.3/testu01/vectorsF2.tex @@ -0,0 +1,594 @@ +\defmodule{vectorsF2} +This module contains many functions that manipulates vectors and + matrices of bits. + +\bigskip\hrule + +\code\hide +#ifndef VECTORSF2_H +#define VECTORSF2_H +\endhide +#include "gdef.h" +\endcode +\code + +#define vectorsF2_WL 32 +\endcode + \tab +Uses computer word of 32 bits. + \endtab +\bigskip + + + +\guisec{\bf \large Operations on bit vectors} + +\code + +typedef struct{ + int n; + unsigned long *vect; +} BitVect; +\endcode + + \tab +The {\tt BitVect} type contains a bit vector of + {\tt n}*{\tt vectorsF2\_WL} bits. Storage space for +the {\tt BitVect} is allocated with the function {\tt AllocBV()}. + \endtab +\code + + +void AllocBV ( BitVect *A, + int l + ); +\endcode + \tab +Function that allocates a {\tt BitVect} of {\tt l} bits. + \endtab +\code + + +void FreeBV ( BitVect *A + ); +\endcode + \tab +Function that frees the space taken by the {\tt BitVect} pointed by {\tt A}. + \endtab +\code + + +void BVCanonic ( BitVect *B, + int t + ); +\endcode + \tab +Function that fills {\tt B} with the $({\tt t}+1)^{\mbox{th}}$ unit vector. + \endtab +\code + + +void AllOnes ( BitVect *B + ); +\endcode + \tab +Function that fills the vector {\tt B} with the bit vector (1, 1, 1, 1,.. , 1). + \endtab +\code + + +void Mask ( BitVect *B, + int t + ); +void InvMask ( BitVect *B, + int t + ); +\endcode + \tab +The function {\tt Mask()} fills the {\tt BitVect} pointed by {\tt B} with a vector composed of {\tt t} ones followed by zeros. +The function {\tt InvMask()} fills the{\tt BitVect} pointed by {\tt B} with a vector composed of {\tt t} zeros followed by ones. + \endtab +\code + + +lebool BVisZero ( BitVect *A + ); +\endcode + \tab +Function that returns {\tt TRUE} if the {\tt BitVect} pointed by {\tt A} is a zero bit vector. Returns {\tt FALSE} otherwise. +\endtab +\code + + +int ValBitBV ( BitVect *A, + int noBit + ); +\endcode + \tab +Returns the value of the {\tt noBit}$^{\mbox{th}}$ bit (the indexation goes from left to right and starts at 0) of the +{\tt BitVect} pointed by {\tt A}. + \endtab +\code + + +void PutBitBV ( BitVect *A, + int noBit, + int valBit + ); +\endcode + \tab +Puts the value of the {\tt noBit}$^{\mbox{th}}$ bit of the {\tt BitVect} pointed by {\tt A} +to {\tt valBit} which can be 0 or 1 (the indexation goes from left to right and starts at 0). + \endtab +\code + + +void PutBVToZero ( BitVect *A + ); +\endcode + \tab +Initializes the {\tt BitVect} pointed by {\tt A} to zero. + \endtab +\code + + +void CopyBV ( BitVect *A, + BitVect *B + ); + \endcode + \tab +Copies the content of {\tt B} into {\tt A} ({\tt A=B}). + \endtab +\code + + +void CopyBVPart ( BitVect *A, + BitVect *B, + int l + ); +\endcode + \tab +Copies the first {\tt l} bits of {\tt B} into {\tt A}. + \endtab +\code + + +lebool CompareBV ( BitVect *A, + BitVect *B + ); +\endcode + \tab +Compares the content of {\tt B} and {\tt A}. Returns {\tt TRUE} if it is the same, {\tt FALSE} otherwise. + \endtab +\code + + +void XORBV ( BitVect *A, + BitVect *B, + BitVect *C + ); +\endcode + \tab +This function does {\tt A} = {\tt B} \verb1^1 {\tt C}. + \endtab +\code + + +void XOR2BV ( BitVect *A, + BitVect *B, + BitVect *C, + BitVect *D + ); +\endcode + \tab +This function does {\tt A} = {\tt B} \verb1^1 {\tt C} \verb1^1 {\tt D}. + \endtab +\code + + +void ANDBV ( BitVect *A, + BitVect *B, + BitVect *C + ); +\endcode + \tab +This function does {\tt A} = {\tt B} \& {\tt C}. + \endtab +\code + + +void ANDBVSelf ( BitVect *A, + BitVect *B + ); +\endcode + \tab +This function does {\tt A} = {\tt A} \& {\tt B}. + \endtab +\code + + +void ANDBVMask ( BitVect *A, + BitVect *B, + int t + ); +\endcode + \tab +Applies the mask composed of {\tt t} ones followed by zeros to the bit vector pointed by {\tt B} +and puts the result in the bit vector pointed by {\tt A}. +\endtab +\code + + +void ANDBVInvMask ( BitVect *A, + BitVect *B, + int t + ); +\endcode + \tab +Applies the mask composed of {\tt t} zeros followed by ones to the bit vector pointed by {\tt B} +and puts the result in the bit vector pointed by {\tt A}. + \endtab +\code + + +void XORBVSelf ( BitVect *A, + BitVect *B + ); +\endcode + \tab +This function does {\tt A} = {\tt A} \verb1^1 {\tt B}. + \endtab +\code + + +void BVLShift ( BitVect *R, + BitVect *A, + int n + ); +\endcode + \tab +This function does {\tt R} = {\tt A} $\ll$ {\tt n}. + \endtab +\code + + +void BVRShift ( BitVect *R, + BitVect *A, + int n + ); +\endcode + \tab +This function does {\tt R} = {\tt A} $\gg$ {\tt n}. + \endtab +\code + + +void BVLShiftSelf ( BitVect *R, + int n + ); +\endcode + \tab +This function does {\tt R} = {\tt R} $\ll$ {\tt n}. + \endtab +\code + + +void BVLS1Self ( BitVect *R + ); +\endcode + \tab +This function does {\tt R} = {\tt R} $\ll$ {\tt 1}. + \endtab +\code + + +void BVRShiftSelf ( BitVect *R, + int n + ); +\endcode + \tab +This function does {\tt R} = {\tt R} $\gg$ {\tt n}. + \endtab +\code + + +void InverseBV ( BitVect *A + ); +\endcode + \tab +Invert the value of all the bits of {\tt A} (i.e. {\tt A} = \~ {\tt A}). + \endtab +\code + + +void DispBitVect ( BitVect *A, + int l, + int mathematica + ); +\endcode + \tab +Displays the bit vector {\tt A} on {\tt l} bits only. If {\tt mathematica} is set to TRUE, then the display will be compatible with +Mathematica input. + \endtab +\code + + +void RandVect ( BitVect *v + ); +\endcode + \tab +Fills the vector {\tt v} with random bits. + \endtab +\code + + +lebool VerifBitsCommuns ( BitVect *ds1, + BitVect *ds2 + ); +\endcode + \tab +Returns {\tt TRUE} if at least one bit set to 1 in {\tt ds1} is also set to 1 in {\tt ds2}. +Returns {\tt FALSE} otherwise. + \endtab + +\guisec{\bf \large Operations on matrices} +\code + + +typedef struct{ + BitVect **lignes; + int nblignes; + int t; + int l; +} Matrix; +\endcode + \tab +The variable {\tt lignes} contains a 2-dimensional array of {\tt l}-bit vectors ({\tt BitVect}). +This array has {\tt nblignes} rows and {\tt t} columns. We allocate the storage space for +the {\tt Matrix} with the function {\tt AllocMat()}. + \endtab + +\code + + +void AllocMat ( Matrix* m, + int nblines, + int l, + int t + ); +\endcode + \tab +Function that allocates a {\tt Matrix} with {\tt nblines} lines and {\tt t*l} columns. +On each line, the function allocates {\tt t} spaces for {\tt BitVect}s of {\tt l} bits. +To allocate a simple 32 $\times$ 32 bit matrix, call +{\tt AllocMat (m,32,32,1)}. This way of structuring matrices is useful for modules like mecf. + \endtab + +\code + + +void FreeMat ( Matrix *m + ); +\endcode + \tab +Frees the space taken by the matrix pointed by {\tt m}. + \endtab + +\code + + +void CopyMat ( Matrix *m, + Matrix *ms, + int nl, + int t + ); +\endcode + \tab +Copies the first {\tt t} {\tt BitVect}s of the first {\tt nl} lines of the matrix {\tt ms} into the +first {\tt t} {\tt BitVect}s of the first {\tt nl} lines of the matrix {\tt m}. + \endtab + +\code + + +void CopyNTupleMat ( Matrix *m, + Matrix *ms, + int nl, + int *colonnes, + int t + ); +\endcode + \tab +Copies the ({\tt t}-1) {\tt BitVect}s indicated by the array {\tt colonnes}, plus the first {\tt BitVect}, on each of the +{\tt nl} first lines of the matrix {\tt ms} to the first {\tt t} {\tt BitVect}s on each of the first {\tt nl} +lines of the matrix {\tt m}. + \endtab +\code + + +lebool Diag ( Matrix *m, + int kg, + int t, + int l, + int *gr + ); +\endcode + \tab +Function that Diagonalizes the matrix pointed by {\tt m}. In fact, it diagonalizes only the sub matrix consisting +of only the first {\tt kg} lines and the first {\tt l} bits of the first {\tt t} {\tt BitVect}s on each line. +The function returns {\tt TRUE} if the sub matrix is of full rank {\tt t}*{\tt l}. In this case, the variable pointed by {\tt gr} +stays unchanged. Otherwise, it returns FALSE and the variable pointed by {\tt gr} is changed to the value of {\tt t} for which +the function would have returned {\tt TRUE}. + \endtab + +\code + + +int GaussianElimination ( Matrix *m, + int nblignes, + int l, + int t + ); +\endcode + \tab +Function that returns the rank of a sub matrix pointed by {\tt m}. This sub matrix is +composed of the first {\tt nblines} lines and the first {\tt l} bits of the first {\tt t} {\tt BitVect}s on each line. + \endtab + +\code + + +int CompleteElimination ( Matrix *m, + int nblignes, + int l, + int t + ); +\endcode + \tab +This function tries to form an identity matrix by elimination. +It returns the rank of a sub matrix pointed by {\tt m}. This sub matrix is +composed of the first {\tt nblines} lines and the first {\tt l} bits of the first {\tt t} {\tt BitVect}s on each line. + \endtab + + +\code + + +int SpecialGaussianElimination ( Matrix *m, + int nblignes, + int l, + int t, + int *indices + ); +\endcode + \tab +Function that returns the rank of a sub matrix of the {\tt Matrix} pointed by {\tt m}. This sub matrix is +composed of the first {\tt nblines} lines and the first {\tt l} bits of the {\tt BitVect}s +indicated by the array {\tt indices}. + \endtab + +\code + + +void MultMatrixByBV ( BitVect *A, + Matrix *m, + BitVect *B + ); +\endcode + \tab +Function that puts in the {\tt BitVect} pointed by {\tt A} the product {\bf m} $\times$ {\tt B}. + \endtab + +\code + + +void TransposeMatrices ( Matrix *T, + Matrix *M, + int nblines, + int t, + int l + ); +\endcode + \tab +Function that transpose the {\tt t} matrices of dimension {\tt nblines}$\times$ +{\tt l} found in {\tt M} and put the result in {\tt T}. + \endtab + +\code + + +void ExchangeVect ( Matrix *m, + int i, + int j + ); +\endcode + \tab +Interchange the lines {\tt i} et {\tt j} of the matrix {\tt *m}. + \endtab + +\code + + +void XorVect ( Matrix *m, + int r, + int s, + int min, + int max + ); +\endcode + \tab +Does a exclusive-OR between the {\tt s}$^{\mbox{th}}$ and {\tt r}$^{\mbox{th}}$ line of the matrix {\tt m} +for the {\tt min}$^{\mbox{th}}$ to the ({\tt max}-1)$^{\mbox{th}}$ {\tt BitVect}s only. The result is put in +the {\tt r}$^{\mbox{th}}$ line of the matrix. ({\tt m[r]} = {\tt m[r]} \verb1^1 {\tt m[s]}) + \endtab +\code + + +void DispMat ( Matrix *m, + int t, + int l, + int nblines, + lebool mathematica + ); +\endcode + \tab +Displays the sub matrix of {\tt *m} defined by the first {\tt nblines} lines and the first {\tt l} bits of the first +{\tt t} {\tt BitVect}s. If {\tt mathematica} is set to TRUE, then the display will be compatible with +Mathematica input. + \endtab +\code + + +lebool InverseMatrix ( Matrix *MInv, + Matrix *M + ); +\endcode +\tab +Function that puts in the {\tt Matrix} pointed by {\tt MInv} the inverse of the {\tt Matrix} pointed by {\tt M}. +The sub matrices of the {\tt Matrix}s pointed by {\tt M} and {\tt MInv} that are considered are the ones composed of +the first column of {\tt BitVect}s. +\endtab +\code + + +void MultMatrixByMatrix ( Matrix *A, + Matrix *B, + Matrix *C + ); +\endcode +\tab +Function that puts in the {\tt Matrix} pointed to by {\tt A} the result of the +multiplication of {\tt B} and {\tt C} ($A = B \times C$). +Only the first submatrices are considered. +\endtab +\code + + +void MatrixTwoPow ( Matrix *A, + Matrix *B, + unsigned int e + ); +\endcode +\tab +Function that puts in the {\tt Matrix} pointed to by {\tt A} the {\tt Matrix} +{\tt B} raised to the power $2^{e}$ ($A = B^{2^{e}}$). +\endtab +\code + +#ifdef USE_LONGLONG + void MatrixPow (Matrix * A, Matrix * B, longlong e); +#else + void MatrixPow (Matrix * A, Matrix * B, long e); +#endif +\endcode +\tab +Function that puts in the {\tt Matrix} pointed to by {\tt A} the {\tt Matrix} +{\tt B} raised to the power $e$ ($A = B^{e}$). +The exponent $e$ can be negative, in which case, the inverse $B^{-1}$ + will be raised to the power $|e|$. +\endtab +\code +\hide +#endif +\endhide +\endcode