2 writes to Length
Microsoft.ML.DataView (2)
796 references to Length
Microsoft.ML.AutoML (1)
Microsoft.ML.Core (56)
Utilities\VBufferUtils.cs (53)
115Contracts.Check(a.Length == b.Length, "Vectors must have the same dimensionality.");
122for (int i = 0; i < a.Length; i++)
166Contracts.Check(a.Length == b.Length, "Vectors must have the same dimensionality.");
173for (int i = 0; i < a.Length; ++i)
180for (int i = 0; i < b.Length; i++)
190for (int i = 0; i < a.Length; i++)
304Contracts.CheckParam(0 <= slot && slot < dst.Length, nameof(slot));
335bool needIndices = dstValuesCount + 1 < dst.Length;
336editor = VBufferEditor.Create(ref dst, dst.Length, dstValuesCount + 1, keepOldOnResize: true);
363dst.Length);
383editor.Values.Slice(min, dst.Length - min).Clear();
401Contracts.Check(0 <= denseCount && denseCount <= dst.Length);
406if (denseCount == dst.Length)
416var newIndicesEditor = VBufferEditor.Create(ref dst, dst.Length, denseCount);
425if (newLen == dst.Length)
431var editor = VBufferEditor.Create(ref dst, dst.Length, newLen, keepOldOnResize: true);
451if (!src.IsDense || src.Length < 20)
458var sparseCountThreshold = (int)(src.Length * sparsityThreshold);
460for (int i = 0; i < src.Length; i++)
472var editor = VBufferEditor.Create(ref dst, src.Length, sparseCount);
476for (int i = 0; i < src.Length; i++)
591Contracts.Check(src.Length == dst.Length, "Vectors must have the same dimensionality.");
631for (int i = 0; i < dst.Length; i++)
665for (int i = 0; i < dst.Length; ++i)
670sIndex = ++sI == srcValues.Length ? src.Length : srcIndices[sI];
689src.Length,
691maxValuesCapacity: src.Length);
726if (newCount == dst.Length)
747src.Length,
749maxValuesCapacity: dst.Length);
817sIndex = ++sI == srcValues.Length ? src.Length : srcIndices[sI];
857src.Length,
859maxValuesCapacity: src.Length);
878Contracts.Check(src.Length == dst.Length, "Vectors must have the same dimensionality.");
881int length = src.Length;
894Contracts.Assert(srcValues.Length == src.Length);
938Contracts.Assert(srcValues.Length == src.Length);
1135Resize(ref dst, src.Length, 0);
1139src.Length,
1141maxValuesCapacity: src.Length);
1145for (int i = 0; i < src.Length; ++i)
1169Contracts.Check(a.Length == b.Length, "Vectors must have the same dimensionality.");
1188Resize(ref dst, a.Length, 0);
1200editor = VBufferEditor.Create(ref dst, a.Length);
1205for (int i = 0; i < b.Length; i++)
1215for (int i = 0; i < a.Length; i++)
1224for (int i = 0; i < a.Length; i++)
1253editor = VBufferEditor.Create(ref dst, a.Length, newCount, requireIndicesOnDense: true);
Microsoft.ML.Core.Tests (45)
UnitTests\TestVBuffer.cs (35)
182var length = a.Length;
201var length = a.Length;
225var length = a.Length;
256var length = a.Length;
290Assert.Equal(10, a.Length);
314Assert.Equal(10, a.Length);
325Contracts.Assert(a.Length == b.Length);
340b = new VBuffer<T2>(a.Length, indices.Length, values, indices);
382b = new VBuffer<T2>(a.Length, indices.Length, values, indices);
478dst = new VBuffer<TDst>(a.Length, indices.Count, values, indices.ToArray());
514dst = new VBuffer<TDst>(a.Length, indices.Length, values, indices);
545Contracts.Assert(0 <= offset && a.Length <= b.Length - offset);
549if (offset == 0 && a.Length == b.Length)
554var editor = VBufferEditor.Create(ref aa, b.Length, aa.GetValues().Length, requireIndicesOnDense: true);
558for (int i = 0; i < aa.Length; i++)
638int offset = rgen.Next(b.Length - a.Length + 1);
667dst = VBufferEditor.Create(ref dst, a.Length, 0).Commit();
715Assert.Equal(len, a.Length);
738Assert.Equal(copyLen, dst.Length);
764Assert.Equal(len, b.Length);
795Assert.Equal(len, b.Length);
899int expectedLength = Math.Max(1, a.Length - slotsDropped);
944len = dst.Length;
1014var editor = VBufferEditor.Create(ref dst, src.Length, src.GetValues().Length);
1029Assert.Equal(expected.Length, actual.Length);
1161Contracts.Assert(a.Length == len);
1162Contracts.Assert(b.Length == len);
1173Assert.Equal(expected.Length, actual.Length);
1175int length = expected.Length;
Microsoft.ML.Data (238)
Deprecated\Vector\VBufferMathUtils.cs (28)
102int length = src.Length;
141Contracts.Check(src.Length == dst.Length, "Vectors must have the same dimensionality.");
149var editor = VBufferEditor.Create(ref dst, dst.Length);
151CpuMathUtils.Add(srcValues, editor.Values, src.Length);
169Contracts.Check(src.Length == dst.Length, "Vectors must have the same dimensionality.");
177var editor = VBufferEditor.Create(ref dst, dst.Length);
179CpuMathUtils.AddScale(c, srcValues, editor.Values, src.Length);
194Contracts.Check(src.Length == dst.Length, "Vectors must have the same dimensionality.");
195int length = src.Length;
224Contracts.Check(a.Length == b.Length, "Vectors must have the same dimensionality.");
242Contracts.CheckParam(0 <= offset && offset <= dst.Length, nameof(offset));
243Contracts.CheckParam(src.Length <= dst.Length - offset, nameof(offset));
253editor = VBufferEditor.Create(ref dst, dst.Length);
269int dLim = dstIndices.Length == 0 ? 0 : dstIndices.FindIndexSorted(dMin, dstIndices.Length, offset + src.Length);
270Contracts.Assert(dMin - dLim <= src.Length);
274gapCount = src.Length - (dLim - dMin);
297dst.Length,
322int iS = src.Length - 1;
389if (src.Length > 0 && src.IsDense)
392var editor = VBufferEditor.Create(ref dst, src.Length);
399VBufferUtils.Resize(ref dst, src.Length, 0);
410if (src.Length == 0)
446if (src.Length == 0)
Deprecated\Vector\VectorUtils.cs (24)
32Contracts.Check(Utils.Size(a) == b.Length, "Vectors must have the same dimensionality.");
37return CpuMathUtils.DotProductDense(a, bValues, b.Length);
43Contracts.Check(a.Length == b.Length, "Vectors must have the same dimensionality.");
53return CpuMathUtils.DotProductDense(aValues, bValues, a.Length);
116var aEditor = VBufferEditor.Create(ref a, a.Length, newCount, requireIndicesOnDense: true);
162Contracts.Check(a.Length == dst.Length, "Vectors must have the same dimensionality.");
167CpuMathUtils.MulElementWise(a.GetValues(), dst.GetValues(), editor.Values, a.Length);
253Contracts.Check(0 <= offset && offset <= a.Length);
254Contracts.Check(b.Length <= a.Length - offset, "VBuffer b must be no longer than a.Length - offset.");
263return CpuMathUtils.DotProductDense(aValues.Slice(offset), bValues, b.Length);
271int aLim = Utils.FindIndexSorted(aIndices, 0, aIndices.Length, offset + b.Length);
306Contracts.Check(b.Length <= a.Length - offset, "VBuffer b must be no longer than a.Length - offset.");
313return CpuMathUtils.DotProductDense(a.AsSpan(offset), bValues, b.Length);
396Contracts.Check(a.Length == b.Length, "Vectors must have the same dimensionality.");
400return L2DiffSquaredDense(a.GetValues(), b.GetValues(), b.Length);
417Contracts.Check(Utils.Size(a) == b.Length, "Vectors must have the same dimensionality.");
419return L2DiffSquaredDense(a, b.GetValues(), b.Length);
444Contracts.CheckParam(src.Length == dst.Length, nameof(dst), "Arrays must have the same dimensionality.");
472Contracts.Check(src.Length <= dst.Length - offset, "Vector src must be no longer than dst.Length - offset.");
480for (int i = 0; i < src.Length; i++)
Evaluators\EvaluatorUtils.cs (20)
483var map = maps[i] = new int[slotNamesCur.Length];
512Contracts.Assert(src.Length == Utils.Size(map));
536Contracts.Assert(src.Length == Utils.Size(map));
697src.Length,
701for (int j = 0; j < src.Length; j++)
967if (currSlotNames.Length != firstDvSlotNames.Length)
980return firstDvSlotNames.Length == 0;
1401int numConfusionTableLabels = sample < 0 ? labelNames.Length : Math.Min(labelNames.Length, sample);
1405var labelIndexToConfIndexMap = new int[labelNames.Length];
1406if (numConfusionTableLabels < labelNames.Length)
1408var tempPerm = Utils.GetRandomPermutation(host.Rand, labelNames.Length);
1409var sampledIndices = tempPerm.Skip(labelNames.Length - numConfusionTableLabels).OrderBy(i => i);
1419for (int i = 0; i < labelNames.Length; i++)
1428confusionTable = GetConfusionTableAsArray(confusionDataView, weightColumn.Value.Index, labelNames.Length,
1431confusionTable = GetConfusionTableAsArray(confusionDataView, countColumn.Index, labelNames.Length,
1443bool sampled = numConfusionTableLabels < labelNames.Length;
1503if (count.Length != numClasses)
1504throw Contracts.Except("Expected {0} values in 'Count' column, but got {1}.", numClasses, count.Length);
Transforms\Hashing.cs (38)
253Host.Assert(_keyValues[invertIinfos[i]].Length == types[invertIinfos[i]].GetItemType().GetKeyCountAsInt32(Host));
254_kvTypes[invertIinfos[i]] = new VectorDataViewType(TextDataViewType.Instance, _keyValues[invertIinfos[i]].Length);
561return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
595return (Hashing.MixHash(hash, values.Length * sizeof(double)) & mask) + 1;
654return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
678return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
702return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
734return (Hashing.MixHash(hash, values.Length * sizeof(ulong)) & mask) + 1;
764return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
784return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
804return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
828return (Hashing.MixHash(hash, values.Length * sizeof(ulong)) & mask) + 1;
862return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
899return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
919return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
939return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
959return (Hashing.MixHash(hash, values.Length * sizeof(uint)) & mask) + 1;
983return (Hashing.MixHash(hash, values.Length * sizeof(long)) & mask) + 1;
1045VBufferUtils.Resize(ref dst, src.Length, 0);
1048var editor = VBufferEditor.Create(ref dst, src.Length, srcValues.Length);
1062var editor = VBufferEditor.Create(ref dst, src.Length);
1076for (int i = 0; i < src.Length; ++i)
1099VBufferUtils.Resize(ref dst, src.Length, 0);
1102var editor = VBufferEditor.Create(ref dst, src.Length, srcValues.Length);
1116var editor = VBufferEditor.Create(ref dst, src.Length);
1130for (int i = 0; i < src.Length; ++i)
1163VBufferUtils.Resize(ref dst, src.Length, 0);
1166var editor = VBufferEditor.Create(ref dst, src.Length, srcValues.Length);
1188var editor = VBufferEditor.Create(ref dst, src.Length);
1200for (int i = 0; i < src.Length; i++)
1227VBufferUtils.Resize(ref dst, src.Length, 0);
1230var editor = VBufferEditor.Create(ref dst, src.Length, srcValues.Length);
1252var editor = VBufferEditor.Create(ref dst, src.Length);
1264for (int i = 0; i < src.Length; i++)
1681Contracts.Assert(_value.Length == _hash.Length);
1726Contracts.Assert(_value.Length == _hash.Length);
Microsoft.ML.DataView (39)
VBuffer.cs (37)
44/// The number of items explicitly represented. This equals <see cref="Length"/> when the representation
45/// is dense and less than <see cref="Length"/> when sparse.
62/// of the returned value will equal <see cref="Length"/>, and otherwise will have length less than
63/// <see cref="Length"/>.
71/// <see cref="Length"/> exclusive, corresponding to all explicitly defined values. All values at unspecified
89Debug.Assert(_count <= Length);
90return _count == Length;
174/// <param name="destination">The destination buffer. After the copy, this will have <see cref="VBuffer{T}.Length"/>
175/// of <see cref="Length"/>.</param>
179var editor = VBufferEditor.Create(ref destination, Length);
183else if (Length > 0)
184_values.AsSpan(0, Length).CopyTo(editor.Values);
191/// <param name="destination">The destination buffer. After the copy, this will have <see cref="VBuffer{T}.Length"/>
192/// of <see cref="Length"/>.</param>
195var editor = VBufferEditor.Create(ref destination, Length, _count);
198if (Length > 0)
200_values.AsSpan(0, Length).CopyTo(editor.Values);
219/// <param name="destination">The destination buffer. After the copy, this will have <see cref="VBuffer{T}.Length"/>
225Contracts.CheckParam(0 <= sourceIndex && sourceIndex <= Length, nameof(sourceIndex));
226Contracts.CheckParam(0 <= length && sourceIndex <= Length - length, nameof(length));
270/// <param name="destination">The destination buffer. This <see cref="Span{T}.Length"/> must have least <see cref="Length"/>.</param>
279/// <param name="destination">The destination buffer. This <see cref="Span{T}.Length"/> must be at least <see cref="Length"/>
287Contracts.CheckParam(0 <= destinationIndex && destinationIndex <= destination.Length - Length,
290if (Length == 0)
294_values.AsSpan(0, Length).CopyTo(destination.Slice(destinationIndex));
300destination.Slice(destinationIndex, Length).Clear();
314while (iv < Length)
344return Items(_values, _indices, Length, _count, all);
348/// Returns an enumerable with <see cref="Length"/> items, representing the values.
352return DenseValues(_values, _indices, Length, _count);
371/// <param name="index">The index, which must be a non-negative number less than <see cref="Length"/>.</param>
376Contracts.CheckParam(0 <= index && index < Length, nameof(index));
390/// <param name="index">The index, which must be a non-negative number less than <see cref="Length"/>.</param>
395Contracts.CheckParam(0 <= index && index < Length, nameof(index));
405=> IsDense ? $"Dense vector of size {Length}" : $"Sparse vector of size {Length}, {_count} explicit values";
417return GetEditor(Length, _count);
Microsoft.ML.Ensemble (19)
Microsoft.ML.FastTree (34)
FastTree.cs (20)
1195ch.Assert(binnedValues.Length == values.Length);
1209bins = new Dense0BitIntArray(values.Length);
1210else if (!values.IsDense && zeroBin == 0 && valuesValues.Length < (1 - sparsifyThreshold) * values.Length)
1215bins = new DeltaSparseIntArray(values.Length, numBitsNeeded, nonZeroValues);
1225for (int i = 0; i < values.Length; i++)
1229Array.Clear(binnedValues, 0, values.Length);
1237firstBinCount += values.Length - valuesValues.Length;
1254bins = IntArray.New(values.Length, arrayType, IntArray.NumBitsNeeded(binUpperBounds.Length), binnedValues);
1311var editor = VBufferEditor.Create(ref dst, src.Length, srcValues.Length);
1416Host.Assert(temp.Length == numExamples);
1444ch.Assert(slotDropper.DstLength < temp.Length);
1446temp.Length - slotDropper.DstLength, temp.Length);
1678BitArray rowHasMissing = new BitArray(temp.Length);
1710return new SlotDropper(temp.Length, minSlots.ToArray(), maxSlots.ToArray());
1719if (groupIds.Length > 0)
2924Host.Check(src.Length == inputVectorSize);
2926Host.Check(src.Length > MaxSplitFeatIdx);
2952Host.Check(src.Length == inputVectorSize);
2954Host.Check(src.Length > MaxSplitFeatIdx);
Microsoft.ML.IntegrationTests (2)
Microsoft.ML.KMeansClustering (10)
Microsoft.ML.Mkl.Components (13)
Microsoft.ML.OnnxConverter (1)
Microsoft.ML.OnnxTransformer (1)
Microsoft.ML.OnnxTransformerTest (9)
Microsoft.ML.PCA (3)
Microsoft.ML.Predictor.Tests (4)
Microsoft.ML.StandardTrainers (121)
Optimizer\DifferentiableFunction.cs (10)
105if (_tempGrads[chunkIndex].Length == 0)
135if (gradient.Length == 0)
198int numIters = Math.Min((int)x.Length, 10);
199int maxDirCount = Math.Min((int)x.Length / 2, 100);
208int index = _r.Next((int)x.Length);
210index = _r.Next((int)x.Length);
214VBuffer<float> dir = new VBuffer<float>(x.Length, values.Count, values.ToArray(), indices.ToArray());
262VBuffer<float> dir = new VBuffer<float>(x.Length, 1, new float[] { 1 }, new int[] { 0 });
263for (int n = 0; n < x.Length; n++)
301VBuffer<float> dir = new VBuffer<float>(x.Length, 1, new float[] { 1 }, new int[] { 0 });
Standard\LinearModelParameters.cs (20)
67public int Count => _pred.Weight.Length;
128_inputType = new VectorDataViewType(NumberDataViewType.Single, Weight.Length);
202_inputType = new VectorDataViewType(NumberDataViewType.Single, Weight.Length);
226ctx.Writer.Write(Weight.Length);
277if (features.Length != Weight.Length)
278throw Contracts.Except("Input is of length {0} does not match expected length of weights {1}", features.Length, Weight.Length);
288if (_weightsDense.Length == 0 && Weight.Length > 0)
293if (_weightsDense.Length == 0 && Weight.Length > 0)
317if (src.Length != Weight.Length)
318throw Contracts.Except("Input is of length {0}, but predictor expected length {1}", src.Length, Weight.Length);
377AnnotationUtils.GetSlotNames(schema, RoleMappedSchema.ColumnRole.Feature, Weight.Length, ref names);
379subBuilder.AddSlotNames(Weight.Length, (ref VBuffer<ReadOnlyMemory<char>> dst) => names.CopyTo(ref dst));
380var colType = new VectorDataViewType(NumberDataViewType.Single, Weight.Length);
552AnnotationUtils.GetSlotNames(schema, RoleMappedSchema.ColumnRole.Feature, Weight.Length, ref names);
Standard\SdcaMulticlass.cs (3)
370int numFeatures = weights[0].Length;
561return new MaximumEntropyModelParameters(Host, weights, bias, bias.Length, weights[0].Length, null, stats: null);
658return new LinearMulticlassModelParameters(Host, weights, bias, bias.Length, weights[0].Length, null, stats: null);
Microsoft.ML.TensorFlow (2)
Microsoft.ML.TensorFlow.Tests (8)
Microsoft.ML.TestFramework (12)
DataPipe\TestDataPipe.cs (9)
237Check(TestCommon.CompareVec(in v1, in v2, v1.Length, fn), "Mismatch");
593if (!TestCommon.CompareVec(in bag1, in bag2, bag1.Length, (x1, x2) => x1 <= x2))
635if (!TestCommon.CompareVec(in bag1, in bag2, bag1.Length, (x1, x2) => 2 * x1 == x2))
787if (!TestCommon.CompareVec(in b1, in b2, b1.Length, (x1, x2) => 2 * x1 == x2))
1157Assert.True(resultRow.Length == r.Length);
1225Assert.Equal(barSlots, value2.Length);
1570Assert.True(resultFirstRow.Length == 3);
1574Assert.True(resultSecondRow.Length == 3);
1578Assert.True(resultThirdRow.Length == 3);
Microsoft.ML.TestFrameworkCommon (8)
Microsoft.ML.Tests (65)
Microsoft.ML.TorchSharp (11)
Microsoft.ML.TorchSharp.Tests (7)
Microsoft.ML.Transforms (83)
Microsoft.ML.Vision (4)