@@ -29,6 +29,9 @@ def valid_array_reference(parray, carray, broadcast_shape=None):
29
29
result = True
30
30
# try numpy broadcast
31
31
try :
32
+ if broadcast_shape is not None and carray is not None :
33
+ if carray .shape != broadcast_shape :
34
+ carray = carray .reshape (broadcast_shape )
32
35
_ = np .broadcast (parray , carray )
33
36
except ValueError :
34
37
result = False
@@ -165,46 +168,32 @@ def _extra_exceptions(self, exceptions):
165
168
166
169
def check_array_references (self , exceptions ):
167
170
168
- # if this Array has a bald__references
169
- # # not implemented yet: and it's a singleton
170
- # if refs:
171
- # # then it must have a bald_array
172
- # ref_dset = self.fhandle[self.subject.attrs.get('bald__references')]
173
- # child_dset = None
174
- # if (hasattr(ref_dset, 'attrs')):
175
- # child_dset = self.fhandle[ref_dset.attrs.get('bald__array', None)]
176
- # elif 'bald__array' in ref_dset.ncattrs():
177
- # child_dset = self.fhandle[ref_dset.bald__array]
178
- # else:
179
- # exceptions.append('A bald__Reference must link to '
180
- # 'one and only one bald__Array')
181
- # # and we impose bald broadcasting rules on it
171
+ # If this Array has a bald__references
172
+ # we impose bald broadcasting rules on it
182
173
parray = None
183
174
if hasattr (self .array , 'bald__shape' ) and self .array .bald__shape :
184
175
parray = np .zeros (self .array .bald__shape )
185
176
for bald_array in self .array .array_references :
177
+ broadcast_shape = None
186
178
parraysubj = self .array .identity
187
179
carray = None
188
180
if hasattr (bald_array , 'bald__shape' ) and bald_array .bald__shape :
189
181
carray = np .zeros (bald_array .bald__shape )
190
- carraysubj = bald_array .identity
191
- if not valid_array_reference (parray , carray ):
192
- msg = ('{} declares a child of {} but the arrays '
193
- 'do not conform to the bald array reference '
194
- 'rules' )
195
- msg = msg .format (parraysubj , carraysubj )
196
- exceptions .append (msg )
197
- if parray is None and carray is not None :
198
- msg = ('{} declares a child of {} but the parent array '
199
- 'is not an extensive array' )
200
- msg = msg .format (parraysubj , carraysubj )
201
- exceptions .append (msg )
202
- if carray is None and parray is not None :
203
- msg = ('{} declares a child of {} but the child array '
204
- 'is not an extensive array' )
205
- msg = msg .format (parraysubj , carraysubj )
206
- exceptions .append (msg )
207
-
182
+ elif hasattr (bald_array , 'bald__array' ):
183
+ if len (bald_array .bald__array ) == 1 :
184
+ array_ref = bald_array .bald__array .copy ().pop ()
185
+ if hasattr (array_ref , 'bald__shape' ):
186
+ carray = np .zeros (bald_array .bald__array .copy ().pop ().bald__shape )
187
+
188
+ if hasattr (bald_array , 'bald__childBroadcast' ):
189
+ broadcast_shape = bald_array .bald__childBroadcast
190
+ carraysubj = bald_array .identity
191
+ if not valid_array_reference (parray , carray , broadcast_shape ):
192
+ msg = ('{} declares a child of {} but the arrays '
193
+ 'do not conform to the bald array reference '
194
+ 'rules' )
195
+ msg = msg .format (parraysubj , carraysubj )
196
+ exceptions .append (msg )
208
197
return exceptions
209
198
210
199
0 commit comments