Commit 4b6b4e79 authored by Theo Steininger's avatar Theo Steininger

Added lazy initialization for Field.val.

Set default dtype for FieldArray
parent 2d541f05
Pipeline #10030 passed with stages
in 17 minutes and 34 seconds
......@@ -34,6 +34,9 @@ class Field(Loggable, Versionable, object):
distribution_strategy=distribution_strategy,
val=val)
if val is None:
self._val = None
else:
self.set_val(new_val=val, copy=copy)
def _parse_domain(self, domain, val=None):
......@@ -406,6 +409,9 @@ class Field(Loggable, Versionable, object):
return self
def get_val(self, copy=False):
if self._val is None:
self.set_val(None)
if copy:
return self._val.copy()
else:
......@@ -413,11 +419,11 @@ class Field(Loggable, Versionable, object):
@property
def val(self):
return self._val
return self.get_val(copy=False)
@val.setter
def val(self, new_val):
self._val = self.cast(new_val)
self.set_val(new_val=new_val, copy=False)
@property
def shape(self):
......
......@@ -2,12 +2,14 @@
import pickle
import numpy as np
from field_type import FieldType
class FieldArray(FieldType):
def __init__(self, dtype, shape):
def __init__(self, shape, dtype=np.float):
try:
new_shape = tuple([int(i) for i in shape])
except TypeError:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment