numpy_do.py 2.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 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-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

19 20
# Data object module for NIFTy that uses simple numpy ndarrays.

Martin Reinecke's avatar
Martin Reinecke committed
21
from __future__ import print_function
22 23
import numpy as np
from numpy import ndarray as data_object
Martin Reinecke's avatar
Martin Reinecke committed
24
from numpy import full, empty, empty_like, sqrt, ones, zeros, vdot, abs, \
Martin Reinecke's avatar
Martin Reinecke committed
25
                  exp, log, tanh
Martin Reinecke's avatar
Martin Reinecke committed
26 27
from .random import Random

Martin Reinecke's avatar
Martin Reinecke committed
28 29 30 31
ntask = 1
rank = 0
master = True

32

Martin Reinecke's avatar
Martin Reinecke committed
33 34 35 36
def mprint(*args):
    print(*args)


37 38
def from_object(object, dtype=None, copy=True):
    return np.array(object, dtype=dtype, copy=copy)
Martin Reinecke's avatar
Martin Reinecke committed
39 40 41 42 43


def from_random(random_type, shape, dtype=np.float64, **kwargs):
    generator_function = getattr(Random, random_type)
    return generator_function(dtype=dtype, shape=shape, **kwargs)
Martin Reinecke's avatar
Martin Reinecke committed
44

Martin Reinecke's avatar
Martin Reinecke committed
45

Martin Reinecke's avatar
Martin Reinecke committed
46 47 48 49
def local_data(arr):
    return arr


50 51 52 53
def ibegin_from_shape(glob_shape, distaxis=-1):
    return (0,)*len(glob_shape)


Martin Reinecke's avatar
Martin Reinecke committed
54 55 56 57 58 59 60 61
def ibegin(arr):
    return (0,)*arr.ndim


def np_allreduce_sum(arr):
    return arr


Martin Reinecke's avatar
fixes  
Martin Reinecke committed
62
def distaxis(arr):
Martin Reinecke's avatar
Martin Reinecke committed
63
    return -1
Martin Reinecke's avatar
Martin Reinecke committed
64 65


Martin Reinecke's avatar
Martin Reinecke committed
66 67
def from_local_data(shape, arr, distaxis):
    if shape != arr.shape:
Martin Reinecke's avatar
Martin Reinecke committed
68 69 70 71
        raise ValueError
    return arr


Martin Reinecke's avatar
Martin Reinecke committed
72
def from_global_data(arr, distaxis=-1):
Martin Reinecke's avatar
Martin Reinecke committed
73 74 75
    return arr


Martin Reinecke's avatar
Martin Reinecke committed
76
def to_global_data(arr):
Martin Reinecke's avatar
Martin Reinecke committed
77 78 79
    return arr


Martin Reinecke's avatar
Martin Reinecke committed
80
def redistribute(arr, dist=None, nodist=None):
Martin Reinecke's avatar
Martin Reinecke committed
81 82 83
    return arr


Martin Reinecke's avatar
fixes  
Martin Reinecke committed
84
def default_distaxis():
Martin Reinecke's avatar
Martin Reinecke committed
85 86 87
    return -1


88
def local_shape(glob_shape, distaxis=-1):
Martin Reinecke's avatar
Martin Reinecke committed
89
    return glob_shape