From 8ea3f39c8489afd2930351fc8b350fa03fce0ffc Mon Sep 17 00:00:00 2001 From: Tom Finley Date: Fri, 29 Mar 2019 11:24:18 -0700 Subject: [PATCH] Gleb review. --- src/Microsoft.ML.DataView/VBuffer.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.ML.DataView/VBuffer.cs b/src/Microsoft.ML.DataView/VBuffer.cs index e11ebc786a..51978bfeb8 100644 --- a/src/Microsoft.ML.DataView/VBuffer.cs +++ b/src/Microsoft.ML.DataView/VBuffer.cs @@ -48,6 +48,12 @@ public readonly struct VBuffer /// /// The logical length of the buffer. /// + /// + /// Note that if this vector , then this will be the same as the + /// as returned from , since all values are explicitly represented in a dense representation. If + /// this is a sparse representation, then that will be somewhat shorter, as this + /// field contains the number of both explicit and implicit entries. + /// public readonly int Length; /// @@ -259,7 +265,7 @@ public void CopyTo(Span dst) /// /// The destination buffer. This must be at least /// plus . - /// The starting index of at which to start copying + /// The starting index of at which to start copying. /// The value to fill in for the implicit sparse entries. This is a potential exception to /// general expectation of sparse that the implicit sparse entries have the default value /// of . @@ -316,7 +322,7 @@ public static void Copy(T[] src, int srcIndex, ref VBuffer dst, int length) /// If all pairs, even those implicit values of a sparse representation, /// will be returned, with the implicit values having the default value, as is appropriate. If left /// then only explicitly defined values are returned. - /// + /// The index/value pairs. public IEnumerable> Items(bool all = false) { return Items(_values, _indices, Length, _count, all); @@ -335,9 +341,20 @@ public IEnumerable DenseValues() /// In the case of a sparse vector, it will try to find the entry with that index, and set /// to that stored value, or if no such value was found, assign it the default value. /// - /// The slot index, which must be a non-negative number less than . - /// If it is not in that - /// The value stored + /// + /// In the case where is , this will take constant time since it an + /// directly lookup. For sparse vectors, however, because it must perform a bisection seach on the indices to + /// find the appropriate value, that takes logarithmic time with respect to the number of explicitly represented + /// items, which is to say, the of the return value of . + /// + /// For that reason, a single completely isolated lookup, since constructing as + /// does is not a free operation, it may be more efficient to use this method. However + /// if one is doing a more involved computation involving many operations, it may be faster to utiltize + /// and, if appropriate, directly. + /// + /// The slot index, which must be a non-negative number less than . + /// The value stored at that index, or if this is a sparse vector where this is an implicit + /// entry, the default value for . public void GetItemOrDefault(int slot, ref T dst) { Contracts.CheckParam(0 <= slot && slot < Length, nameof(slot));