Skip to content

Commit 8ea3f39

Browse files
committed
Gleb review.
1 parent 4dc817f commit 8ea3f39

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/Microsoft.ML.DataView/VBuffer.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public readonly struct VBuffer<T>
4848
/// <summary>
4949
/// The logical length of the buffer.
5050
/// </summary>
51+
/// <remarks>
52+
/// Note that if this vector <see cref="IsDense"/>, then this will be the same as the <see cref="ReadOnlySpan{T}.Length"/>
53+
/// as returned from <see cref="GetValues"/>, since all values are explicitly represented in a dense representation. If
54+
/// this is a sparse representation, then that <see cref="ReadOnlySpan{T}.Length"/> will be somewhat shorter, as this
55+
/// field contains the number of both explicit and implicit entries.
56+
/// </remarks>
5157
public readonly int Length;
5258

5359
/// <summary>
@@ -259,7 +265,7 @@ public void CopyTo(Span<T> dst)
259265
/// </summary>
260266
/// <param name="dst">The destination buffer. This <see cref="Span{T}.Length"/> must be at least <see cref="Length"/>
261267
/// plus <paramref name="ivDst"/>.</param>
262-
/// <param name="ivDst">The starting index of <paramref name="dst"/> at which to start copying</param>
268+
/// <param name="ivDst">The starting index of <paramref name="dst"/> at which to start copying.</param>
263269
/// <param name="defaultValue">The value to fill in for the implicit sparse entries. This is a potential exception to
264270
/// general expectation of sparse <see cref="VBuffer{T}"/> that the implicit sparse entries have the default value
265271
/// of <typeparamref name="T"/>.</param>
@@ -316,7 +322,7 @@ public static void Copy(T[] src, int srcIndex, ref VBuffer<T> dst, int length)
316322
/// <param name="all">If <see langword="true"/> all pairs, even those implicit values of a sparse representation,
317323
/// will be returned, with the implicit values having the default value, as is appropriate. If left
318324
/// <see langword="false"/> then only explicitly defined values are returned.</param>
319-
/// <returns></returns>
325+
/// <returns>The index/value pairs.</returns>
320326
public IEnumerable<KeyValuePair<int, T>> Items(bool all = false)
321327
{
322328
return Items(_values, _indices, Length, _count, all);
@@ -335,9 +341,20 @@ public IEnumerable<T> DenseValues()
335341
/// In the case of a sparse vector, it will try to find the entry with that index, and set <paramref name="dst"/>
336342
/// to that stored value, or if no such value was found, assign it the default value.
337343
/// </summary>
338-
/// <param name="slot">The slot index, which must be a non-negative number less than <see cref="Length"/>.
339-
/// If it is not in that </param>
340-
/// <param name="dst">The value stored </param>
344+
/// <remarks>
345+
/// In the case where <see cref="IsDense"/> is <see langword="true"/>, this will take constant time since it an
346+
/// directly lookup. For sparse vectors, however, because it must perform a bisection seach on the indices to
347+
/// find the appropriate value, that takes logarithmic time with respect to the number of explicitly represented
348+
/// items, which is to say, the <see cref="ReadOnlySpan{Int32}.Length"/> of the return value of <see cref="GetIndices"/>.
349+
///
350+
/// For that reason, a single completely isolated lookup, since constructing <see cref="ReadOnlySpan{T}"/> as
351+
/// <see cref="GetValues"/> does is not a free operation, it may be more efficient to use this method. However
352+
/// if one is doing a more involved computation involving many operations, it may be faster to utiltize
353+
/// <see cref="GetValues"/> and, if appropriate, <see cref="GetIndices"/> directly.
354+
/// </remarks>
355+
/// <param name="slot">The slot index, which must be a non-negative number less than <see cref="Length"/>.</param>
356+
/// <param name="dst">The value stored at that index, or if this is a sparse vector where this is an implicit
357+
/// entry, the default value for <typeparamref name="T"/>.</param>
341358
public void GetItemOrDefault(int slot, ref T dst)
342359
{
343360
Contracts.CheckParam(0 <= slot && slot < Length, nameof(slot));

0 commit comments

Comments
 (0)