defmatches_spec(o:SpecType,spec:SpecType,ignore_batch_dim:bool=False)->bool:"""Test whether data object matches the desired spec. Args: o (SpecType): Data object. spec (SpecType): Metadata for describing the the data object. ignore_batch_dim: Ignore first dimension when checking shapes. Returns: bool: If matches """ifisinstance(spec,(list,tuple)):ifnotisinstance(o,(list,tuple)):raiseValueError(f"data object is not a list or tuple which is required by the spec: {spec}")iflen(spec)!=len(o):raiseValueError(f"data object has a different number of elements than the spec: {spec}")fori,ispecinenumerate(spec):ifnotmatches_spec(o[i],ispec,ignore_batch_dim=ignore_batch_dim):returnFalsereturnTrueifisinstance(spec,dict):ifnotisinstance(o,dict):raiseValueError(f"data object is not a dict which is required by the spec: {spec}")ifspec.keys()!=o.keys():raiseValueError(f"data object has different keys than those specified in the spec: {spec}")forkinspec:ifnotmatches_spec(o[k],spec[k],ignore_batch_dim=ignore_batch_dim):returnFalsereturnTruespec_shape=spec.shape[1:]ifignore_batch_dimelsespec.shapeo_shape=o.shape[1:]ifignore_batch_dimelseo.shapereturnspec_shape==o_shapeandspec.dtype==o.dtype