private static bool VerifyVectorColumnsMatch(int cachedSize, int col, IDataView dv, ColumnType type, ref VBuffer <DvText> firstDvSlotNames) { if (cachedSize != type.VectorSize) { return(false); } // If we detect mismatch it a sign that slots reshuffling has happened. if (dv.Schema.HasSlotNames(col, type.VectorSize)) { // Verify that slots match with slots from 1st idv. VBuffer <DvText> currSlotNames = default(VBuffer <DvText>); dv.Schema.GetMetadata(MetadataUtils.Kinds.SlotNames, col, ref currSlotNames); if (currSlotNames.Length != firstDvSlotNames.Length) { return(false); } else { var result = true; VBufferUtils.ForEachEitherDefined(ref currSlotNames, ref firstDvSlotNames, (slot, val1, val2) => result = result && DvText.Identical(val1, val2)); return(result); } } else { // If we don't have slot names, then the first dataview should not have had slot names either. return(firstDvSlotNames.Length == 0); } }
/// <summary> /// Computes the L1 distance between two VBuffers /// </summary> /// <param name="a">one VBuffer</param> /// <param name="b">another VBuffer</param> /// <returns>L1 Distance from a to b</returns> public static Float L1Distance(ref VBuffer <Float> a, ref VBuffer <Float> b) { Float res = 0; VBufferUtils.ForEachEitherDefined(ref a, ref b, (slot, val1, val2) => res += Math.Abs(val1 - val2)); return(res); }