pax_global_header00006660000000000000000000000064126573147570014533gustar00rootroot0000000000000052 comment=b39e00b067e2c72c0942f4b8513bacd3107830b9 ynfft-1.0.3/000077500000000000000000000000001265731475700126625ustar00rootroot00000000000000ynfft-1.0.3/.dir-locals.el000066400000000000000000000007021265731475700153120ustar00rootroot00000000000000((nil . ((indent-tabs-mode . nil) (tab-width . 8) (coding . utf8) (fill-column . 79) (ispell-local-dictionary . "american"))) (c-mode . ((c-file-style . "bsd") (c-basic-offset . 2))) (java-mode . ((c-basic-offset . 4))) (julia-mode . ()) (sh-mode . ((sh-basic-offset . 4))) (tcl-mode . ((tcl-default-application . "wish") (tcl-indent-level . 2))) (yorick-mode . ((c-basic-offset . 2) (fill-column . 78))) ) ynfft-1.0.3/.gitattributes000066400000000000000000000004031265731475700155520ustar00rootroot00000000000000*.[hc] filter=cleanup-code *.i filter=cleanup-text README filter=cleanup-text TODO filter=cleanup-text AUTHORS filter=cleanup-text NEWS filter=cleanup-text configure filter=cleanup-text Makefile filter=cleanup-yorick-makefile ynfft-1.0.3/.gitignore000066400000000000000000000012441265731475700146530ustar00rootroot00000000000000# Specific files # ################## ywrap.c # Specific directories # ######################## build releases work # Automatic backups # ##################### *~ # Compiled sources and libraries # ################################## *.com *.class *.dll *.exe *.o *.so lib*.a # Packages # ############ # it's better to unpack these files and commit the raw source # git has its own built in compression methods *.7z *.bz2 *.dmg *.gz *.iso *.jar *.rar *.tar *.tar.bz2 *.tar.gz *.tar.xz *.tgz *.txz *.xz *.zip # Logs and databases # ###################### *.log *.sql *.sqlite # OS generated files # ###################### .DS_Store* ehthumbs.db Icon? Thumbs.db .directory ynfft-1.0.3/AUTHORS000066400000000000000000000001351265731475700137310ustar00rootroot00000000000000Éric Thiébaut Ferréol Soulez ynfft-1.0.3/LICENSE000066400000000000000000000525471265731475700137040ustar00rootroot00000000000000 CeCILL-C FREE SOFTWARE LICENSE AGREEMENT Notice This Agreement is a Free Software license agreement that is the result of discussions between its authors in order to ensure compliance with the two main principles guiding its drafting: * firstly, compliance with the principles governing the distribution of Free Software: access to source code, broad rights granted to users, * secondly, the election of a governing law, French law, with which it is conformant, both as regards the law of torts and intellectual property law, and the protection that it offers to both authors and holders of the economic rights over software. The authors of the CeCILL-C (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) license are: Commissariat à l'Energie Atomique - CEA, a public scientific, technical and industrial research establishment, having its principal place of business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France. Centre National de la Recherche Scientifique - CNRS, a public scientific and technological establishment, having its principal place of business at 3 rue Michel-Ange, 75794 Paris cedex 16, France. Institut National de Recherche en Informatique et en Automatique - INRIA, a public scientific and technological establishment, having its principal place of business at Domaine de Voluceau, Rocquencourt, BP 105, 78153 Le Chesnay cedex, France. Preamble The purpose of this Free Software license agreement is to grant users the right to modify and re-use the software governed by this license. The exercising of this right is conditional upon the obligation to make available to the community the modifications made to the source code of the software so as to contribute to its evolution. In consideration of access to the source code and the rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors only have limited liability. In this respect, the risks associated with loading, using, modifying and/or developing or reproducing the software by the user are brought to the user's attention, given its Free Software status, which may make it complicated to use, with the result that its use is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the suitability of the software as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions of security. This Agreement may be freely reproduced and published, provided it is not altered, and that no provisions are either added or removed herefrom. This Agreement may apply to any or all software for which the holder of the economic rights decides to submit the use thereof to its provisions. Article 1 - DEFINITIONS For the purpose of this Agreement, when the following expressions commence with a capital letter, they shall have the following meaning: Agreement: means this license agreement, and its possible subsequent versions and annexes. Software: means the software in its Object Code and/or Source Code form and, where applicable, its documentation, "as is" when the Licensee accepts the Agreement. Initial Software: means the Software in its Source Code and possibly its Object Code form and, where applicable, its documentation, "as is" when it is first distributed under the terms and conditions of the Agreement. Modified Software: means the Software modified by at least one Integrated Contribution. Source Code: means all the Software's instructions and program lines to which access is required so as to modify the Software. Object Code: means the binary files originating from the compilation of the Source Code. Holder: means the holder(s) of the economic rights over the Initial Software. Licensee: means the Software user(s) having accepted the Agreement. Contributor: means a Licensee having made at least one Integrated Contribution. Licensor: means the Holder, or any other individual or legal entity, who distributes the Software under the Agreement. Integrated Contribution: means any or all modifications, corrections, translations, adaptations and/or new functions integrated into the Source Code by any or all Contributors. Related Module: means a set of sources files including their documentation that, without modification to the Source Code, enables supplementary functions or services in addition to those offered by the Software. Derivative Software: means any combination of the Software, modified or not, and of a Related Module. Parties: mean both the Licensee and the Licensor. These expressions may be used both in singular and plural form. Article 2 - PURPOSE The purpose of the Agreement is the grant by the Licensor to the Licensee of a non-exclusive, transferable and worldwide license for the Software as set forth in Article 5 hereinafter for the whole term of the protection granted by the rights over said Software. Article 3 - ACCEPTANCE 3.1 The Licensee shall be deemed as having accepted the terms and conditions of this Agreement upon the occurrence of the first of the following events: * (i) loading the Software by any or all means, notably, by downloading from a remote server, or by loading from a physical medium; * (ii) the first time the Licensee exercises any of the rights granted hereunder. 3.2 One copy of the Agreement, containing a notice relating to the characteristics of the Software, to the limited warranty, and to the fact that its use is restricted to experienced users has been provided to the Licensee prior to its acceptance as set forth in Article 3.1 hereinabove, and the Licensee hereby acknowledges that it has read and understood it. Article 4 - EFFECTIVE DATE AND TERM 4.1 EFFECTIVE DATE The Agreement shall become effective on the date when it is accepted by the Licensee as set forth in Article 3.1. 4.2 TERM The Agreement shall remain in force for the entire legal term of protection of the economic rights over the Software. Article 5 - SCOPE OF RIGHTS GRANTED The Licensor hereby grants to the Licensee, who accepts, the following rights over the Software for any or all use, and for the term of the Agreement, on the basis of the terms and conditions set forth hereinafter. Besides, if the Licensor owns or comes to own one or more patents protecting all or part of the functions of the Software or of its components, the Licensor undertakes not to enforce the rights granted by these patents against successive Licensees using, exploiting or modifying the Software. If these patents are transferred, the Licensor undertakes to have the transferees subscribe to the obligations set forth in this paragraph. 5.1 RIGHT OF USE The Licensee is authorized to use the Software, without any limitation as to its fields of application, with it being hereinafter specified that this comprises: 1. permanent or temporary reproduction of all or part of the Software by any or all means and in any or all form. 2. loading, displaying, running, or storing the Software on any or all medium. 3. entitlement to observe, study or test its operation so as to determine the ideas and principles behind any or all constituent elements of said Software. This shall apply when the Licensee carries out any or all loading, displaying, running, transmission or storage operation as regards the Software, that it is entitled to carry out hereunder. 5.2 RIGHT OF MODIFICATION The right of modification includes the right to translate, adapt, arrange, or make any or all modifications to the Software, and the right to reproduce the resulting software. It includes, in particular, the right to create a Derivative Software. The Licensee is authorized to make any or all modification to the Software provided that it includes an explicit notice that it is the author of said modification and indicates the date of the creation thereof. 5.3 RIGHT OF DISTRIBUTION In particular, the right of distribution includes the right to publish, transmit and communicate the Software to the general public on any or all medium, and by any or all means, and the right to market, either in consideration of a fee, or free of charge, one or more copies of the Software by any means. The Licensee is further authorized to distribute copies of the modified or unmodified Software to third parties according to the terms and conditions set forth hereinafter. 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION The Licensee is authorized to distribute true copies of the Software in Source Code or Object Code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by: 1. a copy of the Agreement, 2. a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9, and that, in the event that only the Object Code of the Software is redistributed, the Licensee allows effective access to the full Source Code of the Software at a minimum during the entire period of its distribution of the Software, it being understood that the additional cost of acquiring the Source Code shall not exceed the cost of transferring the data. 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE When the Licensee makes an Integrated Contribution to the Software, the terms and conditions for the distribution of the resulting Modified Software become subject to all the provisions of this Agreement. The Licensee is authorized to distribute the Modified Software, in source code or object code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by: 1. a copy of the Agreement, 2. a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9, and that, in the event that only the object code of the Modified Software is redistributed, the Licensee allows effective access to the full source code of the Modified Software at a minimum during the entire period of its distribution of the Modified Software, it being understood that the additional cost of acquiring the source code shall not exceed the cost of transferring the data. 5.3.3 DISTRIBUTION OF DERIVATIVE SOFTWARE When the Licensee creates Derivative Software, this Derivative Software may be distributed under a license agreement other than this Agreement, subject to compliance with the requirement to include a notice concerning the rights over the Software as defined in Article 6.4. In the event the creation of the Derivative Software required modification of the Source Code, the Licensee undertakes that: 1. the resulting Modified Software will be governed by this Agreement, 2. the Integrated Contributions in the resulting Modified Software will be clearly identified and documented, 3. the Licensee will allow effective access to the source code of the Modified Software, at a minimum during the entire period of distribution of the Derivative Software, such that such modifications may be carried over in a subsequent version of the Software; it being understood that the additional cost of purchasing the source code of the Modified Software shall not exceed the cost of transferring the data. 5.3.4 COMPATIBILITY WITH THE CeCILL LICENSE When a Modified Software contains an Integrated Contribution subject to the CeCILL license agreement, or when a Derivative Software contains a Related Module subject to the CeCILL license agreement, the provisions set forth in the third item of Article 6.4 are optional. Article 6 - INTELLECTUAL PROPERTY 6.1 OVER THE INITIAL SOFTWARE The Holder owns the economic rights over the Initial Software. Any or all use of the Initial Software is subject to compliance with the terms and conditions under which the Holder has elected to distribute its work and no one shall be entitled to modify the terms and conditions for the distribution of said Initial Software. The Holder undertakes that the Initial Software will remain ruled at least by this Agreement, for the duration set forth in Article 4.2. 6.2 OVER THE INTEGRATED CONTRIBUTIONS The Licensee who develops an Integrated Contribution is the owner of the intellectual property rights over this Contribution as defined by applicable law. 6.3 OVER THE RELATED MODULES The Licensee who develops a Related Module is the owner of the intellectual property rights over this Related Module as defined by applicable law and is free to choose the type of agreement that shall govern its distribution under the conditions defined in Article 5.3.3. 6.4 NOTICE OF RIGHTS The Licensee expressly undertakes: 1. not to remove, or modify, in any manner, the intellectual property notices attached to the Software; 2. to reproduce said notices, in an identical manner, in the copies of the Software modified or not; 3. to ensure that use of the Software, its intellectual property notices and the fact that it is governed by the Agreement is indicated in a text that is easily accessible, specifically from the interface of any Derivative Software. The Licensee undertakes not to directly or indirectly infringe the intellectual property rights of the Holder and/or Contributors on the Software and to take, where applicable, vis-à-vis its staff, any and all measures required to ensure respect of said intellectual property rights of the Holder and/or Contributors. Article 7 - RELATED SERVICES 7.1 Under no circumstances shall the Agreement oblige the Licensor to provide technical assistance or maintenance services for the Software. However, the Licensor is entitled to offer this type of services. The terms and conditions of such technical assistance, and/or such maintenance, shall be set forth in a separate instrument. Only the Licensor offering said maintenance and/or technical assistance services shall incur liability therefor. 7.2 Similarly, any Licensor is entitled to offer to its licensees, under its sole responsibility, a warranty, that shall only be binding upon itself, for the redistribution of the Software and/or the Modified Software, under terms and conditions that it is free to decide. Said warranty, and the financial terms and conditions of its application, shall be subject of a separate instrument executed between the Licensor and the Licensee. Article 8 - LIABILITY 8.1 Subject to the provisions of Article 8.2, the Licensee shall be entitled to claim compensation for any direct loss it may have suffered from the Software as a result of a fault on the part of the relevant Licensor, subject to providing evidence thereof. 8.2 The Licensor's liability is limited to the commitments made under this Agreement and shall not be incurred as a result of in particular: (i) loss due the Licensee's total or partial failure to fulfill its obligations, (ii) direct or consequential loss that is suffered by the Licensee due to the use or performance of the Software, and (iii) more generally, any consequential loss. In particular the Parties expressly agree that any or all pecuniary or business loss (i.e. loss of data, loss of profits, operating loss, loss of customers or orders, opportunity cost, any disturbance to business activities) or any or all legal proceedings instituted against the Licensee by a third party, shall constitute consequential loss and shall not provide entitlement to any or all compensation from the Licensor. Article 9 - WARRANTY 9.1 The Licensee acknowledges that the scientific and technical state-of-the-art when the Software was distributed did not enable all possible uses to be tested and verified, nor for the presence of possible defects to be detected. In this respect, the Licensee's attention has been drawn to the risks associated with loading, using, modifying and/or developing and reproducing the Software which are reserved for experienced users. The Licensee shall be responsible for verifying, by any or all means, the suitability of the product for its requirements, its good working order, and for ensuring that it shall not cause damage to either persons or properties. 9.2 The Licensor hereby represents, in good faith, that it is entitled to grant all the rights over the Software (including in particular the rights set forth in Article 5). 9.3 The Licensee acknowledges that the Software is supplied "as is" by the Licensor without any other express or tacit warranty, other than that provided for in Article 9.2 and, in particular, without any warranty as to its commercial value, its secured, safe, innovative or relevant nature. Specifically, the Licensor does not warrant that the Software is free from any error, that it will operate without interruption, that it will be compatible with the Licensee's own equipment and software configuration, nor that it will meet the Licensee's requirements. 9.4 The Licensor does not either expressly or tacitly warrant that the Software does not infringe any third party intellectual property right relating to a patent, software or any other property right. Therefore, the Licensor disclaims any and all liability towards the Licensee arising out of any or all proceedings for infringement that may be instituted in respect of the use, modification and redistribution of the Software. Nevertheless, should such proceedings be instituted against the Licensee, the Licensor shall provide it with technical and legal assistance for its defense. Such technical and legal assistance shall be decided on a case-by-case basis between the relevant Licensor and the Licensee pursuant to a memorandum of understanding. The Licensor disclaims any and all liability as regards the Licensee's use of the name of the Software. No warranty is given as regards the existence of prior rights over the name of the Software or as regards the existence of a trademark. Article 10 - TERMINATION 10.1 In the event of a breach by the Licensee of its obligations hereunder, the Licensor may automatically terminate this Agreement thirty (30) days after notice has been sent to the Licensee and has remained ineffective. 10.2 A Licensee whose Agreement is terminated shall no longer be authorized to use, modify or distribute the Software. However, any licenses that it may have granted prior to termination of the Agreement shall remain valid subject to their having been granted in compliance with the terms and conditions hereof. Article 11 - MISCELLANEOUS 11.1 EXCUSABLE EVENTS Neither Party shall be liable for any or all delay, or failure to perform the Agreement, that may be attributable to an event of force majeure, an act of God or an outside cause, such as defective functioning or interruptions of the electricity or telecommunications networks, network paralysis following a virus attack, intervention by government authorities, natural disasters, water damage, earthquakes, fire, explosions, strikes and labor unrest, war, etc. 11.2 Any failure by either Party, on one or more occasions, to invoke one or more of the provisions hereof, shall under no circumstances be interpreted as being a waiver by the interested Party of its right to invoke said provision(s) subsequently. 11.3 The Agreement cancels and replaces any or all previous agreements, whether written or oral, between the Parties and having the same purpose, and constitutes the entirety of the agreement between said Parties concerning said purpose. No supplement or modification to the terms and conditions hereof shall be effective as between the Parties unless it is made in writing and signed by their duly authorized representatives. 11.4 In the event that one or more of the provisions hereof were to conflict with a current or future applicable act or legislative text, said act or legislative text shall prevail, and the Parties shall make the necessary amendments so as to comply with said act or legislative text. All other provisions shall remain effective. Similarly, invalidity of a provision of the Agreement, for any reason whatsoever, shall not cause the Agreement as a whole to be invalid. 11.5 LANGUAGE The Agreement is drafted in both French and English and both versions are deemed authentic. Article 12 - NEW VERSIONS OF THE AGREEMENT 12.1 Any person is authorized to duplicate and distribute copies of this Agreement. 12.2 So as to ensure coherence, the wording of this Agreement is protected and may only be modified by the authors of the License, who reserve the right to periodically publish updates or new versions of the Agreement, each with a separate number. These subsequent versions may address new issues encountered by Free Software. 12.3 Any Software distributed under a given version of the Agreement may only be subsequently distributed under the same version of the Agreement or a subsequent version. Article 13 - GOVERNING LAW AND JURISDICTION 13.1 The Agreement is governed by French law. The Parties agree to endeavor to seek an amicable solution to any disagreements or disputes that may arise during the performance of the Agreement. 13.2 Failing an amicable solution within two (2) months as from their occurrence, and unless emergency proceedings are necessary, the disagreements or disputes shall be referred to the Paris Courts having jurisdiction, by the more diligent Party. Version 1.0 dated 2006-09-05. ynfft-1.0.3/Makefile000066400000000000000000000077141265731475700143330ustar00rootroot00000000000000# Where are the sources? (automatically filled in by configure script) srcdir=. # These values filled in by: yorick -batch make.i Y_MAKEDIR= Y_EXE= Y_EXE_PKGS= Y_EXE_HOME= Y_EXE_SITE= Y_HOME_PKG= # ----------------------------------------------------- optimization flags # options for make command line, e.g.- make COPT=-g TGT=exe COPT=$(COPT_DEFAULT) TGT=$(DEFAULT_TGT) # ------------------------------------------------ macros for this package PKG_NAME=yor_nfft PKG_I=${srcdir}/nfft.i OBJS=yor_nfft.o # change to give the executable a name other than yorick PKG_EXENAME=yorick # PKG_DEPLIBS=-Lsomedir -lsomelib for dependencies of this package PKG_DEPLIBS= # set compiler (or rarely loader) flags specific to this package PKG_CFLAGS= PKG_LDFLAGS= # list of additional package names you want in PKG_EXENAME # (typically $(Y_EXE_PKGS) should be first here) EXTRA_PKGS=$(Y_EXE_PKGS) # list of additional files for clean PKG_CLEAN= # autoload file for this package, if any PKG_I_START= # non-pkg.i include files for this package, if any PKG_I_EXTRA= # released files and archive name RELEASE_FILES = AUTHORS LICENSE Makefile NEWS README TODO \ nfft.i nfft-tests.i yor_nfft.c m3d_nfft.c RELEASE_NAME = ${srcdir}/releases/ynfft-$(RELEASE_VERSION).tar.bz2 RELEASE_VERSION = 1.0.3 # -------------------------------- standard targets and rules (in Makepkg) # set macros Makepkg uses in target and dependency names # DLL_TARGETS, LIB_TARGETS, EXE_TARGETS # are any additional targets (defined below) prerequisite to # the plugin library, archive library, and executable, respectively PKG_I_DEPS=$(PKG_I) Y_DISTMAKE=distmake ifeq (,$(strip $(Y_MAKEDIR))) $(info *** WARNING *** Y_MAKEDIR not defined, you may run 'yorick -batch make.i' first.) else include $(Y_MAKEDIR)/Make.cfg include $(Y_MAKEDIR)/Makepkg include $(Y_MAKEDIR)/Make$(TGT) endif # override macros Makepkg sets for rules and other macros # see comments in Y_HOME/Makepkg for a list of possibilities # if this package built with mpy: 1. be sure mpy appears in EXTRA_PKGS, # 2. set TGT=exe, and 3. uncomment following two lines # Y_MAIN_O=$(Y_LIBEXE)/mpymain.o # include $(Y_MAKEDIR)/Makempy # configure script for this package may produce make macros: # include output-makefile-from-package-configure # reduce chance of yorick-1.5 corrupting this Makefile MAKE_TEMPLATE = protect-against-1.5 # ------------------------------------- targets and rules for this package # simple example: #myfunc.o: myapi.h # more complex example (also consider using PKG_CFLAGS above): #myfunc.o: myapi.h myfunc.c # $(CC) $(CPPFLAGS) $(CFLAGS) -DMY_SWITCH -o $@ -c myfunc.c %.o: ${srcdir}/%.c $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $< tests: $(PKG_DLL) $(Y_EXE) -batch nfft-tests.i yor_nfft.o: ${srcdir}/yor_nfft.c ${srcdir}/m3d_nfft.c $(CC) -I. -DVERSION=\"$(RELEASE_VERSION)\" $(CPPFLAGS) $(CFLAGS) -o $@ -c $< release: $(RELEASE_NAME) $(RELEASE_NAME): git checkout master @if test "x$(RELEASE_VERSION)" = "x"; then \ echo >&2 "set package version: make RELEASE_VERSION=... archive"; \ else \ dir=`basename "$(RELEASE_NAME)" .tar.bz2`; \ if test "x$$dir" = "x" -o "x$$dir" = "x."; then \ echo >&2 "bad directory name for archive"; \ elif test -d "$$dir"; then \ echo >&2 "directory $$dir already exists"; \ else \ mkdir -p "$$dir"; \ for file in $(RELEASE_FILES); do \ src="${srcdir}/$$file"; \ dst="$$dir/$$file"; \ if test "$$file" = "Makefile"; then \ sed <"$$src" >"$$dst" -e 's/^\( *Y_\(MAKEDIR\|EXE\(\|_PKGS\|_HOME\|_SITE\)\|HOME_PKG\) *=\).*/\1/'; \ touch -r "$$src" "$$dst"; \ else \ cp -p "$$src" "$$dst"; \ fi; \ done; \ rm -f "$$dir"/*~ "$$dir"/*/*~; \ echo "$(RELEASE_VERSION)" > "$$dir/VERSION"; \ tar jcf "$(RELEASE_NAME)" "$$dir"; \ rm -rf "$$dir"; \ echo "$(RELEASE_NAME) created"; \ fi; \ fi; .PHONY: clean release tests config # -------------------------------------------------------- end of Makefile ynfft-1.0.3/NEWS000066400000000000000000000000411265731475700133540ustar00rootroot000000000000002016/02/12: Changes for NFFT 3.3 ynfft-1.0.3/README000066400000000000000000000053431265731475700135470ustar00rootroot00000000000000YNFFT is a Yorick plugin for NFFT (nonequispaced fast Fourier transform). Installation ============ 1. Make sure you have installed the NFFT library from , the FFTW library from and Yorick from . 2. Unpack the plug-in code somewhere. 3. Configure for compilation. The are two possibilities: a/ For an "in-place" build, go to the source directory of the plug-in code (where this README file is located) and run the configuration script: cd SRC_DIR ./configure --cflags=... --deplibs=... For instance: ./configure --cflags='-I/usr/local/include' --deplibs='-L/usr/local/lib -lnfft3 -lfftw3' or, to use OpenMP: ./configure --cflags='-I/usr/local/include -fopenmp -Ofast -march=native -mfpmath=sse -pedantic -pipe -std=c99' --deplibs='-L/usr/local/lib -lnfft3 -lnfft3_threads -lfftw3_threads -lfftw3' To see the configuration options, call: ./configure --help b/ To compile in a different build directory, say $BUILD_DIR, create the build directory, go to the build directory, and run the configuration script: mkdir -p $BUILD_DIR cd $BUILD_DIR $SRC_DIR/configure --cflags=... --deplibs=... where $SRC_DIR is the path to the source directory of the plug-in code. To see the configuration options, call: $SRC_DIR/configure --help 4. Compile the code: make 5. Optionally, check the plugin: make tests You may have to set some environment variable for the dynamic loader (LD_LIBRARY_PATH on Linux) if the NFFT library is installed in a non-standard location, e.g.: LD_LIBRARY_PATH=$PREFIX/lib make tests 4. Finally, install the plug-in in Yorick directories: make install Alternative installation method =============================== Replace step No. 3 of the installation procedure (see above) by: 3.1. Edit the file "Makefile" and check the values of the variables PKG_DEPLIBS, PKG_CFLAGS and PKG_LDFLAGS; for instance, assuming PREFIX is a variable with the top directory where FFTW and NFFT libraries are installed: PKG_DEPLIBS=-L$(PREFIX)/lib -lnfft3 -lfftw3 PKG_CFLAGS=-I$(PREFIX)/include PKG_LDFLAGS= 3.2. Update the paths in the file "Makefile" for compilation by executing the following command: yorick -batch make.i where "yorick" can be replaced by the full path to your Yorick interpreter if not installed in a standard location. Credits ======= * Yorick * NFFT library * FFTW library ynfft-1.0.3/TODO000066400000000000000000000002411265731475700133470ustar00rootroot00000000000000 * allow for multiple threads Simply call: fftw_plan_with_nthreads(nthreads); before calling nfft_init or nfft_init_guru which allocate the FFTW plans. ynfft-1.0.3/configure000077500000000000000000000143761265731475700146040ustar00rootroot00000000000000#! /bin/sh # # Configuration script for a Yorick plugin. # #------------------------------------------------------------------------------ # # Copyright (C) 2012 Éric Thiébaut # # This software is governed by the CeCILL-C license under French law and # abiding by the rules of distribution of free software. You can use, modify # and/or redistribute the software under the terms of the CeCILL-C license as # circulated by CEA, CNRS and INRIA at the following URL # "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited liability. # # In this respect, the user's attention is drawn to the risks associated with # loading, using, modifying and/or developing or reproducing the software by # the user in light of its specific status of free software, that may mean # that it is complicated to manipulate, and that also therefore means that it # is reserved for developers and experienced professionals having in-depth # computer knowledge. Users are therefore encouraged to load and test the # software's suitability as regards their requirements in conditions enabling # the security of their systems and/or data to be ensured and, more # generally, to use and operate it in the same conditions as regards # security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-C license and that you accept its terms. # #------------------------------------------------------------------------------ # The following default values are specific to the package. They can be # overwritten by options on the command line. cfg_cflags= cfg_deplibs='-lnfft3 -lfftw3_threads -lfftw3' cfg_ldflags= # The other values are pretty general. cfg_tmpdir=. cfg_tmpfile="$cfg_tmpdir/cfg-$$" cfg_debug=no cfg_on_exit () { if test "$cfg_debug" = "no"; then rm -f "$cfg_tmpfile" "$cfg_tmpfile.i" fi } trap cfg_on_exit 0 cfg_progname=$0 cfg_srcdir=$(dirname "$0") #cfg_path=$(readlink -fn "$@") #cfg_srcdir=$(dirname "$cfg_path") cfg_die () { echo >&2 "$cfg_progname: $*"; exit 1; } cfg_opt_value () { echo "$*" | sed 's/^--[^=]*=//'; } cfg_despace () { echo "$*" | sed 's/ /\\ /g'; } cfg_subst_macro () { local s local t s=$* for t in "/" "%" "@" "," "-"; do case "$s" in *$t* ) ;; * ) break esac done if test "$t" = "-"; then cfg_die "No valid separator found" fi s='[ ]*' echo "s${t}^${s}${1}${s}=.*${t}${1}=${2}${t}" } cfg_help () { cat <&2 "Yorick excutable not found." echo >&2 "Try to specify the path with option --yorick=..." exit 1 fi echo >&2 "Yorick executable --------> $cfg_yorick" # Get the Y_HOME and Y_SITE variables. cat >"$cfg_tmpfile.i" < "$cfg_tmpfile" cfg_yhome=$(sed < "$cfg_tmpfile" -e '/^Y_HOME=/!d;s/^Y_HOME=//') cfg_ysite=$(sed < "$cfg_tmpfile" -e '/^Y_SITE=/!d;s/^Y_SITE=//') cfg_ymkdir=$cfg_yhome echo >&2 "Yorick home directory ----> $cfg_yhome" echo >&2 "Yorick site directory ----> $cfg_ysite" # Create the Makefile. cfg_dst="./Makefile" if test "$cfg_inplace" = "yes"; then cfg_src="$cfg_dst.bak" mv -f "$cfg_dst" "$cfg_src" else cfg_src="$cfg_srcdir/Makefile" fi cfg_s0=$(cfg_subst_macro "Y_EXE" "$cfg_yorick") cfg_s1=$(cfg_subst_macro "Y_MAKEDIR" "$cfg_ymkdir") cfg_s2=$(cfg_subst_macro "Y_EXE_HOME" "$cfg_yhome") cfg_s3=$(cfg_subst_macro "Y_EXE_SITE" "$cfg_ysite") cfg_s4=$(cfg_subst_macro "PKG_CFLAGS" "$cfg_cflags") cfg_s5=$(cfg_subst_macro "PKG_DEPLIBS" "$cfg_deplibs") cfg_s6=$(cfg_subst_macro "PKG_LDFLAGS" "$cfg_ldflags") cfg_s7=$(cfg_subst_macro "srcdir" "$cfg_srcdir") sed < "$cfg_src" > "$cfg_dst" \ -e "$cfg_s0;$cfg_s1;$cfg_s2;$cfg_s3;$cfg_s4;$cfg_s5;$cfg_s6;$cfg_s7" if test "$cfg_inplace" = "yes"; then rm -f "$cfg_src" fi echo "Makefile has been updated." echo "You can run 'make' and 'make install' now." # Local Variables: # mode: sh # tab-width: 8 # indent-tabs-mode: nil # fill-column: 78 # coding: utf-8 # End: ynfft-1.0.3/git-notes.txt000066400000000000000000000015671265731475700153450ustar00rootroot00000000000000The "public" branch correspond to developpement for the distributed version of the software. To prepare a new release (replace the version appropriately): * create a new "release" branch from the "public" branch: git checkout -b release-1.0.1 public * edit "Makefile" to change version number (macro RELEASE_VERSION), and make any other suitable changes: emacs Makefile * commit the changes (after checking everything is in order): git status git commit -a -m 'Bumped version number to 1.0.1' * go to the "master" branch which is only used for releases (see http://nvie.com/posts/a-successful-git-branching-model/), merge the changes and add a tag: git checkout master git merge --no-ff release-1.0.1 git tag -a '1.0.1' -m 'Public version 1.0.1 released.' make release * delete the release branch which is no longer needed: git branch -d release-1.0.1 ynfft-1.0.3/m3d_nfft.c000066400000000000000000000002531265731475700145260ustar00rootroot00000000000000#if !defined(DEFAULT_FFTW_FLAGS) # error This file is supposed to be included by yor_nfft.c #endif void Y_nfft_mira3d_new(int argc) { y_error("not yet implemented"); } ynfft-1.0.3/nfft-tests.i000066400000000000000000000160541265731475700151370ustar00rootroot00000000000000/* * nfft-tests.i -- * * Suite of tests for NFFT Yorick plugin. * *----------------------------------------------------------------------------- * * Copyright (C) 2012, Éric Thiébaut * Copyright (C) 2013-2014, Ferréol Soulez * and Éric Thiébaut * * This software is governed by the CeCILL-C license under French law and * abiding by the rules of distribution of free software. You can use, modify * and/or redistribute the software under the terms of the CeCILL-C license as * circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited liability. * * In this respect, the user's attention is drawn to the risks associated with * loading, using, modifying and/or developing or reproducing the software by * the user in light of its specific status of free software, that may mean * that it is complicated to manipulate, and that also therefore means that it * is reserved for developers and experienced professionals having in-depth * computer knowledge. Users are therefore encouraged to load and test the * software's suitability as regards their requirements in conditions enabling * the security of their systems and/or data to be ensured and, more * generally, to use and operate it in the same conditions as regards * security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. * *----------------------------------------------------------------------------- */ func _nfft_test_init { if (! is_func(nfft_new)) { here = current_include(); index = strfind("/", here, back=1n)(2); if (index < 0) error, "bad path"; dir = strpart(here, 1:index); prev = plug_dir(dir); include, dir+"nfft.i", 1; plug_dir, prev; } } func _nfft_test_info(name, a, b, threshold) { r = abs(a - b); i = where(r); e = array(1.0, dimsof(r)); if (is_array(i)) { e(i) = 1.0/max(abs(a(i)), abs(b(i))); } e *= r; if (is_void(threshold)) threshold = 1e-6; failure = (max(e) > threshold); write, format = "%s: %s\n", name, (failure ? "FAILURE" : "SUCCESS"); write, format = " - absolute error: max. = %.1e, RMS = %.1e\n", max(r), sqrt(avg(r*r)); //write, format = " - relative error: max. = %.1e, RMS = %.1e\n", max(e), sqrt(avg(e*e)); } errs2caller, _nfft_test_info; func _nfft_test_newline { write, format="%s", "\n"; } func nfft_test_clone(f, cutoff=, flags=, ovr_dims=, ovr_fact=) { if (is_void(cutoff)) cutoff = f.cutoff; if (is_void(flags)) flags = f.flags; if (is_void(ovr_fact)) { if (is_void(ovr_dims)) ovr_dims = f.ovr_dims(2:0); return nfft_new(f.inp_dims, f.nodes, cutoff=cutoff, flags=flags, ovr_dims=ovr_dims); } else { if (! is_void(ovr_dims)) error, "keywords OVR_DIMS and OVR_FACT are exclusive"; return nfft_new(f.inp_dims, f.nodes, cutoff=cutoff, flags=flags, ovr_fact=ovr_fact); } } func nfft_test { PI = 3.1415926535897932384626433832795029; if (4*atan(1) != PI) error, "bad value for PI?"; METER = 1.0; MICRON = 1E-6*METER; ARCSEC = PI/(180*3600); PIXSCALE = 1e-3*ARCSEC; BMAX = 180.0*METER; LAMBDA = 1.2*MICRON; FLAGS1 = (NFFT_PRE_PHI_HUT | NFFT_PRE_PSI | NFFT_ESTIMATE); FLAGS2 = (FLAGS1 | NFFT_SORT_NODES); num_nodes = 42; n1 = 20; // input size along 1st axis n2 = 22; // input size along 2nd axis n3 = 12; // input size along 3rd axis u1 = (random(num_nodes) - 0.5)*(BMAX/LAMBDA); u2 = (random(num_nodes) - 0.5)*(BMAX/LAMBDA); u3 = (random(num_nodes) - 0.5)*(BMAX/LAMBDA); // 1-D test f = nfft_new(n1, u1*PIXSCALE); a0 = nfft_full_matrix(f, 0); a1 = nfft_full_matrix(f, 1); a2 = nfft_full_matrix(f, 2); _nfft_test_info, "1-D transform (A0 vs. A1)", a0, a1; _nfft_test_info, "1-D transform (A1 vs. A2)", a1, a2; _nfft_test_newline; if (anyof(f.nodes != u1*PIXSCALE)) error, "nodes have changed"; f1 = nfft_test_clone(f, flags=FLAGS1); if (f1.flags != FLAGS1) error, "flags have changed"; f2 = nfft_test_clone(f, flags=FLAGS2); if (f2.flags != FLAGS2) error, "flags have changed"; if (anyof(f2.nodes != f.nodes)) { write, format="WARNING - %s\n", "nodes have changed with NFFT_SORT_NODES"; } a11 = nfft_full_matrix(f1, 1); if (anyof(a11 != a1)) error, "matrix coefficients have changed"; a12 = nfft_full_matrix(f1, 2); if (anyof(a12 != a2)) error, "matrix coefficients have changed"; a21 = nfft_full_matrix(f2, 1); if (anyof(a21 != a1)) error, "matrix coefficients have changed"; a22 = nfft_full_matrix(f2, 2); if (anyof(a22 != a2)) error, "matrix coefficients have changed"; // 2-D test f = nfft_new(n1, u1*PIXSCALE, n2, u2*PIXSCALE); a0 = nfft_full_matrix(f, 0); a1 = nfft_full_matrix(f, 1); a2 = nfft_full_matrix(f, 2); _nfft_test_info, "2-D transform (A0 vs. A1)", a0, a1; _nfft_test_info, "2-D transform (A1 vs. A2)", a1, a2; _nfft_test_newline; if (anyof(f.nodes != [u1,u2]*PIXSCALE)) error, "nodes have changed"; f1 = nfft_test_clone(f, flags=FLAGS1); if (f1.flags != FLAGS1) error, "flags have changed"; f2 = nfft_test_clone(f, flags=FLAGS2); if (f2.flags != FLAGS2) error, "flags have changed"; if (anyof(f2.nodes != f.nodes)) { write, format="WARNING - %s\n", "nodes have changed with NFFT_SORT_NODES"; } a11 = nfft_full_matrix(f1, 1); if (anyof(a11 != a1)) error, "matrix coefficients have changed"; a12 = nfft_full_matrix(f1, 2); if (anyof(a12 != a2)) error, "matrix coefficients have changed"; a21 = nfft_full_matrix(f2, 1); if (anyof(a21 != a1)) error, "matrix coefficients have changed"; a22 = nfft_full_matrix(f2, 2); if (anyof(a22 != a2)) error, "matrix coefficients have changed"; // 3-D test f = nfft_new(n1, u1*PIXSCALE, n2, u2*PIXSCALE, n3, u3*PIXSCALE); a0 = nfft_full_matrix(f, 0); a1 = nfft_full_matrix(f, 1); a2 = nfft_full_matrix(f, 2); _nfft_test_info, "3-D transform (A0 vs. A1)", a0, a1; _nfft_test_info, "3-D transform (A1 vs. A2)", a1, a2; _nfft_test_newline; if (anyof(f.nodes != [u1,u2,u3]*PIXSCALE)) error, "nodes have changed"; f1 = nfft_test_clone(f, flags=FLAGS1); if (f1.flags != FLAGS1) error, "flags have changed"; f2 = nfft_test_clone(f, flags=FLAGS2); if (f2.flags != FLAGS2) error, "flags have changed"; if (anyof(f2.nodes != f.nodes)) { write, format="WARNING - %s\n", "nodes have changed with NFFT_SORT_NODES"; } a11 = nfft_full_matrix(f1, 1); if (anyof(a11 != a1)) error, "matrix coefficients have changed"; a12 = nfft_full_matrix(f1, 2); if (anyof(a12 != a2)) error, "matrix coefficients have changed"; a21 = nfft_full_matrix(f2, 1); if (anyof(a21 != a1)) error, "matrix coefficients have changed"; a22 = nfft_full_matrix(f2, 2); if (anyof(a22 != a2)) error, "matrix coefficients have changed"; } _nfft_test_init; if (batch()) { nfft_test; } ynfft-1.0.3/nfft.i000066400000000000000000000330401265731475700137710ustar00rootroot00000000000000/* * nfft.i -- * * Yorick interface to NFFT (non-uniform fast Fourier transform). * *----------------------------------------------------------------------------- * * Copyright (C) 2012, 2015-2016, Éric Thiébaut * Copyright (C) 2013-2014, Ferréol Soulez and * Éric Thiébaut * * This software is governed by the CeCILL-C license under French law and * abiding by the rules of distribution of free software. You can use, modify * and/or redistribute the software under the terms of the CeCILL-C license as * circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited liability. * * In this respect, the user's attention is drawn to the risks associated with * loading, using, modifying and/or developing or reproducing the software by * the user in light of its specific status of free software, that may mean * that it is complicated to manipulate, and that also therefore means that it * is reserved for developers and experienced professionals having in-depth * computer knowledge. Users are therefore encouraged to load and test the * software's suitability as regards their requirements in conditions enabling * the security of their systems and/or data to be ensured and, more * generally, to use and operate it in the same conditions as regards * security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. * *----------------------------------------------------------------------------- */ if (is_func(plug_in)) plug_in, "yor_nfft"; extern nfft_version; /* DOCUMENT nfft_version(); Returns the version of NFFT plug-in as a string. SEE ALSO: nfft_new. */ local NFFT_PRE_PHI_HUT, NFFT_FG_PSI, NFFT_PRE_LIN_PSI, NFFT_PRE_FG_PSI; local NFFT_PRE_PSI, NFFT_PRE_FULL_PSI, NFFT_SORT_NODES; local NFFT_ESTIMATE, NFFT_MEASURE, NFFT_PATIENT, NFFT_EXHAUSTIVE; extern nfft_new; /* DOCUMENT op = nfft_new(dims, x); or op = nfft_new(n1, x1, n2, x2, ...); The function nfft_new() creates a new operator for nonequidistant fast Fourier transform (NFFT). DIMS is the dimension list of the input evenly sampled arrays to transform, and X is an M-by-D real array which gives the coordinates of the nonequispaced nodes: X(j,t) = t-th coordinate of j-th node thus D is the number of dimensions and M the number of nonequispaced nodes and DIMS is: DIMS = [D, N1, N2, ..., ND] or DIMS = [N1, N2, ..., ND] with N1, N2, ..., ND, the lengths of the dimensions. Alternately, the transform may be specified as: N1, X1, N2, X2, ... with: N1 = length of 1st dimension; X1 = 1st coordinates of the nonequispaced nodes; N2 = length of 2nd dimension; X2 = 2nd coordinates of the nonequispaced nodes; ... The coordinates of the nonequispaced nodes must be in the range [-1/2,1/2) and all dimensions N1, N2, ..., must be even. The new operator can be called as a function to apply the transform. For instance: b = op(a) where A is a complex array of dimensions DIMS (see above) yields a complex vector of length M set with: b(j) = sum_k a(k) * exp(-2i*pi*) for j = 1, ..., M, and where k is the multi-index to access the elements of A, and the "scalar product" is: = sum_t (k(t) - (1 + n(t)/2))*x(j,t) with x(j,t) the t-th coordinate of j-th node, n(t) the length of t-th axis and k(t) = 1, ..., n(t), the index along this axis (using Yorick conventions). The transpose transform is obtained by: a = op(b, 1) The 1-D transform is: b(j) = sum_{k1=1}^{n1} a(k1)*exp(-2i*pi*(k1 - 1 - n1/2)*x(j)); Operator object can be used as a structure to query its parameters: op.rank = number of dimensions D; op.num_nodes = number of nonequispaced nodes; op.nodes = packed coordinates of nonequispaced nodes (NUM_NODES vector if RANK=1, a NUM_NODES-by-RANK array else); op.inp_dims = dimension list of input array; op.ovr_dims = oversampled dimension list; op.ovr_fact = oversampling factors (for each dimension); op.flags = flags and options for NFFT and FFTW; op.nfft_flags = flags for NFFT (for debug only); op.fftw_flags = flags for FFTW (for debug only); op.cutoff = size of window; op.nevals = number of evaluations; The operator is approximated by: A ~ B.F.D where A is the exact transform, D is a diagonal matrix which perform the deconvolution step (division by the Fourier transform of the interpolation kernel), F is a discrete Fourier transform (computed by FFTW) and B is a sparse interpolation matrix. KEYWORDS: Keyword OVR_FACT (a scalar or a vector of length D) can be used to specify the oversampling factor. By default, the oversampling factor is at least two. The actual oversampling factor can be larger because dimensions are rounded up to powers of 2, 3 and 5. OP.ovr_fact will gives the actual oversampling factor. Keyword OVR_DIMS can be set with a vector of integers [L1,L2, ...] or a dimension list [D,L1,L2,...] to specify the dimensions of the oversampled array. Keywords OVR_FACT and OVR_DIMS are exclusive. Keyword CUTOFF specifies the cut-off of the window function used for the interpolation of the discrete Fourier samples. The number of neighbors taken into account for interpolating along a direction is 2*CUTOFF + 2. Keyword FLAGS can be set with a combination of: NFFT_PRE_PHI_HUT - If this flag is set, the deconvolution step (the multiplication with the diagonal matrix D) uses precomputed values of the Fourier transformed window function. NFFT_FG_PSI - If this flag is set, the convolution step (the multiplication with the sparse interpolation matrix B) uses particular properties of the Gaussian window function to trade multiplications for direct calls to exponential function. NFFT_PRE_LIN_PSI - If this flag is set, the convolution step (the multiplication with the sparse interpolation matrix B) uses linear interpolation from a lookup table of equispaced samples of the window function instead of exact values of the window function. NFFT_PRE_FG_PSI - If this flag is set, the convolution step (the multiplication with the sparse interpolation matrix B) uses particular properties of the Gaussian window function to trade multiplications for direct calls to exponential function (the remaining direct calls are precomputed). NFFT_PRE_PSI - If this flag is set, the convolution step (the multiplication with the sparse interpolation matrix B) uses NUM_NODES*(2*CUTOFF + 2)*RANK precomputed values of the window function. NFFT_PRE_FULL_PSI - If this flag is set, the convolution step (the multiplication with the sparse interpolation matrix B) uses NUM_NODES*(2*CUTOFF + 2)^RANK precomputed values of the window function, in addition indices of source and target vectors are stored. NFFT_SORT_NODES - If set, the sampling nodes are internally sorted, which can result in a performance increase. This has no other side effects for the user. plus at most one of the following values to specify the strategy for searching for a fast FFT in FFTW library: NFFT_ESTIMATE specifies that, instead of actual measurements of different algorithms, a simple heuristic is used to pick a (probably sub-optimal) plan quickly. NFFT_MEASURE tells FFTW to find an optimized plan by actually computing several FFTs and measuring their execution time. Depending on your machine, this can take some time (often a few seconds). NFFT_PATIENT is like NFFT_MEASURE, but considers a wider range of algorithms and often produces a "more optimal" plan (especially for large transforms), but at the expense of several times longer planning time (especially for large transforms). NFFT_EXHAUSTIVE is like NFFT_PATIENT, but considers an even wider range of algorithms, including many that we think are unlikely to be fast, to produce the most optimal plan but with a substantially increased planning time. The default flags are: (NFFT_PRE_PHI_HUT | NFFT_PRE_PSI | NFFT_ESTIMATE | (RANK > 1 ? NFFT_SORT_NODES : 0)) SEE ALSO: xfft, mvmult. */ /* NFFT flags. */ NFFT_PRE_PHI_HUT = (1n << 0n); NFFT_FG_PSI = (1n << 1n); NFFT_PRE_LIN_PSI = (1n << 2n); NFFT_PRE_FG_PSI = (1n << 3n); NFFT_PRE_PSI = (1n << 4n); NFFT_PRE_FULL_PSI = (1n << 5n); NFFT_SORT_NODES = (1n << 11n); /* FFTW options. */ NFFT_ESTIMATE = (1n << 20n); NFFT_MEASURE = (2n << 20n); NFFT_PATIENT = (3n << 20n); NFFT_EXHAUSTIVE = (4n << 20n); extern nfft_indgen; /* DOCUMENT nfft_indgen(len); or nfft_indgen(len, stp); Generate a vector of LEN elements correspong to NFFT input coordinate index frame. If optional argument STP is missing an array of longs [-(LEN/2), 1 - (LEN/2), 2 - (LEN/2), ...] is returned; otherwise, an array of doubles [-(LEN/2), 1 - (LEN/2), 2 - (LEN/2), ...]*STP is returned. SEE ALSO: indgen. */ func nfft_full_matrix(op, mode) /* DOCUMENT nfft_full_matrix(op); or nfft_full_matrix(op, mode); This function returns the coefficients of the NFFT operator OP as a plain complex array of dimensions OP.NUM_NODES by OP.INP_DIMS. If MODE is 0 or omitted, the coefficients are computed directly from the formula. If MODE is 1, the coefficients are computed by applying the operator OP to each "vectors" of the canonical basis of the input space. If MODE is 2, the coefficients are computed by applying the adjoint operator OP to each "vectors" of the canonical basis of the output space. This function is mostly needed for testing purposes. SEE ALSO: nfft_new. */ { PI = 3.1415926535897932384626433832795029; if (4*atan(1) != PI) error, "bad value for PI?"; rank = op.rank; nodes = op.nodes; num_nodes = op.num_nodes; inp_dims = op.inp_dims; ovr_dims = op.ovr_dims; if (rank >= 1) { n1 = inp_dims(2); x1 = nfft_indgen(n1); u1 = nodes(,1); } if (rank >= 2) { n2 = inp_dims(3); x2 = nfft_indgen(n2); u2 = nodes(,2); } if (rank >= 3) { n3 = inp_dims(4); x3 = nfft_indgen(n3); u3 = nodes(,3); } a = array(complex, num_nodes, inp_dims); if (! mode) { /* Directly compute coefficients of operator. */ if (rank == 1) { phi = 2*PI*u1*x1(-,); } else if (rank == 2) { phi = 2*PI*(u1*x1(-,) + u2*x2(-,-,)); } else if (rank == 3) { phi = 2*PI*(u1*x1(-,) + u2*x2(-,-,) + u3*x3(-,-,-,)); } a.re = cos(phi); a.im = -sin(phi); } else if (mode == 1) { /* Apply the operator to the canonical basis. */ x = array(complex, inp_dims); if (rank == 1) { for (i1 = 1; i1 <= n1; ++i1) { x(i1) = 1; a(, i1) = op(x); x(i1) = 0; } } else if (rank == 2) { for (i1 = 1; i1 <= n1; ++i1) { for (i2 = 1; i2 <= n2; ++i2) { x(i1, i2) = 1; a(, i1, i2) = op(x); x(i1, i2) = 0; } } } else if (rank == 3) { for (i1 = 1; i1 <= n1; ++i1) { for (i2 = 1; i2 <= n2; ++i2) { for (i3 = 1; i3 <= n3; ++i3) { x(i1, i2, i3) = 1; a(, i1, i2, i3) = op(x); x(i1, i2, i3) = 0; } } } } } else if (mode == 2) { /* Apply the adjoint operator to the canonical basis. */ y = array(complex, num_nodes); for (j = 1; j <= num_nodes; ++j) { y(j) = 1; a(j,..) = conj(op(y,1)); y(j) = 0; } } else { error, "invalid method for computing the full matrix"; } return a; } extern nfft_mira3d_new; /* DOCUMENT H = nfft_mira3d_new(u, v, w, pixelsize, nx, ny, wlist, complex_meas=); U, V and W are the spatial frequency coordinates and wavelength they must all be of the same size and in compatible units. WLIST = list of model wavelengths (must be in ascending order). COMPLEX_MEAS keyword can be used to specify whether the measurements model is an array composed of complex number or pairs of reals. (default: COMPLEX_MEAS = 0). SEE ALSO: nfft_new. */ ynfft-1.0.3/tools/000077500000000000000000000000001265731475700140225ustar00rootroot00000000000000ynfft-1.0.3/tools/README000066400000000000000000000017421265731475700147060ustar00rootroot00000000000000This directory contains scripts for filtering source files when commiting or checking-out these files with GIT. To use these scripts, add the following settings in .git/config: ------------------------------------------ [filter "cleanup-c"] clean = ./tools/code_cleanup smudge = cat [filter "cleanup-code"] clean = ./tools/code_cleanup smudge = cat [filter "cleanup-text"] clean = ./tools/code_cleanup smudge = cat [filter "cleanup-yorick-makefile"] clean = ./tools/ymk_cleanup smudge = cat ------------------------------------------ and add the following rules in .gitattributes: ------------------------------------------ *.[hc] filter=cleanup-code *.i filter=cleanup-text README filter=cleanup-text TODO filter=cleanup-text AUTHORS filter=cleanup-text NEWS filter=cleanup-text configure filter=cleanup-text Makefile filter=cleanup-yorick-makefile ------------------------------------------ ynfft-1.0.3/tools/code_cleanup000077500000000000000000000011461265731475700163730ustar00rootroot00000000000000#! /bin/sh # # This script is a filter to cleanup text or code files. The following # operations are performed: # - Trailing spaces are removed. # - Unix-like end of line markers are used (LF). # - Leading tabulations are replaced by spaces. # debug=no bypass=no if test "$debug" = "yes"; then echo >&2 "command -----> $0 $@" fi # Simply execute "cat" to bypass the filter: test "$bypass" = "yes" && exec cat expand --initial --tabs=8 \ | sed -e 's/\x0d$//;s/[ ]*$//;s/[ ]*\x0d/\x0a/g' # Local Variables: # mode: sh # tab-width: 8 # indent-tabs-mode: nil # fill-column: 78 # coding: utf-8 # End: ynfft-1.0.3/tools/ymk_cleanup000077500000000000000000000007251265731475700162630ustar00rootroot00000000000000#! /bin/sed -f # # This SED script is a filter to Yorick Makefile. The following # operations are performed: # - Trailing spaces are removed. # - Tabulations are left unchanged (this is intended for Makefiles). # - Unix-like end of line markers are used (LF). # - Macros like Y_HOME which are overwritten by 'yorick -batch make.i' are # cleared. # s/\x0d$// s/ *$// s/ *\x0d/\x0a/g s/^\( *Y_\(MAKEDIR\|EXE\(\|_PKGS\|_HOME\|_SITE\)\|HOME_PKG\) *=\).*/\1/ # ynfft-1.0.3/yor_nfft.c000066400000000000000000000722111265731475700146570ustar00rootroot00000000000000/* * yor_nfft.c -- * * Implementation of NFFT Yorick interface. * *----------------------------------------------------------------------------- * * Copyright (C) 2012, 2015-2016, Éric Thiébaut * Copyright (C) 2013-2014, Ferréol Soulez and * Éric Thiébaut * * This software is governed by the CeCILL-C license under French law and * abiding by the rules of distribution of free software. You can use, modify * and/or redistribute the software under the terms of the CeCILL-C license as * circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited liability. * * In this respect, the user's attention is drawn to the risks associated with * loading, using, modifying and/or developing or reproducing the software by * the user in light of its specific status of free software, that may mean * that it is complicated to manipulate, and that also therefore means that it * is reserved for developers and experienced professionals having in-depth * computer knowledge. Users are therefore encouraged to load and test the * software's suitability as regards their requirements in conditions enabling * the security of their systems and/or data to be ensured and, more * generally, to use and operate it in the same conditions as regards * security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. * *----------------------------------------------------------------------------- */ /* * IMPLEMENTATION NOTES * ==================== * * The dimensions are ordered as in FFTW which is reverse order of Yorick. * That is Yorick dimensions list is (RANK,DIM1,DIM2,...) while for NFFT (and * FFTW) it is (...,DIM2,DIM1): * * dims_yorick(t) = t-th dimension * = dims_nfft[rank - t] * * This also applies for the coordinate system used for the nodes: * * x_yorick(j,t) = t-th coordinate of j-th node * = x_nfft[(rank - t) + (j - 1)*rank] * * with t = 1, ..., rank and j = 1, ..., num_nodes (beware of the bounds of * these ranges). * * Using 0-based indices, this leads to: * * x_yorick[j + t*num_nodes] = x_nfft[(rank - 1 - t) + j*rank] */ #include #include #include #include #include #include #if defined(_OPENMP) # include #endif #include #include /* Deal with different versions of NFFT3. */ #ifdef NFFT_DEFINE_MALLOC_API # define MEMBER_NFFT_FLAGS flags #else # define NFFT_INT int # define MEMBER_NFFT_FLAGS nfft_flags #endif #define MAX(a,b) ((a) >= (b) ? (a) : (b)) #define MIN(a,b) ((a) <= (b) ? (a) : (b)) #define BUILTIN(name) PLUG_API void Y_nfft_##name #define MAX_RANK 3 /* maximum number of dimensions (limit set by NFFT) */ #define FALSE 0 #define TRUE 1 #define SUCCESS 0 #define FAILURE (-1) #if (Y_CHAR != 0) # error code assumes that Y_CHAR = 0 #endif #if (Y_SHORT != 1) # error code assumes that Y_SHORT = 1 #endif #if (Y_INT != 2) # error code assumes that Y_INT = 2 #endif #if (Y_LONG != 3) # error code assumes that Y_LONG = 3 #endif #if (Y_FLOAT != 4) # error code assumes that Y_FLOAT = 4 #endif #if (Y_DOUBLE != 5) # error code assumes that Y_DOUBLE = 5 #endif #if (Y_COMPLEX != 6) # error code assumes that Y_COMPLEX = 6 #endif /* Loop over arguments of a built-in function (i is the variable index, n is the number of arguments). */ #define ARG_LOOP(i,n) for (i = (n) - 1; i >= 0; --i) /* Values returned by yarg_number. */ #define NUM_NONE 0 #define NUM_INTEGER 1 #define NUM_REAL 2 #define NUM_COMPLEX 3 #define IS_INTEGER(id) ((id) >= Y_CHAR && (id) <= Y_LONG) #define IS_REAL(id) ((id) == Y_DOUBLE || (id) == Y_FLOAT) #define IS_COMPLEX(id) ((id) == Y_COMPLEX) #define IS_INTEGER_OR_REAL(id) ((id) >= Y_CHAR && (id) <= Y_DOUBLE) #define IS_NUMERICAL(id) ((id) >= Y_CHAR && (id) <= Y_COMPLEX) /* Flags and options (must match values in nfft.i). */ #define YNFFT_PRE_PHI_HUT (1 << 0) #define YNFFT_FG_PSI (1 << 1) #define YNFFT_PRE_LIN_PSI (1 << 2) #define YNFFT_PRE_FG_PSI (1 << 3) #define YNFFT_PRE_PSI (1 << 4) #define YNFFT_PRE_FULL_PSI (1 << 5) #define YNFFT_SORT_NODES (1 << 11) #define YNFFT_ESTIMATE (1 << 20) #define YNFFT_MEASURE (2 << 20) #define YNFFT_PATIENT (3 << 20) #define YNFFT_EXHAUSTIVE (4 << 20) static unsigned int get_flags(unsigned int nfft_flags, unsigned int fftw_flags); static unsigned int get_nfft_flags(unsigned int flags); static unsigned int get_fftw_flags(unsigned int flags); /* Sets of flags/options for FFTW library. */ #define DEFAULT_FFTW_FLAGS (FFTW_ESTIMATE) #define MINIMAL_FFTW_FLAGS (FFTW_DESTROY_INPUT) #define ALLOWED_FFTW_FLAGS (FFTW_ESTIMATE | FFTW_MEASURE | \ FFTW_PATIENT | FFTW_EXHAUSTIVE) /* Sets of flags/options for NFFT library. */ #define SORT_NODES NFFT_SORT_NODES /* oddly this macro is the only one prefixed in NFFT */ #define DEFAULT_NFFT_FLAGS (PRE_PHI_HUT | PRE_PSI) #define _MINIMAL_NFFT_FLAGS MALLOC_X | MALLOC_F_HAT | MALLOC_F | \ FFTW_INIT | FFT_OUT_OF_PLACE #ifdef _OPENMP # define MINIMAL_NFFT_FLAGS (_MINIMAL_NFFT_FLAGS | NFFT_OMP_BLOCKWISE_ADJOINT) #else # define MINIMAL_NFFT_FLAGS (_MINIMAL_NFFT_FLAGS) #endif #define ALLOWED_NFFT_FLAGS (PRE_PHI_HUT | FG_PSI | PRE_LIN_PSI | \ PRE_FG_PSI | PRE_PSI | PRE_FULL_PSI | \ SORT_NODES) static void make_nfft_plan(nfft_plan *plan, long rank, const long inp_dims[], const long ovr_dims[], long num_nodes, const double *x[], double xscale, double cutoff, unsigned int nfft_flags, unsigned int fftw_flags); /* Indices of keywords. */ static long cutoff_index = -1L; static long extend_index = -1L; static long flags_index = -1L; static long inp_dims_index = -1L; static long nevals_index = -1L; static long nodes_index = -1L; static long num_nodes_index = -1L; static long ovr_dims_index = -1L; static long ovr_fact_index = -1L; static long rank_index = -1L; static long fftw_flags_index = -1L; static long nfft_flags_index = -1L; static long complex_meas_index = -1L; static long num_threads_index = -1L; /* Default value for cutoff number (negative means not yet determined). */ static long default_cutoff = -1; #define INITIALIZE if (default_cutoff > 0) /* do nothing */; else initialize() static void initialize(void) { if (default_cutoff < 1) { #define SET_INDEX(name) name##_index = yget_global(#name, 0) SET_INDEX(cutoff); SET_INDEX(extend); SET_INDEX(flags); SET_INDEX(inp_dims); SET_INDEX(nevals); SET_INDEX(nodes); SET_INDEX(num_nodes); SET_INDEX(ovr_dims); SET_INDEX(ovr_fact); SET_INDEX(rank); SET_INDEX(nfft_flags); SET_INDEX(complex_meas); SET_INDEX(num_threads); SET_INDEX(fftw_flags); #undef SET_INDEX { /* Get default size of window (in case of interupts, must be done last). */ nfft_plan p; nfft_init_1d(&p, 100, 1); default_cutoff = p.m; nfft_finalize(&p); } } } /*---------------------------------------------------------------------------*/ /* MANAGE YORICK ARGUMENTS */ static int get_scalar_int(int iarg, int *ptr) { if (yarg_number(iarg) == NUM_INTEGER && yarg_rank(iarg) == 0) { long temp = ygets_l(iarg); *ptr = (int)temp; if (*ptr == temp) { return SUCCESS; } } return FAILURE; } #if 0 static int get_scalar_long(int iarg, long *ptr) { if (yarg_number(iarg) == NUM_INTEGER && yarg_rank(iarg) == 0) { *ptr = ygets_l(iarg); return SUCCESS; } return FAILURE; } static int get_scalar_double(int iarg, double *ptr) { int type = yarg_number(iarg); if ((type == NUM_INTEGER || type == NUM_REAL) && yarg_rank(iarg) == 0) { *ptr = ygets_d(iarg); return SUCCESS; } return FAILURE; } #endif /*---------------------------------------------------------------------------*/ /* OTHER UTILITY FUNCTIONS */ static int best_fft_length(int len) { int best, l2, l3, l5; best = 2*len; for (l5 = 1; l5 < best; l5 *= 5) { for (l3 = l5; l3 < best; l3 *= 3) { for (l2 = l3; l2 < len; l2 *= 2) { ; /* empty loop body */ } if (l2 == len) { return len; } if (l2 < best) { best = l2; } } } return best; } static const char *ordinal_suffix(long n) { if (n > 0) { switch (n%10) { case 1: if (n != 11) return "st"; break; case 2: if (n != 12) return "nd"; break; case 3: if (n != 13) return "rd"; break; } } return "th"; } /*---------------------------------------------------------------------------*/ /* DECLARATION OF THE OPERATOR CLASS */ /* Structure to stores an instance of the operator. */ typedef struct _op op_t; struct _op { nfft_plan plan; long nevals; int initialized; }; #define GET_RANK(op) ((op)->plan.d) #define GET_NUM_NODES(op) ((op)->plan.M_total) #define GET_NODES(op) ((op)->plan.x) #define GET_INP_DIMS(op) ((op)->plan.N) #define GET_OVR_DIMS(op) ((op)->plan.n) #define GET_OVR_FACT(op) ((op)->plan.sigma) #define GET_NFFT_FLAGS(op) ((op)->plan.MEMBER_NFFT_FLAGS) #define GET_FFTW_FLAGS(op) ((op)->plan.fftw_flags) #define GET_CUTOFF(op) ((op)->plan.m) #define GET_NEVALS(op) ((op)->nevals) /* Methods. */ static void op_free(void *); static void op_print(void *); static void op_eval(void *, int); static void op_extract(void *, char *); /* Class definition. */ static y_userobj_t op_class = { /* type_name: */ "NFFT operator", /* on_free: */ op_free, /* on_print: */ op_print, /* on_eval: */ op_eval, /* on_extract: */ op_extract, /* uo_ops: */ (void *)0 }; /*---------------------------------------------------------------------------*/ /* IMPLEMENTATION OF METHODS FOR THE OPERATOR CLASS */ static void op_free(void *ptr) { op_t *op = (op_t *)ptr; if (op->initialized) { nfft_finalize(&op->plan); } } static void op_print(void *ptr) { y_print("NFFT operator", 1); } static void op_eval(void *ptr, int argc) { op_t *op = (op_t *)ptr; const double *src; double *dst; const NFFT_INT *inp_dims; long dims[Y_DIMSIZE]; long t, rank, num_nodes, dim, nsrc, ndst; int arg_type, job = 0; /* Get the direction of the transform and check number of arguments. */ if (argc == 2) { arg_type = yarg_typeid(0); if (IS_INTEGER(arg_type) && yarg_rank(0) == 0) { job = ygets_i(0); } else if (arg_type != Y_VOID) { y_error("bad job"); } yarg_drop(1); } else if (argc != 1) { y_error("syntax: op(a) or op(a, job) with op the NFFT operator"); } /*FIXME: for efficiency make the conversion and padding myself */ /*FIXME: add a flag to pretend result is a double */ src = ygeta_z(0, &nsrc, dims); rank = GET_RANK(op); num_nodes = GET_NUM_NODES(op); inp_dims = GET_INP_DIMS(op); if (job) { /* Apply adjoint. */ if (dims[0] > 1 || nsrc != num_nodes) { goto bad_dims; } memcpy(op->plan.f, src, nsrc*(2*sizeof(double))); yarg_drop(1); /* source no longer needed */ nfft_adjoint(&op->plan); dims[0] = rank; ndst = 1; for (t = 0; t < rank; ++t) { dim = inp_dims[rank - 1 - t]; ndst *= dim; dims[1 + t] = dim; } dst = ypush_z(dims); memcpy(dst, op->plan.f_hat, ndst*(2*sizeof(double))); } else { /* Apply transform. */ if (dims[0] != rank) { goto bad_dims; } for (t = 0; t < rank; ++t) { if (dims[1 + t] != inp_dims[rank - 1 - t]) { goto bad_dims; } } memcpy(op->plan.f_hat, src, nsrc*(2*sizeof(double))); yarg_drop(1); /* source no longer needed */ nfft_trafo(&op->plan); ndst = num_nodes; dims[0] = (ndst > 1 ? 1 : 0); dims[1] = ndst; dst = ypush_z(dims); memcpy(dst, op->plan.f, ndst*(2*sizeof(double))); } ++op->nevals; return; bad_dims: y_error("bad dimensions"); } /* Implement the on_extract method to query a member of the object. */ static void op_extract(void *ptr, char *member) { op_t *op = (op_t *)ptr; long index = yget_global(member, 0); long dims[Y_DIMSIZE]; long j, t, rank, num_nodes; /* No needs to initialize as this as laready been done by the op_new method. */ if (index == ovr_fact_index) { double *dst; const double *src = GET_OVR_FACT(op); rank = GET_RANK(op); dims[0] = 1; dims[1] = rank; dst = ypush_d(dims); for (t = 0; t < rank; ++t) { dst[t] = src[rank - 1 - t]; } } else if (index == rank_index) { long value = GET_RANK(op); ypush_long(value); } else if (index == ovr_dims_index) { const NFFT_INT *src = GET_OVR_DIMS(op); long *dst; rank = GET_RANK(op); dims[0] = 1; dims[1] = rank + 1; dst = ypush_l(dims); dst[0] = rank; for (t = 0; t < rank; ++t) { dst[1 + t] = src[rank - 1 - t]; } } else if (index == inp_dims_index) { const NFFT_INT *src = GET_INP_DIMS(op); long *dst; rank = GET_RANK(op); dims[0] = 1; dims[1] = rank + 1; dst = ypush_l(dims); dst[0] = rank; for (t = 0; t < rank; ++t) { dst[1 + t] = src[rank - 1 - t]; } } else if (index == nodes_index) { /* Copy coordinates of nodes. */ double *dst; const double *src = GET_NODES(op); if (src == NULL) { y_error("creation of NFFT plan failed"); } rank = GET_RANK(op); num_nodes = GET_NUM_NODES(op); dims[0] = (rank > 1 ? 2 : 1); dims[1] = num_nodes; dims[2] = rank; dst = ypush_d(dims); for (t = 0; t < rank; ++t) { for (j = 0; j < num_nodes; ++j) { /* Take into account storage order: * x_yorick[j + num_nodes*t] = x_nfft[(rank - 1 - t) + j*rank] */ dst[j + num_nodes*t] = src[rank - 1 - t + rank*j]; } } } else if (index == num_nodes_index) { long value = GET_NUM_NODES(op); ypush_long(value); } else if (index == cutoff_index) { long value = GET_CUTOFF(op); ypush_long(value); } else if (index == nevals_index) { long value = GET_NEVALS(op); ypush_long(value); } else if (index == flags_index) { int value = get_flags(GET_NFFT_FLAGS(op), GET_FFTW_FLAGS(op)); ypush_int(value); } else if (index == nfft_flags_index) { int value = GET_NFFT_FLAGS(op); ypush_int(value); } else if (index == fftw_flags_index) { int value = GET_FFTW_FLAGS(op); ypush_int(value); } else { y_error("invalid NFFT member"); /*ypush_nil();*/ } } static unsigned int get_flags(unsigned int nfft_flags, unsigned int fftw_flags) { unsigned int flags; #define CASE(a) case FFTW_##a: flags = YNFFT_##a; break switch (fftw_flags & (FFTW_ESTIMATE|FFTW_MEASURE|FFTW_PATIENT|FFTW_EXHAUSTIVE)) { CASE(ESTIMATE); CASE(MEASURE); CASE(PATIENT); CASE(EXHAUSTIVE); default: flags = 0; } #undef CASE #define SET_FLAG(a) if ((nfft_flags & a) != 0) flags |= YNFFT_##a SET_FLAG(PRE_PHI_HUT); SET_FLAG(FG_PSI); SET_FLAG(PRE_LIN_PSI); SET_FLAG(PRE_FG_PSI); SET_FLAG(PRE_PSI); SET_FLAG(PRE_FULL_PSI); SET_FLAG(SORT_NODES); #undef SET_FLAG return flags; } static unsigned int get_nfft_flags(unsigned int flags) { if (flags == -1) { return (MINIMAL_NFFT_FLAGS | DEFAULT_NFFT_FLAGS); } else { unsigned int nfft_flags = MINIMAL_NFFT_FLAGS; #define SET_FLAG(a) if ((flags & YNFFT_##a) != 0) nfft_flags |= a SET_FLAG(PRE_PHI_HUT); SET_FLAG(FG_PSI); SET_FLAG(PRE_LIN_PSI); SET_FLAG(PRE_FG_PSI); SET_FLAG(PRE_PSI); SET_FLAG(PRE_FULL_PSI); SET_FLAG(SORT_NODES); #undef SET_FLAG return nfft_flags; } } static unsigned int get_fftw_flags(unsigned int flags) { if (flags != -1) { #define CASE(a) case YNFFT_##a: return (MINIMAL_FFTW_FLAGS | FFTW_##a); break switch (flags & (YNFFT_ESTIMATE|YNFFT_MEASURE|YNFFT_PATIENT|YNFFT_EXHAUSTIVE)) { CASE(ESTIMATE); CASE(MEASURE); CASE(PATIENT); CASE(EXHAUSTIVE); } #undef CASE } return (MINIMAL_FFTW_FLAGS | DEFAULT_FFTW_FLAGS); } /*---------------------------------------------------------------------------*/ /* BUILT-IN FUNCTIONS */ BUILTIN(version)(int argc) { ypush_q(NULL)[0] = p_strcpy(VERSION); } BUILTIN(indgen)(int argc) { double stp; long k, k0, k1, len, dims[2]; if (argc == 2) { stp = ygets_d(0); if (stp <= 0.0) { y_error("step size must be strictly positive"); } yarg_drop(1); } else { stp = 0.0; if (argc != 1) { y_error("nfft_indgen takes one or two arguments"); } } len = ygets_l(0); if (len <= 0 || len%2 != 0) { y_error("length must be a strictly positive even number"); } dims[0] = 1; dims[1] = len; k0 = -(len/2); k1 = len + k0; if (stp > 0.0) { double *dst = ypush_d(dims) - k0; for (k = k0; k < k1; ++k) { dst[k] = k*stp; } } else { long *dst = ypush_l(dims) - k0; for (k = k0; k < k1; ++k) { dst[k] = k; } } } BUILTIN(new)(int argc) { /* Oversampling factors. */ double ovr_fact_buf[MAX_RANK]; const double *ovr_fact = NULL; long ovr_fact_ntot = 0; int ovr_fact_rank = -1; /* Oversampled dimensions. */ const long *ovr_dims = NULL; long ovr_dims_ntot = 0; int ovr_dims_rank = -1; long ovr_dims_buf[MAX_RANK]; /* Dimensions of the input space. */ long *inp_dims; long inp_dims_ntot; long inp_dims_buf[MAX_RANK]; /* Other parameters of the transform. */ int rank; int cutoff = -1; int flags = -1; unsigned int nfft_flags, fftw_flags; long num_nodes = 0; const double *x[MAX_RANK]; long j; op_t *op; int t; int iarg, packed = FALSE, positional_args = 0, arg_is_dim; char errbuf[256]; /* Variables to store the characteristics of an argument. */ long index; long arg_ntot, arg_dims[Y_DIMSIZE]; int arg_type; /* Setup internals. */ INITIALIZE; /* Calling this builtin as a subroutine does not make sense. */ if (yarg_subroutine()) { y_error("nfft_new must be called as a function"); } /* First pass to count the number of positional arguments. */ positional_args = 0; ARG_LOOP(iarg, argc) { index = yarg_key(iarg); if (index < 0L) { ++positional_args; } else { --iarg; } } if (positional_args < 2) { y_error("too few arguments"); } if (positional_args > 2*MAX_RANK) { sprintf(errbuf, "too many arguments (max. rank = %d)", MAX_RANK); y_error(errbuf); } if (positional_args%2 != 0) { y_error("bad number of arguments"); } packed = (positional_args == 2); inp_dims = (packed ? NULL : inp_dims_buf); inp_dims_ntot = 0; rank = 0; for (t = 0; t < rank; ++t) { inp_dims_buf[t] = -1; } /* Parse arguments. */ arg_is_dim = FALSE; ARG_LOOP(iarg, argc) { index = yarg_key(iarg); if (index < 0L) { /* Got a positional argument. */ arg_is_dim = !arg_is_dim; /* toggle dim/coord flag */ if (arg_is_dim) { /* Parse input dimension(s). */ if (yarg_number(iarg) != NUM_INTEGER) { y_error("bad type for dimension(s)"); } if (packed) { /* This must be the first positional argument. */ inp_dims = ygeta_l(iarg, &inp_dims_ntot, NULL); } else if (yarg_rank(iarg) == 0) { if (++rank > MAX_RANK) { goto too_many_dims; } inp_dims[rank - 1] = ygets_l(iarg); } else { goto expecting_salar_dim; } } else { /* Get coordinates. */ arg_type = yarg_number(iarg); if (arg_type != NUM_INTEGER && arg_type != NUM_REAL) { goto bad_coord_type; } if (packed) { /* Get packed coordinates. */ const double *arg_ptr; arg_ptr = ygeta_d(iarg, &arg_ntot, arg_dims); switch (arg_dims[0]) { case 0: num_nodes = 1; rank = 1; break; case 1: num_nodes = arg_dims[1]; rank = 1; break; case 2: num_nodes = arg_dims[1]; rank = arg_dims[2]; break; default: goto bad_coord_dims; } if (rank > MAX_RANK) { goto too_many_dims; } if (inp_dims_ntot != rank) { /* Input dimensions not given as [N1,N2,...,ND]. */ if (inp_dims_ntot == rank + 1 && inp_dims[0] == rank) { /* Input dimensions given as [D,N1,N2,...,ND]. */ ++inp_dims; /* skip the leading D */ } else { goto incompatible_dims; } } for (t = 0; t < rank; ++t) { x[t] = arg_ptr + num_nodes*t; } } else { /* Get split coordinates. */ if (yarg_rank(iarg) > 1) { goto bad_coord_dims; } x[rank - 1] = ygeta_d(iarg, &arg_ntot, NULL); if (rank == 1) { num_nodes = arg_ntot; } else if (num_nodes != arg_ntot) { goto not_same_lengths; } } } } else if (index == cutoff_index) { --iarg; if (get_scalar_int(iarg, &cutoff) != SUCCESS || cutoff < 0) { y_error("invalid value for CUTOFF keyword"); } } else if (index == flags_index) { --iarg; if (get_scalar_int(iarg, &flags) != SUCCESS) { y_error("invalid value for FFTW_FLAGS keyword"); } } else if (index == ovr_dims_index) { /* Get oversampled dimensions. */ if (ovr_fact != NULL) { goto ovr_fact_and_ovr_dims_exclusive; } --iarg; if (yarg_number(iarg) != NUM_INTEGER) { y_error("bad type for OVR_DIMS keyword"); } ovr_dims_rank = yarg_rank(iarg); if (ovr_dims_rank != 0 && ovr_dims_rank != 1) { y_error("bad dimensions for OVR_DIMS keyword"); } ovr_dims = ygeta_l(iarg, &ovr_dims_ntot, NULL); } else if (index == ovr_fact_index) { /* Get oversampling factors. */ if (ovr_dims != NULL) { goto ovr_fact_and_ovr_dims_exclusive; } --iarg; arg_type = yarg_number(iarg); if (arg_type != NUM_INTEGER && arg_type != NUM_REAL) { y_error("bad type for OVR_FACT keyword"); } ovr_fact_rank = yarg_rank(iarg); if (ovr_fact_rank == 0) { ovr_fact_buf[0] = ygets_d(iarg); ovr_fact = ovr_fact_buf; ovr_fact_ntot = 1; } else if (ovr_fact_rank == 1) { ovr_fact = ygeta_d(iarg, &ovr_fact_ntot, NULL); } else { y_error("bad dimensions for OVR_FACT keyword"); } } else { y_error("unknown keyword"); } } /* N_t (for t = 0,...,d-1) are the dimensions of the input array, they * must be even numbers and coordinates along these dimensions are: * -N_t/2 <= k_t < N_t/2 * * Extended dimensions n_t must be strictly larger (n_t > N_t) and * preferably good dimensions for the FFT (by FFTW). Moreover the * dimensions N_t must be strictly larger than the cutoff * parameter m. */ /* Use default cutoff if not set. */ if (cutoff < 0) { cutoff = default_cutoff; } /* Check node coordinates. */ for (t = 0; t < rank; ++t) { for (j = 0; j < num_nodes; ++j) { if (x[t][j] < -0.5 || x[t][j] >= 0.5) { y_error("coordinates of nonequidistant nodes out of range [-0.5,0.5)"); } } } /* Check input dimensions. */ for (t = 0; t < rank; ++t) { if (inp_dims[t] <= cutoff) { sprintf(errbuf, "%d%s dimension is smaller than cut-off (= %d)", t, ordinal_suffix(t), cutoff); y_error(errbuf); } if (inp_dims[t]%2 != 0) { sprintf(errbuf, "%d%s dimension is odd (must be even)", t, ordinal_suffix(t)); y_error(errbuf); } } /* Check oversampled dimensions, if given; otherwise, compute them. */ if (ovr_dims != NULL) { if (ovr_dims_rank == 0) { /* Duplicate scalar oversampled dimension. */ for (t = 0; t < rank; ++t) { ovr_dims_buf[t] = ovr_dims[0]; } ovr_dims = ovr_dims_buf; } else if (ovr_dims_ntot != rank) { y_error("bad number of oversampled dimensions in OVR_DIMS keyword"); } for (t = 0; t < rank; ++t) { if (ovr_dims[t] <= inp_dims[t]) { sprintf(errbuf, "%d%s oversampled dimension too small in OVR_DIMS keyword", t, ordinal_suffix(t)); y_error(errbuf); } } } else { /* Check oversampling factors, if given; otherwise, use a default oversampling factor of 2. */ if (ovr_fact == NULL) { /* Duplicate scalar oversampled factor. */ for (t = 0; t < rank; ++t) { ovr_fact_buf[t] = 2.0; } ovr_fact = ovr_fact_buf; } else { if (ovr_fact_rank == 0) { for (t = 0; t < rank; ++t) { ovr_fact_buf[t] = ovr_fact[0]; } ovr_fact = ovr_fact_buf; } else if (ovr_fact_ntot != rank) { y_error("bad number of oversampling factors in OVR_FACT keyword"); } } /* Compute oversampled dimensions. */ for (t = 0; t < rank; ++t) { long dim; if (ovr_fact[t] <= 0.0) { dim = -1; } else { double min_dim = ovr_fact[t]*inp_dims[t]; dim = best_fft_length((long)min_dim); while (dim < min_dim) { dim = best_fft_length(dim + 1); } } if (dim <= inp_dims[t]) { sprintf(errbuf, "oversampling factor too small for %d%s " "dimension in OVR_FACT keyword", t, ordinal_suffix(t)); y_error(errbuf); } ovr_dims_buf[t] = dim; } ovr_dims = ovr_dims_buf; } /* Set flags (defaults come from file nfft.c in NFFT3 sources). */ fftw_flags = get_fftw_flags(flags); nfft_flags = get_nfft_flags(flags); if (flags == -1 && rank > 1) { /* According to NFFT documentation, this should yield some speedup. */ nfft_flags |= NFFT_SORT_NODES; } /* Create object instance. */ op = (op_t *)ypush_obj(&op_class, sizeof(op_t)); /* Create NFFT plan. */ make_nfft_plan(&op->plan, rank, inp_dims, ovr_dims, num_nodes, x, 1.0, cutoff, nfft_flags, fftw_flags); op->initialized = TRUE; return; /* Error management. */ { char *errmsg; #define THROW(msg) errmsg = msg; goto throw too_many_dims: sprintf(errbuf, "too many dimensions (max. rank = %d)", MAX_RANK); y_error(errbuf); bad_coord_type: THROW("bad type for coordinates of nonequidistant nodes"); bad_coord_dims: THROW("bad dimensions for coordinates of nonequidistant nodes"); not_same_lengths: THROW("coordinates of nonequidistant nodes have not same lengths"); expecting_salar_dim: THROW("expecting scalar dimension"); ovr_fact_and_ovr_dims_exclusive: THROW("keywords OVR_FACT and OVR_DIMS are exclusive"); incompatible_dims: THROW("number of input dimensions does not rank of coordinates"); #undef THROW throw: y_error(errmsg); } } static void make_nfft_plan(nfft_plan *plan, long rank, const long inp_dims[], const long ovr_dims[], long num_nodes, const double *x[], double xscale, double cutoff, unsigned int nfft_flags, unsigned int fftw_flags) { /* Work arrays to convert/swap integers. */ int _inp_dims[MAX_RANK], _ovr_dims[MAX_RANK]; int _num_nodes; long j, t; double *plan_x; if (rank > MAX_RANK) { y_error("too many dimensions"); } /* Create NFFT plan (taking care of integer overflow for 64-bit -> 32-bit conversion and of ordering of dimensions). */ if ((_num_nodes = (int)num_nodes) != num_nodes) { goto integer_overflow; } for (t = 0; t < rank; ++t) { if ((_inp_dims[rank - 1 - t] = (int)inp_dims[t]) != inp_dims[t] || (_ovr_dims[rank - 1 - t] = (int)ovr_dims[t]) != ovr_dims[t]) { goto integer_overflow; } } nfft_init_guru(plan, rank, _inp_dims, _num_nodes, _ovr_dims, cutoff, nfft_flags, fftw_flags); /* Copy coordinates of nodes. Taking into account storage order: * x_yorick[j + num_nodes*t] = x_nfft[(rank - 1 - t) + j*rank] */ plan_x = plan->x; if (plan_x == NULL) { /* FIXME: do more extensive tests. */ y_error("creation of NFFT plan failed"); } for (t = 0; t < rank; ++t) { for (j = 0; j < num_nodes; ++j) { plan_x[rank - 1 - t + rank*j] = xscale*x[t][j]; } } /* Precompute interpolation weights. */ if ((plan->MEMBER_NFFT_FLAGS & PRE_ONE_PSI) != 0) { nfft_precompute_one_psi(plan); } return; integer_overflow: y_error("integer overflow (too many nodes or dimensions too large)"); } #include "m3d_nfft.c"