Skip to content

Commit ad2271f

Browse files
committed
Implement VBuffer master plan WIP #1
1 parent 2c799c3 commit ad2271f

File tree

25 files changed

+816
-681
lines changed

25 files changed

+816
-681
lines changed

src/Microsoft.ML.Core/Data/MetadataUtils.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ public static void GetSlotNames(RoleMappedSchema schema, RoleMappedSchema.Column
318318

319319
IReadOnlyList<ColumnInfo> list;
320320
if ((list = schema?.GetColumns(role)) == null || list.Count != 1 || !schema.Schema.HasSlotNames(list[0].Index, vectorSize))
321-
slotNames = new VBuffer<ReadOnlyMemory<char>>(vectorSize, 0, slotNames.Values, slotNames.Indices);
321+
{
322+
VBufferMutationContext.Create(ref slotNames, vectorSize, 0)
323+
.Complete(ref slotNames);
324+
}
322325
else
323326
schema.Schema.GetMetadata(Kinds.SlotNames, list[0].Index, ref slotNames);
324327
}
@@ -447,21 +450,22 @@ public static bool TryGetCategoricalFeatureIndices(Schema schema, int colIndex,
447450
{
448451
int previousEndIndex = -1;
449452
isValid = true;
450-
for (int i = 0; i < catIndices.Values.Length; i += 2)
453+
var catIndicesValues = catIndices.GetValues();
454+
for (int i = 0; i < catIndicesValues.Length; i += 2)
451455
{
452-
if (catIndices.Values[i] > catIndices.Values[i + 1] ||
453-
catIndices.Values[i] <= previousEndIndex ||
454-
catIndices.Values[i] >= columnSlotsCount ||
455-
catIndices.Values[i + 1] >= columnSlotsCount)
456+
if (catIndicesValues[i] > catIndicesValues[i + 1] ||
457+
catIndicesValues[i] <= previousEndIndex ||
458+
catIndicesValues[i] >= columnSlotsCount ||
459+
catIndicesValues[i + 1] >= columnSlotsCount)
456460
{
457461
isValid = false;
458462
break;
459463
}
460464

461-
previousEndIndex = catIndices.Values[i + 1];
465+
previousEndIndex = catIndicesValues[i + 1];
462466
}
463467
if (isValid)
464-
categoricalFeatures = catIndices.Values.Select(val => val).ToArray();
468+
categoricalFeatures = catIndicesValues.ToArray();
465469
}
466470
}
467471

0 commit comments

Comments
 (0)