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,7 +34,10 @@ class Field(Loggable, Versionable, object): ...@@ -34,7 +34,10 @@ class Field(Loggable, Versionable, object):
distribution_strategy=distribution_strategy, distribution_strategy=distribution_strategy,
val=val) val=val)
self.set_val(new_val=val, copy=copy) if val is None:
self._val = None
else:
self.set_val(new_val=val, copy=copy)
def _parse_domain(self, domain, val=None): def _parse_domain(self, domain, val=None):
if domain is None: if domain is None:
...@@ -406,6 +409,9 @@ class Field(Loggable, Versionable, object): ...@@ -406,6 +409,9 @@ class Field(Loggable, Versionable, object):
return self return self
def get_val(self, copy=False): def get_val(self, copy=False):
if self._val is None:
self.set_val(None)
if copy: if copy:
return self._val.copy() return self._val.copy()
else: else:
...@@ -413,11 +419,11 @@ class Field(Loggable, Versionable, object): ...@@ -413,11 +419,11 @@ class Field(Loggable, Versionable, object):
@property @property
def val(self): def val(self):
return self._val return self.get_val(copy=False)
@val.setter @val.setter
def val(self, new_val): def val(self, new_val):
self._val = self.cast(new_val) self.set_val(new_val=new_val, copy=False)
@property @property
def shape(self): def shape(self):
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import pickle import pickle
import numpy as np
from field_type import FieldType from field_type import FieldType
class FieldArray(FieldType): class FieldArray(FieldType):
def __init__(self, dtype, shape): def __init__(self, shape, dtype=np.float):
try: try:
new_shape = tuple([int(i) for i in shape]) new_shape = tuple([int(i) for i in shape])
except TypeError: 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