Given a record of np.arrays, create a BlobReference for each one of them, returning a record containing BlobReferences. The name of each returned blob is NextScopedBlob(field_name), which guarantees unique name in the current net. Use NameScope explicitly to avoid name conflictions
(net, schema)
| 1187 | |
| 1188 | |
| 1189 | def NewRecord(net, schema): |
| 1190 | """ |
| 1191 | Given a record of np.arrays, create a BlobReference for each one of them, |
| 1192 | returning a record containing BlobReferences. The name of each returned blob |
| 1193 | is NextScopedBlob(field_name), which guarantees unique name in the current |
| 1194 | net. Use NameScope explicitly to avoid name conflictions between different |
| 1195 | nets. |
| 1196 | """ |
| 1197 | if isinstance(schema, Scalar): |
| 1198 | result = schema.clone() |
| 1199 | result.set_value( |
| 1200 | blob=net.NextScopedBlob('unnamed_scalar'), |
| 1201 | unsafe=True, |
| 1202 | ) |
| 1203 | return result |
| 1204 | |
| 1205 | assert isinstance(schema, Field), 'Record must be a schema.Field instance.' |
| 1206 | blob_refs = [ |
| 1207 | net.NextScopedBlob(prefix=name) |
| 1208 | for name in schema.field_names() |
| 1209 | ] |
| 1210 | return from_blob_list(schema, blob_refs) |
| 1211 | |
| 1212 | |
| 1213 | def ConstRecord(net, array_record): |
searching dependent graphs…