Example #1
0
        public static Type DTypeToType(DType type)
        {
            Type temp = null;
            if (!fundamentalTypes.TryGetValue(type, out temp))
                temp = null;

            return temp;
        }
Example #2
0
 static DigitsArray()
 {
     unchecked
     {
         AllBits = (DType)~((DType)0);
         HiBitSet = (DType)(((DType)1) << (DataSizeBits) - 1);
     }
 }
Example #3
0
		internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
		{
			access = info.Access;

			type = analyzer.ResolveTypeName(typeName, analyzer.CurrentType, analyzer.CurrentRoutine, position, false);

			analyzer.AnalyzeConstructedType(type);

			return new Evaluation(this);
		}
Example #4
0
		internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
		{
			access = info.Access;

            this.typeRef.Analyze(analyzer);
            this.type = this.typeRef.ResolvedTypeOrUnknown;

			analyzer.AnalyzeConstructedType(type);

			return new Evaluation(this);
		}
Example #5
0
		//helper method, should not be used generally
		public object ReadValue (DType dtype)
		{
			switch (dtype)
			{
				case DType.Byte:
					return ReadByte ();

				case DType.Boolean:
					return ReadBoolean ();

				case DType.Int16:
					return ReadInt16 ();

				case DType.UInt16:
					return ReadUInt16 ();

				case DType.Int32:
					return ReadInt32 ();

				case DType.UInt32:
					return ReadUInt32 ();

				case DType.Int64:
					return ReadInt64 ();

				case DType.UInt64:
					return ReadUInt64 ();

#if !DISABLE_SINGLE
				case DType.Single:
					return ReadSingle ();
#endif

				case DType.Double:
					return ReadDouble ();

				case DType.String:
					return ReadString ();

				case DType.ObjectPath:
					return ReadObjectPath ();

				case DType.Signature:
					return ReadSignature ();

				case DType.Variant:
					return ReadVariant ();

				default:
					throw new Exception ("Unhandled D-Bus type: " + dtype);
			}
		}
Example #6
0
        public DVar[] Fields = new DVar[12]; //This is explicityly left unprotected to reduce access overhead

        public DType SetType(DType type)
        {
            if (!DType.IsParentOf(type))
                throw new Exception(string.Format("Type {0} is not a parent of tyoe {1} and so cannot be extended", DType, type));
            DType = type;
            var maxFieldIndex = DType.FieldIndex;
            if (maxFieldIndex >= Fields.Length)
            {
                var newFields = new DVar[Fields.Length + 10];
                Array.Copy(Fields, newFields, Fields.Length);
                Fields = newFields;
            }
            return type;
        }
        public PropertyInvokeDialog(Window parent, Bus bus, string busName, ObjectPath path, IElement element)
            : base(element.Name, parent, DialogFlags.DestroyWithParent | DialogFlags.Modal)
        {
            this.Build ();
            this.parent = parent;
            this.setAlign.HideAll ();
            this.WidthRequest = 250;
            this.HeightRequest = 150;
            this.propertyName.Text = element.Name;
            this.propertyType = Mapper.DTypeFromString (element.Data.ReturnType);

            try {
                this.caller = new PropertyCaller (bus, busName, path, element.Parent.Name, element.Name, element.Data);
            } catch (Exception e) {
                Logging.Error ("Error while creating the invocation proxy", e, parent);
                buttonExecute.Sensitive = false;
            }
        }
Example #8
0
 public static int GetAlignment(DType dtype)
 {
     switch (dtype) {
         case DType.Byte:
             return 1;
         case DType.Boolean:
             return 4;
         case DType.Int16:
         case DType.UInt16:
             return 2;
         case DType.Int32:
         case DType.UInt32:
             return 4;
         case DType.Int64:
         case DType.UInt64:
             return 8;
     #if !DISABLE_SINGLE
         case DType.Single: //Not yet supported!
             return 4;
     #endif
         case DType.Double:
             return 8;
         case DType.String:
             return 4;
         case DType.ObjectPath:
             return 4;
         case DType.Signature:
             return 1;
         case DType.Array:
             return 4;
         case DType.Struct:
         case DType.StructBegin:
             return 8;
         case DType.Variant:
             return 1;
         case DType.DictEntry:
         case DType.DictEntryBegin:
             return 8;
         case DType.Invalid:
         default:
             throw new Exception ("Cannot determine alignment of " + dtype);
     }
 }
		public static int GetAlignment (DType dtype)
		{
			switch (dtype) {
				case DType.Byte:
					return 1;
				case DType.Boolean:
					return 4;
				case DType.Int16:
				case DType.UInt16:
					return 2;
				case DType.Int32:
				case DType.UInt32:
					return 4;
				case DType.Int64:
				case DType.UInt64:
					return 8;
#if !DISABLE_SINGLE
				case DType.Single: //Not yet supported!
					return 4;
#endif
				case DType.Double:
					return 8;
				case DType.String:
					return 4;
				case DType.ObjectPath:
					return 4;
				case DType.Signature:
					return 1;
				case DType.Array:
					return 4;
				case DType.StructBegin:
					return 8;
				case DType.Variant:
					return 1;
				case DType.DictEntryBegin:
					return 8;
				case DType.UnixFileDescriptor:
					return 4;//note that this refers to the length of the INDEX to the FD, not the FD itself
				case DType.Invalid:
				default:
					throw new Exception ("Cannot determine alignment of " + dtype);
			}
		}
Example #10
0
        internal Signature(DType[] value)
        {
            if (value == null)
                throw new ArgumentNullException ("value");

            if (value.Length == 0) {
                this.data = Empty.data;
                return;
            }

            if (value.Length == 1) {
                this.data = DataForDType (value[0]);
                return;
            }

            this.data = new byte[value.Length];

            for (int i = 0 ; i != value.Length ; i++)
                this.data[i] = (byte)value[i];
        }
Example #11
0
 public static object Convert(DType type, string value)
 {
     switch (type) {
     case DType.Boolean:
         return bool.Parse (value);
     case DType.Byte:
         return byte.Parse (value);
     case DType.Int16:
         return short.Parse (value);
     case DType.Int32:
         return int.Parse (value);
     case DType.Int64:
         return long.Parse (value);
     case DType.UInt32:
         return uint.Parse (value);
     case DType.UInt64:
         return ulong.Parse (value);
     case DType.UInt16:
         return ushort.Parse (value);
     default:
         return value;
     }
 }
Example #12
0
 public XArray LogNormal(Shape shape, double mean, double std_dev, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomLogNormal(shape, mean, std_dev, dtype));
 }
Example #13
0
 public XArray FisherF(Shape shape, double m, double n, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomFisherF(shape, m, n, dtype));
 }
Example #14
0
 internal Signature(DType value)
 {
     this.data = DataForDType(value);
 }
Example #15
0
 public XArray Weibull(Shape shape, double a, double b, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomWeibull(shape, a, b, dtype));
 }
Example #16
0
		public void EmitDirectTypeOf(DType/*!*/ dtype)
		{
			Debug.Assert(dtype != null);
			
			il.Emit(OpCodes.Ldtoken, dtype.RealType);
			il.Emit(OpCodes.Call, Methods.GetTypeFromHandle);
			il.Emit(OpCodes.Call, Methods.ClrObject_WrapRealObject);
		}
Example #17
0
		public DMemberRef(DMember/*!*/ member, DType/*!*/ type)
		{
			Debug.Assert(member != null && type != null);

			this.member = member;
			this.type = type;
		}
Example #18
0
        public static XArray RandomChoice(Shape shape, int n, XArray weight, bool replace = true, DType dtype = DType.Float32)
        {
            XArray r = new XArray(shape, dtype);

            NativeWrapper.TS_Random_ChoiceWithWeight(r.GetRef(), n, weight.GetRef(), replace);
            return(r);
        }
Example #19
0
        internal static int ShiftRight(DType[] buffer, int shiftCount)
        {
            int shiftAmount = DigitsArray.DataSizeBits;
            int invShift = 0;
            int bufLen = buffer.Length;

            while (bufLen > 1 && buffer[bufLen - 1] == 0)
            {
                bufLen--;
            }

            for (int count = shiftCount; count > 0; count -= shiftAmount)
            {
                if (count < shiftAmount)
                {
                    shiftAmount = count;
                    invShift = DigitsArray.DataSizeBits - shiftAmount;
                }

                ulong carry = 0;
                for (int i = bufLen - 1; i >= 0; i--)
                {
                    ulong val = ((ulong)buffer[i]) >> shiftAmount;
                    val |= carry;

                    carry = ((ulong)buffer[i]) << invShift;
                    buffer[i] = (DType)(val);
                }
            }

            while (bufLen > 1 && buffer[bufLen - 1] == 0)
            {
                bufLen--;
            }

            return bufLen;
        }
Example #20
0
		/// <summary>
		/// Used by the compiler for unresolved properties.
		/// </summary>
		public UnknownProperty(DType/*!*/ declaringType, string/*!*/ name)
			: base(name)
		{
			Debug.Assert(declaringType != null && name != null);

			this.declaringType = declaringType;
		}
Example #21
0
        public static XArray RandomLogNormal(Shape shape, double mean, double std_dev, DType dtype = DType.Float32)
        {
            XArray r = new XArray(shape, dtype);

            NativeWrapper.TS_Random_LogNormal(r.GetRef(), mean, std_dev);
            return(r);
        }
Example #22
0
		internal override DMemberRef GetImplementationInSuperTypes(DType/*!*/ type, bool searchSupertypes, ref bool inSupertype)
		{
			while (type != null && !type.IsUnknown)
			{
				KnownProperty result = type.GetDeclaredProperty<KnownProperty>(this.Name);
				if (result != null)
				{
					// private members are not visible from subtype:
					if (result.IsPrivate && inSupertype) break;

					return new DMemberRef(result, type);
				}

				if (!searchSupertypes) break;
				inSupertype = true;
				type = type.Base;
			}

			inSupertype = false;
			return null;
		}
Example #23
0
		internal override void ReportAbstractNotImplemented(ErrorSink/*!*/ errors, DType/*!*/ declaringType, PhpType/*!*/ referringType)
		{
			errors.Add(Errors.AbstractPropertyNotImplemented, referringType.Declaration.SourceUnit,
				referringType.Declaration.Position, referringType.FullName, declaringType.MakeFullGenericName(), this.FullName);

			ReportError(errors, Errors.RelatedLocation);
		}
Example #24
0
        public override bool CheckInvocation(TexlNode[] args, DType[] argTypes, IErrorContainer errors, out DType returnType, out Dictionary <TexlNode, DType> nodeToCoercedTypeMap)
        {
            Contracts.AssertValue(args);
            Contracts.AssertAllValues(args);
            Contracts.AssertValue(argTypes);
            Contracts.Assert(args.Length == argTypes.Length);
            Contracts.AssertValue(errors);
            Contracts.Assert(MinArity <= args.Length && args.Length <= MaxArity);

            nodeToCoercedTypeMap = new Dictionary <TexlNode, DType>();
            int count = args.Length;

            // Check the args.
            bool fArgsValid = true;

            for (int i = 0; i < count; i++)
            {
                fArgsValid &= CheckType(args[i], argTypes[i], DType.Boolean, errors, out var matchedWithCoercion);
                if (matchedWithCoercion)
                {
                    CollectionUtils.Add(ref nodeToCoercedTypeMap, args[i], DType.Boolean);
                }
            }

            returnType = ReturnType;

            return(fArgsValid);
        }
Example #25
0
 public XArray Choice(Shape shape, int n, bool replace = true, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomChoice(shape, n, replace, dtype));
 }
Example #26
0
 /// <summary>
 /// Randoms the bernoulli.
 /// </summary>
 /// <param name="seedSource">The seed source.</param>
 /// <param name="p">The p.</param>
 /// <param name="allocator">The allocator.</param>
 /// <param name="type">The type.</param>
 /// <param name="sizes">The sizes.</param>
 /// <returns>TVar.</returns>
 public static Variable RandomBernoulli(SeedSource seedSource, ScalarVar p, IAllocator allocator, DType type, params long[] sizes)
 {
     return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomBernoulli(res, seedSource, p.Evaluate()))));
 }
Example #27
0
		internal Signature (DType[] value)
		{
			this.data = new byte[value.Length];

			/*
			MemoryStream ms = new MemoryStream (this.data);

			foreach (DType t in value)
				ms.WriteByte ((byte)t);
			*/

			for (int i = 0 ; i != value.Length ; i++)
				this.data[i] = (byte)value[i];
		}
Example #28
0
 /// <summary>
 /// Ases the type.
 /// </summary>
 /// <param name="elementType">Type of the element.</param>
 /// <returns>TVar.</returns>
 public Variable AsType(DType elementType)
 {
     return(new Variable(new AsTypeExpression(this.Expression, elementType)));
 }
Example #29
0
 internal DigitsArray(DType[] copyFrom)
 {
     Allocate(copyFrom.Length);
     CopyFrom(copyFrom, 0, 0, copyFrom.Length);
     ResetDataUsed();
 }
Example #30
0
 /// <summary>
 /// Fills the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="allocator">The allocator.</param>
 /// <param name="type">The type.</param>
 /// <param name="sizes">The sizes.</param>
 /// <returns>TVar.</returns>
 public static Variable Fill(ScalarVar value, IAllocator allocator, DType type, params long[] sizes)
 {
     return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.Fill(res, value.Evaluate()))));
 }
Example #31
0
		internal virtual DMemberRef GetImplementationInSuperTypes(DType/*!*/ type, bool searchSupertypes, ref bool inSupertype)
		{
			Debug.Fail("N/A");
			throw null;
		}
Example #32
0
 /// <summary>
 /// Randoms the uniform.
 /// </summary>
 /// <param name="seedSource">The seed source.</param>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <param name="allocator">The allocator.</param>
 /// <param name="type">The type.</param>
 /// <param name="sizes">The sizes.</param>
 /// <returns>TVar.</returns>
 public static Variable RandomUniform(SeedSource seedSource, ScalarVar min, ScalarVar max, IAllocator allocator, DType type, params long[] sizes)
 {
     return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomUniform(res, seedSource, min.Evaluate(), max.Evaluate()))));
 }
		public override int GetAttributeUsageCount(DType/*!*/ type, AST.CustomAttribute.TargetSelectors selector)
		{
			return attributes.Count(type, selector);
		}
Example #34
0
 /// <summary>
 /// Randoms the normal.
 /// </summary>
 /// <param name="seedSource">The seed source.</param>
 /// <param name="mean">The mean.</param>
 /// <param name="stdv">The STDV.</param>
 /// <param name="allocator">The allocator.</param>
 /// <param name="type">The type.</param>
 /// <param name="sizes">The sizes.</param>
 /// <returns>TVar.</returns>
 public static Variable RandomNormal(SeedSource seedSource, ScalarVar mean, ScalarVar stdv, IAllocator allocator, DType type, params long[] sizes)
 {
     return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomNormal(res, seedSource, mean.Evaluate(), stdv.Evaluate()))));
 }
Example #35
0
 public XArray Gamma(Shape shape, double alpha, double beta, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomGamma(shape, alpha, beta, dtype));
 }
Example #36
0
 /// <summary>
 /// Randoms the exponential.
 /// </summary>
 /// <param name="seedSource">The seed source.</param>
 /// <param name="lambda">The lambda.</param>
 /// <param name="allocator">The allocator.</param>
 /// <param name="type">The type.</param>
 /// <param name="sizes">The sizes.</param>
 /// <returns>TVar.</returns>
 public static Variable RandomExponential(SeedSource seedSource, ScalarVar lambda, IAllocator allocator, DType type, params long[] sizes)
 {
     return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomExponential(res, seedSource, lambda.Evaluate()))));
 }
Example #37
0
 public XArray ExtremeValue(Shape shape, double a, double b, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomExtremeValue(shape, a, b, dtype));
 }
Example #38
0
 /// <summary>
 /// Randoms the cauchy.
 /// </summary>
 /// <param name="seedSource">The seed source.</param>
 /// <param name="median">The median.</param>
 /// <param name="sigma">The sigma.</param>
 /// <param name="allocator">The allocator.</param>
 /// <param name="type">The type.</param>
 /// <param name="sizes">The sizes.</param>
 /// <returns>TVar.</returns>
 public static Variable RandomCauchy(SeedSource seedSource, ScalarVar median, ScalarVar sigma, IAllocator allocator, DType type, params long[] sizes)
 {
     return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomCauchy(res, seedSource, median.Evaluate(), sigma.Evaluate()))));
 }
Example #39
0
 public XArray Cauchy(Shape shape, double a, double b, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomCauchy(shape, a, b, dtype));
 }
Example #40
0
 public XArray Shuffle(Shape shape, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomShuffle(shape, dtype));
 }
Example #41
0
 public XArray StudentT(Shape shape, double n, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomStudentT(shape, n, dtype));
 }
Example #42
0
 public XArray Permutation(Shape shape, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomPermutation(shape, dtype));
 }
Example #43
0
		internal override void ResolveName(Analyzer/*!*/ analyzer)
		{
            this.typeRef.Analyze(analyzer);
            this.type = this.typeRef.ResolvedTypeOrUnknown;

            // analyze constructed type (we are in the full analysis):
			analyzer.AnalyzeConstructedType(type);

			constant = analyzer.ResolveClassConstantName(type, name, position, analyzer.CurrentType, analyzer.CurrentRoutine,
				  out runtimeVisibilityCheck);
		}
Example #44
0
 public XArray Rand(Shape shape, DType dtype = DType.Float32)
 {
     return(Uniform(shape, 0, 1, dtype));
 }
Example #45
0
		//this will become obsolete soon
		internal Signature (DType value)
		{
			this.data = new byte[] {(byte)value};
		}
Example #46
0
 internal void CopyFrom(DType[] source, int sourceOffset, int offset, int length)
 {
     Array.Copy(source, sourceOffset, m_data, 0, length);
 }
Example #47
0
        internal static int ShiftLeft(DType[] buffer, int shiftCount)
        {
            int shiftAmount = DigitsArray.DataSizeBits;
            int bufLen = buffer.Length;

            while (bufLen > 1 && buffer[bufLen - 1] == 0)
            {
                bufLen--;
            }

            for (int count = shiftCount; count > 0; count -= shiftAmount)
            {
                if (count < shiftAmount)
                {
                    shiftAmount = count;
                }

                ulong carry = 0;
                for (int i = 0; i < bufLen; i++)
                {
                    ulong val = ((ulong)buffer[i]) << shiftAmount;
                    val |= carry;

                    buffer[i] = (DType)(val & DigitsArray.AllBits);
                    carry = (val >> DigitsArray.DataSizeBits);
                }

                if (carry != 0)
                {
                    if (bufLen + 1 <= buffer.Length)
                    {
                        buffer[bufLen] = (DType)carry;
                        bufLen++;
                        carry = 0;
                    }
                    else
                    {
                        throw new OverflowException();
                    }
                }
            }
            return bufLen;
        }
Example #48
0
		private static void MultiDivide(BigInteger leftSide, BigInteger rightSide, out BigInteger quotient, out BigInteger remainder)
		{
			if (rightSide.IsZero)
			{
				throw new DivideByZeroException();
			}

			DType val = rightSide.m_digits[rightSide.m_digits.DataUsed - 1];
			int d = 0;
			for (uint mask = DigitsArray.HiBitSet; mask != 0 && (val & mask) == 0; mask >>= 1)
			{
				d++;
			}

			int remainderLen = leftSide.m_digits.DataUsed + 1;
			DType[] remainderDat = new DType[remainderLen];
			leftSide.m_digits.CopyTo(remainderDat, 0, leftSide.m_digits.DataUsed);

			DigitsArray.ShiftLeft(remainderDat, d);
			rightSide = rightSide << d;

			ulong firstDivisor = rightSide.m_digits[rightSide.m_digits.DataUsed - 1];
			ulong secondDivisor = (rightSide.m_digits.DataUsed < 2 ? (DType)0 : rightSide.m_digits[rightSide.m_digits.DataUsed - 2]);

			int divisorLen = rightSide.m_digits.DataUsed + 1;
			DigitsArray dividendPart = new DigitsArray(divisorLen, divisorLen);
			DType[] result = new DType[leftSide.m_digits.Count + 1];
			int resultPos = 0;

			ulong carryBit = (ulong)0x1 << DigitsArray.DataSizeBits; // 0x100000000
			for (int j = remainderLen - rightSide.m_digits.DataUsed, pos = remainderLen - 1; j > 0; j--, pos--)
			{
				ulong dividend = ((ulong)remainderDat[pos] << DigitsArray.DataSizeBits) + (ulong)remainderDat[pos - 1];
				ulong qHat = (dividend / firstDivisor);
				ulong rHat = (dividend % firstDivisor);

				while (pos >= 2)
				{
					if (qHat == carryBit || (qHat * secondDivisor) > ((rHat << DigitsArray.DataSizeBits) + remainderDat[pos - 2]))
					{
						qHat--;
						rHat += firstDivisor;
						if (rHat < carryBit)
						{
							continue;
						}
					}
					break;
				}

				for (int h = 0; h < divisorLen; h++)
				{
					dividendPart[divisorLen - h - 1] = remainderDat[pos - h];
				}

				BigInteger dTemp = new BigInteger(dividendPart);
				BigInteger rTemp = rightSide * (long)qHat;
				while (rTemp > dTemp)
				{
					qHat--;
					rTemp -= rightSide;
				}

				rTemp = dTemp - rTemp;
				for (int h = 0; h < divisorLen; h++)
				{
					remainderDat[pos - h] = rTemp.m_digits[rightSide.m_digits.DataUsed - h];
				}

				result[resultPos++] = (DType)qHat;
			}

			Array.Reverse(result, 0, resultPos);
			quotient = new BigInteger(new DigitsArray(result));

			int n = DigitsArray.ShiftRight(remainderDat, d);
			DigitsArray rDA = new DigitsArray(n, n);
			rDA.CopyFrom(remainderDat, 0, 0, rDA.DataUsed);
			remainder = new BigInteger(rDA);
		}
Example #49
0
 public XArray RandInt(Shape shape, double low = 0, double high = 1, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomRandInt(shape, low, high, dtype));
 }
Example #50
0
        public Type ToType(ref int pos)
        {
            // TODO: Find a way to avoid these null checks everywhere.
            if (data == null)
            {
                return(typeof(void));
            }

            DType dtype = (DType)data[pos++];

            switch (dtype)
            {
            case DType.Invalid:
                return(typeof(void));

            case DType.Byte:
                return(typeof(byte));

            case DType.Boolean:
                return(typeof(bool));

            case DType.Int16:
                return(typeof(short));

            case DType.UInt16:
                return(typeof(ushort));

            case DType.Int32:
                return(typeof(int));

            case DType.UInt32:
                return(typeof(uint));

            case DType.Int64:
                return(typeof(long));

            case DType.UInt64:
                return(typeof(ulong));

            case DType.Single:             ////not supported by libdbus at time of writing
                return(typeof(float));

            case DType.Double:
                return(typeof(double));

            case DType.String:
                return(typeof(string));

            case DType.ObjectPath:
                return(typeof(ObjectPath));

            case DType.Signature:
                return(typeof(Signature));

            case DType.Array:
                //peek to see if this is in fact a dictionary
                if ((DType)data[pos] == DType.DictEntryBegin)
                {
                    //skip over the {
                    pos++;
                    Type keyType   = ToType(ref pos);
                    Type valueType = ToType(ref pos);
                    //skip over the }
                    pos++;
                    return(typeof(Dictionary <,>).MakeGenericType(new [] { keyType, valueType }));
                }
                else
                {
                    return(ToType(ref pos).MakeArrayType());
                }

            case DType.StructBegin:
                List <Type> innerTypes = new List <Type> ();
                while (((DType)data[pos]) != DType.StructEnd)
                {
                    innerTypes.Add(ToType(ref pos));
                }
                // go over the struct end
                pos++;
                return(DBusStruct.FromInnerTypes(innerTypes.ToArray()));

            case DType.DictEntryBegin:
                return(typeof(System.Collections.Generic.KeyValuePair <,>));

            case DType.Variant:
                return(typeof(object));

            default:
                throw new NotSupportedException("Parsing or converting this signature is not yet supported (signature was '" + this + "'), at DType." + dtype);
            }
        }
Example #51
0
 internal void CopyTo(DType[] array, int offset, int length)
 {
     Array.Copy(m_data, 0, array, offset, length);
 }
Example #52
0
 public XArray Geometric(Shape shape, double prob, DType dtype = DType.Int32)
 {
     return(NativeHelper.RandomGeometric(shape, prob, dtype));
 }
Example #53
0
		private static void SingleDivide(BigInteger leftSide, BigInteger rightSide, out BigInteger quotient, out BigInteger remainder)
		{
			if (rightSide.IsZero)
			{
				throw new DivideByZeroException();
			}

			DigitsArray remainderDigits = new DigitsArray(leftSide.m_digits);
			remainderDigits.ResetDataUsed();

			int pos = remainderDigits.DataUsed - 1;
			ulong divisor = (ulong)rightSide.m_digits[0];
			ulong dividend = (ulong)remainderDigits[pos];

			DType[] result = new DType[leftSide.m_digits.Count];
			leftSide.m_digits.CopyTo(result, 0, result.Length);
			int resultPos = 0;

			if (dividend >= divisor)
			{
				result[resultPos++] = (DType)(dividend / divisor);
				remainderDigits[pos] = (DType)(dividend % divisor);
			}
			pos--;

			while (pos >= 0)
			{
				dividend = ((ulong)(remainderDigits[pos + 1]) << DigitsArray.DataSizeBits) + (ulong)remainderDigits[pos];
				result[resultPos++] = (DType)(dividend / divisor);
				remainderDigits[pos + 1] = 0;
				remainderDigits[pos--] = (DType)(dividend % divisor);
			}
			remainder = new BigInteger(remainderDigits);

			DigitsArray quotientDigits = new DigitsArray(resultPos + 1, resultPos);
			int j = 0;
			for (int i = quotientDigits.DataUsed - 1; i >= 0; i--, j++)
			{
				quotientDigits[j] = result[i];
			}
			quotient = new BigInteger(quotientDigits);
		}
Example #54
0
 public XArray NegativeBinomial(Shape shape, int k, double prob, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomNegativeBinomial(shape, k, prob, dtype));
 }
Example #55
0
 internal virtual void ReportMethodNotCompatible(ErrorSink/*!*/ errors, DType/*!*/ declaringType, PhpType/*!*/ referringType)
 {
     // to be implemented by methods and properties
     Debug.Fail();
     throw null;
 }
Example #56
0
 public XArray Poisson(Shape shape, double rate, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomPoisson(shape, rate, dtype));
 }
Example #57
0
		internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
		{
			base.Analyze(analyzer, info);
            this.typeRef.Analyze(analyzer);
            this.type = this.typeRef.ResolvedTypeOrUnknown;

			// analyze constructed type (new constructed type cane be used here):
			analyzer.AnalyzeConstructedType(type);

			if (type.TypeDesc.Equals(DTypeDesc.InterlockedTypeDesc))
				analyzer.ErrorSink.Add(Warnings.ClassBehaviorMayBeUnexpected, analyzer.SourceUnit, position, type.FullName);

			return new Evaluation(this);
		}
Example #58
0
 public XArray Exponential(Shape shape, double rate, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomExponential(shape, rate, dtype));
 }
Example #59
0
 public XArray Binomial(Shape shape, int trials, double prob, DType dtype = DType.Float32)
 {
     return(NativeHelper.RandomBinomial(shape, trials, prob, dtype));
 }
Example #60
0
        public static Signature GetSig(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            //this is inelegant, but works for now
            if (type == typeof(Signature))
            {
                return(Signature.SignatureSig);
            }

            if (type == typeof(ObjectPath))
            {
                return(Signature.ObjectPathSig);
            }

            if (type == typeof(void))
            {
                return(Signature.Empty);
            }

            if (type == typeof(string))
            {
                return(Signature.StringSig);
            }

            if (type == typeof(object))
            {
                return(Signature.VariantSig);
            }

            if (type.IsArray)
            {
                return(MakeArray(GetSig(type.GetElementType())));
            }

            if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(IDictionary <,>) || type.GetGenericTypeDefinition() == typeof(Dictionary <,>)))
            {
                Type[] genArgs = type.GetGenericArguments();
                return(Signature.MakeDict(GetSig(genArgs[0]), GetSig(genArgs[1])));
            }

            if (Mapper.IsPublic(type))
            {
                return(Signature.ObjectPathSig);
            }

            if (!type.IsPrimitive && !type.IsEnum)
            {
                Signature sig = Signature.Empty;

                foreach (FieldInfo fi in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    sig += GetSig(fi.FieldType);
                }

                return(Signature.MakeStruct(sig));
            }

            DType dtype = Signature.TypeToDType(type);

            return(new Signature(dtype));
        }