@@ -126,12 +126,10 @@ def maybe_set_random_value(
126126 except (ValueError , AttributeError , IndexError , RuntimeError ):
127127 return
128128
129+ shape = []
129130 if primitive .metadata .name .endswith ("_error_upper" ):
130131 name = primitive .metadata .name [: - len ("_error_upper" )]
131- try :
132- data = primitive ._parent [name ]
133- except (KeyError , AttributeError ):
134- return
132+ data = primitive ._parent [name ]
135133 if (
136134 not data .has_value
137135 or len (data .shape ) == 0
@@ -142,12 +140,10 @@ def maybe_set_random_value(
142140 same_as .references for same_as in primitive .metadata .coordinates_same_as
143141 ):
144142 return
143+ shape = list (data .shape )
145144 elif primitive .metadata .name .endswith ("_error_lower" ):
146145 name = primitive .metadata .name [: - len ("_error_lower" )] + "_error_upper"
147- try :
148- data = primitive ._parent [name ]
149- except (KeyError , AttributeError ):
150- return
146+ data = primitive ._parent [name ]
151147 if (
152148 not data .has_value
153149 or len (data .shape ) == 0
@@ -158,60 +154,39 @@ def maybe_set_random_value(
158154 same_as .references for same_as in primitive .metadata .coordinates_same_as
159155 ):
160156 return
157+ shape = list (data .shape )
158+ else :
159+ for dim , coordinate in enumerate (primitive .metadata .coordinates ):
160+ same_as = primitive .metadata .coordinates_same_as [dim ]
161161
162- shape = []
163- for dim , coordinate in enumerate (primitive .metadata .coordinates ):
164- same_as = primitive .metadata .coordinates_same_as [dim ]
165-
166- if primitive .metadata .name .endswith ("_error_upper" ):
167- name = primitive .metadata .name [: - len ("_error_upper" )]
168- data = primitive ._parent [name ]
169- if dim >= len (data .shape ):
170- return
171- size = data .shape [dim ]
172- if size == 0 :
173- return
174- elif primitive .metadata .name .endswith ("_error_lower" ):
175- name = primitive .metadata .name [: - len ("_error_lower" )] + "_error_upper"
176- data = primitive ._parent [name ]
177- if dim >= len (data .shape ):
178- return
179- size = data .shape [dim ]
162+ if not coordinate .has_validation and not same_as .has_validation :
163+ # we can independently choose a size for this dimension:
164+ size = random .randint (1 , 6 )
165+ elif coordinate .references or same_as .references :
166+ try :
167+ if coordinate .references :
168+ refs = [ref .goto (primitive ) for ref in coordinate .references ]
169+ filled_refs = [ref for ref in refs if len (ref ) > 0 ]
170+ assert len (filled_refs ) in (0 , 1 )
171+ coordinate_element = filled_refs [0 ] if filled_refs else refs [0 ]
172+ else :
173+ coordinate_element = same_as .references [0 ].goto (primitive )
174+ except (ValueError , AttributeError , IndexError ):
175+ # Ignore invalid coordinate specs or empty array references
176+ coordinate_element = np .ones ((1 ,) * 6 )
177+
178+ if len (coordinate_element ) == 0 :
179+ maybe_set_random_value (coordinate_element , 0.5 ** ndim , skip_complex )
180+ size = coordinate_element .shape [0 if coordinate .references else dim ]
181+
182+ if coordinate .size : # coordinateX = <path> OR 1...1
183+ if random .random () < 0.5 :
184+ size = coordinate .size
185+ else :
186+ size = coordinate .size
180187 if size == 0 :
181- return
182- elif not coordinate .has_validation and not same_as .has_validation :
183- # we can independently choose a size for this dimension:
184- size = random .randint (1 , 6 )
185- elif coordinate .references or same_as .references :
186- try :
187- if coordinate .references :
188- refs = [ref .goto (primitive ) for ref in coordinate .references ]
189- filled_refs = [ref for ref in refs if len (ref ) > 0 ]
190- assert len (filled_refs ) in (0 , 1 )
191- coordinate_element = filled_refs [0 ] if filled_refs else refs [0 ]
192- else :
193- coordinate_element = same_as .references [0 ].goto (primitive )
194- except (ValueError , AttributeError , IndexError ):
195- # Ignore invalid coordinate specs or empty array references
196- coordinate_element = np .ones ((1 ,) * 6 )
197-
198- if len (coordinate_element ) == 0 :
199- # Scale chance of not setting a coordinate by our number of dimensions,
200- # such that overall there is roughly a 50% chance that any coordinate
201- # remains empty
202- maybe_set_random_value (coordinate_element , 0.5 ** ndim , skip_complex )
203- size = coordinate_element .shape [0 if coordinate .references else dim ]
204-
205- if coordinate .size : # coordinateX = <path> OR 1...1
206- # Coin flip whether to use the size as determined by
207- # coordinate.references, or the size from coordinate.size
208- if random .random () < 0.5 :
209- size = coordinate .size
210- else :
211- size = coordinate .size
212- if size == 0 :
213- return # Leave empty
214- shape .append (size )
188+ return # Leave empty
189+ shape .append (size )
215190
216191 if primitive .metadata .data_type is IDSDataType .STR :
217192 primitive .value = [random_string () for i in range (shape [0 ])]
@@ -313,53 +288,10 @@ def fill_consistent(
313288 elif any (len (coordinate .references ) > 1 for coordinate in coordinates ):
314289 exclusive_coordinates .append (child )
315290 else :
316- same_as_skip = False
317- for dim , same_as in enumerate (child .metadata .coordinates_same_as ):
318- if same_as .references :
319- try :
320- ref_elem = same_as .references [0 ].goto (child )
321- if len (ref_elem .shape ) <= dim or ref_elem .shape [dim ] == 0 :
322- same_as_skip = True
323- break
324- except (ValueError , AttributeError , IndexError , RuntimeError ):
325- same_as_skip = True
326- break
327-
328- error_skip = False
329- if child .metadata .name .endswith ("_error_upper" ):
330- name = child .metadata .name [: - len ("_error_upper" )]
331- try :
332- data = child ._parent [name ]
333- if not data .has_value :
334- maybe_set_random_value (data , 0.0 , skip_complex )
335- if (
336- not data .has_value
337- or len (data .shape ) == 0
338- or any (s == 0 for s in data .shape )
339- ):
340- error_skip = True
341- except (KeyError , AttributeError , RuntimeError , ValueError ):
342- error_skip = True
343- elif child .metadata .name .endswith ("_error_lower" ):
344- name = child .metadata .name [: - len ("_error_lower" )] + "_error_upper"
345- try :
346- data = child ._parent [name ]
347- if not data .has_value :
348- maybe_set_random_value (data , 0.0 , skip_complex )
349- if (
350- not data .has_value
351- or len (data .shape ) == 0
352- or any (s == 0 for s in data .shape )
353- ):
354- error_skip = True
355- except (KeyError , AttributeError , RuntimeError , ValueError ):
356- error_skip = True
357-
358- if not same_as_skip and not error_skip :
359- try :
360- maybe_set_random_value (child , leave_empty , skip_complex )
361- except (RuntimeError , ValueError ):
362- pass
291+ try :
292+ maybe_set_random_value (child , leave_empty , skip_complex )
293+ except (RuntimeError , ValueError ):
294+ pass
363295
364296 if isinstance (structure , IDSToplevel ):
365297 # handle exclusive_coordinates
0 commit comments