# HG changeset patch # User jwe # Date 1076963540 0 # Node ID adf8d68d71438b8b394cbbce59e817a557db5ecd # Parent 88b638195bd1d4ed1f3be0ea7a73e6d5a1407c3e [project @ 2004-02-16 20:32:20 by jwe] diff -r 88b638195bd1 -r adf8d68d7143 src/ChangeLog --- a/src/ChangeLog Mon Feb 16 19:57:06 2004 +0000 +++ b/src/ChangeLog Mon Feb 16 20:32:20 2004 +0000 @@ -3,6 +3,26 @@ * version.h (OCTAVE_VERSION): Now 2.1.54. (OCTAVE_API_VERSION): Now api-v5. + * Makefile.in (DLD_XSRC): Always include fftw_wisdom.cc. + + * DLD-FUNCTIONS/fftw_wisdom.cc: + Rename from DLD-FUNCTIONS/fft_wisdom.cc. + (Vfftw_wisdom_prog): Delete extern decl. + (Ffftw_wisdom): Rename from Ffft_wisdom. + Use Vfftw_wisdom_prog instead of Vwisdom_prog. + Always define function. Signal error if not configured to use FFTW3. + + * defaults.cc (symbols_of_defaults): Rename WISDOM_PROGRAM to be + FFTW_WISDOM_PROGRAM. + (Vfftw_wisdom_prog): Rename from Vwisdom_prog. + (fftw_wisdom_program): Rename from wisdom_program. + For simplicity, always define FFTW_WISDOM_PROGRAM even when not + using fftw3. + (set_default_wisdom_prog): Look for OCTAVE_FFTW_WISDOM_PROGRAM in + the environment instead of OCTAVE_WISDOM_PROGRAM. + (set_default_fftw_wisdom_prog): Rename from set_default_wisdom_prog. + * defaults.h.in (Vfftw_wisdom_prog): Provide extern decl. + 2004-02-16 David Bateman * DLD-FUNCTIONS/fft.cc: Adapt for Nd arrays, combine with ifft.cc. diff -r 88b638195bd1 -r adf8d68d7143 src/DLD-FUNCTIONS/fft_wisdom.cc --- a/src/DLD-FUNCTIONS/fft_wisdom.cc Mon Feb 16 19:57:06 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/* - -Copyright (C) 2004 David Bateman - -This file is part of Octave. - -Octave 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. - -Octave 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 Octave; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "file-ops.h" -#include "lo-sstream.h" -#include "oct-env.h" -#include "defaults.h" -#include "lo-mappers.h" -#include "defun-dld.h" -#include "error.h" -#include "gripes.h" -#include "oct-obj.h" -#include "utils.h" -#include "sighandlers.h" - -// Name of the FFTW wisdom program we'd like to use. -extern std::string Vwisdom_prog; - -DEFUN_DLD (fft_wisdom, args, , - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} fft_wisdom (@var{file}, @var{ow})\n\ -@deftypefnx {Loadable Function} {} fft_wisdom (@var{n})\n\ -\n\ -This function is used to manipulate the FFTW wisdom data. It can\n\ -be used to load previously stored wisdom from a file, create wisdom\n\ -needed by Octave and to save the current wisdom to a file. Wisdom\n\ -data can be used to significantly accelerate the calculation of the FFTs,\n\ -but is only profitable if the same FFT is called many times due to the\n\ -overhead in calculating the wisdom data.\n\ -\n\ -Called with a single string argument, @code{fft_wisdom (@var{file})}\n\ -will load the wisdom data found in @var{file}. If @var{file} does\n\ -not exist, then the current wisdom used by FFTW is saved to this\n\ -file. If the flag @var{ow} is non-zero, then even if @var{file}\n\ -exists, it will be overwritten.\n\ -\n\ -It is assumed that each row of @var{n} represents the size of a FFT for\n\ -which it is desired to pre-calculate the wisdom needed to accelerate it.\n\ -Any value of the matrix that is less than 1, is assumed to indicate an\n\ -absent dimension. That is\n\ -\n\ -@example\n\ -fftw_wisdom ([102, 0, 0; 103, 103, 0; 102, 103, 105]);\n\ -a = fft (rand (1,102));\n\ -b = fft (rand (103,103));\n\ -c = fftn (rand ([102, 103, 105]));\n\ -@end example\n\ -\n\ -calculates the wisdom necessary to accelerate the 103, 102x102 and\n\ -the 102x103x105 FFTs. Note that calculated wisdom will be lost when\n\ -when restarting Octave. However, if it is saved as discussed above, it\n\ -can be reloaded. Also, any system-wide wisdom file that has been found\n\ -will also be used. Saved wisdom files should not be used on different\n\ -platforms since they will not be efficient and the point of calculating\n\ -the wisdom is lost.\n\ -\n\ -Note that the program @code{fftw-wisdom} supplied with FFTW can equally\n\ -be used to create a file containing wisdom that can be imported into\n\ -Octave.\n\ -@end deftypefn\n\ -@seealso {fft, ifft, fft2, ifft2, fftn, ifftn}") -{ - octave_value retval; - int nargin = args.length(); - - if (nargin < 1 || nargin > 2) - { - print_usage ("fft_wisdom"); - return retval; - } - - if (args(0).is_string ()) - { - bool overwrite = false; - - if (nargin != 1) - { - double dval = args (1).double_value (); - if (NINT (dval) != 0) - overwrite = true; - } - - std::string wisdom = octave_env::make_absolute - (Vload_path_dir_path.find_first_of (args(0).string_value ().c_str ()), - octave_env::getcwd ()); - - if (wisdom.empty () || overwrite) - { - FILE *ofile = fopen (wisdom.c_str (), "wb"); - fftw_export_wisdom_to_file (ofile); - fclose (ofile); - } - else - { - FILE *ifile = fopen (wisdom.c_str (), "r"); - if (! fftw_import_wisdom_from_file (ifile)) - error ("fft_wisdom: can not import wisdom from file"); - fclose (ifile); - } - - } - else - { - Matrix m = args (0).matrix_value (); - - if (error_state) - { - error ("fft_wisdom: argument must be a matrix or a string"); - return retval; - } - - std::string name = file_ops::tempnam ("", "oct-"); - - if (name.empty ()) - { - error ("fft_wisdom: can not open temporary file"); - return retval; - } - - OSSTREAM cmd_buf; - cmd_buf << Vwisdom_prog << " -n -o \"" << name << "\""; - - for (int k = 0; k < m.rows (); k++) - { - bool first = true; - - cmd_buf << " "; - - // Note reversal of dimensions for column major storage in FFTW - for (int j = m.columns()-1; j >= 0; j--) - if (NINT(m(k,j)) > 0) - { - if (first) - first = false; - else - cmd_buf << "x"; - cmd_buf << NINT(m(k,j)) ; - } - } - - cmd_buf << OSSTREAM_ENDS; - - volatile octave_interrupt_handler old_interrupt_handler - = octave_ignore_interrupts (); - - int status = system (OSSTREAM_C_STR (cmd_buf)); - - OSSTREAM_FREEZE (cmd_buf); - - octave_set_interrupt_handler (old_interrupt_handler); - - if (WIFEXITED (status)) - { - FILE *ifile = fopen (name.c_str (), "r"); - if (! fftw_import_wisdom_from_file (ifile)) - error ("fft_wisdom: can not import wisdom from temporary file"); - fclose (ifile); - } - else - error ("fft_wisdom: error running %s", Vwisdom_prog.c_str ()); - - } - - return retval; -} diff -r 88b638195bd1 -r adf8d68d7143 src/DLD-FUNCTIONS/fftw_wisdom.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/DLD-FUNCTIONS/fftw_wisdom.cc Mon Feb 16 20:32:20 2004 +0000 @@ -0,0 +1,198 @@ +/* + +Copyright (C) 2004 David Bateman + +This file is part of Octave. + +Octave 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. + +Octave 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 Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if defined (HAVE_FFTW3) +#include +#endif + +#include "defaults.h" +#include "defun-dld.h" +#include "error.h" +#include "file-ops.h" +#include "gripes.h" +#include "lo-mappers.h" +#include "lo-sstream.h" +#include "oct-env.h" +#include "oct-obj.h" +#include "sighandlers.h" +#include "utils.h" + +DEFUN_DLD (fftw_wisdom, args, , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} fftw_wisdom (@var{file}, @var{ow})\n\ +@deftypefnx {Loadable Function} {} fftw_wisdom (@var{n})\n\ +\n\ +This function is used to manipulate the FFTW wisdom data. It can\n\ +be used to load previously stored wisdom from a file, create wisdom\n\ +needed by Octave and to save the current wisdom to a file. Wisdom\n\ +data can be used to significantly accelerate the calculation of the FFTs,\n\ +but is only profitable if the same FFT is called many times due to the\n\ +overhead in calculating the wisdom data.\n\ +\n\ +Called with a single string argument, @code{fftw_wisdom (@var{file})}\n\ +will load the wisdom data found in @var{file}. If @var{file} does\n\ +not exist, then the current wisdom used by FFTW is saved to this\n\ +file. If the flag @var{ow} is non-zero, then even if @var{file}\n\ +exists, it will be overwritten.\n\ +\n\ +It is assumed that each row of @var{n} represents the size of a FFT for\n\ +which it is desired to pre-calculate the wisdom needed to accelerate it.\n\ +Any value of the matrix that is less than 1, is assumed to indicate an\n\ +absent dimension. That is\n\ +\n\ +@example\n\ +fftw_wisdom ([102, 0, 0; 103, 103, 0; 102, 103, 105]);\n\ +a = fft (rand (1,102));\n\ +b = fft (rand (103,103));\n\ +c = fftn (rand ([102, 103, 105]));\n\ +@end example\n\ +\n\ +calculates the wisdom necessary to accelerate the 103, 102x102 and\n\ +the 102x103x105 FFTs. Note that calculated wisdom will be lost when\n\ +when restarting Octave. However, if it is saved as discussed above, it\n\ +can be reloaded. Also, any system-wide wisdom file that has been found\n\ +will also be used. Saved wisdom files should not be used on different\n\ +platforms since they will not be efficient and the point of calculating\n\ +the wisdom is lost.\n\ +\n\ +Note that the program @code{fftw-wisdom} supplied with FFTW can equally\n\ +be used to create a file containing wisdom that can be imported into\n\ +Octave.\n\ +@end deftypefn\n\ +@seealso {fft, ifft, fft2, ifft2, fftn, ifftn}") +{ + octave_value retval; + +#if defined (HAVE_FFTW3) + + int nargin = args.length(); + + if (nargin < 1 || nargin > 2) + { + print_usage ("fftw_wisdom"); + return retval; + } + + if (args(0).is_string ()) + { + bool overwrite = false; + + if (nargin != 1) + { + double dval = args (1).double_value (); + if (NINT (dval) != 0) + overwrite = true; + } + + std::string wisdom = octave_env::make_absolute + (Vload_path_dir_path.find_first_of (args(0).string_value ().c_str ()), + octave_env::getcwd ()); + + if (wisdom.empty () || overwrite) + { + FILE *ofile = fopen (wisdom.c_str (), "wb"); + fftw_export_wisdom_to_file (ofile); + fclose (ofile); + } + else + { + FILE *ifile = fopen (wisdom.c_str (), "r"); + if (! fftw_import_wisdom_from_file (ifile)) + error ("fftw_wisdom: can not import wisdom from file"); + fclose (ifile); + } + + } + else + { + Matrix m = args (0).matrix_value (); + + if (error_state) + { + error ("fftw_wisdom: argument must be a matrix or a string"); + return retval; + } + + std::string name = file_ops::tempnam ("", "oct-"); + + if (name.empty ()) + { + error ("fftw_wisdom: can not open temporary file"); + return retval; + } + + OSSTREAM cmd_buf; + cmd_buf << Vfftw_wisdom_prog << " -n -o \"" << name << "\""; + + for (int k = 0; k < m.rows (); k++) + { + bool first = true; + + cmd_buf << " "; + + // Note reversal of dimensions for column major storage in FFTW + for (int j = m.columns()-1; j >= 0; j--) + if (NINT(m(k,j)) > 0) + { + if (first) + first = false; + else + cmd_buf << "x"; + cmd_buf << NINT(m(k,j)) ; + } + } + + cmd_buf << OSSTREAM_ENDS; + + volatile octave_interrupt_handler old_interrupt_handler + = octave_ignore_interrupts (); + + int status = system (OSSTREAM_C_STR (cmd_buf)); + + OSSTREAM_FREEZE (cmd_buf); + + octave_set_interrupt_handler (old_interrupt_handler); + + if (WIFEXITED (status)) + { + FILE *ifile = fopen (name.c_str (), "r"); + if (! fftw_import_wisdom_from_file (ifile)) + error ("fftw_wisdom: can not import wisdom from temporary file"); + fclose (ifile); + } + else + error ("fftw_wisdom: error running %s", Vfftw_wisdom_prog.c_str ()); + + } + +#else + + error ("fftw_wisdom: this copy of Octave was not configured to use FFTW3"); + +#endif + + return retval; +} diff -r 88b638195bd1 -r adf8d68d7143 src/Makefile.in --- a/src/Makefile.in Mon Feb 16 19:57:06 2004 +0000 +++ b/src/Makefile.in Mon Feb 16 20:32:20 2004 +0000 @@ -43,13 +43,9 @@ OPT_HANDLERS := DASPK-opts.cc DASRT-opts.cc DASSL-opts.cc \ LSODE-opts.cc NLEqn-opts.cc ODESSA-opts.cc Quad-opts.cc -ifneq ($(FFTW_LIBS), ) - DLD_WISDOM := fft_wisdom.cc -endif - DLD_XSRC := balance.cc besselj.cc betainc.cc chol.cc colloc.cc \ daspk.cc dasrt.cc dassl.cc det.cc eig.cc expm.cc fft.cc fft2.cc \ - fftn.cc $(DLD_WISDOM) filter.cc find.cc fsolve.cc gammainc.cc \ + fftn.cc fftw_wisdom.cc filter.cc find.cc fsolve.cc gammainc.cc \ getgrent.cc getpwent.cc getrusage.cc givens.cc hess.cc \ inv.cc kron.cc lpsolve.cc lsode.cc lu.cc minmax.cc \ odessa.cc pinv.cc qr.cc quad.cc qz.cc rand.cc schur.cc \ diff -r 88b638195bd1 -r adf8d68d7143 src/defaults.cc --- a/src/defaults.cc Mon Feb 16 19:57:06 2004 +0000 +++ b/src/defaults.cc Mon Feb 16 20:32:20 2004 +0000 @@ -92,10 +92,8 @@ std::string Vlocal_site_defaults_file; std::string Vsite_defaults_file; -#ifdef HAVE_FFTW3 -// Name of the FFTW wisdom program -std::string Vwisdom_prog; -#endif +// Name of the FFTW wisdom program. +std::string Vfftw_wisdom_prog; // Each element of A and B should be directory names. For each // element of A not in the list B, execute SCRIPT_FILE in that @@ -315,18 +313,16 @@ Vinfo_prog = std::string (oct_info_prog); } -#ifdef HAVE_FFTW3 static void -set_default_wisdom_prog (void) +set_default_fftw_wisdom_prog (void) { - std::string oct_wisdom_prog = octave_env::getenv ("OCTAVE_WISDOM_PROGRAM"); + std::string oct_wisdom_prog = octave_env::getenv ("OCTAVE_FFTW_WISDOM_PROGRAM"); if (oct_wisdom_prog.empty ()) - Vwisdom_prog = "fftw-wisdom"; + Vfftw_wisdom_prog = "fftw-wisdom"; else - Vwisdom_prog = std::string (oct_wisdom_prog); + Vfftw_wisdom_prog = std::string (oct_wisdom_prog); } -#endif static void set_default_editor (void) @@ -418,9 +414,7 @@ set_default_info_prog (); -#ifdef HAVE_FFTW3 - set_default_wisdom_prog (); -#endif + set_default_fftw_wisdom_prog (); set_default_editor (); @@ -506,25 +500,23 @@ return status; } -#ifdef HAVE_FFTW3 static int -wisdom_prog (void) +fftw_wisdom_prog (void) { int status = 0; - std::string s = builtin_string_variable ("WISDOM_PROGRAM"); + std::string s = builtin_string_variable ("FFTW_WISDOM_PROGRAM"); if (s.empty ()) { - gripe_invalid_value_specified ("WISDOM_PROGRAM"); + gripe_invalid_value_specified ("FFTW_WISDOM_PROGRAM"); status = -1; } else - Vwisdom_prog = s; + Vfftw_wisdom_prog = s; return status; } -#endif static int default_exec_path (void) @@ -629,17 +621,15 @@ @code{\"emacs\"}.\n\ @end defvr"); -#ifdef HAVE_FFTW3 - DEFVAR (WISDOM_PROGRAM, Vwisdom_prog, wisdom_prog, + DEFVAR (FFTW_WISDOM_PROGRAM, Vfftw_wisdom_prog, fftw_wisdom_prog, "-*- texinfo -*-\n\ -@defvr {Built-in Variable} WISDOM_PROGRAM\n\ +@defvr {Built-in Variable} FFTW_WISDOM_PROGRAM\n\ A string naming the FFTW wisdom program to use to create wisdom data\n\ to accelerate Fourier transforms. If the environment variable\n\ @code{OCTAVE_WISDOM_PROGRAM} is set when Octave starts, its value is used\n\ as the default. Otherwise, @code{WISDOM_PROGRAM} is set to\n\ @code{\"fftw-wisdom\"}.\n\ @end defvr"); -#endif DEFVAR (EXEC_PATH, Vexec_path, exec_path, "-*- texinfo -*-\n\ diff -r 88b638195bd1 -r adf8d68d7143 src/defaults.h.in --- a/src/defaults.h.in Mon Feb 16 19:57:06 2004 +0000 +++ b/src/defaults.h.in Mon Feb 16 20:32:20 2004 +0000 @@ -194,6 +194,9 @@ extern std::string Vlocal_site_defaults_file; extern std::string Vsite_defaults_file; +// Name of the FFTW wisdom program. +extern std::string Vfftw_wisdom_prog; + extern void execute_default_pkg_add_files (void); extern std::string maybe_add_default_load_path (const std::string& pathstring);