@@ -15,14 +15,14 @@ namespace Microsoft.ML.Runtime.Data
1515{
1616 using Stopwatch = System . Diagnostics . Stopwatch ;
1717
18- public sealed class TlcEnvironment : HostEnvironmentBase < TlcEnvironment >
18+ public sealed class ConsoleEnvironment : HostEnvironmentBase < ConsoleEnvironment >
1919 {
2020 public const string ComponentHistoryKey = "ComponentHistory" ;
2121
2222 private sealed class ConsoleWriter
2323 {
2424 private readonly object _lock ;
25- private readonly TlcEnvironment _parent ;
25+ private readonly ConsoleEnvironment _parent ;
2626 private readonly TextWriter _out ;
2727 private readonly TextWriter _err ;
2828
@@ -34,7 +34,7 @@ private sealed class ConsoleWriter
3434 private const int _maxDots = 50 ;
3535 private int _dots ;
3636
37- public ConsoleWriter ( TlcEnvironment parent , TextWriter outWriter , TextWriter errWriter )
37+ public ConsoleWriter ( ConsoleEnvironment parent , TextWriter outWriter , TextWriter errWriter )
3838 {
3939 Contracts . AssertValue ( parent ) ;
4040 Contracts . AssertValue ( outWriter ) ;
@@ -331,7 +331,7 @@ private bool PrintDot()
331331 private sealed class Channel : ChannelBase
332332 {
333333 public readonly Stopwatch Watch ;
334- public Channel ( TlcEnvironment root , ChannelProviderBase parent , string shortName ,
334+ public Channel ( ConsoleEnvironment root , ChannelProviderBase parent , string shortName ,
335335 Action < IMessageSource , ChannelMessage > dispatch )
336336 : base ( root , parent , shortName , dispatch )
337337 {
@@ -358,20 +358,36 @@ protected override void DisposeCore()
358358 private volatile ConsoleWriter _consoleWriter ;
359359 private readonly MessageSensitivity _sensitivityFlags ;
360360
361- public TlcEnvironment ( int ? seed = null , bool verbose = false ,
361+ /// <summary>
362+ /// Create an ML.NET <see cref="IHostEnvironment"/> for local execution, with console feedback.
363+ /// </summary>
364+ /// <param name="seed">Random seed. Set to <c>null</c> for a non-deterministic environment.</param>
365+ /// <param name="verbose">Set to <c>true</c> for fully verbose logging.</param>
366+ /// <param name="sensitivity">Allowed message sensitivity.</param>
367+ /// <param name="conc">Concurrency level. Set to 1 to run single-threaded. Set to 0 to pick automatically.</param>
368+ /// <param name="outWriter">Text writer to print normal messages to.</param>
369+ /// <param name="errWriter">Text writer to print error messages to.</param>
370+ public ConsoleEnvironment ( int ? seed = null , bool verbose = false ,
362371 MessageSensitivity sensitivity = MessageSensitivity . All , int conc = 0 ,
363372 TextWriter outWriter = null , TextWriter errWriter = null )
364373 : this ( RandomUtils . Create ( seed ) , verbose , sensitivity , conc , outWriter , errWriter )
365374 {
366375 }
367376
377+ // REVIEW: do we really care about custom random? If we do, let's make this ctor public.
368378 /// <summary>
369- /// This takes ownership of the random number generator .
379+ /// Create an ML.NET environment for local execution, with console feedback .
370380 /// </summary>
371- public TlcEnvironment ( IRandom rand , bool verbose = false ,
381+ /// <param name="rand">An custom source of randomness to use in the environment.</param>
382+ /// <param name="verbose">Set to <c>true</c> for fully verbose logging.</param>
383+ /// <param name="sensitivity">Allowed message sensitivity.</param>
384+ /// <param name="conc">Concurrency level. Set to 1 to run single-threaded. Set to 0 to pick automatically.</param>
385+ /// <param name="outWriter">Text writer to print normal messages to.</param>
386+ /// <param name="errWriter">Text writer to print error messages to.</param>
387+ private ConsoleEnvironment ( IRandom rand , bool verbose = false ,
372388 MessageSensitivity sensitivity = MessageSensitivity . All , int conc = 0 ,
373389 TextWriter outWriter = null , TextWriter errWriter = null )
374- : base ( rand , verbose , conc , nameof ( TlcEnvironment ) )
390+ : base ( rand , verbose , conc , nameof ( ConsoleEnvironment ) )
375391 {
376392 Contracts . CheckValueOrNull ( outWriter ) ;
377393 Contracts . CheckValueOrNull ( errWriter ) ;
@@ -401,7 +417,7 @@ protected override IFileHandle CreateTempFileCore(IHostEnvironment env, string s
401417 return base . CreateTempFileCore ( env , suffix , "TLC_" + prefix ) ;
402418 }
403419
404- protected override IHost RegisterCore ( HostEnvironmentBase < TlcEnvironment > source , string shortName , string parentFullName , IRandom rand , bool verbose , int ? conc )
420+ protected override IHost RegisterCore ( HostEnvironmentBase < ConsoleEnvironment > source , string shortName , string parentFullName , IRandom rand , bool verbose , int ? conc )
405421 {
406422 Contracts . AssertValue ( rand ) ;
407423 Contracts . AssertValueOrNull ( parentFullName ) ;
@@ -413,15 +429,15 @@ protected override IHost RegisterCore(HostEnvironmentBase<TlcEnvironment> source
413429 protected override IChannel CreateCommChannel ( ChannelProviderBase parent , string name )
414430 {
415431 Contracts . AssertValue ( parent ) ;
416- Contracts . Assert ( parent is TlcEnvironment ) ;
432+ Contracts . Assert ( parent is ConsoleEnvironment ) ;
417433 Contracts . AssertNonEmpty ( name ) ;
418434 return new Channel ( this , parent , name , GetDispatchDelegate < ChannelMessage > ( ) ) ;
419435 }
420436
421437 protected override IPipe < TMessage > CreatePipe < TMessage > ( ChannelProviderBase parent , string name )
422438 {
423439 Contracts . AssertValue ( parent ) ;
424- Contracts . Assert ( parent is TlcEnvironment ) ;
440+ Contracts . Assert ( parent is ConsoleEnvironment ) ;
425441 Contracts . AssertNonEmpty ( name ) ;
426442 return new Pipe < TMessage > ( parent , name , GetDispatchDelegate < TMessage > ( ) ) ;
427443 }
@@ -439,11 +455,11 @@ internal IDisposable RedirectChannelOutput(TextWriter newOutWriter, TextWriter n
439455
440456 private sealed class OutputRedirector : IDisposable
441457 {
442- private readonly TlcEnvironment _root ;
458+ private readonly ConsoleEnvironment _root ;
443459 private ConsoleWriter _oldConsoleWriter ;
444460 private readonly ConsoleWriter _newConsoleWriter ;
445461
446- public OutputRedirector ( TlcEnvironment env , TextWriter newOutWriter , TextWriter newErrWriter )
462+ public OutputRedirector ( ConsoleEnvironment env , TextWriter newOutWriter , TextWriter newErrWriter )
447463 {
448464 Contracts . AssertValue ( env ) ;
449465 Contracts . AssertValue ( newOutWriter ) ;
@@ -467,7 +483,7 @@ public void Dispose()
467483
468484 private sealed class Host : HostBase
469485 {
470- public Host ( HostEnvironmentBase < TlcEnvironment > source , string shortName , string parentFullName , IRandom rand , bool verbose , int ? conc )
486+ public Host ( HostEnvironmentBase < ConsoleEnvironment > source , string shortName , string parentFullName , IRandom rand , bool verbose , int ? conc )
471487 : base ( source , shortName , parentFullName , rand , verbose , conc )
472488 {
473489 IsCancelled = source . IsCancelled ;
@@ -489,7 +505,7 @@ protected override IPipe<TMessage> CreatePipe<TMessage>(ChannelProviderBase pare
489505 return new Pipe < TMessage > ( parent , name , GetDispatchDelegate < TMessage > ( ) ) ;
490506 }
491507
492- protected override IHost RegisterCore ( HostEnvironmentBase < TlcEnvironment > source , string shortName , string parentFullName , IRandom rand , bool verbose , int ? conc )
508+ protected override IHost RegisterCore ( HostEnvironmentBase < ConsoleEnvironment > source , string shortName , string parentFullName , IRandom rand , bool verbose , int ? conc )
493509 {
494510 return new Host ( source , shortName , parentFullName , rand , verbose , conc ) ;
495511 }
0 commit comments