// Computes the types of the columns and constructs the kvMaps. private void ComputeKvMaps(ISchema schema, out ColumnType[] types, out KeyToValueMap[] kvMaps) { types = new ColumnType[_parent.ColumnPairs.Length]; kvMaps = new KeyToValueMap[_parent.ColumnPairs.Length]; for (int iinfo = 0; iinfo < types.Length; iinfo++) { // Construct kvMaps. Contracts.Assert(types[iinfo] == null); var typeSrc = schema.GetColumnType(ColMapNewToOld[iinfo]); var typeVals = schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.KeyValues, ColMapNewToOld[iinfo]); Host.Check(typeVals != null, "Metadata KeyValues does not exist"); Host.Check(typeVals.VectorSize == typeSrc.ItemType.KeyCount, "KeyValues metadata size does not match column type key count"); if (!typeSrc.IsVector) { types[iinfo] = typeVals.ItemType; } else { types[iinfo] = new VectorType(typeVals.ItemType.AsPrimitive, typeSrc.AsVector); } // MarshalInvoke with two generic params. Func <int, ColumnType, ColumnType, KeyToValueMap> func = GetKeyMetadata <int, int>; var meth = func.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod( new Type[] { typeSrc.ItemType.RawType, types[iinfo].ItemType.RawType }); kvMaps[iinfo] = (KeyToValueMap)meth.Invoke(this, new object[] { iinfo, typeSrc, typeVals }); } }
// Computes the types of the columns and constructs the kvMaps. private void ComputeKvMaps(Schema schema, out ColumnType[] types, out KeyToValueMap[] kvMaps) { types = new ColumnType[_parent.ColumnPairs.Length]; kvMaps = new KeyToValueMap[_parent.ColumnPairs.Length]; for (int iinfo = 0; iinfo < types.Length; iinfo++) { // Construct kvMaps. Contracts.Assert(types[iinfo] == null); var typeSrc = schema[ColMapNewToOld[iinfo]].Type; var typeVals = schema[ColMapNewToOld[iinfo]].Metadata.Schema.GetColumnOrNull(MetadataUtils.Kinds.KeyValues)?.Type; Host.Check(typeVals != null, "Metadata KeyValues does not exist"); Host.Check(typeVals.VectorSize == typeSrc.ItemType.KeyCount, "KeyValues metadata size does not match column type key count"); if (!(typeSrc is VectorType vectorType)) { types[iinfo] = typeVals.ItemType; }
// Computes the types of the columns and constructs the kvMaps. private void ComputeKvMaps(DataViewSchema schema, out DataViewType[] types, out KeyToValueMap[] kvMaps) { types = new DataViewType[_parent.ColumnPairs.Length]; kvMaps = new KeyToValueMap[_parent.ColumnPairs.Length]; for (int iinfo = 0; iinfo < types.Length; iinfo++) { // Construct kvMaps. Contracts.Assert(types[iinfo] == null); var typeSrc = schema[ColMapNewToOld[iinfo]].Type; var typeVals = schema[ColMapNewToOld[iinfo]].Annotations.Schema.GetColumnOrNull(AnnotationUtils.Kinds.KeyValues)?.Type; Host.Check(typeVals != null, "Metadata KeyValues does not exist"); DataViewType valsItemType = typeVals.GetItemType(); DataViewType srcItemType = typeSrc.GetItemType(); Host.Check(typeVals.GetVectorSize() == srcItemType.GetKeyCountAsInt32(Host), "KeyValues metadata size does not match column type key count"); if (!(typeSrc is VectorDataViewType vectorType)) { types[iinfo] = valsItemType; }
// Computes the types of the columns and constructs the kvMaps. private void ComputeKVMapsAndMetadata(out ColumnType[] types, out KeyToValueMap[] kvMaps) { Contracts.Assert(Utils.Size(Infos) > 0); var md = Metadata; types = new ColumnType[Infos.Length]; kvMaps = new KeyToValueMap[Infos.Length]; for (int iinfo = 0; iinfo < types.Length; iinfo++) { // Inherit slot names from source. using (var bldr = md.BuildMetadata(iinfo, Source.Schema, Infos[iinfo].Source, MetadataUtils.Kinds.SlotNames)) { } // Construct kvMaps. Contracts.Assert(types[iinfo] == null); var typeSrc = Infos[iinfo].TypeSrc; var typeVals = Source.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.KeyValues, Infos[iinfo].Source); Host.Check(typeVals != null, "Metadata KeyValues does not exist"); Host.Check(typeVals.VectorSize == typeSrc.ItemType.KeyCount, "KeyValues metadata size does not match column type key count"); if (!typeSrc.IsVector) { types[iinfo] = typeVals.ItemType; } else { types[iinfo] = new VectorType(typeVals.ItemType.AsPrimitive, typeSrc.AsVector); } Func <int, ColumnType, ColumnType, KeyToValueMap> func = GetKeyMetadata <int, int>; var meth = func.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod(new Type[] { typeSrc.ItemType.RawType, types[iinfo].ItemType.RawType }); kvMaps[iinfo] = (KeyToValueMap)meth.Invoke(this, new object[] { iinfo, typeSrc, typeVals }); } md.Seal(); }