diff --git a/.gitignore b/.gitignore index 2db2292b9b53808fc83619b87524190bc2c802d4..ae734ec29cf3729236a0f1f7f6aa81facc3eed83 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ git_version.py # custom +*.txt setup.cfg .idea .DS_Store diff --git a/demos/plot_test.py b/demos/plot_test.py deleted file mode 100644 index 792b53ebe651e19f059a145566eeea2b8ca4ff4d..0000000000000000000000000000000000000000 --- a/demos/plot_test.py +++ /dev/null @@ -1,61 +0,0 @@ -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# Copyright(C) 2013-2019 Max-Planck-Society -# -# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik. - -import nifty5 as ift -import numpy as np - - -def plot_test(): - rg_space1 = ift.makeDomain(ift.RGSpace((100,))) - rg_space2 = ift.makeDomain(ift.RGSpace((80, 60), distances=1)) - hp_space = ift.makeDomain(ift.HPSpace(64)) - gl_space = ift.makeDomain(ift.GLSpace(128)) - - fft = ift.FFTOperator(rg_space2) - - field_rg1_1 = ift.Field.from_global_data(rg_space1, np.random.randn(100)) - field_rg1_2 = ift.Field.from_global_data(rg_space1, np.random.randn(100)) - field_rg2 = ift.Field.from_global_data( - rg_space2, np.random.randn(80*60).reshape((80, 60))) - field_hp = ift.Field.from_global_data(hp_space, np.random.randn(12*64**2)) - field_gl = ift.Field.from_global_data(gl_space, np.random.randn(32640)) - field_ps = ift.power_analyze(fft.times(field_rg2)) - - # Start various plotting tests - - plot = ift.Plot() - plot.add(field_rg1_1, title='Single plot') - plot.output() - - plot = ift.Plot() - plot.add(field_rg2, title='2d rg') - plot.add([field_rg1_1, field_rg1_2], title='list 1d rg', label=['1', '2']) - plot.add(field_rg1_2, title='1d rg, xmin, ymin', xmin=0.5, ymin=0., - xlabel='xmin=0.5', ylabel='ymin=0') - plot.output(title='Three plots') - - plot = ift.Plot() - plot.add(field_hp, title='HP planck-color', colormap='Planck-like') - plot.add(field_rg1_2, title='1d rg') - plot.add(field_ps) - plot.add(field_gl, title='GL') - plot.add(field_rg2, title='2d rg') - plot.output(nx=2, ny=3, title='Five plots') - - -if __name__ == '__main__': - plot_test() diff --git a/docs/source/citations.rst b/docs/source/citations.rst index 3d7315907b5decaefd99785b327cf8fbb44d5b30..b9c864a259d9f9914fda84f3352e6419d9eaa929 100644 --- a/docs/source/citations.rst +++ b/docs/source/citations.rst @@ -17,7 +17,7 @@ NIFTy-related publications date = {2018-04-05}, } - @ARTICLE{2013A&A...554A..26S, + @article{2013A&A...554A..26S, author = {{Selig}, M. and {Bell}, M.~R. and {Junklewitz}, H. and {Oppermann}, N. and {Reinecke}, M. and {Greiner}, M. and {Pachajoa}, C. and {En{\ss}lin}, T.~A.}, title = "{NIFTY - Numerical Information Field Theory. A versatile PYTHON library for signal inference}", journal = {\aap}, @@ -35,7 +35,7 @@ NIFTy-related publications adsnote = {Provided by the SAO/NASA Astrophysics Data System} } - @ARTICLE{2017arXiv170801073S, + @article{2017arXiv170801073S, author = {{Steininger}, T. and {Dixit}, J. and {Frank}, P. and {Greiner}, M. and {Hutschenreuter}, S. and {Knollm{\"u}ller}, J. and {Leike}, R. and {Porqueres}, N. and {Pumpe}, D. and {Reinecke}, M. and {{\v S}raml}, M. and {Varady}, C. and {En{\ss}lin}, T.}, title = "{NIFTy 3 - Numerical Information Field Theory - A Python framework for multicomponent signal inference on HPC clusters}", journal = {ArXiv e-prints}, diff --git a/nifty5/extra.py b/nifty5/extra.py index 8d8760f26cde3925b03ed55a5253c8b13c70f0e4..97146e3778e9613e27a5148d52fcbfc0f2ee04ca 100644 --- a/nifty5/extra.py +++ b/nifty5/extra.py @@ -70,6 +70,9 @@ def _full_implementation(op, domain_dtype, target_dtype, atol, rtol, def _check_linearity(op, domain_dtype, atol, rtol): + needed_cap = op.TIMES + if (op.capability & needed_cap) != needed_cap: + return fld1 = from_random("normal", op.domain, dtype=domain_dtype) fld2 = from_random("normal", op.domain, dtype=domain_dtype) alpha = np.random.random() # FIXME: this can break badly with MPI! @@ -121,6 +124,9 @@ def consistency_check(op, domain_dtype=np.float64, target_dtype=np.float64, raise TypeError('This test tests only linear operators.') _domain_check(op) _check_linearity(op, domain_dtype, atol, rtol) + _check_linearity(op.adjoint, target_dtype, atol, rtol) + _check_linearity(op.inverse, target_dtype, atol, rtol) + _check_linearity(op.adjoint.inverse, domain_dtype, atol, rtol) _full_implementation(op, domain_dtype, target_dtype, atol, rtol, only_r_linear) _full_implementation(op.adjoint, target_dtype, domain_dtype, atol, rtol, diff --git a/nifty5/fft.py b/nifty5/fft.py index 714e502b4274a45c73540eedfbbdc193f6d8db35..ede615ffe81e22c2969d114e238cee1cbbfcee07 100644 --- a/nifty5/fft.py +++ b/nifty5/fft.py @@ -26,7 +26,7 @@ def nthreads(): def set_nthreads(nthr): global _nthreads - _nthreads = nthr + _nthreads = int(nthr) def fftn(a, axes=None): diff --git a/nifty5/library/gridder.py b/nifty5/library/gridder.py index c9d33ed9283bf18bd7b573b819e91a3594f387e3..4160b69f85546315aa3f8dbff7eab1e23502e160 100644 --- a/nifty5/library/gridder.py +++ b/nifty5/library/gridder.py @@ -15,12 +15,13 @@ # # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik. +import numpy as np + from ..domain_tuple import DomainTuple from ..domains.rg_space import RGSpace from ..domains.unstructured_domain import UnstructuredDomain from ..operators.linear_operator import LinearOperator from ..sugar import from_global_data, makeDomain -import numpy as np class GridderMaker(object): diff --git a/nifty5/minimization/conjugate_gradient.py b/nifty5/minimization/conjugate_gradient.py index 8e7adaf3c9d84a1f290b6424a36d52f9c388bbcf..0dbc89a24c033f12b330d113d4e5ba7826a35dde 100644 --- a/nifty5/minimization/conjugate_gradient.py +++ b/nifty5/minimization/conjugate_gradient.py @@ -74,27 +74,27 @@ class ConjugateGradient(Minimizer): if previous_gamma == 0: return energy, controller.CONVERGED - iter = 0 + ii = 0 while True: q = energy.apply_metric(d) - ddotq = d.vdot(q).real - if ddotq == 0.: - logger.error("Error: ConjugateGradient: ddotq==0.") + curv = d.vdot(q).real + if curv == 0.: + logger.error("Error: ConjugateGradient: curv==0.") return energy, controller.ERROR - alpha = previous_gamma/ddotq + alpha = previous_gamma/curv if alpha < 0: logger.error("Error: ConjugateGradient: alpha<0.") return energy, controller.ERROR - iter += 1 - if iter < self._nreset: + ii += 1 + if ii < self._nreset: r = r - q*alpha energy = energy.at_with_grad(energy.position - alpha*d, r) else: energy = energy.at(energy.position - alpha*d) r = energy.gradient - iter = 0 + ii = 0 s = r if preconditioner is None else preconditioner(r) diff --git a/nifty5/operators/block_diagonal_operator.py b/nifty5/operators/block_diagonal_operator.py index 0996983350b2df9def4980f0b4fcf4e8a255eee0..fef27414a0e3b7dcc1303dd1e513c52ad527721c 100644 --- a/nifty5/operators/block_diagonal_operator.py +++ b/nifty5/operators/block_diagonal_operator.py @@ -15,6 +15,8 @@ # # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik. +import numpy as np + from ..multi_domain import MultiDomain from ..multi_field import MultiField from .endomorphic_operator import EndomorphicOperator @@ -46,11 +48,10 @@ class BlockDiagonalOperator(EndomorphicOperator): for op, v in zip(self._ops, x.values())) return MultiField(self._domain, val) -# def draw_sample(self, from_inverse=False, dtype=np.float64): -# dtype = MultiField.build_dtype(dtype, self._domain) -# val = tuple(op.draw_sample(from_inverse, dtype) -# for op in self._op) -# return MultiField(self._domain, val) + def draw_sample(self, from_inverse=False, dtype=np.float64): + val = tuple(op.draw_sample(from_inverse, dtype) + if op is not None else None for op in self._ops) + return MultiField(self._domain, val) def _combine_chain(self, op): if self._domain != op._domain: