Skip to content

Commit 95734e2

Browse files
committed
Finish forgotten utils since I apparently got distracted
1 parent 1898bab commit 95734e2

File tree

18 files changed

+62
-48
lines changed

18 files changed

+62
-48
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
1313
/// The sample is created in one pass by calling <see cref="Sample"/> for every data point in the stream. Implementations should have
1414
/// a delegate for getting the next data point, which is invoked if the current data point should go into the reservoir.
1515
/// </summary>
16-
public interface IReservoirSampler<T>
16+
[BestFriend]
17+
internal interface IReservoirSampler<T>
1718
{
1819
/// <summary>
1920
/// If the number of elements sampled is less than the reservoir size, this should return the number of elements sampled.
@@ -49,7 +50,8 @@ public interface IReservoirSampler<T>
4950
/// for every data point in the stream. In case the next data point does not get 'picked' into the reservoir, the delegate is not invoked.
5051
/// Sampling is done according to the algorithm in this paper: <a href="https://epubs.siam.org/doi/pdf/10.1137/1.9781611972740.53">https://epubs.siam.org/doi/pdf/10.1137/1.9781611972740.53</a>.
5152
/// </summary>
52-
public sealed class ReservoirSamplerWithoutReplacement<T> : IReservoirSampler<T>
53+
[BestFriend]
54+
internal sealed class ReservoirSamplerWithoutReplacement<T> : IReservoirSampler<T>
5355
{
5456
// This array contains a cache of the elements composing the reservoir.
5557
private readonly T[] _cache;
@@ -122,7 +124,8 @@ public IEnumerable<T> GetSample()
122124
/// for every data point in the stream. In case the next data point does not get 'picked' into the reservoir, the delegate is not invoked.
123125
/// Sampling is done according to the algorithm in this paper: <a href="https://epubs.siam.org/doi/pdf/10.1137/1.9781611972740.53">https://epubs.siam.org/doi/pdf/10.1137/1.9781611972740.53</a>.
124126
/// </summary>
125-
public sealed class ReservoirSamplerWithReplacement<T> : IReservoirSampler<T>
127+
[BestFriend]
128+
internal sealed class ReservoirSamplerWithReplacement<T> : IReservoirSampler<T>
126129
{
127130
// This array contains pointers to the elements in the _cache array that are currently in the reservoir (may contain duplicates).
128131
private readonly int[] _reservoir;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
1616
/// This class takes care of downloading resources needed by ML.NET components. Resources are located in
1717
/// a pre-defined location, that can be overridden by defining Environment variable <see cref="CustomResourcesUrlEnvVariable"/>.
1818
/// </summary>
19-
public sealed class ResourceManagerUtils
19+
[BestFriend]
20+
internal sealed class ResourceManagerUtils
2021
{
2122
private static volatile ResourceManagerUtils _instance;
2223
public static ResourceManagerUtils Instance
@@ -301,7 +302,9 @@ public static ResourceDownloadResults GetErrorMessage(out string errorMessage, p
301302
return errorResult;
302303
}
303304

305+
#pragma warning disable IDE1006
304306
[DllImport("libc", SetLastError = true)]
305307
private static extern int chmod(string pathname, int mode);
308+
#pragma warning restore IDE1006
306309
}
307310
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
1111
/// <summary>
1212
/// A class containing common statistical functions
1313
/// </summary>
14-
public static class Stats
14+
[BestFriend]
15+
internal static class Stats
1516
{
1617
/// <summary>
1718
/// Returns a number uniformly sampled from 0...(rangeSize-1)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
2222
/// subset stream, the underlying stream will always remain open and
2323
/// undisposed.
2424
/// </summary>
25-
public sealed class SubsetStream : Stream
25+
[BestFriend]
26+
internal sealed class SubsetStream : Stream
2627
{
2728
private readonly Stream _stream;
2829
// The position of the stream.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.ML.Runtime.Internal.Utilities
88
{
9-
public abstract class SummaryStatisticsBase
9+
internal abstract class SummaryStatisticsBase
1010
{
1111
// Sum of squared difference from the current mean.
1212
protected double M2;
@@ -152,7 +152,8 @@ public void Add(SummaryStatisticsBase s)
152152
}
153153
}
154154

155-
public sealed class SummaryStatisticsUpToSecondOrderMoments : SummaryStatisticsBase
155+
[BestFriend]
156+
internal sealed class SummaryStatisticsUpToSecondOrderMoments : SummaryStatisticsBase
156157
{
157158
/// <summary>
158159
/// A convenient way to combine the observations of two Stats objects
@@ -177,7 +178,8 @@ public sealed class SummaryStatisticsUpToSecondOrderMoments : SummaryStatisticsB
177178
/// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
178179
/// All quantities are weighted, except for <c>RawCount</c>.
179180
/// </summary>
180-
public sealed class SummaryStatistics : SummaryStatisticsBase
181+
[BestFriend]
182+
internal sealed class SummaryStatistics : SummaryStatisticsBase
181183
{
182184
// Sum of cubed difference from the current mean.
183185
private double _m3;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
2020
/// The class can be used several times sequentially, it is stateful and not thread-safe.
2121
/// Both Single and Double precision processing is implemented, and is identical.
2222
/// </summary>
23-
public sealed class SupervisedBinFinder
23+
[BestFriend]
24+
internal sealed class SupervisedBinFinder
2425
{
2526
private readonly struct ValuePair<T> : IComparable<ValuePair<T>>
2627
where T : IComparable<T>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
1414
/// compensates by inserting <c>\n</c> line feed characters at the end of every
1515
/// input line, including the last one.
1616
/// </summary>
17-
public sealed class TextReaderStream : Stream
17+
[BestFriend]
18+
internal sealed class TextReaderStream : Stream
1819
{
1920
private readonly TextReader _baseReader;
2021
private readonly Encoding _encoding;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public static Thread CreateForegroundThread(ThreadStart start)
5959
/// that the workers have finished by its own means, will call <see cref="ThrowIfSet"/> to throw
6060
/// the set exception as an inner exception, in the wrapping thread.
6161
/// </summary>
62-
public sealed class ExceptionMarshaller : IDisposable
62+
[BestFriend]
63+
internal sealed class ExceptionMarshaller : IDisposable
6364
{
6465
private readonly CancellationTokenSource _ctSource;
6566
private readonly object _lock;
@@ -130,7 +131,8 @@ public void ThrowIfSet(IExceptionContext ectx)
130131
/// Provides a task scheduler that ensures a maximum concurrency level while
131132
/// running on top of the ThreadPool.
132133
/// </summary>
133-
public sealed class LimitedConcurrencyLevelTaskScheduler : TaskScheduler
134+
[BestFriend]
135+
internal sealed class LimitedConcurrencyLevelTaskScheduler : TaskScheduler
134136
{
135137
// Whether the current thread is processing work items.
136138
[ThreadStatic]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
1717
/// </summary>
1818
/// <typeparam name="TKey">Children are keyed with values of this type</typeparam>
1919
/// <typeparam name="TValue">The type of the node value</typeparam>
20-
public sealed class Tree<TKey, TValue> : IDictionary<TKey, Tree<TKey, TValue>>
20+
[BestFriend]
21+
internal sealed class Tree<TKey, TValue> : IDictionary<TKey, Tree<TKey, TValue>>
2122
{
2223
// The key of this node in the parent, assuming this is a child node at all.
2324
// This back reference is necessary to complete any "remove" operations.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
1414
/// <summary>
1515
/// Convenience utilities for vector operations on <see cref="VBuffer{T}"/>.
1616
/// </summary>
17-
public static class VBufferUtils
17+
[BestFriend]
18+
internal static class VBufferUtils
1819
{
1920
private const float SparsityThreshold = 0.25f;
2021

0 commit comments

Comments
 (0)