示例#1
0
        // BackupProcessor constructor:
        /// <summary>Initializes a new <c>BackupProcessor</c> object to use the given configuration and user interface object.</summary>
        /// <param name="configuration">A <c>Configuration</c> object containing all the settings for this backup run.</param>
        /// <param name="userInterface">A <c>ConsoleOutput</c> object which can be used for output to the user.</param>
        public BackupProcessor(Configuration configuration, ConsoleOutput userInterface)
        {
            // Get and store the current operating system.
            systemType = Configuration.getSystemType();

            // Each OS has a different means of creating hard links. Set the hardLinker object to whichever type of linker is appropriate.
            if (systemType == Configuration.SystemType.Windows)
            {
                hardLinker = new WindowsLinker();
            }
            else if (systemType == Configuration.SystemType.Linux)
            {
                hardLinker = new LinuxLinker();
            }
            else
            {
                throw new NotImplementedException("Unsupported operating system.");
            }

            // Get and store the limits on use of old physical copies for creating new hard links.
            maxHardLinksPerFile          = configuration.MaxHardLinksPerFile;
            maxDaysBeforeNewFullFileCopy = configuration.MaxDaysBeforeNewFullFileCopy;

            // Get and store the source and destination info for the backup.
            sourcePaths = configuration.BackupSourcePaths;
            backupsDestinationRootPath = configuration.BackupDestinationPath;

            // Set up an empty list to contain any warnings generated during the backup process.
            backupProcessWarnings = new List <string>();

            // Store the user output object.
            this.userInterface = userInterface;
        }         // end BackupProcessor constructor
        internal static double evaluateLinker(QuestionDialogDatasetReader dataset, ILinker linker)
        {
            var totalDialogCount = 0;
            var correctLinkCount = 0;

            foreach (var dialog in dataset.Dialogs)
            {
                if (!dialog.HasCorrectAnswer)
                {
                    continue;
                }

                totalDialogCount += 1;

                var linkedQuestion = linker.LinkUtterance(dialog.Question);

                var contextEntities = linkedQuestion.Parts.SelectMany(p => p.Entities.Take(1)).ToArray();

                var answerPhrase = getAnswerPhrase(dialog);
                var linkedAnswer = linker.LinkUtterance(answerPhrase, contextEntities);

                var answerPhraseEntities = linkedAnswer == null ? new EntityInfo[0] : linkedAnswer.Entities;
                var isLinkingCorrect     = answerPhraseEntities.Select(e => e.Mid).Contains(dialog.AnswerMid);

                if (isLinkingCorrect)
                {
                    ++correctLinkCount;
                }
            }

            return(1.0 * correctLinkCount / totalDialogCount);
        }
        internal GraphNavigationManager(NavigationData data, IEnumerable <string> entityPhrases, ILinker linker)
        {
            _data          = data;
            _linker        = linker;
            _entityPhrases = entityPhrases.ToArray();
            _edges         = new string[]
            {
                "/location/country/form_of_government",
                "/biology/organism_classification/higher_classification",
                "/people/person/profession",
                "/education/field_of_study/students_majoring",
                "/sports/school_sports_team/school",
                "/music/genre/albums",
                "/medicine/disease/causes",
                "/tv/tv_program/regular_cast",
                "/people/person/nationality",
                "/film/film_genre/films_in_this_genre",
                "/music/artist/genre",
                "/business/business_operation/industry",
                "/common/topic/notable_types",
                "/location/location/contains",
            };

            sampleEdgeRepresentants(20);
        }
 internal GraphNavigationWebConsole(string databasePath, IEnumerable <string> phrases, NavigationData data, ILinker linker)
 {
     _databasePath = databasePath;
     _phrases      = phrases;
     _data         = data;
     _linker       = linker;
 }
示例#5
0
        private static void exportAugmentedLinkedAnswerHints(ILinker linker, string filePath, IEnumerable <QuestionDialog> dialogs)
        {
            var file = new StreamWriter(filePath);

            foreach (var dialog in dialogs)
            {
                var answerEntity = new EntityInfo(dialog.AnswerMid, null, 0, 0);

                var linkedQuestion = linker.LinkUtterance(dialog.Question);
                //inject answer entities to question - forcing correct linking
                var questionEntities = linkedQuestion.Parts.SelectMany(p => p.Entities).Concat(new[] { answerEntity }).ToArray();

                var answerTurn = dialog.AnswerTurns.Last();
                var answerHint = answerTurn.InputChat;

                var linkedAnswerHint = linker.LinkUtterance(answerHint, questionEntities);
                if (linkedAnswerHint == null)
                {
                    continue;
                }

                var featureText = linkedQuestion.GetEntityBasedRepresentation() + " ## " + linkedAnswerHint.GetEntityBasedRepresentation();
                if (featureText.Contains("|"))
                {
                    throw new NotImplementedException("escape feature text");
                }

                file.WriteLine("{0}|{1}|{2}", dialog.Id, featureText, dialog.AnswerMid);
            }

            file.Close();
        }
示例#6
0
        /// <summary>Generates.</summary>
        /// <param name="desc">The description.</param>
        /// <param name="examples">The examples.</param>
        /// <param name="linker">The linker.</param>
        /// <returns>A Cluster.</returns>
        public Cluster Generate(Descriptor desc, IEnumerable<object> examples, ILinker linker)
        {
            // Load data 
            var exampleArray = examples.ToArray();
            Descriptor = desc;
            Matrix X = Descriptor.Convert(examples).ToMatrix();

            return GenerateClustering(X, linker, exampleArray);
        }
示例#7
0
        public FlowGraphBuilder(ILinker linker)
        {
            _layersList = new List <BaseLayer>();

            _firstLayers = null;
            _finalLayers = null;

            _linker = linker;
        }
 public CommandExecutor(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IConfig defaultConfig, IArgumentParser argumentHandler, ILinker linker, IPathResolver pathResolver)
 {
     this.console         = console;
     this.configHandler   = configHandler;
     this.fileSystem      = fileSystem;
     this.defaultConfig   = defaultConfig;
     this.argumentHandler = argumentHandler;
     this.linker          = linker;
     this.pathResolver    = pathResolver;
 }
示例#9
0
        /// <summary>Generates.</summary>
        /// <param name="desc">The description.</param>
        /// <param name="examples">The examples.</param>
        /// <param name="linker">The linker.</param>
        /// <returns>A Cluster.</returns>
        public Cluster Generate(Descriptor desc, IEnumerable <object> examples, ILinker linker)
        {
            // Load data
            var exampleArray = examples.ToArray();

            this.Descriptor = desc;
            var X = this.Descriptor.Convert(examples).ToMatrix();

            return(this.GenerateClustering(X, linker, exampleArray));
        }
示例#10
0
        private static void extractAnswer(string utterance, ILinker linker, LinkBasedExtractor extractor, QuestionDialogDatasetReader dataset)
        {
            var utteranceWords = getCleanWords(utterance).Distinct();

            QuestionDialog dialogToAnswer = null;

            foreach (var dialog in dataset.Dialogs)
            {
                if (!dialog.HasCorrectAnswer)
                {
                    continue;
                }

                var questionWords = getCleanWords(dialog.Question);
                if (utteranceWords.Except(questionWords).Count() == 0)
                {
                    dialogToAnswer = dialog;
                }

                foreach (var turn in dialog.AnswerTurns)
                {
                    var words = getCleanWords(turn.InputChat);
                    if (utteranceWords.Except(words).Count() == 0)
                    {
                        dialogToAnswer = dialog;
                        break;
                    }
                }

                if (dialogToAnswer != null)
                {
                    break;
                }
            }

            Console.WriteLine(dialogToAnswer.Question);

            var answerPhrase   = getAnswerPhrase(dialogToAnswer);
            var linkedQuestion = linker.LinkUtterance(dialogToAnswer.Question);

            Console.WriteLine(linkedQuestion);

            var contextEntities = linkedQuestion.Parts.SelectMany(p => p.Entities).ToArray();
            var result          = linker.LinkUtterance(answerPhrase, contextEntities);

            Console.WriteLine(result);

            var answers = extractor.ExtractAnswerEntity(dialogToAnswer);

            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
示例#11
0
 void OnConnect(bool success)
 {
     if (!success)
     {
         this._linker = null;
     }
     if (this._onConnect != null)
     {
         this._onConnect(success);
     }
 }
示例#12
0
        /// <summary>
        /// Compiles the specified type system.
        /// </summary>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="internalTrace">The internal trace.</param>
        /// <param name="enabledSSA">if set to <c>true</c> [enabled ssa].</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="simAdapter">The sim adapter.</param>
        /// <param name="linker">The linker.</param>
        /// <returns></returns>
        public static SimCompiler Compile(TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, bool enabledSSA, BaseArchitecture architecture, ISimAdapter simAdapter, ILinker linker)
        {
            CompilerOptions compilerOptions = new CompilerOptions();
            compilerOptions.EnableSSA = enabledSSA;
            compilerOptions.EnableSSAOptimizations = enabledSSA;

            SimCompiler compiler = new SimCompiler(architecture, typeSystem, typeLayout, linker, compilerOptions, internalTrace, simAdapter);

            compiler.Compile();

            return compiler;
        }
        public OOPEmulator(ICompilation compilation, IMetadataImporter metadataImporter, IRuntimeLibrary runtimeLibrary, INamer namer, ILinker linker, IAttributeStore attributeStore, IErrorReporter errorReporter)
        {
            _compilation  = compilation;
            _systemScript = new JsTypeReferenceExpression(compilation.FindType(new FullTypeName("System.Script")).GetDefinition());
            _systemObject = new JsTypeReferenceExpression(compilation.FindType(KnownTypeCode.Object).GetDefinition());

            _metadataImporter = metadataImporter;
            _runtimeLibrary   = runtimeLibrary;
            _namer            = namer;
            _linker           = linker;
            _attributeStore   = attributeStore;
            _errorReporter    = errorReporter;
            _defaultReflectionRuntimeContext = new ReflectionRuntimeContext(false, _systemObject, _namer);
            _genericSpecializationReflectionRuntimeContext = new ReflectionRuntimeContext(true, _systemObject, _namer);
        }
示例#14
0
        /// <summary>
        /// Prevents a default instance of the <see cref="SimCompiler" /> class from being created.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        /// <param name="internalTrace">The internal trace.</param>
        /// <param name="simAdapter">The sim adapter.</param>
        public SimCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ILinker linker, CompilerOptions compilerOptions, IInternalTrace internalTrace, ISimAdapter simAdapter)
            : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, linker, compilerOptions)
        {
            this.simAdapter = simAdapter;

            // Build the assembly compiler pipeline
            Pipeline.Add(new ICompilerStage[] {
                new PlugStage(),
                new MethodCompilerSchedulerStage(),
                new TypeInitializerSchedulerStage(),
                new SimPowerUpStage(),
                new TypeLayoutStage(),
                new MetadataStage(),
                new LinkerFinalizationStage(),
            });

            architecture.ExtendCompilerPipeline(Pipeline);
        }
示例#15
0
 /// <summary>
 /// 连接到对应主机
 /// </summary>
 /// <param name="host"></param>
 /// <param name="port"></param>
 /// <param name="sendBufferSize"></param>
 /// <param name="receiveBufferSize"></param>
 /// <param name="useAsyncSocket">true: 使用异步发送和接受, false:另开线程同步发送</param>
 public void Connect(string host, int port, int sendBufferSize, int receiveBufferSize, Action <bool> onConnect, bool useAsyncSocket = false)
 {
     if (this._linker != null)
     {
         return;
     }
     if (useAsyncSocket)
     {
         this._linker = new AsyncLinker(host, port, sendBufferSize, receiveBufferSize, this.ExceptionProcess);
     }
     else
     {
         this._linker = new ThdLinker(host, port, sendBufferSize, receiveBufferSize, this.ExceptionProcess);
     }
     this._onConnect         = onConnect;
     this._linker.OnConnect += OnConnect;
     this._linker.Connect();
 }
示例#16
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        /// <param name="internalTrace">The internal trace.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        protected BaseCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ICompilationScheduler compilationScheduler, IInternalTrace internalTrace, ILinker linker, CompilerOptions compilerOptions)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"Architecture");

            Pipeline = new CompilerPipeline();
            Architecture = architecture;
            TypeSystem = typeSystem;
            TypeLayout = typeLayout;
            InternalTrace = internalTrace;
            CompilerOptions = compilerOptions;
            Counters = new Counters();
            CompilationScheduler = compilationScheduler;
            PlugSystem = new PlugSystem();
            Linker = linker;

            if (Linker == null)
            {
                Linker = compilerOptions.LinkerFactory();
                Linker.Initialize(compilerOptions.OutputFile, architecture.Endianness, architecture.ElfMachineType);
            }
        }
示例#17
0
        private void CreateLink(object control, object context, string controlName, object view)
        {
            if (control == null)
            {
                return;
            }

            IReadOnlyList <LinkRule> linkRules = RuleProvider.GetLinkRulesForType(control.GetType());

            if (linkRules.Count <= 0)
            {
                return;
            }

            ILinker linker = LinkerManager.GetLinkerForType(control.GetType());

            if (linker == null)
            {
                return;
            }

            Link(control, context, linkRules, linker, controlName, view);
        }
示例#18
0
        public GraphNavigationExperiment(string experimentsRoot, string experimentId, int taskCount, QuestionDialogDatasetReader seedDialogs)
            : base(experimentsRoot, experimentId)
        {
            _db = Configuration.Db;
            var phrases = LoadPhrases(seedDialogs, _db);

            _phrases = phrases.ToArray();
            var navigationDataPath = Path.Combine(ExperimentRootPath, "navigation_data.nvd");

            _data = new NavigationData(navigationDataPath);

            _linker = createLinker(_phrases);

            var writer = new CrowdFlowerCodeWriter(ExperimentRootPath, experimentId);

            //generate all tasks
            for (var taskIndex = 0; taskIndex < taskCount; ++taskIndex)
            {
                add(taskIndex, writer);
            }

            writer.Close();
        }
示例#19
0
 public void RemoveLinker(ILinker linker)
 {
     m_Linkers.Remove(linker);
 }
示例#20
0
 public void AddLinker(ILinker linker)
 {
     m_Linkers.Add(linker);
 }
        internal static AnswerExtractionResult evaluateExtractor(QuestionDialogDatasetReader dataset, ILinker linker, Func <QuestionDialog, IEnumerable <EntityInfo> > extractor, int n = 1)
        {
            var totalDialogCount       = 0;
            var correctLinkCount       = 0;
            var correctExtractionCount = 0;

            foreach (var dialog in dataset.Dialogs)
            {
                if (!dialog.HasCorrectAnswer)
                {
                    continue;
                }

                totalDialogCount += 1;

                var linkedQuestion = linker.LinkUtterance(dialog.Question);
                //Console.WriteLine(linkedQuestion);

                var contextEntities = linkedQuestion.Parts.SelectMany(p => p.Entities).ToArray();

                var answerPhrase = getAnswerPhrase(dialog);
                var linkedAnswer = linker.LinkUtterance(answerPhrase, contextEntities);

                var answerPhraseEntities = linkedAnswer == null ? new EntityInfo[0] : linkedAnswer.Entities;
                var utteranceEntities    = linkedAnswer.Parts.SelectMany(p => p.Entities).ToArray();
                var isLinkingCorrect     = utteranceEntities.Select(e => e.Mid).Contains(dialog.AnswerMid);

                if (!isLinkingCorrect)
                {
                    continue;
                }

                ++correctLinkCount;

                var denotations         = extractor(dialog).Take(n).ToArray();
                var isExtractionCorrect = denotations.Any(d => d.Mid == dialog.AnswerMid);

                if (isExtractionCorrect)
                {
                    ++correctExtractionCount;
                }
            }

            return(new AnswerExtractionResult(1.0 * correctExtractionCount / totalDialogCount, 1.0 * correctExtractionCount / correctLinkCount));
        }
示例#22
0
        public HCluster Generate(IEnumerable <T> examples, ILinker linker)
        {
            // Initialize

            Linker = linker;

            var clusters  = new List <HCluster>();
            var distances = new Dictionary <Tuple <int, int>, double>();

            // Load data

            if (Description == null)
            {
                Description = Converter.GetDescription(typeof(T)).BuildDictionaries <T>(examples);
            }

            Matrix X = Converter.Convert <T>(examples, Description.Features);

            // Create a new cluster for each data point

            for (int i = 0; i < X.Rows; i++)
            {
                clusters.Add(new HCluster {
                    Id = i, Points = new Vector[] { X[i, VectorType.Row] }
                });
            }

            // Set the current closest distance/pair to the first pair of clusters
            var key      = new Tuple <int, int>(0, 0);
            var distance = 0.0;

            var clusterId = -1;

            while (clusters.Count > 1)
            {
                var closestClusters  = new Tuple <int, int>(0, 1);
                var smallestDistance = Linker.Distance(clusters[0].Points, clusters[1].Points);

                // Loop through each of the clusters looking for the two closest

                for (int i = 0; i < clusters.Count; i++)
                {
                    for (int j = i + 1; j < clusters.Count; j++)
                    {
                        key = new Tuple <int, int>(clusters[i].Id, clusters[j].Id);

                        // Cache the distance if it hasn't been calculated yet

                        if (!distances.ContainsKey(key))
                        {
                            distances.Add(key, Linker.Distance(clusters[i].Points, clusters[j].Points));
                        }

                        // Update closest clusters and distance if necessary

                        distance = distances[key];

                        if (distance < smallestDistance)
                        {
                            smallestDistance = distance;
                            closestClusters  = new Tuple <int, int>(i, j);
                        }
                    }
                }

                var min = System.Math.Min(closestClusters.Item1, closestClusters.Item2);
                var max = System.Math.Max(closestClusters.Item1, closestClusters.Item2);

                var newCluster = new HCluster(clusterId, clusters[min],
                                              clusters[max]);

                // Remove the merged clusters

                clusters.RemoveAt(min);
                clusters.RemoveAt(max - 1);

                // Add new cluster

                clusters.Add(newCluster);

                clusterId += 1;
            }

            return(clusters.Single());
        }
示例#23
0
 internal LinkBasedExtractor(ILinker linker, FreebaseDbProvider db)
 {
     Db     = db;
     Linker = linker;
 }
示例#24
0
        public void StartSimulator(string platform)
        {
            if (TypeSystem == null)
                return;

            Status = "Compiling...";

            Architecture = GetArchitecture(platform);
            var simAdapter = GetSimAdaptor(platform);
            Linker = new SimLinker(simAdapter);

            compileStartTime = DateTime.Now;

            SimCompiler.Compile(TypeSystem, TypeLayout, InternalTrace, true, Architecture, simAdapter, Linker);
            SimCPU = simAdapter.SimCPU;

            SimCPU.Monitor.BreakAtTick = 1;
            SimCPU.Monitor.BreakOnException = true;
            SimCPU.Monitor.OnStateUpdate = UpdateSimState;
            SimCPU.Reset();

            Display32 = SimCPU.GetState().NativeRegisterSize == 32;

            SimCPU.Monitor.OnExecutionStepCompleted(true);

            Status = "Compiled.";

            symbolView.CreateEntries();
        }
 void ICompilerStage.Setup(BaseCompiler compiler)
 {
     base.Setup(compiler);
     linker = RetrieveLinkerFromCompiler();
 }
示例#26
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        /// <param name="internalTrace">The internal trace.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        protected BaseCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, ICompilationScheduler compilationScheduler, IInternalTrace internalTrace, CompilerOptions compilerOptions)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.pipeline = new CompilerPipeline();
            this.architecture = architecture;
            this.typeSystem = typeSystem;
            this.typeLayout = typeLayout;
            this.internalTrace = internalTrace;
            this.compilerOptions = compilerOptions;
            this.genericTypePatcher = new GenericTypePatcher(typeSystem);
            this.counters = new Counters();
            this.compilationScheduler = compilationScheduler;
            this.linker = compilerOptions.Linker;
            this.plugSystem = new PlugSystem();
        }
示例#27
0
        /// <summary>
        /// Initializes a new instance of <see cref="BaseCodeEmitter" />.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="codeStream">The stream the machine code is written to.</param>
        /// <param name="typeSystem">The type system.</param>
        public void Initialize(string methodName, ILinker linker, Stream codeStream, TypeSystem typeSystem)
        {
            Debug.Assert(codeStream != null);
            Debug.Assert(linker != null);

            this.MethodName = methodName;
            this.linker = linker;
            this.codeStream = codeStream;
            this.codeStreamBasePosition = codeStream.Position;
            this.TypeSystem = typeSystem;
        }
示例#28
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public MermaidResolver(ILinker linker)
 {
     m_linker = linker;
 }
示例#29
0
        /// <summary>Generates a clustering.</summary>
        /// <param name="X">The Matrix to process.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="data">(Optional) the data.</param>
        /// <returns>The clustering.</returns>
        private Cluster GenerateClustering(Matrix X, ILinker linker, object[] data = null)
        {
            // Initialize
            this.Linker = linker;

            var clusters  = new List <Cluster>();
            var distances = new Dictionary <Tuple <int, int>, double>();

            // Create a new cluster for each data point
            for (var i = 0; i < X.Rows; i++)
            {
                clusters.Add(
                    new Cluster
                {
                    Id      = i, Points = new[] { (Vector)X.Row(i) },
                    Members = data != null ? new[] { data[i] } : new object[] { X.Row(i) }
                });
            }

            // Set the current closest distance/pair to the first pair of clusters
            var key      = new Tuple <int, int>(0, 0);
            var distance = 0.0;

            var clusterId = X.Rows;

            while (clusters.Count > 1)
            {
                var closestClusters  = new Tuple <int, int>(0, 1);
                var smallestDistance = this.Linker.Distance(clusters[0].Points, clusters[1].Points);

                // this needs to be parallelized....
                // Loop through each of the clusters looking for the two closest
                for (var i = 0; i < clusters.Count; i++)
                {
                    for (var j = i + 1; j < clusters.Count; j++)
                    {
                        key = new Tuple <int, int>(clusters[i].Id, clusters[j].Id);

                        // Cache the distance if it hasn't been calculated yet
                        if (!distances.ContainsKey(key))
                        {
                            distances.Add(key, this.Linker.Distance(clusters[i].Points, clusters[j].Points));
                        }

                        // Update closest clusters and distance if necessary
                        distance = distances[key];

                        if (distance < smallestDistance)
                        {
                            smallestDistance = distance;
                            closestClusters  = new Tuple <int, int>(i, j);
                        }
                    }
                }

                // order clusters by distance
                var min = Math.Min(closestClusters.Item1, closestClusters.Item2);
                var max = Math.Max(closestClusters.Item1, closestClusters.Item2);

                var newCluster = new Cluster(clusterId, clusters[min], clusters[max]);

                // Remove the merged clusters
                clusters.RemoveAt(min);
                clusters.RemoveAt(max - 1);

                // Add new cluster
                clusters.Add(newCluster);
                clusterId++;
            }

            return(clusters.Single());
        }
示例#30
0
        /// <summary>
        /// Initializes a new instance of <see cref="BaseCodeEmitter"/>.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        /// <param name="codeStream">The stream the machine code is written to.</param>
        void ICodeEmitter.Initialize(BaseMethodCompiler compiler, Stream codeStream)
        {
            Debug.Assert(null != compiler, @"MachineCodeEmitter needs a method compiler.");
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");
            Debug.Assert(null != codeStream, @"MachineCodeEmitter needs a code stream.");
            if (codeStream == null)
                throw new ArgumentNullException(@"codeStream");

            this.compiler = compiler;
            this.codeStream = codeStream;
            this.codeStreamBasePosition = codeStream.Position;
            this.linker = compiler.Linker;
        }
示例#31
0
 public void Process(ILinker linker, object args)
 {
 }
示例#32
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="composer">Injected composer</param>
 /// <param name="linker">Injected linker</param>
 /// <param name="processLogger">Process logger instance</param>
 public PrinterMarkdown(ITypeComposer composer, ILinker linker, IIndefiniteProcess processLogger)
 {
     m_linker        = linker;
     m_processLogger = processLogger;
     m_composer      = composer;
 }
示例#33
0
        /// <summary>Generates a clustering.</summary>
        /// <param name="X">The Matrix to process.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="data">(Optional) the data.</param>
        /// <returns>The clustering.</returns>
        private Cluster GenerateClustering(Matrix X, ILinker linker, object[] data = null)
        {
            // Initialize
            Linker = linker;

            var clusters = new List<Cluster>();
            var distances = new Dictionary<Tuple<int, int>, double>();

            // Create a new cluster for each data point
            for (int i = 0; i < X.Rows; i++)
                clusters.Add(new Cluster
                {
                    Id = i,
                    Points = new Vector[] { (Vector)X.Row(i) },
                    Members = data != null ? new object[] { data[i] } : new object[] { X.Row(i) }
                });

            // Set the current closest distance/pair to the first pair of clusters
            var key = new Tuple<int, int>(0, 0);
            var distance = 0.0;

            var clusterId = X.Rows;

            while (clusters.Count > 1)
            {
                var closestClusters = new Tuple<int, int>(0, 1);
                var smallestDistance = Linker.Distance(clusters[0].Points, clusters[1].Points);

                // this needs to be parallelized....
                // Loop through each of the clusters looking for the two closest
                for (int i = 0; i < clusters.Count; i++)
                {
                    for (int j = i + 1; j < clusters.Count; j++)
                    {
                        key = new Tuple<int, int>(clusters[i].Id, clusters[j].Id);

                        // Cache the distance if it hasn't been calculated yet
                        if (!distances.ContainsKey(key))
                            distances.Add(key, Linker.Distance(clusters[i].Points, clusters[j].Points));

                        // Update closest clusters and distance if necessary
                        distance = distances[key];

                        if (distance < smallestDistance)
                        {
                            smallestDistance = distance;
                            closestClusters = new Tuple<int, int>(i, j);
                        }
                    }
                }

                // order clusters by distance
                var min = System.Math.Min(closestClusters.Item1, closestClusters.Item2);
                var max = System.Math.Max(closestClusters.Item1, closestClusters.Item2);

                var newCluster = new Cluster(clusterId, clusters[min], clusters[max]);

                // Remove the merged clusters
                clusters.RemoveAt(min);
                clusters.RemoveAt(max - 1);

                // Add new cluster
                clusters.Add(newCluster);
                clusterId++;
            }

            return clusters.Single();
        }
示例#34
0
        public HomeController(ILogger <HomeController> logger, ILinker linker)
        {
            _logger = logger;

            _linker = linker;
        }
示例#35
0
 void ExceptionProcess(ILinker linker, NetExceptionType excType, Exception exc)
 {
 }
示例#36
0
 /// <summary>Generates.</summary>
 /// <param name="x">The Matrix to process.</param>
 /// <param name="linker">The linker.</param>
 /// <returns>A Cluster.</returns>
 public Cluster Generate(Matrix x, ILinker linker)
 {
     return(this.GenerateClustering(x, linker));
 }
示例#37
0
        private void Link(object control, object context, IEnumerable <LinkRule> linkRules, ILinker linker, string controlName, object view)
        {
            Type contextType = context?.GetType();

            List <LinkData> linkData = new List <LinkData>();

            foreach (LinkRule rule in linkRules)
            {
                LinkData data = CreateLinkData(controlName, rule, context.GetType(), context, rule.InfoName, null, view);

                if (data != null)
                {
                    linkData.Add(data);
                }
            }

            //if no data found to link then return and don't call / add the linker
            if (linkData.Count == 0)
            {
                return;
            }

            _linkers.Add(linker);
            linker.Link(control, linkData, CreateLink);
        }
示例#38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AotCompiler"/> class.
 /// </summary>
 /// <param name="architecture">The architecture.</param>
 /// <param name="linker">The linker.</param>
 /// <param name="typeSystem">The type system.</param>
 /// <param name="typeLayout">The type layout.</param>
 /// <param name="internalTrace">The internal trace.</param>
 /// <param name="compilerOptions">The compiler options.</param>
 public AotCompiler(IArchitecture architecture, ILinker linker, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions)
     : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, compilerOptions)
 {
 }
示例#39
0
        void ICompilerStage.Setup(BaseCompiler compiler)
        {
            base.Setup(compiler);
            linker = RetrieveLinkerFromCompiler();

            if (compiler.CompilerOptions.Multiboot.VideoDepth.HasValue)
                this.VideoDepth = compiler.CompilerOptions.Multiboot.VideoDepth.Value;
            if (compiler.CompilerOptions.Multiboot.VideoHeight.HasValue)
                this.VideoHeight = compiler.CompilerOptions.Multiboot.VideoHeight.Value;
            if (compiler.CompilerOptions.Multiboot.VideoMode.HasValue)
                this.VideoMode = compiler.CompilerOptions.Multiboot.VideoMode.Value;
            if (compiler.CompilerOptions.Multiboot.VideoWidth.HasValue)
                this.VideoWidth = compiler.CompilerOptions.Multiboot.VideoWidth.Value;
        }
示例#40
0
 /// <summary>Generates.</summary>
 /// <param name="x">The Matrix to process.</param>
 /// <param name="linker">The linker.</param>
 /// <returns>A Cluster.</returns>
 public Cluster Generate(Matrix x, ILinker linker)
 {
     return GenerateClustering(x, linker);
 }
示例#41
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="instructionSet">The instruction set.</param>
        protected BaseMethodCompiler(BaseCompiler compiler, RuntimeMethod method, InstructionSet instructionSet)
        {
            this.compiler = compiler;
            this.method = method;
            this.type = method.DeclaringType;
            this.compilationScheduler = compiler.Scheduler;
            this.moduleTypeSystem = method.Module;
            this.architecture = compiler.Architecture;
            this.typeSystem = compiler.TypeSystem;
            this.typeLayout = Compiler.TypeLayout;
            this.internalTrace = Compiler.InternalTrace;
            this.linker = compiler.Linker;

            this.basicBlocks = new BasicBlocks();

            this.instructionSet = instructionSet ?? new InstructionSet(256);

            this.pipeline = new CompilerPipeline();

            this.stackLayout = new StackLayout(architecture, method.Parameters.Count + (method.Signature.HasThis || method.Signature.HasExplicitThis ? 1 : 0));

            this.virtualRegisterLayout = new VirtualRegisterLayout(architecture, stackLayout);

            EvaluateParameterOperands();

            this.stopMethodCompiler = false;
        }
示例#42
0
 public void Process(ILinker linker, object args)
 {
     throw new NotImplementedException();
 }
示例#43
0
        internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, ILinker linker, IPathResolver pathResolver)
        {
            if (!configHandler.DoesConfigExist(path))
            {
                console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative);
                return;
            }

            IConfig config = configHandler.LoadConfig(path);

            console.WriteLine("\nCreating links based on config...");

            int successes = 0;

            // Allow linkers verbose output if flag is set for this command
            linker.verbose = verbose;

            foreach (ConfigLink configLink in config.LinkList)
            {
                string resolvedSourcePath = pathResolver.GetAbsoluteResolvedPath(configLink.sourcePath, config.Variables);
                string resolvedTargetPath = pathResolver.GetAbsoluteResolvedPath(configLink.targetPath, config.Variables);

                CreateSubDirectories(console, fileSystem, pathResolver, config, resolvedTargetPath);

                if (fileSystem.Directory.Exists(resolvedTargetPath) || fileSystem.File.Exists(resolvedTargetPath))
                {
                    console.Write($"Path '{configLink.targetPath}' already exists", IConsole.ContentType.Negative);

                    if (verbose)
                    {
                        console.Write($" (resolved to '{resolvedTargetPath}')", IConsole.ContentType.Negative);
                    }

                    console.WriteLine();
                }
                else if (linker.CreateLink(resolvedSourcePath, resolvedTargetPath, configLink.linkType))
                {
                    successes++;
                }
            }

            console.WriteLine("\n### Finished! Created {0} / {1} links ###", successes, config.LinkList.Count);
        }