Esempio n. 1
0
        public void VerifyOperation_TypeCast(ILanguageType targetType)
        {
            //Cast an integer to a scalar
            if (targetType.IsScalar() && Operand1Type.IsInteger())
            {
                ForceAtomicOperands(targetType);
            }

            //Cast a number to a multivector
            else if (targetType.IsFrameMultivector() && Operand1Type.IsNumber())
            {
                ForceAtomicOperands(targetType);
            }

            //Cast multivector to a multivector with the same frame dimension (by diectly copying coeffecients)
            //useful for example when transforming a computation to Euclidean space with the same dimensions
            else if (targetType.IsFrameMultivector() && Operand1Type.IsFrameMultivector() && targetType.GetFrame().VSpaceDimension == Operand1Type.GetFrame().VSpaceDimension)
            {
                ForceAtomicOperands(targetType);
            }

            else
            {
                Context.CreateTypeMismatch("Cannot apply type cast " + targetType.TypeSignature + " to expression of type " + Operand1TypeSignature);
            }
        }
Esempio n. 2
0
        private ValuePrimitive <MathematicaScalar> GetRandomValue(ILanguageType valueType)
        {
            Expr valueExpr;

            if (valueType.IsInteger())
            {
                valueExpr = new Expr(_randomSource.Next(1, 10));
            }

            else if (valueType.IsBoolean())
            {
                valueExpr = new Expr(_randomSource.Next(0, 1) != 0);
            }

            else if (valueType.IsScalar())
            {
                valueExpr = new Expr(_randomSource.NextDouble() * 10.0 - 5.0);
            }
            //value_expr = new Expr(new Expr(ExpressionType.Symbol, "Rational"), _RandomSource.Next(1, 10), _RandomSource.Next(1, 10));

            else
            {
                throw new InvalidOperationException();
            }

            return
                (ValuePrimitive <MathematicaScalar> .Create(
                     (TypePrimitive)valueType,
                     MathematicaScalar.Create(SymbolicUtils.Cas, valueExpr)
                     ));
        }
Esempio n. 3
0
        private void VerifyOperation_PolyadicOperandAssignment(ILanguageType lhsType)
        {
            if (lhsType.IsSameType(Operand1Type))
            {
                ForceAtomicOperands(null);
            }

            else if (lhsType.IsScalar() && Operand1Type.IsNumber())
            {
                ForceAtomicScalarOperands(null);
            }

            else if (lhsType.IsFrameMultivector() && Operand1Type.IsNumber())
            {
                ForceAtomicMultivectorOperands(null);
            }

            else
            {
                Context.CreateTypeMismatch("Cannot assign expression of type " + Operand1TypeSignature + " to parameter of type " + lhsType);
            }
        }