示例#1
0
        public void TestIf()
        {
            // There is no such thing as a logical literal
            const double trueDouble  = 42;
            const double falseDouble = 666;

            var input    = Declare <MValue>("input");
            var output   = Declare <double>("output");
            var function = CompileFunction <Func <MValue, double> >(
                input, output,
                new If(input,
                       new Literal(output, trueDouble),
                       new Literal(output, falseDouble)));

            Assert.AreEqual(trueDouble, function(MFullArray <double> .CreateScalar(1)));
            Assert.AreEqual(falseDouble, function(MFullArray <double> .CreateScalar(0)));
            Assert.AreEqual(falseDouble, function(MFullArray <double> .CreateRowVector(0, 0, 1, 0)));
            Assert.AreEqual(trueDouble, function(MFullArray <double> .CreateRowVector(1, 1, 1, 1)));
        }
示例#2
0
        public void TestCopyAssignmentWithMFullArray()
        {
            // function result = copy(x)
            //   result = x;

            var input    = Declare <MFullArray <double> >("input");
            var output   = Declare <MFullArray <double> >("output");
            var function = CompileFunction <Func <MFullArray <double>, MFullArray <double> > >(
                input, output,
                new Copy(output, input));

            var argument = MFullArray <double> .CreateScalar(42);

            var result = function(argument);

            Assert.AreEqual(argument.Shape, result.Shape);
            Assert.AreEqual(argument[0], result[0]);
            Assert.AreNotSame(argument, result);
        }
示例#3
0
        public void TestArrayStore()
        {
            // function output = arraystore(array, index, value)
            //   array(index) = value;
            //   output = array;
            // end

            var arrayInput = Declare <MFullArray <double> >("array");
            var indexInput = Declare <MFullArray <double> >("index");
            var valueInput = Declare <MFullArray <double> >("value");
            var output     = Declare <MFullArray <double> >("output");
            var function   = CompileFunction <Func <MFullArray <double>, MFullArray <double>, MFullArray <double>, MFullArray <double> > >(
                new[] { arrayInput, indexInput, valueInput }, output,
                new StoreParenthesized(arrayInput, (IndexArgument)indexInput, valueInput),
                new Copy(output, arrayInput));

            var array = MFullArray <double> .CreateScalar(42);

            var result = function(array, 1, 666);

            Assert.IsTrue(result.IsScalar);
            Assert.AreEqual(42.0, array[0]);
            Assert.AreEqual(666.0, result[0]);
        }