field.py 20.1 KB
Newer Older
csongor's avatar
csongor committed
1
2
3
4
from __future__ import division
import numpy as np
import pylab as pl

5
from d2o import distributed_data_object,\
6
    STRATEGIES as DISTRIBUTION_STRATEGIES
csongor's avatar
csongor committed
7

8
9
10
from nifty.config import about,\
                         nifty_configuration as gc,\
                         dependency_injector as gdi
csongor's avatar
csongor committed
11

12
13
from nifty.field_types import FieldType,\
                              FieldArray
14

15
from nifty.spaces.space import Space
csongor's avatar
csongor committed
16

csongor's avatar
csongor committed
17
import nifty.nifty_utilities as utilities
18
19
from nifty.random import Random

csongor's avatar
csongor committed
20
21

POINT_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
theos's avatar
theos committed
22
COMM = getattr(gdi[gc['mpi_module']], gc['default_comm'])
csongor's avatar
csongor committed
23
24


25
class Field(object):
theos's avatar
theos committed
26
27
28
    # ---Initialization methods---
    def __init__(self, domain=None, val=None, dtype=None, field_type=None,
                 datamodel=None, copy=False):
csongor's avatar
csongor committed
29

30
        self.domain = self._parse_domain(domain=domain, val=val)
31
        self.domain_axes = self._get_axes_tuple(self.domain)
csongor's avatar
csongor committed
32

33
        self.field_type = self._parse_field_type(field_type, val=val)
34

theos's avatar
theos committed
35
36
37
38
39
40
        try:
            start = len(reduce(lambda x, y: x+y, self.domain_axes))
        except TypeError:
            start = 0
        self.field_type_axes = self._get_axes_tuple(self.field_type,
                                                    start=start)
41

theos's avatar
theos committed
42
43
44
        self.dtype = self._infer_dtype(dtype=dtype,
                                       domain=self.domain,
                                       field_type=self.field_type)
45

theos's avatar
theos committed
46
47
        self.datamodel = self._parse_datamodel(datamodel=datamodel,
                                               val=val)
csongor's avatar
csongor committed
48
49
50

        self.set_val(new_val=val, copy=copy)

51
    def _parse_domain(self, domain, val):
52
        if domain is None:
53
54
55
56
            if isinstance(val, Field):
                domain = val.domain
            else:
                domain = ()
57
        elif not isinstance(domain, tuple):
58
            domain = (domain,)
csongor's avatar
csongor committed
59
        for d in domain:
60
            if not isinstance(d, Space):
csongor's avatar
csongor committed
61
                raise TypeError(about._errors.cstring(
62
63
                    "ERROR: Given domain contains something that is not a "
                    "nifty.space."))
csongor's avatar
csongor committed
64
65
        return domain

66
    def _parse_field_type(self, field_type, val):
67
        if field_type is None:
68
69
70
71
            if isinstance(val, Field):
                field_type = val.field_type
            else:
                field_type = ()
72
73
74
        elif not isinstance(field_type, tuple):
            field_type = (field_type,)
        for ft in field_type:
75
            if not isinstance(ft, FieldType):
76
                raise TypeError(about._errors.cstring(
77
                    "ERROR: Given object is not a nifty.FieldType."))
78
79
        return field_type

theos's avatar
theos committed
80
81
82
83
84
85
86
87
88
89
    def _get_axes_tuple(self, things_with_shape, start=0):
        i = start
        axes_list = []
        for thing in things_with_shape:
            l = []
            for j in range(len(thing.shape)):
                l += [i]
                i += 1
            axes_list += [tuple(l)]
        return tuple(axes_list)
90

91
    def _infer_dtype(self, dtype, val, domain, field_type):
csongor's avatar
csongor committed
92
        if dtype is None:
93
94
95
            if isinstance(val, Field) or \
               isinstance(val, distributed_data_object):
                dtype = val.dtype
theos's avatar
theos committed
96
97
98
99
100
101
102
            dtype_tuple = (np.dtype(gc['default_field_dtype']),)
        else:
            dtype_tuple = (np.dtype(dtype),)
        if domain is not None:
            dtype_tuple += tuple(np.dtype(sp.dtype) for sp in domain)
        if field_type is not None:
            dtype_tuple += tuple(np.dtype(ft.dtype) for ft in field_type)
csongor's avatar
csongor committed
103

theos's avatar
theos committed
104
        dtype = reduce(lambda x, y: np.result_type(x, y), dtype_tuple)
105

theos's avatar
theos committed
106
        return dtype
107

theos's avatar
theos committed
108
    def _parse_datamodel(self, datamodel, val):
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
        if datamodel is None:
            if isinstance(val, distributed_data_object):
                datamodel = val.distribution_strategy
            elif isinstance(val, Field):
                datamodel = val.datamodel
            else:
                about.warnings.cprint("WARNING: Datamodel set to default!")
                datamodel = gc['default_datamodel']
        elif datamodel not in DISTRIBUTION_STRATEGIES['all']:
            raise ValueError(about._errors.cstring(
                    "ERROR: Invalid datamodel!"))
        return datamodel


    # ---Factory methods---
    @classmethod
    def from_random(cls, random_type, domain=None, dtype=None, field_type=None,
                    datamodel=None, **kwargs):
        # create a initially empty field
        f = cls(domain=domain, dtype=dtype, field_type=field_type,
                datamodel=datamodel)

        # now use the processed input in terms of f in order to parse the
        # random arguments
        random_arguments = cls._parse_random_arguments(random_type=random_type,
                                                       f=f,
                                                       **kwargs)

        # extract the distributed_dato_object from f and apply the appropriate
        # random number generator to it
        sample = f.get_val(copy=False)
        generator_function = getattr(Random, random_type)
        sample.apply_generator(
            lambda shape: generator_function(dtype=f.dtype,
                                             shape=shape,
                                             **random_arguments))
        return f

    @staticmethod
    def _parse_random_arguments(random_type, f, **kwargs):

        if random_type == "pm1":
            random_arguments = {}

        elif random_type == "normal":
            mean = kwargs.get('mean', 0)
            std = kwargs.get('std', 1)
            random_arguments = {'mean': mean,
                                'std': std}

        elif random_type == "uniform":
            low = kwargs.get('low', 0)
            high = kwargs.get('high', 1)
            random_arguments = {'low': low,
                                'high': high}

#        elif random_type == 'syn':
#            pass

csongor's avatar
csongor committed
168
        else:
169
170
            raise KeyError(about._errors.cstring(
                "ERROR: unsupported random key '" + str(random_type) + "'."))
csongor's avatar
csongor committed
171

172
        return random_arguments
csongor's avatar
csongor committed
173

theos's avatar
theos committed
174
175
    # ---Properties---
    def set_val(self, new_val=None, copy=False):
176
177
        new_val = self.cast(new_val)
        if copy:
theos's avatar
theos committed
178
179
180
            new_val = new_val.copy()
        self._val = new_val
        return self._val
csongor's avatar
csongor committed
181

182
183
    def get_val(self, copy=False):
        if copy:
theos's avatar
theos committed
184
            return self._val.copy()
185
        else:
theos's avatar
theos committed
186
            return self._val
csongor's avatar
csongor committed
187

theos's avatar
theos committed
188
189
190
    @property
    def val(self):
        return self._val
csongor's avatar
csongor committed
191

theos's avatar
theos committed
192
193
194
    @val.setter
    def val(self, new_val):
        self._val = self.cast(new_val)
csongor's avatar
csongor committed
195

196
197
    @property
    def shape(self):
198
199
200
201
202
203
204
        shape_tuple = ()
        shape_tuple += tuple(sp.shape for sp in self.domain)
        shape_tuple += tuple(ft.shape for ft in self.field_type)
        try:
            global_shape = reduce(lambda x, y: x + y, shape_tuple)
        except TypeError:
            global_shape = ()
csongor's avatar
csongor committed
205

206
        return global_shape
csongor's avatar
csongor committed
207

208
209
    @property
    def dim(self):
theos's avatar
theos committed
210
211
212
213
214
215
216
        dim_tuple = ()
        dim_tuple += tuple(sp.dim for sp in self.domain)
        dim_tuple += tuple(ft.dim for ft in self.field_type)
        try:
            return reduce(lambda x, y: x * y, dim_tuple)
        except TypeError:
            return 0
csongor's avatar
csongor committed
217

218
219
    @property
    def dof(self):
theos's avatar
theos committed
220
221
222
223
224
225
226
227
        dof = self.dim
        if issubclass(self.dtype.type, np.complexfloating):
            dof *= 2
        return dof

    @property
    def total_volume(self):
        volume_tuple = tuple(sp.total_volume for sp in self.domain)
228
        try:
theos's avatar
theos committed
229
            return reduce(lambda x, y: x * y, volume_tuple)
230
        except TypeError:
theos's avatar
theos committed
231
            return 0
232

theos's avatar
theos committed
233
    # ---Special unary/binary operations---
csongor's avatar
csongor committed
234
235
236
    def cast(self, x=None, dtype=None):
        if dtype is None:
            dtype = self.dtype
237
238
        else:
            dtype = np.dtype(dtype)
239

theos's avatar
theos committed
240
        casted_x = self._actual_cast(x, dtype=dtype)
241
242

        for ind, sp in enumerate(self.domain):
243
            casted_x = sp.complement_cast(casted_x,
theos's avatar
theos committed
244
                                          axes=self.domain_axes[ind])
245
246
247

        for ind, ft in enumerate(self.field_type):
            casted_x = ft.complement_cast(casted_x,
theos's avatar
theos committed
248
                                          axes=self.field_type_axes[ind])
249
250

        return casted_x
csongor's avatar
csongor committed
251

theos's avatar
theos committed
252
    def _actual_cast(self, x, dtype=None):
253
        if isinstance(x, Field):
csongor's avatar
csongor committed
254
255
256
257
258
            x = x.get_val()

        if dtype is None:
            dtype = self.dtype

theos's avatar
theos committed
259
260
261
        x = distributed_data_object(x,
                                    global_shape=self.shape,
                                    dtype=dtype,
csongor's avatar
csongor committed
262
263
                                    distribution_strategy=self.datamodel)

theos's avatar
theos committed
264
265
266
267
268
269
270
271
272
273
274
        return x

    def copy(self, domain=None, dtype=None, field_type=None,
             datamodel=None):
        copied_val = self.get_val(copy=True)
        new_field = self.copy_empty(domain=domain,
                                    dtype=dtype,
                                    field_type=field_type,
                                    datamodel=datamodel)
        new_field.set_val(new_val=copied_val, copy=False)
        return new_field
csongor's avatar
csongor committed
275

theos's avatar
theos committed
276
277
278
279
    def copy_empty(self, domain=None, dtype=None, field_type=None,
                   datamodel=None):
        if domain is None:
            domain = self.domain
csongor's avatar
csongor committed
280
        else:
theos's avatar
theos committed
281
            domain = self._parse_domain(domain)
csongor's avatar
csongor committed
282

theos's avatar
theos committed
283
284
285
286
        if dtype is None:
            dtype = self.dtype
        else:
            dtype = np.dtype(dtype)
csongor's avatar
csongor committed
287

theos's avatar
theos committed
288
289
290
291
        if field_type is None:
            field_type = self.field_type
        else:
            field_type = self._parse_field_type(field_type)
csongor's avatar
csongor committed
292

theos's avatar
theos committed
293
294
        if datamodel is None:
            datamodel = self.datamodel
csongor's avatar
csongor committed
295

theos's avatar
theos committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
        fast_copyable = True
        try:
            for i in xrange(len(self.domain)):
                if self.domain[i] is not domain[i]:
                    fast_copyable = False
                    break
            for i in xrange(len(self.field_type)):
                if self.field_type[i] is not field_type[i]:
                    fast_copyable = False
                    break
        except IndexError:
            fast_copyable = False

        if (fast_copyable and dtype == self.dtype and
                datamodel == self.datamodel):
            new_field = self._fast_copy_empty()
        else:
            new_field = Field(domain=domain,
                              dtype=dtype,
                              field_type=field_type,
                              datamodel=datamodel)
        return new_field
csongor's avatar
csongor committed
318

theos's avatar
theos committed
319
320
321
322
323
324
325
326
327
328
329
330
331
332
    def _fast_copy_empty(self):
        # make an empty field
        new_field = EmptyField()
        # repair its class
        new_field.__class__ = self.__class__
        # copy domain, codomain and val
        for key, value in self.__dict__.items():
            if key != 'val':
                new_field.__dict__[key] = value
            else:
                new_field.__dict__[key] = self.val.copy_empty()
        return new_field

    def weight(self, power=1, inplace=False, spaces=None):
333
        if inplace:
csongor's avatar
csongor committed
334
335
336
337
            new_field = self
        else:
            new_field = self.copy_empty()

338
        new_val = self.get_val(copy=False)
csongor's avatar
csongor committed
339

csongor's avatar
csongor committed
340
        if spaces is None:
theos's avatar
theos committed
341
342
343
            spaces = range(len(self.domain))
        else:
            spaces = utilities.cast_axis_to_tuple(spaces, len(self.domain))
csongor's avatar
csongor committed
344

345
        for ind, sp in enumerate(self.domain):
theos's avatar
theos committed
346
347
348
349
350
            if ind in spaces:
                new_val = sp.weight(new_val,
                                    power=power,
                                    axes=self.domain_axes[ind],
                                    inplace=inplace)
351
352

        new_field.set_val(new_val=new_val, copy=False)
csongor's avatar
csongor committed
353
354
        return new_field

theos's avatar
theos committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
    def dot(self, x=None, bare=False):
        if isinstance(x, Field):
            try:
                assert len(x.domain) == len(self.domain)
                for index in xrange(len(self.domain)):
                    assert x.domain[index] == self.domain[index]
                for index in xrange(len(self.field_type)):
                    assert x.field_type[index] == self.field_type[index]
            except AssertionError:
                raise ValueError(about._errors.cstring(
                    "ERROR: domains are incompatible."))
            # extract the data from x and try to dot with this
            x = x.get_val(copy=False)

        # Compute the dot respecting the fact of discrete/continous spaces
        if bare:
            y = self
        else:
            y = self.weight(power=1)

        y = y.get_val(copy=False)

        # Cast the input in order to cure dtype and shape differences
        x = self.cast(x)

        dotted = x.conjugate() * y

        return dotted.sum()

384
    def norm(self, q=2):
csongor's avatar
csongor committed
385
386
387
388
389
390
391
392
393
394
395
396
397
398
        """
            Computes the Lq-norm of the field values.

            Parameters
            ----------
            q : scalar
                Parameter q of the Lq-norm (default: 2).

            Returns
            -------
            norm : scalar
                The Lq-norm of the field values.

        """
399
        if q == 2:
400
            return (self.dot(x=self)) ** (1 / 2)
csongor's avatar
csongor committed
401
        else:
402
            return self.dot(x=self ** (q - 1)) ** (1 / q)
csongor's avatar
csongor committed
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

    def conjugate(self, inplace=False):
        """
            Computes the complex conjugate of the field.

            Returns
            -------
            cc : field
                The complex conjugated field.

        """
        if inplace:
            work_field = self
        else:
            work_field = self.copy_empty()

419
        new_val = self.get_val(copy=False)
theos's avatar
theos committed
420
        new_val = new_val.conjugate()
421
        work_field.set_val(new_val=new_val, copy=False)
csongor's avatar
csongor committed
422
423
424

        return work_field

theos's avatar
theos committed
425
426
427
    # ---General unary/contraction methods---
    def __pos__(self):
        return self.copy()
428

theos's avatar
theos committed
429
430
431
432
    def __neg__(self):
        return_field = self.copy_empty()
        new_val = -self.get_val(copy=False)
        return_field.set_val(new_val, copy=False)
csongor's avatar
csongor committed
433
434
        return return_field

theos's avatar
theos committed
435
436
437
438
439
    def __abs__(self):
        return_field = self.copy_empty()
        new_val = abs(self.get_val(copy=False))
        return_field.set_val(new_val, copy=False)
        return return_field
csongor's avatar
csongor committed
440

theos's avatar
theos committed
441
442
443
444
445
446
    def _contraction_helper(self, op, spaces, types):
        # build a list of all axes
        if spaces is None:
            spaces = xrange(len(self.domain))
        else:
            spaces = utilities.cast_axis_to_tuple(spaces, len(self.domain))
csongor's avatar
csongor committed
447

theos's avatar
theos committed
448
449
450
451
        if types is None:
            types = xrange(len(self.field_type))
        else:
            types = utilities.cast_axis_to_tuple(types, len(self.field_type))
452

theos's avatar
theos committed
453
454
455
456
        axes_list = ()
        axes_list += tuple(self.domain_axes[sp_index] for sp_index in spaces)
        axes_list += tuple(self.field_type_axes[ft_index] for
                           ft_index in types)
457
        try:
theos's avatar
theos committed
458
            axes_list = reduce(lambda x, y: x+y, axes_list)
459
        except TypeError:
theos's avatar
theos committed
460
            axes_list = ()
csongor's avatar
csongor committed
461

theos's avatar
theos committed
462
463
464
        # perform the contraction on the d2o
        data = self.get_val(copy=False)
        data = getattr(data, op)(axis=axes_list)
csongor's avatar
csongor committed
465

theos's avatar
theos committed
466
467
468
        # check if the result is scalar or if a result_field must be constr.
        if np.isscalar(data):
            return data
csongor's avatar
csongor committed
469
        else:
theos's avatar
theos committed
470
471
472
473
474
475
476
477
478
479
480
            return_domain = tuple(self.domain[i]
                                  for i in xrange(len(self.domain))
                                  if i not in spaces)
            return_field_type = tuple(self.field_type[i]
                                      for i in xrange(len(self.field_type))
                                      if i not in types)
            return_field = Field(domain=return_domain,
                                 val=data,
                                 field_type=return_field_type,
                                 copy=False)
            return return_field
csongor's avatar
csongor committed
481

theos's avatar
theos committed
482
483
    def sum(self, spaces=None, types=None):
        return self._contraction_helper('sum', spaces, types)
csongor's avatar
csongor committed
484

theos's avatar
theos committed
485
486
    def prod(self, spaces=None, types=None):
        return self._contraction_helper('prod', spaces, types)
csongor's avatar
csongor committed
487

theos's avatar
theos committed
488
489
    def all(self, spaces=None, types=None):
        return self._contraction_helper('all', spaces, types)
csongor's avatar
csongor committed
490

theos's avatar
theos committed
491
492
    def any(self, spaces=None, types=None):
        return self._contraction_helper('any', spaces, types)
csongor's avatar
csongor committed
493

theos's avatar
theos committed
494
495
    def min(self, spaces=None, types=None):
        return self._contraction_helper('min', spaces, types)
csongor's avatar
csongor committed
496

theos's avatar
theos committed
497
498
    def nanmin(self, spaces=None, types=None):
        return self._contraction_helper('nanmin', spaces, types)
csongor's avatar
csongor committed
499

theos's avatar
theos committed
500
501
    def max(self, spaces=None, types=None):
        return self._contraction_helper('max', spaces, types)
csongor's avatar
csongor committed
502

theos's avatar
theos committed
503
504
    def nanmax(self, spaces=None, types=None):
        return self._contraction_helper('nanmax', spaces, types)
csongor's avatar
csongor committed
505

theos's avatar
theos committed
506
507
    def mean(self, spaces=None, types=None):
        return self._contraction_helper('mean', spaces, types)
csongor's avatar
csongor committed
508

theos's avatar
theos committed
509
510
    def var(self, spaces=None, types=None):
        return self._contraction_helper('var', spaces, types)
csongor's avatar
csongor committed
511

theos's avatar
theos committed
512
513
    def std(self, spaces=None, types=None):
        return self._contraction_helper('std', spaces, types)
csongor's avatar
csongor committed
514

theos's avatar
theos committed
515
    # ---General binary methods---
csongor's avatar
csongor committed
516

theos's avatar
theos committed
517
    def _binary_helper(self, other, op, inplace=False):
csongor's avatar
csongor committed
518
        # if other is a field, make sure that the domains match
519
        if isinstance(other, Field):
theos's avatar
theos committed
520
521
522
523
            try:
                assert len(other.domain) == len(self.domain)
                for index in xrange(len(self.domain)):
                    assert other.domain[index] == self.domain[index]
524
                assert len(other.field_type) == len(self.field_type)
theos's avatar
theos committed
525
526
527
528
529
530
                for index in xrange(len(self.field_type)):
                    assert other.field_type[index] == self.field_type[index]
            except AssertionError:
                raise ValueError(about._errors.cstring(
                    "ERROR: domains are incompatible."))
            other = other.get_val(copy=False)
csongor's avatar
csongor committed
531

theos's avatar
theos committed
532
533
        self_val = self.get_val(copy=False)
        return_val = getattr(self_val, op)(other)
csongor's avatar
csongor committed
534
535
536
537
538
539

        if inplace:
            working_field = self
        else:
            working_field = self.copy_empty()

theos's avatar
theos committed
540
        working_field.set_val(return_val, copy=False)
csongor's avatar
csongor committed
541
542
543
        return working_field

    def __add__(self, other):
theos's avatar
theos committed
544
        return self._binary_helper(other, op='__add__')
545

546
    def __radd__(self, other):
theos's avatar
theos committed
547
        return self._binary_helper(other, op='__radd__')
csongor's avatar
csongor committed
548
549

    def __iadd__(self, other):
theos's avatar
theos committed
550
        return self._binary_helper(other, op='__iadd__', inplace=True)
csongor's avatar
csongor committed
551
552

    def __sub__(self, other):
theos's avatar
theos committed
553
        return self._binary_helper(other, op='__sub__')
csongor's avatar
csongor committed
554
555

    def __rsub__(self, other):
theos's avatar
theos committed
556
        return self._binary_helper(other, op='__rsub__')
csongor's avatar
csongor committed
557
558

    def __isub__(self, other):
theos's avatar
theos committed
559
        return self._binary_helper(other, op='__isub__', inplace=True)
csongor's avatar
csongor committed
560
561

    def __mul__(self, other):
theos's avatar
theos committed
562
        return self._binary_helper(other, op='__mul__')
563

564
    def __rmul__(self, other):
theos's avatar
theos committed
565
        return self._binary_helper(other, op='__rmul__')
csongor's avatar
csongor committed
566
567

    def __imul__(self, other):
theos's avatar
theos committed
568
        return self._binary_helper(other, op='__imul__', inplace=True)
csongor's avatar
csongor committed
569
570

    def __div__(self, other):
theos's avatar
theos committed
571
        return self._binary_helper(other, op='__div__')
csongor's avatar
csongor committed
572
573

    def __rdiv__(self, other):
theos's avatar
theos committed
574
        return self._binary_helper(other, op='__rdiv__')
csongor's avatar
csongor committed
575
576

    def __idiv__(self, other):
theos's avatar
theos committed
577
        return self._binary_helper(other, op='__idiv__', inplace=True)
578

csongor's avatar
csongor committed
579
    def __pow__(self, other):
theos's avatar
theos committed
580
        return self._binary_helper(other, op='__pow__')
csongor's avatar
csongor committed
581
582

    def __rpow__(self, other):
theos's avatar
theos committed
583
        return self._binary_helper(other, op='__rpow__')
csongor's avatar
csongor committed
584
585

    def __ipow__(self, other):
theos's avatar
theos committed
586
        return self._binary_helper(other, op='__ipow__', inplace=True)
csongor's avatar
csongor committed
587
588

    def __lt__(self, other):
theos's avatar
theos committed
589
        return self._binary_helper(other, op='__lt__')
csongor's avatar
csongor committed
590
591

    def __le__(self, other):
theos's avatar
theos committed
592
        return self._binary_helper(other, op='__le__')
csongor's avatar
csongor committed
593
594
595
596
597

    def __ne__(self, other):
        if other is None:
            return True
        else:
theos's avatar
theos committed
598
            return self._binary_helper(other, op='__ne__')
csongor's avatar
csongor committed
599
600
601
602
603

    def __eq__(self, other):
        if other is None:
            return False
        else:
theos's avatar
theos committed
604
            return self._binary_helper(other, op='__eq__')
csongor's avatar
csongor committed
605
606

    def __ge__(self, other):
theos's avatar
theos committed
607
        return self._binary_helper(other, op='__ge__')
csongor's avatar
csongor committed
608
609

    def __gt__(self, other):
theos's avatar
theos committed
610
611
612
613
614
615
616
617
618
619
620
621
622
        return self._binary_helper(other, op='__gt__')

    def __repr__(self):
        return "<nifty_core.field>"

    def __str__(self):
        minmax = [self.min(), self.max()]
        mean = self.mean()
        return "nifty_core.field instance\n- domain      = " + \
               repr(self.domain) + \
               "\n- val         = " + repr(self.get_val()) + \
               "\n  - min.,max. = " + str(minmax) + \
               "\n  - mean = " + str(mean)
csongor's avatar
csongor committed
623

624

625
class EmptyField(Field):
csongor's avatar
csongor committed
626
627
    def __init__(self):
        pass