Skip to content

Commit ef2bade

Browse files
eerhardtZruty0
authored andcommitted
Rename RefPredicate to InPredicate and change ref to in. (#1405)
1 parent 4b83195 commit ef2bade

File tree

21 files changed

+194
-194
lines changed

21 files changed

+194
-194
lines changed

src/Microsoft.ML.Core/Data/TypeUtils.cs renamed to src/Microsoft.ML.Core/Data/InPredicate.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
namespace Microsoft.ML.Runtime.Data
66
{
7-
public delegate bool RefPredicate<T>(ref T value);
7+
public delegate bool InPredicate<T>(in T value);
88
}

src/Microsoft.ML.Core/Utilities/VBufferUtils.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public static void DensifyFirst<T>(ref VBuffer<T> dst, int denseCount)
492492
/// Creates a maybe sparse copy of a VBuffer.
493493
/// Whether the created copy is sparse or not is determined by the proportion of non-default entries compared to the sparsity parameter.
494494
/// </summary>
495-
public static void CreateMaybeSparseCopy<T>(ref VBuffer<T> src, ref VBuffer<T> dst, RefPredicate<T> isDefaultPredicate, float sparsityThreshold = SparsityThreshold)
495+
public static void CreateMaybeSparseCopy<T>(ref VBuffer<T> src, ref VBuffer<T> dst, InPredicate<T> isDefaultPredicate, float sparsityThreshold = SparsityThreshold)
496496
{
497497
Contracts.CheckParam(0 < sparsityThreshold && sparsityThreshold < 1, nameof(sparsityThreshold));
498498
if (!src.IsDense || src.Length < 20)
@@ -505,7 +505,7 @@ public static void CreateMaybeSparseCopy<T>(ref VBuffer<T> src, ref VBuffer<T> d
505505
var sparseCountThreshold = (int)(src.Length * sparsityThreshold);
506506
for (int i = 0; i < src.Length; i++)
507507
{
508-
if (!isDefaultPredicate(ref src.Values[i]))
508+
if (!isDefaultPredicate(in src.Values[i]))
509509
sparseCount++;
510510

511511
if (sparseCount > sparseCountThreshold)
@@ -527,7 +527,7 @@ public static void CreateMaybeSparseCopy<T>(ref VBuffer<T> src, ref VBuffer<T> d
527527
int j = 0;
528528
for (int i = 0; i < src.Length; i++)
529529
{
530-
if (!isDefaultPredicate(ref src.Values[i]))
530+
if (!isDefaultPredicate(in src.Values[i]))
531531
{
532532
Contracts.Assert(j < sparseCount);
533533
indices[j] = i;

src/Microsoft.ML.Data/Data/Conversion.cs

+97-97
Large diffs are not rendered by default.

src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderParser.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public override bool Consume(int irow, int index, ref ReadOnlyMemory<char> text)
258258
{
259259
Contracts.Assert(0 <= irow && irow < _values.Length);
260260
Contracts.Assert(index == 0);
261-
return _conv(ref text, out _values[irow]);
261+
return _conv(in text, out _values[irow]);
262262
}
263263

264264
public void Get(ref TResult value)
@@ -337,7 +337,7 @@ public bool Consume(int index, ref ReadOnlyMemory<char> text)
337337
Contracts.Assert(_indexPrev < index & index < _size);
338338

339339
TItem tmp = default(TItem);
340-
bool f = _conv(ref text, out tmp);
340+
bool f = _conv(in text, out tmp);
341341
if (_count < _size)
342342
{
343343
if (_count < _size / 2)

src/Microsoft.ML.Data/DataView/LambdaFilter.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.ML.Runtime.Data
1616
public static class LambdaFilter
1717
{
1818
public static IDataView Create<TSrc>(IHostEnvironment env, string name, IDataView input,
19-
string src, ColumnType typeSrc, RefPredicate<TSrc> predicate)
19+
string src, ColumnType typeSrc, InPredicate<TSrc> predicate)
2020
{
2121
Contracts.CheckValue(env, nameof(env));
2222
env.CheckNonEmpty(name, nameof(name));
@@ -58,7 +58,7 @@ public static IDataView Create<TSrc>(IHostEnvironment env, string name, IDataVie
5858
else
5959
{
6060
Func<IHostEnvironment, string, IDataView, int,
61-
RefPredicate<int>, ValueMapper<int, int>, Impl<int, int>> del = CreateImpl<int, int>;
61+
InPredicate<int>, ValueMapper<int, int>, Impl<int, int>> del = CreateImpl<int, int>;
6262
var meth = del.GetMethodInfo().GetGenericMethodDefinition()
6363
.MakeGenericMethod(typeOrig.RawType, typeof(TSrc));
6464
impl = (IDataView)meth.Invoke(null, new object[] { env, name, input, colSrc, predicate, conv });
@@ -69,19 +69,19 @@ public static IDataView Create<TSrc>(IHostEnvironment env, string name, IDataVie
6969

7070
private static Impl<T1, T2> CreateImpl<T1, T2>(
7171
IHostEnvironment env, string name, IDataView input, int colSrc,
72-
RefPredicate<T2> pred, ValueMapper<T1, T2> conv)
72+
InPredicate<T2> pred, ValueMapper<T1, T2> conv)
7373
{
7474
return new Impl<T1, T2>(env, name, input, colSrc, pred, conv);
7575
}
7676

7777
private sealed class Impl<T1, T2> : FilterBase
7878
{
7979
private readonly int _colSrc;
80-
private readonly RefPredicate<T2> _pred;
80+
private readonly InPredicate<T2> _pred;
8181
private readonly ValueMapper<T1, T2> _conv;
8282

8383
public Impl(IHostEnvironment env, string name, IDataView input,
84-
int colSrc, RefPredicate<T2> pred, ValueMapper<T1, T2> conv = null)
84+
int colSrc, InPredicate<T2> pred, ValueMapper<T1, T2> conv = null)
8585
: base(env, name, input)
8686
{
8787
Host.AssertValue(pred);
@@ -150,7 +150,7 @@ private Func<int, bool> GetActive(Func<int, bool> predicate, out bool[] active)
150150
private sealed class RowCursor : LinkedRowFilterCursorBase
151151
{
152152
private readonly ValueGetter<T1> _getSrc;
153-
private readonly RefPredicate<T1> _pred;
153+
private readonly InPredicate<T1> _pred;
154154
private T1 _src;
155155

156156
public RowCursor(Impl<T1, T2> parent, IRowCursor input, bool[] active)
@@ -160,26 +160,26 @@ public RowCursor(Impl<T1, T2> parent, IRowCursor input, bool[] active)
160160
if (parent._conv == null)
161161
{
162162
Ch.Assert(typeof(T1) == typeof(T2));
163-
_pred = (RefPredicate<T1>)(Delegate)parent._pred;
163+
_pred = (InPredicate<T1>)(Delegate)parent._pred;
164164
}
165165
else
166166
{
167167
T2 val = default(T2);
168168
var pred = parent._pred;
169169
var conv = parent._conv;
170170
_pred =
171-
(ref T1 src) =>
171+
(in T1 src) =>
172172
{
173173
conv(ref _src, ref val);
174-
return pred(ref val);
174+
return pred(in val);
175175
};
176176
}
177177
}
178178

179179
protected override bool Accept()
180180
{
181181
_getSrc(ref _src);
182-
return _pred(ref _src);
182+
return _pred(in _src);
183183
}
184184
}
185185

src/Microsoft.ML.Data/DataView/Transposer.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ protected override ValueGetter<VBuffer<T>> GetGetterCore()
461461
len++;
462462
Ch.Assert(len <= _len);
463463
getter(ref value);
464-
if (isDefault(ref value))
464+
if (isDefault(in value))
465465
continue;
466466
Utils.EnsureSize(ref indices, ++count);
467467
indices[count - 1] = len;
@@ -567,7 +567,7 @@ private void EnsureValid()
567567
var type = _view.Schema.GetColumnType(_colCurr);
568568
Ch.Assert(type.ItemType.RawType == typeof(T));
569569
Ch.Assert(type.ValueCount > 0);
570-
RefPredicate<T> isDefault = Conversion.Conversions.Instance.GetIsDefaultPredicate<T>(type.ItemType);
570+
InPredicate<T> isDefault = Conversion.Conversions.Instance.GetIsDefaultPredicate<T>(type.ItemType);
571571
int vecLen = type.ValueCount;
572572
int maxPossibleSize = _rbuff.Length * vecLen;
573573
const int sparseThresholdRatio = 5;
@@ -619,7 +619,7 @@ private void EnsureValid()
619619
if (rbuff.IsDense)
620620
{
621621
// Store it as sparse. We will densify later, if we must.
622-
if (!isDefault(ref rbuff.Values[s]))
622+
if (!isDefault(in rbuff.Values[s]))
623623
{
624624
indices[_counts[s]] = rowNum;
625625
values[_counts[s]++] = rbuff.Values[s];
@@ -630,7 +630,7 @@ private void EnsureValid()
630630
int ii = _rbuffIndices[r];
631631
if (ii < rbuff.Count && rbuff.Indices[ii] == s)
632632
{
633-
if (!isDefault(ref rbuff.Values[ii]))
633+
if (!isDefault(in rbuff.Values[ii]))
634634
{
635635
indices[_counts[s]] = rowNum;
636636
values[_counts[s]++] = rbuff.Values[ii];

src/Microsoft.ML.Data/Transforms/ConvertTransform.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,13 @@ private TypeNaInfo KindReport<T>(IChannel ch, PrimitiveType type)
646646
ch.Assert(type.IsStandardScalar);
647647

648648
var conv = Conversions.Instance;
649-
RefPredicate<T> isNaDel;
649+
InPredicate<T> isNaDel;
650650
bool hasNaPred = conv.TryGetIsNAPredicate(type, out isNaDel);
651651
bool defaultIsNa = false;
652652
if (hasNaPred)
653653
{
654654
T def = default(T);
655-
defaultIsNa = isNaDel(ref def);
655+
defaultIsNa = isNaDel(in def);
656656
}
657657
return new TypeNaInfo(hasNaPred, defaultIsNa);
658658
}

src/Microsoft.ML.Data/Transforms/KeyToValueTransform.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private class KeyToValueMap<TKey, TValue> : KeyToValueMap
305305
private readonly TValue _na;
306306

307307
private readonly bool _naMapsToDefault;
308-
private readonly RefPredicate<TValue> _isDefault;
308+
private readonly InPredicate<TValue> _isDefault;
309309

310310
private readonly ValueMapper<TKey, UInt32> _convertToUInt;
311311

@@ -441,7 +441,7 @@ public override Delegate GetMappingGetter(IRow input)
441441
// Current slot has an explicitly defined value.
442442
Parent.Host.Assert(islotSrc < srcCount);
443443
MapKey(ref srcValues[islotSrc], ref dstItem);
444-
if (!_isDefault(ref dstItem))
444+
if (!_isDefault(in dstItem))
445445
{
446446
dstValues[islotDst] = dstItem;
447447
dstIndices[islotDst++] = srcIndices[islotSrc];

src/Microsoft.ML.Data/Transforms/NAFilter.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ private static ValueVec<T> CreateVec<T>(RowCursor cursor, ColInfo info)
328328
private abstract class TypedValue<T> : Value
329329
{
330330
private readonly ValueGetter<T> _getSrc;
331-
private readonly RefPredicate<T> _hasBad;
331+
private readonly InPredicate<T> _hasBad;
332332
public T Src;
333333

334-
protected TypedValue(RowCursor cursor, ValueGetter<T> getSrc, RefPredicate<T> hasBad)
334+
protected TypedValue(RowCursor cursor, ValueGetter<T> getSrc, InPredicate<T> hasBad)
335335
: base(cursor)
336336
{
337337
Contracts.AssertValue(getSrc);
@@ -343,15 +343,15 @@ protected TypedValue(RowCursor cursor, ValueGetter<T> getSrc, RefPredicate<T> ha
343343
public override bool Refresh()
344344
{
345345
_getSrc(ref Src);
346-
return !_hasBad(ref Src);
346+
return !_hasBad(in Src);
347347
}
348348
}
349349

350350
private sealed class ValueOne<T> : TypedValue<T>
351351
{
352352
private readonly ValueGetter<T> _getter;
353353

354-
public ValueOne(RowCursor cursor, ValueGetter<T> getSrc, RefPredicate<T> hasBad)
354+
public ValueOne(RowCursor cursor, ValueGetter<T> getSrc, InPredicate<T> hasBad)
355355
: base(cursor, getSrc, hasBad)
356356
{
357357
_getter = GetValue;
@@ -373,7 +373,7 @@ private sealed class ValueVec<T> : TypedValue<VBuffer<T>>
373373
{
374374
private readonly ValueGetter<VBuffer<T>> _getter;
375375

376-
public ValueVec(RowCursor cursor, ValueGetter<VBuffer<T>> getSrc, RefPredicate<VBuffer<T>> hasBad)
376+
public ValueVec(RowCursor cursor, ValueGetter<VBuffer<T>> getSrc, InPredicate<VBuffer<T>> hasBad)
377377
: base(cursor, getSrc, hasBad)
378378
{
379379
_getter = GetValue;

src/Microsoft.ML.Data/Transforms/TermTransformImpl.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ private static Builder CreateCore<T>(PrimitiveType type, bool sorted)
6363
// If this is a type with NA values, we should ignore those NA values for the purpose
6464
// of building our term dictionary. For the other types (practically, only the UX types),
6565
// we should ignore nothing.
66-
RefPredicate<T> mapsToMissing;
66+
InPredicate<T> mapsToMissing;
6767
if (!Runtime.Data.Conversion.Conversions.Instance.TryGetIsNAPredicate(type, out mapsToMissing))
68-
mapsToMissing = (ref T val) => false;
68+
mapsToMissing = (in T val) => false;
6969
return new Impl<T>(type, mapsToMissing, sorted);
7070
}
7171

@@ -142,7 +142,7 @@ private sealed class Impl<T> : Builder<T>
142142
{
143143
// Because we can't know the actual mapping till we finish.
144144
private readonly HashArray<T> _values;
145-
private readonly RefPredicate<T> _mapsToMissing;
145+
private readonly InPredicate<T> _mapsToMissing;
146146
private readonly bool _sort;
147147

148148
public override int Count
@@ -158,7 +158,7 @@ public override int Count
158158
/// to the missing value. If this returns true for a value then we do not attempt
159159
/// to store it in the map.</param>
160160
/// <param name="sort">Indicates whether to sort mapping IDs by input values.</param>
161-
public Impl(PrimitiveType type, RefPredicate<T> mapsToMissing, bool sort)
161+
public Impl(PrimitiveType type, InPredicate<T> mapsToMissing, bool sort)
162162
: base(type)
163163
{
164164
Contracts.Assert(type.RawType == typeof(T));
@@ -171,7 +171,7 @@ public Impl(PrimitiveType type, RefPredicate<T> mapsToMissing, bool sort)
171171

172172
public override bool TryAdd(ref T val)
173173
{
174-
return !_mapsToMissing(ref val) && _values.TryAdd(val);
174+
return !_mapsToMissing(in val) && _values.TryAdd(val);
175175
}
176176

177177
public override TermMap Finish()
@@ -212,7 +212,7 @@ public override void ParseAddTermArg(ref ReadOnlyMemory<char> terms, IChannel ch
212212
term = ReadOnlyMemoryUtils.TrimSpaces(term);
213213
if (term.IsEmpty)
214214
ch.Warning("Empty strings ignored in 'terms' specification");
215-
else if (!tryParse(ref term, out val))
215+
else if (!tryParse(in term, out val))
216216
ch.Warning("Item '{0}' ignored in 'terms' specification since it could not be parsed as '{1}'", term, ItemType);
217217
else if (!TryAdd(ref val))
218218
ch.Warning("Duplicate item '{0}' ignored in 'terms' specification", term);
@@ -237,7 +237,7 @@ public override void ParseAddTermArg(string[] terms, IChannel ch)
237237
term = ReadOnlyMemoryUtils.TrimSpaces(term);
238238
if (term.IsEmpty)
239239
ch.Warning("Empty strings ignored in 'term' specification");
240-
else if (!tryParse(ref term, out val))
240+
else if (!tryParse(in term, out val))
241241
ch.Warning("Item '{0}' ignored in 'term' specification since it could not be parsed as '{1}'", term, ItemType);
242242
else if (!TryAdd(ref val))
243243
ch.Warning("Duplicate item '{0}' ignored in 'term' specification", term);

src/Microsoft.ML.FastTree/FastTree.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ private Dataset Construct(RoleMappedData examples, ref int numExamples, int maxB
14731473
out BinUpperBounds[iFeature]);
14741474
}
14751475
else
1476-
hasMissing = hasMissingPred(ref temp);
1476+
hasMissing = hasMissingPred(in temp);
14771477

14781478
if (hasMissing)
14791479
{

src/Microsoft.ML.FastTree/TreeEnsembleFeaturizer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ private static IDataView AppendFloatMapper<TInput>(IHostEnvironment env, IChanne
747747
mapper =
748748
(ref TInput src, ref Single dst) =>
749749
{
750-
if (isNa(ref src))
750+
if (isNa(in src))
751751
{
752752
dst = Single.NaN;
753753
return;
@@ -763,7 +763,7 @@ private static IDataView AppendFloatMapper<TInput>(IHostEnvironment env, IChanne
763763
mapper =
764764
(ref TInput src, ref Single dst) =>
765765
{
766-
if (isNa(ref src))
766+
if (isNa(in src))
767767
{
768768
dst = Single.NaN;
769769
return;

src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void Apply(IntermediateColumn[] columns)
134134
.All(x =>
135135
{
136136
bool value;
137-
return Conversions.Instance.TryParse(ref x, out value);
137+
return Conversions.Instance.TryParse(in x, out value);
138138
})
139139
)
140140
{
@@ -144,7 +144,7 @@ public void Apply(IntermediateColumn[] columns)
144144
col.SuggestedType = BoolType.Instance;
145145
bool first;
146146

147-
col.HasHeader = !Conversions.Instance.TryParse(ref col.RawData[0], out first);
147+
col.HasHeader = !Conversions.Instance.TryParse(in col.RawData[0], out first);
148148
}
149149
}
150150
}
@@ -159,7 +159,7 @@ public void Apply(IntermediateColumn[] columns)
159159
.All(x =>
160160
{
161161
Single value;
162-
return Conversions.Instance.TryParse(ref x, out value);
162+
return Conversions.Instance.TryParse(in x, out value);
163163
})
164164
)
165165
{

0 commit comments

Comments
 (0)