Exemplo n.º 1
0
        public void ShareArgumentVariablesBetweenFunctionsInOneValueStore()
        {
            IVariable xVariable  = new Variable <double>("x");
            IVariable tVariable  = new Variable <double>("t");
            IVariable f1Variable = new Variable <double>("f1");
            IVariable f2Variable = new Variable <double>("f2");
            IVariable f3Variable = new Variable <double>("f2");

            IFunction f1 = new Function();

            f1.Arguments.Add(xVariable);
            f1.Arguments.Add(tVariable);
            f1.Components.Add(f1Variable);
            f1.Components.Add(f2Variable);

            IFunction f2 = new Function();

            IFunctionStore store = f1.Store;

            store.Functions.Add(f2); // add it to the same store where f1 is stored

            f2.Arguments.Add(xVariable);
            f2.Arguments.Add(tVariable);
            f2.Components.Add(f3Variable);
            // Assert the store is the same for every thing
            Assert.AreSame(f1.Store, f2.Store);
            Assert.AreSame(f1.Store, xVariable.Store);
            Assert.AreSame(f1.Store, tVariable.Store);
            Assert.AreSame(f1.Store, f1Variable.Store);
            Assert.AreSame(f1.Store, f2Variable.Store);
            Assert.AreSame(f1.Store, f3Variable.Store);
        }
Exemplo n.º 2
0
        public void GetIndependentValuesUsingMultipleFilters()
        {
            Variable <int> x = new Variable <int>();

            x.SetValues(new[] { 1, 2, 3, 4, 5 });

            IFunctionStore store = x.Store;

            IMultiDimensionalArray <int> filteredValues;

            filteredValues = store.GetVariableValues <int>(
                x,
                new VariableValueFilter <int>(x, new[] { 1, 2, 3 })
                );

            Assert.AreEqual(3, filteredValues.Count);
            Assert.AreEqual(1, filteredValues[0]);

            //same filters different ordering
            filteredValues = store.GetVariableValues <int>(
                x,
                new VariableValueFilter <int>(x, new[] { 3, 2, 1 })
                );

            Assert.AreEqual(3, filteredValues.Count);
            Assert.AreEqual(1, filteredValues[0]);
        }
Exemplo n.º 3
0
        //TODO: get this near functiontest. This is not a general function.
        public static IFunction CreateSimpleFunction(IFunctionStore store)
        {
            var function = new Function("test");

            store.Functions.Add(function);

            // initialize schema
            IVariable x  = new Variable <double>("x", 3);
            IVariable y  = new Variable <double>("y", 2);
            IVariable f1 = new Variable <double>("f1");

            function.Arguments.Add(x);
            function.Arguments.Add(y);
            function.Components.Add(f1);


            // write some data
            var xValues = new double[] { 0, 1, 2 };
            var yValues = new double[] { 0, 1 };
            var fValues = new double[] { 100, 101, 102, 103, 104, 105 };

            function.SetValues(fValues,
                               new VariableValueFilter <double>(x, xValues),
                               new VariableValueFilter <double>(y, yValues),
                               new ComponentFilter(f1));
            return(function);
        }
Exemplo n.º 4
0
        //TODO: get this near functiontest. This is not a general function.
        public static IFunction CreateSimpleFunction(IFunctionStore store)
        {
            var function = new Function("test");

            store.Functions.Add(function);

            // initialize schema
            IVariable x = new Variable<double>("x", 3);
            IVariable y = new Variable<double>("y", 2);
            IVariable f1 = new Variable<double>("f1");

            function.Arguments.Add(x);
            function.Arguments.Add(y);
            function.Components.Add(f1);


            // write some data
            var xValues = new double[] {0, 1, 2};
            var yValues = new double[] {0, 1};
            var fValues = new double[] {100, 101, 102, 103, 104, 105};

            function.SetValues(fValues,
                               new VariableValueFilter<double>(x, xValues),
                               new VariableValueFilter<double>(y, yValues),
                               new ComponentFilter(f1));
            return function;
        }
        /// <summary>
        /// Copy constructor, creates memory function store with cloned functions from original store.
        /// Does not copy values!!
        /// </summary>
        /// <param name="sourceStore"></param>
        public MemoryFunctionStore(IFunctionStore sourceStore) : this()
        {
            foreach (var function in sourceStore.Functions)
            {
                var clone = (IFunction)function.Clone(false, true, true);
                Functions.Add(clone);
            }

            ReconnectClonedComponentsAndArguments(Functions, sourceStore.Functions);
            UpdateDependentVariables();
        }
Exemplo n.º 6
0
        public static IFunction CopyToStore(this IFunction function, IFunctionStore store)
        {
            if (function.Parent == null)
            {
                var clone = (IFunction)function.Clone();

                FixFixedSize(clone);

                store.Functions.Add(clone);
                return(clone);
            }

            var variables      = function.Arguments.Concat(function.Components).ToList();
            var variableValues = new List <IMultiDimensionalArray>();

            //copy values of all variables into temp array (write them as soon as first Flush() or first SetValues() occurs).
            foreach (var variable in variables)
            {
                variableValues.Add(variable.Values);
            }

            IFunction topParent = function.Parent;

            while (topParent.Parent != null)
            {
                topParent = topParent.Parent;
            }
            var detachedFunction = (IFunction)topParent.Clone(false); //can only clone unfiltered function

            var detachedVariables = detachedFunction.Arguments.Concat(detachedFunction.Components).ToList();

            for (int i = 0; i < variableValues.Count; i++)
            {
                var values = variableValues[i];
                detachedVariables[i].FixedSize = values.Count;
            }

            store.Functions.Add(detachedFunction);

            // copy temp values back to netCdf
            for (int i = 0; i < variableValues.Count; i++)
            {
                var values = variableValues[i];
                if (values.Count > 0)
                {
                    var detachedVariable = detachedVariables[i];
                    detachedVariable.SetValues(values);
                }
            }

            return(detachedFunction);
        }
Exemplo n.º 7
0
        public void SimpleDependendVariable()
        {
            //create a single variable dependency.
            IVariable <double> x = new Variable <double>("x");
            IVariable <double> y = new Variable <double>("y");

            y.Arguments.Add(x);

            IFunctionStore store = y.Store;

            store.SetVariableValues(x, new[] { 0.0, 0.1, 0.2 });

            Assert.AreEqual(3, store.GetVariableValues(y).Count);
        }
Exemplo n.º 8
0
        public void DependentOn2Variables()
        {
            IVariable <double> x1 = new Variable <double>("x1");
            IVariable <double> x2 = new Variable <double>("x2");
            IVariable <double> y  = new Variable <double>("y");

            y.Arguments.Add(x1);
            y.Arguments.Add(x2);

            IFunctionStore store = y.Store;

            store.SetVariableValues(x1, new[] { 0.0, 0.1, 0.2 });
            store.SetVariableValues(x2, new[] { 0.0, 0.1 });

            Assert.AreEqual(6, store.GetVariableValues(y).Count);
        }
        /// <summary>
        /// Copy constructor, creates memory function store with cloned functions from original store.
        /// Does not copy values!!
        /// </summary>
        /// <param name="sourceStore"></param>
        public MemoryFunctionStore(IFunctionStore sourceStore) : this()
        {
            foreach (var function in sourceStore.Functions)
            {
                var clone = (IFunction)function.Clone(false, true, true);
                Functions.Add(clone);
            }

            ReconnectClonedComponentsAndArguments(Functions, sourceStore.Functions);
            UpdateDependentVariables();

            // reset cache
            foreach (var variable in Functions.OfType <IVariable>())
            {
                variable.CachedValues = null;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates an instance of a new Function which uses memory-based values store by default.
        /// </summary>
        public Function(string name)
        {
            this.name = name;

            Filters    = new EventedList <IVariableFilter>();
            Components = new EventedList <IVariable>();
            Arguments  = new EventedList <IVariable>();


            // create default store for this function
            store = new MemoryFunctionStore();
            store.Functions.Add(this);
            Store = store;

            UseDefaultValueIfNoValuesDefined = true;
            IsEditable = true;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates an instance of a new Function which uses memory-based values store by default.
        /// </summary>
        public Function(string name)
        {
            this.name = name;

            Attributes = new Dictionary <string, string>();
            Filters    = new EventedList <IVariableFilter>();
            Components = new EventedList <IVariable>();
            Arguments  = new EventedList <IVariable>();

            // create default store for this function
            store = new MemoryFunctionStore();
            store.Functions.Add(this);
            Store = store;

            useDefaultValueIfNoValuesDefined = true;
            IsEditable = true;

            _propertyChangeImplementation = (NotifyPropertyChangeImplementation)propertyChangedImplementationField.GetValue(this);
        }
Exemplo n.º 12
0
        public void GetVariableValueFiltersShouldDealWithNonValueComparableValues()
        {
            IVariable <TestNode> x = new Variable <TestNode>("x");
            IVariable <double>   y = new Variable <double>("y");

            var amount = 2;

            y.Arguments.Add(x);

            var node1 = new TestNode {
                Name = "1"
            };
            var node2 = new TestNode {
                Name = "2"
            };
            var node3 = new TestNode {
                Name = "3"
            };
            var node4 = new TestNode {
                Name = "4"
            };

            y[node1] = 2.0;
            y[node2] = 5.0;
            y[node3] = 8.0;
            y[node4] = 10.0;

            IFunctionStore store = y.Store;

            IList <TestNode> valuesToSelect = new List <TestNode>();

            valuesToSelect.Add(node1);
            valuesToSelect.Add(node2);
            valuesToSelect.Add(node3);
            valuesToSelect.Add(node4);

            IMultiDimensionalArray array = store.GetVariableValues(x, new VariableValueFilter <TestNode>(x, valuesToSelect));

            array[0].Should("1").Be.EqualTo(node1);
            array[1].Should("2").Be.EqualTo(node2);
            array[2].Should("3").Be.EqualTo(node3);
            array[3].Should("4").Be.EqualTo(node4);
        }
Exemplo n.º 13
0
        public void GetVariableValueFilterIndexesShouldBeFast()
        {
            IVariable <double> x = new Variable <double>("x");
            IVariable <double> y = new Variable <double>("y");

            var amount = 5000;

            IList <double> allValues = new List <double>(amount);

            for (int i = 0; i < amount; i++)
            {
                allValues.Add(i);
            }

            x.AddValues(allValues);

            y.Arguments.Add(x);

            IFunctionStore store = y.Store;

            IList <double> valuesToSelect = new List <double>();

            valuesToSelect.Add(allValues[0]);
            valuesToSelect.Add(allValues[50]);
            valuesToSelect.Add(allValues[amount - 1]);

            IMultiDimensionalArray array = null;

            TestHelper.AssertIsFasterThan(130,
                                          () =>
            {
                for (int i = 0; i < 5000; i++)
                {
                    array = store.GetVariableValues(x, new VariableValueFilter <double>(x, valuesToSelect));
                }
            });
            //orig: 600ms
            //now: 15ms

            Assert.AreEqual(3, array.Count);
        }
Exemplo n.º 14
0
 /// <summary>
 ///     Creates an instance of the <see cref="SpecializeController" />.
 /// </summary>
 /// <param name="logger">A logger instance for the <see cref="SpecializeController" />.</param>
 /// <param name="store">The function store service. See <see cref="IFunctionStore" />.</param>
 public SpecializeController(ILogger <SpecializeController> logger, IFunctionStore store)
 {
     this.logger = logger;
     this.store  = store;
 }
Exemplo n.º 15
0
 public virtual object Clone(IFunctionStore targetStore)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 /// <summary>
 ///     Creates an instance of this <see cref="FunctionController" />.
 /// </summary>
 /// <param name="logger">A logger for the <see cref="FunctionController" />.</param>
 /// <param name="funcLogger">A logger for the function invoked by the <see cref="FunctionController" />.</param>
 /// <param name="store">The function storage service (see <see cref="IFunctionStore" />).</param>
 /// <remarks>
 ///     The second logger exists to permit ready differentiation of function-internal errors and other messages from those
 ///     originating with the host environment.
 /// </remarks>
 public FunctionController(ILogger <FunctionController> logger, ILogger <IFissionFunction> funcLogger, IFunctionStore store)
 {
     this.logger     = logger;
     this.funcLogger = funcLogger;
     this.store      = store;
 }
Exemplo n.º 17
0
 public HomeController(IFunctionStore <Function, FunctionInputDto> functionStore,
                       IModuleStore <Module, ModuleInputDto, int> moduleStore)
 {
     _functionStore = functionStore;
     _moduleStore   = moduleStore;
 }